全パッケージ クラス階層 このパッケージ 前項目 次項目 インデックス
java.lang.Object
   |
   +----java.text.Format
           |
           +----java.text.NumberFormat
                   |
                   +----java.text.ChoiceFormat
ChoiceFormatでは、ある範囲の数値にフォーマットを関係付けることができます。これは通常、複数のものを扱うときに MessageFormatで使用します。この選択項目は doubleの昇順リストで指定され、それぞれの項目は、次の項目までの一方が開いた間隔を指定します。
 一致するものがないと、数値(X)が小さ過ぎるか大き過ぎるかによって、最初か最後のインデックスが使用されます。X matches j if and only if limit[j] <= X < limit[j+1]
 Note:
 ChoiceFormatは、他の Formatクラスとは次の点で異なります。すなわち、ChoiceFormatオブジェクトは、getInstance スタイルファクトリメソッドではなく、構築子で作成するということです。ChoiceFormatでは、与えたれたロケールに対して複雑なセットアップは必要ありませんので、ファクトリメソッドは不要です。実際、ChoiceFormatには、ロケール固有の動作は実装されません。
 
ChoiceFormatを作成する場合には、フォーマットの配列とリミットの配列を指定する必要があります。これらの配列の長さは同じでなければなりません。たとえば、次はその例です。
 
nextDouble can be used to get the next higher double, to
     make the half-open interval.)
 次に、フォーマットと解析を行う簡単な例を示します。
 
 double[] limits = {1,2,3,4,5,6,7};
 String[] monthNames = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"};
 ChoiceFormat form = new ChoiceFormat(limits, monthNames);
 ParsePosition status = new ParsePosition(0);
 for (double i = 0.0; i <= 8.0; ++i) {
     status.setIndex(0);
     System.out.println(i + " -> " + form.format(i) + " -> "
                              + form.parse(form.format(i),status));
 }
 
 次に、パターンフォーマットを使うもっと複雑な例を示します。
 
 
 double[] filelimits = {0,1,2};
 String[] filepart = {"are no files","is one file","are {2} files"};
 ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);
 Format[] testFormats = {fileform, null, NumberFormat.getInstance()};
 MessageFormat pattform = new MessageFormat("There {0} on {1}");
 pattform.setFormats(testFormats);
 Object[] testArgs = {null, "ADisk", null};
 for (int i = 0; i < 4; ++i) {
     testArgs[0] = new Integer(i);
     testArgs[2] = testArgs[0];
     System.out.println(pattform.format(testArgs));
 }
 
 
 
 ChoiceFormat(double[], String[])
	ChoiceFormat(double[], String[])
   ChoiceFormat(String)
	ChoiceFormat(String)
   
 applyPattern(String)
	applyPattern(String)
   clone()
	clone()
   equals(Object)
	equals(Object)
   format(double, StringBuffer, FieldPosition)
	format(double, StringBuffer, FieldPosition)
   format(long, StringBuffer, FieldPosition)
	format(long, StringBuffer, FieldPosition)
   getFormats()
	getFormats()
   getLimits()
	getLimits()
   hashCode()
	hashCode()
   nextDouble(double)
	nextDouble(double)
   nextDouble(double, boolean)
	nextDouble(double, boolean)
   parse(String, ParsePosition)
	parse(String, ParsePosition)
   previousDouble(double)
	previousDouble(double)
   setChoices(double[], String[])
	setChoices(double[], String[])
   toPattern()
	toPattern()
   
 ChoiceFormat
ChoiceFormat
public ChoiceFormat(String newPattern)
 ChoiceFormat
ChoiceFormat
  public ChoiceFormat(double limits[],
                      String formats[])
 
 applyPattern
applyPattern
public void applyPattern(String newPattern)
 toPattern
toPattern
public String toPattern()
 setChoices
setChoices
  public void setChoices(double limits[],
                         String formats[])
 getLimits
getLimits
public double[] getLimits()
 getFormats
getFormats
public Object[] getFormats()
 format
format
  public StringBuffer format(long number,
                             StringBuffer toAppendTo,
                             FieldPosition status)
format(double, StringBuffer, FieldPosition)を呼び出します。したがって、サポートされる longの範囲は、doubleで格納できる範囲に限られます。これが実際的な制限となることはありません。
 format
format
  public StringBuffer format(double number,
                             StringBuffer toAppendTo,
                             FieldPosition status)
 parse
parse
  public Number parse(String text,
                      ParsePosition status)
 nextDouble
nextDouble
public static final double nextDouble(double d)
一方が開いた間隔を作るのに使用します。
 previousDouble
previousDouble
public static final double previousDouble(double d)
 clone
clone
public Object clone()
 hashCode
hashCode
public int hashCode()
 equals
equals
public boolean equals(Object obj)
 nextDouble
nextDouble
  public static double nextDouble(double d,
                                  boolean positive)
全パッケージ クラス階層 このパッケージ 前項目 次項目 インデックス