|
JavaTM Platform Standard Ed. 6 |
|||||||||
전의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
개요 : 상자 | 필드 | 생성자 | 메소드 | 상세: 필드 | 생성자 | 메소드 |
java.lang.Objectjava.text.Format
java.text.NumberFormat
java.text.ChoiceFormat
public class ChoiceFormat
ChoiceFormat
를 사용하면(자), 어느 범위의 수치에 포맷을 추가할 수가 있습니다. 이것은 일반적으로, 복수를 처리할 경우에 MessageFormat
로 사용됩니다. 이 선택 항목은 double 의 승순 리스트로 지정되어 각각의 항목은, 다음의 항목까지의 한편이 열린 간격을 지정합니다.
일치하는 것이 없는 경우, 수치 (X)가 너무 작은지 너무 큰지에 의해, 최초 또는 마지막 인덱스가 사용됩니다. 리밋트 배열이 승순이 아닌 경우, 포맷의 결과는 올바르게 안 되는 ChoiceFormat 는 또,X matches j if and only if limit[j] <= X < limit[j+1]
\u221E
를 infinity(INF)와 동등한 것으로 해 받아들입니다.
주: ChoiceFormat
는, 다른 Format
클래스와는 다음의 점으로써 다릅니다. ChoiceFormat
객체는,getInstance
스타일 팩토리 메소드는 아니고, 생성자 으로 작성합니다. ChoiceFormat
에서는, 지정된 로케일에 대해서 복잡한 셋업은 필요없기 때문에, 팩토리 메소드는 불필요합니다. 실제,ChoiceFormat
에는, 로케일 고유의 동작은 구현되지 않습니다.
ChoiceFormat
를 작성하는 경우에는, 포맷의 배열과 리밋트의 배열을 지정할 필요가 있습니다. 이러한 배열의 길이는 같지 않으면 안됩니다. 다음에 예를 나타냅니다.
nextDouble
는, 다음에 큰 double 를 취득해, 한편이 열린 간격을 만드는데 사용한다)
다음에, 포맷과 해석을 실시하는 간단한 예를 나타냅니다.
다음에, 패턴 포맷을 사용하고 말이야들에게 복잡한 예를 나타냅니다.double[] limits = {1,2,3,4,5,6,7}; String[] dayOfWeekNames = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}; ChoiceFormat form = new ChoiceFormat(limits, dayOfWeekNames); 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 객체의 패턴 지정은 매우 간단합니다. 다음에 예를 나타냅니다.
출력 결과는 다음과 같이 됩니다.ChoiceFormat fmt = new ChoiceFormat( "-1#is negative| 0#is zero or fraction | 1#is one |1. 0<is 1+ |2#is two |2<is more than 2. "); System.out.println("Formatter Pattern :" + fmt.toPattern()); System.out.println("Format with -INF :" + fmt.format(Double.NEGATIVE_INFINITY)); System.out.println("Format with -1. 0 : " + fmt.format(-1. 0)); System.out.println("Format with 0 : " + fmt.format(0)); System.out.println("Format with 0.9 : " + fmt.format(0.9)); System.out.println("Format with 1.0 : " + fmt.format(1)); System.out.println("Format with 1.5 : " + fmt.format(1.5)); System.out.println("Format with 2 : " + fmt.format(2)); System.out.println("Format with 2.1 : " + fmt.format(2.1)); System.out.println("Format with NaN : " + fmt.format(Double.NaN)); System.out.println("Format with +INF :" + fmt.format(Double.POSITIVE_INFINITY));
Format with -INF : is negative Format with -1. 0 : is negative Format with 0 : is zero or fraction Format with 0.9 : is zero or fraction Format with 1.0 : is one Format with 1.5 : is 1+ Format with 2 : is two Format with 2.1 :is more than 2. Format with NaN : is negative Format with +INF :is more than 2.
choice 포맷은 동기화 되지 않습니다. thread 마다 다른 포맷 인스턴스를 작성하는 것을 추천합니다. 복수의 thread가 포맷에 동시에 액세스 하는 경우는, 외부적으로 동기화할 필요가 있습니다.
DecimalFormat
,
MessageFormat
,
직렬화 된 형식 상자의 클래스의 개요 |
---|
클래스 java.text. NumberFormat 로부터 상속된 상자의 클래스/인터페이스 |
---|
NumberFormat.Field |
필드의 개요 |
---|
클래스 java.text. NumberFormat 로부터 상속된 필드 |
---|
FRACTION_FIELD , INTEGER_FIELD |
생성자 의 개요 | |
---|---|
ChoiceFormat (double[] limits,
String [] formats)
지정된 리밋트와 거기에 대응하는 포맷에 의해 객체를 구축합니다. |
|
ChoiceFormat (String newPattern)
지정된 패턴에 근거하는 리밋트와 거기에 대응하는 포맷에 의해 객체를 구축합니다. |
메소드의 개요 | |
---|---|
void |
applyPattern (String newPattern)
패턴을 설정합니다. |
Object |
clone ()
Cloneable 를 오버라이드(override) 합니다. |
boolean |
equals (Object obj)
2 개가 동일한지 어떤지를 비교합니다. |
StringBuffer |
format (double number,
StringBuffer toAppendTo,
FieldPosition status)
포맷 된 double 로 패턴을 돌려줍니다. |
StringBuffer |
format (long number,
StringBuffer toAppendTo,
FieldPosition status)
포맷의 특수화입니다. |
Object [] |
getFormats ()
생성자 중(안)에서 건네받는 포맷을 가져옵니다. |
double[] |
getLimits ()
생성자 중(안)에서 건네받는 리밋트를 가져옵니다. |
int |
hashCode ()
메세지 포맷 객체의 해시 코드를 생성합니다. |
static double |
nextDouble (double d)
d 보다 큰 최소의 double 를 찾아냅니다. |
static double |
nextDouble (double d,
boolean positive)
d (if positive == true)보다 큰 최소의 double, 또는 d (if positive == false)보다 작은 최대의 double 를 찾아냅니다. |
Number |
parse (String text,
ParsePosition status)
입력 텍스트로부터 Number 를 해석합니다. |
static double |
previousDouble (double d)
d 보다 작은 최대의 double 를 찾아냅니다. |
void |
setChoices (double[] limits,
String [] formats)
포맷 시에 사용하는 선택 항목을 설정합니다. |
String |
toPattern ()
패턴을 가져옵니다. |
클래스 java.text. Format 로부터 상속된 메소드 |
---|
format , formatToCharacterIterator , parseObject |
클래스 java.lang. Object 로부터 상속된 메소드 |
---|
finalize , getClass , notify , notifyAll , toString , wait , wait , wait |
생성자 의 상세 |
---|
public ChoiceFormat(String newPattern)
applyPattern(java.lang.String)
public ChoiceFormat(double[] limits, String [] formats)
setChoices(double[], java.lang.String[])
메소드의 상세 |
---|
public void applyPattern(String newPattern)
newPattern
- 클래스의 설명을 참조public String toPattern()
public void setChoices(double[] limits, String [] formats)
limits
- 그 포맷으로 해석하는 1 번 큰 값.
이것은 승순이 아니면 안된다. X 를 포맷 하는 경우,
limit[i] <= X < limit[i+1] 이면,
선택 항목은 i 가 된다.
리밋트 배열이 승순이 아닌 경우, 포맷의 결과는
올바르게 안 되는formats
- 각각의 리밋트에 대해서 사용하는 포맷.
이것은, Format 객체나 캐릭터 라인이다.
객체 Y 로 포맷 하는 경우,
객체가 NumberFormat 이면,
((NumberFormat) Y). format(X)가 불려 간다. 그렇지 않으면, Y.toString()가 불려 간다public double[] getLimits()
public Object [] getFormats()
public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition status)
format(double, StringBuffer, FieldPosition)
를 호출합니다. 따라서, 지원되는 long 의 범위는, double 로 포함할 수 있는 범위에 한정됩니다. 이것이 실제의 제한이 될 것은 없습니다.
NumberFormat
내의 format
Format.format(java.lang.Object)
public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition status)
NumberFormat
내의 format
number
- 포맷 및 치환되는 수치toAppendTo
- 텍스트가 추가되는 위치status
- 사용할 수 있는 상태가 돌려주어지지 않은 것은 무시하는Format.format(java.lang.Object)
public Number parse(String text, ParsePosition status)
NumberFormat
내의 parse
text
- 소스 텍스트status
- 입출력 파라미터. 입력시에는,
status.index 필드는 해석되는 소스 텍스트의
최초의 문자를 나타낸다. 출구에서 에러가 발생하지 않았던 경우는,
status.index 는 소스 텍스트내의
해석되어 있지 않은 최초의 문자로 설정된다. 출구에서 에러가 발생했을 경우는,
status.index 는 변경되지 않고,
status.errorIndex 는 해석이 실패한 원인이 된 문자의 최초의 인덱스로 설정된다
NumberFormat.isParseIntegerOnly()
,
Format.parseObject(java.lang.String, java.text.ParsePosition)
public static final double nextDouble(double d)
한편이 열린 간격을 만드는데 사용합니다.
previousDouble(double)
public static final double previousDouble(double d)
nextDouble(double)
public Object clone()
NumberFormat
내의 clone
Cloneable
public int hashCode()
NumberFormat
내의 hashCode
Object.equals(java.lang.Object)
,
Hashtable
public boolean equals(Object obj)
NumberFormat
내의 equals
obj
- 비교 대상의 참조 객체
true
, 그렇지 않은 경우는 false
Object.hashCode()
,
Hashtable
public static double nextDouble(double d, boolean positive)
|
JavaTM Platform Standard Ed. 6 |
|||||||||
전의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
개요 : 상자 | 필드 | 생성자 | 메소드 | 상세: 필드 | 생성자 | 메소드 |
Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.