FieldIfComparisonResult

Inheritance: java.lang.Object

public class FieldIfComparisonResult

Specifies the result of the IF field condition evaluation.

Examples:

Shows how to insert an IF field.


 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);

 builder.write("Statement 1: ");
 FieldIf field = (FieldIf) builder.insertField(FieldType.FIELD_IF, true);
 field.setLeftExpression("0");
 field.setComparisonOperator("=");
 field.setRightExpression("1");

 // The IF field will display a string from either its "TrueText" property,
 // or its "FalseText" property, depending on the truth of the statement that we have constructed.
 field.setTrueText("True");
 field.setFalseText("False");
 field.update();

 // In this case, "0 = 1" is incorrect, so the displayed result will be "False".
 Assert.assertEquals(" IF  0 = 1 True False", field.getFieldCode());
 Assert.assertEquals(FieldIfComparisonResult.FALSE, field.evaluateCondition());
 Assert.assertEquals("False", field.getResult());

 builder.write("\nStatement 2: ");
 field = (FieldIf) builder.insertField(FieldType.FIELD_IF, true);
 field.setLeftExpression("5");
 field.setComparisonOperator("=");
 field.setRightExpression("2 + 3");
 field.setTrueText("True");
 field.setFalseText("False");
 field.update();

 // This time the statement is correct, so the displayed result will be "True".
 Assert.assertEquals(" IF  5 = \"2 + 3\" True False", field.getFieldCode());
 Assert.assertEquals(FieldIfComparisonResult.TRUE, field.evaluateCondition());
 Assert.assertEquals("True", field.getResult());

 doc.updateFields();
 doc.save(getArtifactsDir() + "Field.IF.docx");
 

Fields

FieldDescription
ERRORThere is an error in the condition.
FALSEThe condition is false .
TRUEThe condition is true .
length

Methods

MethodDescription
fromName(String fieldIfComparisonResultName)
getName(int fieldIfComparisonResult)
getValues()
toString(int fieldIfComparisonResult)

ERROR

public static int ERROR

There is an error in the condition.

FALSE

public static int FALSE

The condition is false .

TRUE

public static int TRUE

The condition is true .

length

public static int length

fromName(String fieldIfComparisonResultName)

public static int fromName(String fieldIfComparisonResultName)

Parameters:

ParameterTypeDescription
fieldIfComparisonResultNamejava.lang.String

Returns: int

getName(int fieldIfComparisonResult)

public static String getName(int fieldIfComparisonResult)

Parameters:

ParameterTypeDescription
fieldIfComparisonResultint

Returns: java.lang.String

getValues()

public static int[] getValues()

Returns: int[]

toString(int fieldIfComparisonResult)

public static String toString(int fieldIfComparisonResult)

Parameters:

ParameterTypeDescription
fieldIfComparisonResultint

Returns: java.lang.String