SimpleSegmentPredicate implements PredicateRuleProducer { @Override public String getPredicateRule() { StringBuilder bldr = new StringBuilder(); bldr.append("( ").append(this.getMissingFieldName()).append(" == false )") .append(" && ( ").append(this.getValueFieldName()); if (operator.equalsIgnoreCase(GREATER)) { bldr.append(" > ").append(getValue()).append(" )"); return bldr.toString(); } else if (operator.equalsIgnoreCase(LESSER)) { bldr.append(" < ").append(getValue()).append(" )"); return bldr.toString(); } else if (operator.equalsIgnoreCase(EQUAL)) { bldr.append(" == ").append(getValue()).append(" )"); return bldr.toString(); } else if (operator.equalsIgnoreCase(NOT_EQUAL)) { bldr.append(" != ").append(getValue()).append(" )"); return bldr.toString(); } else if (operator.equalsIgnoreCase(MISSING)) { return this.getMissingFieldName()+" == true"; } else if (operator.equalsIgnoreCase(NOT_MISSING)) { return this.getMissingFieldName()+" == false"; } else if (operator.equalsIgnoreCase(GREATER_EQUAL)) { bldr.append(" >= ").append(getValue()).append(" )"); return bldr.toString(); } else if (operator.equalsIgnoreCase(LESSER_EQUAL)) { bldr.append(" <= ").append(getValue()).append(" )"); return bldr.toString(); } throw new IllegalStateException("PMML - SimplePredicate: Unknown operator ("+operator+")"); } SimpleSegmentPredicate();  SimpleSegmentPredicate(SimplePredicate predicate); String getBaseFieldName(); String getCapitalizedFieldName(); String getValueFieldName(); String getMissingFieldName(); @Override String getPredicateRule(); boolean isStringLiteralValue(); void setStringLiteralValue(boolean stringLiteralValue); @Override List<String> getPredicateFieldNames(); @Override List<String> getFieldMissingFieldNames(); @Override boolean isAlwaysTrue(); @Override boolean isAlwaysFalse(); static final String EQUAL; static final String NOT_EQUAL; static final String GREATER; static final String GREATER_EQUAL; static final String LESSER; static final String LESSER_EQUAL; static final String MISSING; static final String NOT_MISSING; }
@Test public void testStringValue() { stringPred.setOperator(SimpleSegmentPredicate.EQUAL); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(stringPred); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF3 == false ) && ( vTF3 == \"optA\" )",text); predicate.setOperator(SimpleSegmentPredicate.EQUAL); ssp = new SimpleSegmentPredicate(predicate); text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 == 123 )",text); }
@Test public void testEquals() { predicate.setOperator(SimpleSegmentPredicate.EQUAL); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 == 123 )",text); }
@Test public void testNotEquals() { predicate.setOperator(SimpleSegmentPredicate.NOT_EQUAL); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 != 123 )",text); }
@Test public void testGreaterThan() { predicate.setOperator(SimpleSegmentPredicate.GREATER); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 > 123 )",text); }
@Test public void testLessThan() { predicate.setOperator(SimpleSegmentPredicate.LESSER); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 < 123 )",text); }
@Test public void testMissing() { predicate.setOperator(SimpleSegmentPredicate.MISSING); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("mTF2 == true",text); }
@Test public void testGreaterEqual() { predicate.setOperator(SimpleSegmentPredicate.GREATER_EQUAL); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 >= 123 )",text); }
@Test public void testLesserEqual() { predicate.setOperator(SimpleSegmentPredicate.LESSER_EQUAL); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("( mTF2 == false ) && ( vTF2 <= 123 )",text); }
@Test public void testNotMissing() { predicate.setOperator(SimpleSegmentPredicate.NOT_MISSING); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNotNull(text); assertEquals("mTF2 == false",text); }
@Test(expected=IllegalStateException.class) public void testBadOperator() { predicate.setOperator(BAD_OP); SimpleSegmentPredicate ssp = new SimpleSegmentPredicate(predicate); String text = ssp.getPredicateRule(); assertNull(text); }