public class GeneralFormatCollection
Example:
Shows how to format field results.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert a field that displays a result with no format applied. Field field = builder.insertField("= 2 + 3"); Assert.assertEquals("= 2 + 3", field.getFieldCode()); Assert.assertEquals("5", field.getResult()); // We can apply a format to a field's result using the field's attributes. // Below are three types of formats that we can apply to a field's result. // 1 - Numeric format: FieldFormat format = field.getFormat(); format.setNumericFormat("$###.00"); field.update(); Assert.assertEquals("= 2 + 3 \\# $###.00", field.getFieldCode()); Assert.assertEquals("$ 5.00", field.getResult()); // 2 - Date/time format: field = builder.insertField("DATE"); format = field.getFormat(); format.setDateTimeFormat("dddd, MMMM dd, yyyy"); field.update(); Assert.assertEquals("DATE \\@ \"dddd, MMMM dd, yyyy\"", field.getFieldCode()); System.out.println("Today's date, in {format.DateTimeFormat} format:\n\t{field.Result}"); // 3 - General format: field = builder.insertField("= 25 + 33"); format = field.getFormat(); format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().add(GeneralFormat.UPPER); field.update(); int index = 0; Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator(); while (generalFormatEnumerator.hasNext()) { int value = generalFormatEnumerator.next(); System.out.println(MessageFormat.format("General format index {0}: {1}", index++, value)); } Assert.assertEquals("= 25 + 33 \\* roman \\* Upper", field.getFieldCode()); Assert.assertEquals("LVIII", field.getResult()); Assert.assertEquals(2, format.getGeneralFormats().getCount()); Assert.assertEquals(GeneralFormat.LOWERCASE_ROMAN, format.getGeneralFormats().get(0)); // We can remove our formats to revert the field's result to its original form. format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().removeAt(0); Assert.assertEquals(0, format.getGeneralFormats().getCount()); field.update(); Assert.assertEquals("= 25 + 33 ", field.getFieldCode()); Assert.assertEquals("58", field.getResult()); Assert.assertEquals(0, format.getGeneralFormats().getCount());
Property Getters/Setters Summary | ||
---|---|---|
int | getCount() | |
Gets the total number of the items in the collection.
|
||
int | get(int index) | |
Gets a general format at the specified index.
The value of the property is GeneralFormat integer constant. |
Method Summary | ||
---|---|---|
void | add(int item) | |
Adds a general format to the collection.
|
||
java.util.Iterator<GeneralFormat> | iterator() | |
Returns an enumerator object.
|
||
void | remove(int item) | |
Removes all occurrences of the specified general format from the collection.
|
||
void | removeAt(int index) | |
Removes a general format occurrence at the specified index.
|
public int getCount()
Example:
Shows how to format field results.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert a field that displays a result with no format applied. Field field = builder.insertField("= 2 + 3"); Assert.assertEquals("= 2 + 3", field.getFieldCode()); Assert.assertEquals("5", field.getResult()); // We can apply a format to a field's result using the field's attributes. // Below are three types of formats that we can apply to a field's result. // 1 - Numeric format: FieldFormat format = field.getFormat(); format.setNumericFormat("$###.00"); field.update(); Assert.assertEquals("= 2 + 3 \\# $###.00", field.getFieldCode()); Assert.assertEquals("$ 5.00", field.getResult()); // 2 - Date/time format: field = builder.insertField("DATE"); format = field.getFormat(); format.setDateTimeFormat("dddd, MMMM dd, yyyy"); field.update(); Assert.assertEquals("DATE \\@ \"dddd, MMMM dd, yyyy\"", field.getFieldCode()); System.out.println("Today's date, in {format.DateTimeFormat} format:\n\t{field.Result}"); // 3 - General format: field = builder.insertField("= 25 + 33"); format = field.getFormat(); format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().add(GeneralFormat.UPPER); field.update(); int index = 0; Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator(); while (generalFormatEnumerator.hasNext()) { int value = generalFormatEnumerator.next(); System.out.println(MessageFormat.format("General format index {0}: {1}", index++, value)); } Assert.assertEquals("= 25 + 33 \\* roman \\* Upper", field.getFieldCode()); Assert.assertEquals("LVIII", field.getResult()); Assert.assertEquals(2, format.getGeneralFormats().getCount()); Assert.assertEquals(GeneralFormat.LOWERCASE_ROMAN, format.getGeneralFormats().get(0)); // We can remove our formats to revert the field's result to its original form. format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().removeAt(0); Assert.assertEquals(0, format.getGeneralFormats().getCount()); field.update(); Assert.assertEquals("= 25 + 33 ", field.getFieldCode()); Assert.assertEquals("58", field.getResult()); Assert.assertEquals(0, format.getGeneralFormats().getCount());
public int get(int index)
index
- The index of a general format.Example:
Shows how to format field results.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert a field that displays a result with no format applied. Field field = builder.insertField("= 2 + 3"); Assert.assertEquals("= 2 + 3", field.getFieldCode()); Assert.assertEquals("5", field.getResult()); // We can apply a format to a field's result using the field's attributes. // Below are three types of formats that we can apply to a field's result. // 1 - Numeric format: FieldFormat format = field.getFormat(); format.setNumericFormat("$###.00"); field.update(); Assert.assertEquals("= 2 + 3 \\# $###.00", field.getFieldCode()); Assert.assertEquals("$ 5.00", field.getResult()); // 2 - Date/time format: field = builder.insertField("DATE"); format = field.getFormat(); format.setDateTimeFormat("dddd, MMMM dd, yyyy"); field.update(); Assert.assertEquals("DATE \\@ \"dddd, MMMM dd, yyyy\"", field.getFieldCode()); System.out.println("Today's date, in {format.DateTimeFormat} format:\n\t{field.Result}"); // 3 - General format: field = builder.insertField("= 25 + 33"); format = field.getFormat(); format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().add(GeneralFormat.UPPER); field.update(); int index = 0; Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator(); while (generalFormatEnumerator.hasNext()) { int value = generalFormatEnumerator.next(); System.out.println(MessageFormat.format("General format index {0}: {1}", index++, value)); } Assert.assertEquals("= 25 + 33 \\* roman \\* Upper", field.getFieldCode()); Assert.assertEquals("LVIII", field.getResult()); Assert.assertEquals(2, format.getGeneralFormats().getCount()); Assert.assertEquals(GeneralFormat.LOWERCASE_ROMAN, format.getGeneralFormats().get(0)); // We can remove our formats to revert the field's result to its original form. format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().removeAt(0); Assert.assertEquals(0, format.getGeneralFormats().getCount()); field.update(); Assert.assertEquals("= 25 + 33 ", field.getFieldCode()); Assert.assertEquals("58", field.getResult()); Assert.assertEquals(0, format.getGeneralFormats().getCount());
public void add(int item) throws java.lang.Exception
item
- A Example:
Shows how to format field results.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert a field that displays a result with no format applied. Field field = builder.insertField("= 2 + 3"); Assert.assertEquals("= 2 + 3", field.getFieldCode()); Assert.assertEquals("5", field.getResult()); // We can apply a format to a field's result using the field's attributes. // Below are three types of formats that we can apply to a field's result. // 1 - Numeric format: FieldFormat format = field.getFormat(); format.setNumericFormat("$###.00"); field.update(); Assert.assertEquals("= 2 + 3 \\# $###.00", field.getFieldCode()); Assert.assertEquals("$ 5.00", field.getResult()); // 2 - Date/time format: field = builder.insertField("DATE"); format = field.getFormat(); format.setDateTimeFormat("dddd, MMMM dd, yyyy"); field.update(); Assert.assertEquals("DATE \\@ \"dddd, MMMM dd, yyyy\"", field.getFieldCode()); System.out.println("Today's date, in {format.DateTimeFormat} format:\n\t{field.Result}"); // 3 - General format: field = builder.insertField("= 25 + 33"); format = field.getFormat(); format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().add(GeneralFormat.UPPER); field.update(); int index = 0; Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator(); while (generalFormatEnumerator.hasNext()) { int value = generalFormatEnumerator.next(); System.out.println(MessageFormat.format("General format index {0}: {1}", index++, value)); } Assert.assertEquals("= 25 + 33 \\* roman \\* Upper", field.getFieldCode()); Assert.assertEquals("LVIII", field.getResult()); Assert.assertEquals(2, format.getGeneralFormats().getCount()); Assert.assertEquals(GeneralFormat.LOWERCASE_ROMAN, format.getGeneralFormats().get(0)); // We can remove our formats to revert the field's result to its original form. format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().removeAt(0); Assert.assertEquals(0, format.getGeneralFormats().getCount()); field.update(); Assert.assertEquals("= 25 + 33 ", field.getFieldCode()); Assert.assertEquals("58", field.getResult()); Assert.assertEquals(0, format.getGeneralFormats().getCount());
public java.util.Iterator<GeneralFormat> iterator()
Example:
Shows how to format field results.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert a field that displays a result with no format applied. Field field = builder.insertField("= 2 + 3"); Assert.assertEquals("= 2 + 3", field.getFieldCode()); Assert.assertEquals("5", field.getResult()); // We can apply a format to a field's result using the field's attributes. // Below are three types of formats that we can apply to a field's result. // 1 - Numeric format: FieldFormat format = field.getFormat(); format.setNumericFormat("$###.00"); field.update(); Assert.assertEquals("= 2 + 3 \\# $###.00", field.getFieldCode()); Assert.assertEquals("$ 5.00", field.getResult()); // 2 - Date/time format: field = builder.insertField("DATE"); format = field.getFormat(); format.setDateTimeFormat("dddd, MMMM dd, yyyy"); field.update(); Assert.assertEquals("DATE \\@ \"dddd, MMMM dd, yyyy\"", field.getFieldCode()); System.out.println("Today's date, in {format.DateTimeFormat} format:\n\t{field.Result}"); // 3 - General format: field = builder.insertField("= 25 + 33"); format = field.getFormat(); format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().add(GeneralFormat.UPPER); field.update(); int index = 0; Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator(); while (generalFormatEnumerator.hasNext()) { int value = generalFormatEnumerator.next(); System.out.println(MessageFormat.format("General format index {0}: {1}", index++, value)); } Assert.assertEquals("= 25 + 33 \\* roman \\* Upper", field.getFieldCode()); Assert.assertEquals("LVIII", field.getResult()); Assert.assertEquals(2, format.getGeneralFormats().getCount()); Assert.assertEquals(GeneralFormat.LOWERCASE_ROMAN, format.getGeneralFormats().get(0)); // We can remove our formats to revert the field's result to its original form. format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().removeAt(0); Assert.assertEquals(0, format.getGeneralFormats().getCount()); field.update(); Assert.assertEquals("= 25 + 33 ", field.getFieldCode()); Assert.assertEquals("58", field.getResult()); Assert.assertEquals(0, format.getGeneralFormats().getCount());
public void remove(int item) throws java.lang.Exception
item
- A Example:
Shows how to format field results.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert a field that displays a result with no format applied. Field field = builder.insertField("= 2 + 3"); Assert.assertEquals("= 2 + 3", field.getFieldCode()); Assert.assertEquals("5", field.getResult()); // We can apply a format to a field's result using the field's attributes. // Below are three types of formats that we can apply to a field's result. // 1 - Numeric format: FieldFormat format = field.getFormat(); format.setNumericFormat("$###.00"); field.update(); Assert.assertEquals("= 2 + 3 \\# $###.00", field.getFieldCode()); Assert.assertEquals("$ 5.00", field.getResult()); // 2 - Date/time format: field = builder.insertField("DATE"); format = field.getFormat(); format.setDateTimeFormat("dddd, MMMM dd, yyyy"); field.update(); Assert.assertEquals("DATE \\@ \"dddd, MMMM dd, yyyy\"", field.getFieldCode()); System.out.println("Today's date, in {format.DateTimeFormat} format:\n\t{field.Result}"); // 3 - General format: field = builder.insertField("= 25 + 33"); format = field.getFormat(); format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().add(GeneralFormat.UPPER); field.update(); int index = 0; Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator(); while (generalFormatEnumerator.hasNext()) { int value = generalFormatEnumerator.next(); System.out.println(MessageFormat.format("General format index {0}: {1}", index++, value)); } Assert.assertEquals("= 25 + 33 \\* roman \\* Upper", field.getFieldCode()); Assert.assertEquals("LVIII", field.getResult()); Assert.assertEquals(2, format.getGeneralFormats().getCount()); Assert.assertEquals(GeneralFormat.LOWERCASE_ROMAN, format.getGeneralFormats().get(0)); // We can remove our formats to revert the field's result to its original form. format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().removeAt(0); Assert.assertEquals(0, format.getGeneralFormats().getCount()); field.update(); Assert.assertEquals("= 25 + 33 ", field.getFieldCode()); Assert.assertEquals("58", field.getResult()); Assert.assertEquals(0, format.getGeneralFormats().getCount());
public void removeAt(int index) throws java.lang.Exception
index
- Example:
Shows how to format field results.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert a field that displays a result with no format applied. Field field = builder.insertField("= 2 + 3"); Assert.assertEquals("= 2 + 3", field.getFieldCode()); Assert.assertEquals("5", field.getResult()); // We can apply a format to a field's result using the field's attributes. // Below are three types of formats that we can apply to a field's result. // 1 - Numeric format: FieldFormat format = field.getFormat(); format.setNumericFormat("$###.00"); field.update(); Assert.assertEquals("= 2 + 3 \\# $###.00", field.getFieldCode()); Assert.assertEquals("$ 5.00", field.getResult()); // 2 - Date/time format: field = builder.insertField("DATE"); format = field.getFormat(); format.setDateTimeFormat("dddd, MMMM dd, yyyy"); field.update(); Assert.assertEquals("DATE \\@ \"dddd, MMMM dd, yyyy\"", field.getFieldCode()); System.out.println("Today's date, in {format.DateTimeFormat} format:\n\t{field.Result}"); // 3 - General format: field = builder.insertField("= 25 + 33"); format = field.getFormat(); format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().add(GeneralFormat.UPPER); field.update(); int index = 0; Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator(); while (generalFormatEnumerator.hasNext()) { int value = generalFormatEnumerator.next(); System.out.println(MessageFormat.format("General format index {0}: {1}", index++, value)); } Assert.assertEquals("= 25 + 33 \\* roman \\* Upper", field.getFieldCode()); Assert.assertEquals("LVIII", field.getResult()); Assert.assertEquals(2, format.getGeneralFormats().getCount()); Assert.assertEquals(GeneralFormat.LOWERCASE_ROMAN, format.getGeneralFormats().get(0)); // We can remove our formats to revert the field's result to its original form. format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().removeAt(0); Assert.assertEquals(0, format.getGeneralFormats().getCount()); field.update(); Assert.assertEquals("= 25 + 33 ", field.getFieldCode()); Assert.assertEquals("58", field.getResult()); Assert.assertEquals(0, format.getGeneralFormats().getCount());