|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
ÀÌÀü Ŭ·¡½º ´ÙÀ½ Ŭ·¡½º | ÇÁ·¹ÀÓÀ¸·Î ÇÁ·¹ÀÓ ¾øÀÌ | |||||||||
°³¿ä: »óÀÚ | Çʵå | constructor | ¸Þ¼µå | »ó¼¼: Çʵå | »ý¼ºÀÚ | ¸Þ¼µå |
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[] 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 °´Ã¼ÀÇ ÆÐÅÏ ÁöÁ¤Àº ¸Å¿ì °£´ÜÇÕ´Ï´Ù. ´ÙÀ½¿¡ ¿¹¸¦ ³ªÅ¸³À´Ï´Ù.
Ãâ·Â °á°ú´Â ´ÙÀ½°ú °°ÀÌ µË´Ï´Ù.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
,
Á÷·ÄÈ µÈ Çü½Ä Áßø(Nested) Ŭ·¡½º °³¿ä |
---|
Ŭ·¡½º java.text. NumberFormat ·ÎºÎÅÍ »ó¼ÓµÈ Áßø(Nested) Ŭ·¡½º/ÀÎÅÍÆäÀ̽º |
---|
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 °´Ã¼³ª ij¸¯ÅÍ ¶óÀÎÀÌ´Ù. °´Ã¼ 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 2 Platform Standard Ed. 5.0 |
|||||||||
ÀÌÀü Ŭ·¡½º ´ÙÀ½ Ŭ·¡½º | ÇÁ·¹ÀÓÀ¸·Î ÇÁ·¹ÀÓ ¾øÀÌ | |||||||||
°³¿ä: »óÀÚ | Çʵå | constructor | ¸Þ¼µå | »ó¼¼: Çʵå | »ý¼ºÀÚ | ¸Þ¼µå |
Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy µµ ÂüÁ¶ÇϽʽÿÀ.