Java 8 ChoiceFormat - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ChoiceFormat class.

This code example shows how to use the following methods:format
 
	/** 
	 * @tests java.text.ChoiceFormat#format(long) 
	 */ 
	public void test_formatL() { 
		ChoiceFormat fmt = new ChoiceFormat(
				"-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE"); 
 
		assertEquals("NEGATIVE_ONE", fmt.format(Long.MIN_VALUE));
		assertEquals("NEGATIVE_ONE", fmt.format(-1));
		assertEquals("ZERO", fmt.format(0));
		assertEquals("ONE", fmt.format(1));
		assertEquals("GREATER_THAN_ONE", fmt.format(Long.MAX_VALUE));
	} 
	 
	/** 
	 * @tests java.text.ChoiceFormat#format(double) 
	 */ 
	public void test_formatD() { 
		ChoiceFormat fmt = new ChoiceFormat(
6
CodeRank
This code example shows how to use the following methods:
    { 
      throw new NullPointerException();
    } 
    this.pattern = pattern;
    this.locale = locale;
    this.choiceFormat = new ChoiceFormat(pattern);
  } 
 
  /** 
   * Returns the current locale of the formatter. 
   * 
   * @return the current locale, never null. 
   */ 
  public Locale getLocale()
  { 
    return locale;
  } 
 
  /** 
   * Returns the currently active pattern. 
5
CodeRank
This code example shows how to use the following methods:format
		NumberFormat anotherCurrency = NumberFormat.getNumberInstance();
		anotherCurrency.setCurrency(Currency.getInstance("RUB"));
 
		System.out.println(anotherCurrency.format(1000000000000.123));
 
		Format format = new ChoiceFormat(new double[]{0, 1, 2}, new String[]{"zero", "one", "two"});
 
		System.out.println(format.format(0));
		System.out.println(format.format(1));
		System.out.println(format.format(2));
		System.out.println(format.format(3));
 
		Scanner scanner = new Scanner(System.in);
		System.out.println("Please enter your name");
		String name = scanner.next("[a-z][A-Z]+");
		System.out.println("Hello " + name);
 
 
	} 
} 
5
CodeRank
This code example shows how to use the following methods:
        MessageFormat fmt = new MessageFormat("");
        fmt.setLocale(Locale.getDefault());
        double[] limits = {1, 2};
        String[] keys = {RESOURCE_BUNDLE.getString("compile.errors.one"), 
                RESOURCE_BUNDLE.getString("compile.errors.several")};
        ChoiceFormat choice = new ChoiceFormat(limits, keys);
        fmt.applyPattern(RESOURCE_BUNDLE.getString("compile.errors.pattern"));
        Format[] formats = {choice, NumberFormat.getInstance()};
        fmt.setFormats(formats);
        return fmt.format(new Object[]{numErrors});
    } 
     
    static String msgSystemError() {
        return msg("error.system")  
                + msg("error.report.url") 
                + msg("error.report.list") 
                + msg("error.report.description") 
                + msg("error.report.thanks"); 
    } 
     
5
CodeRank
This code example shows how to use the following methods:
                .getTimeInstance()));
        assertTrue("Wrong date format", formats[1].equals(DateFormat
                .getDateInstance()));
        assertTrue("Wrong number format", formats[2].equals(NumberFormat
                .getInstance()));
        assertTrue("Wrong choice format", formats[3].equals(new ChoiceFormat(
                "0.0#low|1.0#high"))); 
		assertNull("Wrong string format", formats[4]);
 
        Date date = new Date();
        FieldPosition pos = new FieldPosition(-1);
        StringBuffer buffer = new StringBuffer();
        format.format(new Object[] { "123", new Double(1.6), new Double(7.2),
                date, date }, buffer, pos);
        String result = buffer.toString();
        buffer.setLength(0);
        buffer.append("abc ");
        buffer.append(DateFormat.getTimeInstance().format(date));
        buffer.append(" def ");
        buffer.append(DateFormat.getDateInstance().format(date));
4
CodeRank
This code example shows how to use the following methods:clone
  public FastChoiceFormat clone() 
  { 
    try 
    { 
      final FastChoiceFormat format = (FastChoiceFormat) super.clone();
      format.choiceFormat = (ChoiceFormat) choiceFormat.clone();
      return format;
    } 
    catch (CloneNotSupportedException e)
    { 
      throw new IllegalStateException();
    } 
  } 
} 
4
CodeRank
This code example shows how to use the following methods:
 * @Author: Denis Tulskiy 
 * @Date: Feb 12, 2010 
 */ 
public class PlaylistColumn implements Comparable<PlaylistColumn> {
    private static MessageFormat format = new MessageFormat("\"{0}\" \"{1}\" {2,number,integer} {3}");
    private static ChoiceFormat choice = new ChoiceFormat(new double[]{0, 2, 4}, new String[]{"CENTER", "LEFT", "RIGHT"});
 
    static { 
        format.setFormatByArgumentIndex(3, choice);
    } 
 
    private String name;
    private String expression;
    private int size = 150;
    private int allign = 2; //LEFT by default
 
    //position in the model, used for sorting purposes only 
    private int position;
 
    private Expression expr;
4
CodeRank
This code example shows how to use the following methods:
    private static final String[] MINUTES_PART = {"", "1 minute ", "{0,number,###############} minutes "};
 
    private static final String[] SECONDS_PART = {"0 seconds", "1 second", "{1,number} seconds"};
 
    private static final ChoiceFormat MINUTES_FORMAT =
            new ChoiceFormat(LIMITS, MINUTES_PART);
 
    private static final ChoiceFormat SECONDS_FORMAT =
            new ChoiceFormat(LIMITS, SECONDS_PART);
 
    static { 
        MINUTE_SECONDS.setFormat(0, MINUTES_FORMAT);
        MINUTE_SECONDS.setFormat(1, SECONDS_FORMAT);
    } 
 
    /** private constructor */ 
    private DateUtils() { 
    } 
 
 
4
CodeRank
This code example shows how to use the following methods:
    private static final String[] MINUTES_PART = {"", "1 minute ", "{0,number,###############} minutes "};
 
    private static final String[] SECONDS_PART = {"0 seconds", "1 second", "{1,number} seconds"};
 
    private static final ChoiceFormat MINUTES_FORMAT =
            new ChoiceFormat(LIMITS, MINUTES_PART);
 
    private static final ChoiceFormat SECONDS_FORMAT =
            new ChoiceFormat(LIMITS, SECONDS_PART);
 
    static { 
        MINUTE_SECONDS.setFormat(0, MINUTES_FORMAT);
        MINUTE_SECONDS.setFormat(1, SECONDS_FORMAT);
    } 
 
    /** private constructor */ 
    private DateUtils() { 
    } 
 
 
3
CodeRank
This code example shows how to use the following methods:
		} else if (delta < 12 * MONTH) {
			MessageFormat form = new MessageFormat("{0}");
			Object[] formArgs = new Object[] { delta / MONTH };
			double[] tweetLimits = { 1, 2 };
			String[] tweetPart = { "one month ago", "{0} months ago" };
			ChoiceFormat tweetForm = new ChoiceFormat(tweetLimits, tweetPart);
			form.setFormatByArgumentIndex(0, tweetForm);
			value = form.format(formArgs);
		} 
		return value;
	} 
} 
4
CodeRank
See Code Examples for Java 8 ChoiceFormat Methods: