Java Code Examples for java.text.DateFormat#getInstance()

The following examples show how to use java.text.DateFormat#getInstance() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
protected DateFormat createFormatInstance ( final long timeRange )
{
    if ( hasFormat () )
    {
        try
        {
            return new SimpleDateFormat ( this.format );
        }
        catch ( final IllegalArgumentException e )
        {
            return DateFormat.getInstance ();
        }
    }
    else
    {
        return Helper.makeFormat ( timeRange );
    }
}
 
Example 2
Source Project: j2objc   File: DateFormatTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @tests java.text.DateFormat#clone()
 */
public void test_clone() {
	DateFormat format = DateFormat.getInstance();
	DateFormat clone = (DateFormat) format.clone();
	assertTrue("Clone not equal", format.equals(clone));
	clone.getNumberFormat().setMinimumFractionDigits(123);
	assertTrue("Clone shares NumberFormat", !format.equals(clone));
}
 
Example 3
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    IntervalCategoryToolTipGenerator g1
            = new IntervalCategoryToolTipGenerator("{3} - {4}",
            DateFormat.getInstance());
    IntervalCategoryToolTipGenerator g2 = (IntervalCategoryToolTipGenerator)
            TestUtilities.serialised(g1);
    assertEquals(g1, g2);
}
 
Example 4
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    IntervalCategoryToolTipGenerator g1
            = new IntervalCategoryToolTipGenerator("{3} - {4}",
            DateFormat.getInstance());
    IntervalCategoryToolTipGenerator g2 = (IntervalCategoryToolTipGenerator)
            TestUtilities.serialised(g1);
    assertEquals(g1, g2);
}
 
Example 5
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    IntervalCategoryItemLabelGenerator g1
            = new IntervalCategoryItemLabelGenerator("{3} - {4}",
            DateFormat.getInstance());
    IntervalCategoryItemLabelGenerator g2 = (IntervalCategoryItemLabelGenerator) TestUtilities.serialised(g1);
    assertEquals(g1, g2);
}
 
Example 6
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    IntervalCategoryItemLabelGenerator g1
            = new IntervalCategoryItemLabelGenerator("{3} - {4}",
            DateFormat.getInstance());
    IntervalCategoryItemLabelGenerator g2 = (IntervalCategoryItemLabelGenerator) TestUtilities.serialised(g1);
    assertEquals(g1, g2);
}
 
Example 7
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    StandardCategoryItemLabelGenerator g1
            = new StandardCategoryItemLabelGenerator("{2}",
            DateFormat.getInstance());
    StandardCategoryItemLabelGenerator g2 = (StandardCategoryItemLabelGenerator) 
            TestUtilities.serialised(g1);
    assertEquals(g1, g2);
}
 
Example 8
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    IntervalCategoryItemLabelGenerator g1
            = new IntervalCategoryItemLabelGenerator("{3} - {4}",
            DateFormat.getInstance());
    IntervalCategoryItemLabelGenerator g2 = (IntervalCategoryItemLabelGenerator) TestUtilities.serialised(g1);
    assertEquals(g1, g2);
}
 
Example 9
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    StandardCategoryToolTipGenerator g1
            = new StandardCategoryToolTipGenerator("{2}",
            DateFormat.getInstance());
    StandardCategoryToolTipGenerator g2 = (StandardCategoryToolTipGenerator)
            TestUtilities.serialised(g1);
    assertEquals(g1, g2);
}
 
Example 10
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    StandardCategoryItemLabelGenerator g1
            = new StandardCategoryItemLabelGenerator("{2}",
            DateFormat.getInstance());
    StandardCategoryItemLabelGenerator g2 = (StandardCategoryItemLabelGenerator) 
            TestUtilities.serialised(g1);
    assertEquals(g1, g2);
}
 
Example 11
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    IntervalCategoryToolTipGenerator g1
            = new IntervalCategoryToolTipGenerator("{3} - {4}",
            DateFormat.getInstance());
    IntervalCategoryToolTipGenerator g2 = (IntervalCategoryToolTipGenerator)
            TestUtilities.serialised(g1);
    assertEquals(g1, g2);
}
 
Example 12
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    IntervalCategoryItemLabelGenerator g1
            = new IntervalCategoryItemLabelGenerator("{3} - {4}",
            DateFormat.getInstance());
    IntervalCategoryItemLabelGenerator g2 = (IntervalCategoryItemLabelGenerator) TestUtilities.serialised(g1);
    assertEquals(g1, g2);
}
 
Example 13
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    StandardXYItemLabelGenerator g1 = new StandardXYItemLabelGenerator();
    StandardXYItemLabelGenerator g2 = (StandardXYItemLabelGenerator) 
            g1.clone();
    assertTrue(g1 != g2);
    assertTrue(g1.getClass() == g2.getClass());
    assertTrue(g1.equals(g2));

    // check independence
    g1.getXFormat().setMinimumIntegerDigits(2);
    assertFalse(g1.equals(g2));
    g2.getXFormat().setMinimumIntegerDigits(2);
    assertTrue(g1.equals(g2));

    g1.getYFormat().setMinimumIntegerDigits(2);
    assertFalse(g1.equals(g2));
    g2.getYFormat().setMinimumIntegerDigits(2);
    assertTrue(g1.equals(g2));

    // another test...
    g1 = new StandardXYItemLabelGenerator("{0} {1} {2}",
            DateFormat.getInstance(), DateFormat.getInstance());
    g2 = (StandardXYItemLabelGenerator) g1.clone();
    assertTrue(g1 != g2);
    assertTrue(g1.getClass() == g2.getClass());
    assertTrue(g1.equals(g2));

    // check independence
    g1.getXDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertFalse(g1.equals(g2));
    g2.getXDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertTrue(g1.equals(g2));

    g1.getYDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertFalse(g1.equals(g2));
    g2.getYDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertTrue(g1.equals(g2));

}
 
Example 14
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    StandardXYItemLabelGenerator g1 = new StandardXYItemLabelGenerator();
    StandardXYItemLabelGenerator g2 = (StandardXYItemLabelGenerator) 
            g1.clone();
    assertTrue(g1 != g2);
    assertTrue(g1.getClass() == g2.getClass());
    assertTrue(g1.equals(g2));

    // check independence
    g1.getXFormat().setMinimumIntegerDigits(2);
    assertFalse(g1.equals(g2));
    g2.getXFormat().setMinimumIntegerDigits(2);
    assertTrue(g1.equals(g2));

    g1.getYFormat().setMinimumIntegerDigits(2);
    assertFalse(g1.equals(g2));
    g2.getYFormat().setMinimumIntegerDigits(2);
    assertTrue(g1.equals(g2));

    // another test...
    g1 = new StandardXYItemLabelGenerator("{0} {1} {2}",
            DateFormat.getInstance(), DateFormat.getInstance());
    g2 = (StandardXYItemLabelGenerator) g1.clone();
    assertTrue(g1 != g2);
    assertTrue(g1.getClass() == g2.getClass());
    assertTrue(g1.equals(g2));

    // check independence
    g1.getXDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertFalse(g1.equals(g2));
    g2.getXDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertTrue(g1.equals(g2));

    g1.getYDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertFalse(g1.equals(g2));
    g2.getYDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertTrue(g1.equals(g2));

}
 
Example 15
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    StandardXYItemLabelGenerator g1 = new StandardXYItemLabelGenerator();
    StandardXYItemLabelGenerator g2 = (StandardXYItemLabelGenerator) 
            g1.clone();
    assertTrue(g1 != g2);
    assertTrue(g1.getClass() == g2.getClass());
    assertTrue(g1.equals(g2));

    // check independence
    g1.getXFormat().setMinimumIntegerDigits(2);
    assertFalse(g1.equals(g2));
    g2.getXFormat().setMinimumIntegerDigits(2);
    assertTrue(g1.equals(g2));

    g1.getYFormat().setMinimumIntegerDigits(2);
    assertFalse(g1.equals(g2));
    g2.getYFormat().setMinimumIntegerDigits(2);
    assertTrue(g1.equals(g2));

    // another test...
    g1 = new StandardXYItemLabelGenerator("{0} {1} {2}",
            DateFormat.getInstance(), DateFormat.getInstance());
    g2 = (StandardXYItemLabelGenerator) g1.clone();
    assertTrue(g1 != g2);
    assertTrue(g1.getClass() == g2.getClass());
    assertTrue(g1.equals(g2));

    // check independence
    g1.getXDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertFalse(g1.equals(g2));
    g2.getXDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertTrue(g1.equals(g2));

    g1.getYDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertFalse(g1.equals(g2));
    g2.getYDateFormat().setNumberFormat(new DecimalFormat("0.000"));
    assertTrue(g1.equals(g2));

}
 
Example 16
/**
 * Returns a tool tip generator that formats the x-values as dates and the 
 * y-values as numbers.
 * 
 * @return A tool tip generator (never <code>null</code>).
 */
public static StandardXYToolTipGenerator getTimeSeriesInstance() {
    return new StandardXYToolTipGenerator(DEFAULT_TOOL_TIP_FORMAT, 
            DateFormat.getInstance(), NumberFormat.getInstance());
}
 
Example 17
/**
 * Creates an item label generator using the default date and number 
 * formats.
 */
public HighLowItemLabelGenerator() {
    this(DateFormat.getInstance(), NumberFormat.getInstance());
}
 
Example 18
/**
 * Returns a tool tip generator that formats the x-values as dates and the
 * y-values as numbers.
 *
 * @return A tool tip generator (never <code>null</code>).
 */
public static StandardXYToolTipGenerator getTimeSeriesInstance() {
    return new StandardXYToolTipGenerator(DEFAULT_TOOL_TIP_FORMAT,
            DateFormat.getInstance(), NumberFormat.getInstance());
}
 
Example 19
/**
 * Creates an item label generator using the default date and number 
 * formats.
 */
public HighLowItemLabelGenerator() {
    this(DateFormat.getInstance(), NumberFormat.getInstance());
}
 
Example 20
/**
 * Creates an item label generator using the default date and number 
 * formats.
 */
public HighLowItemLabelGenerator() {
    this(DateFormat.getInstance(), NumberFormat.getInstance());
}