/** * This method moves up atomic conditions if there is only one sub-condition. * * @return true if there was a simplification. */ public boolean simplify() { if ( nrConditions() == 1 ) { Condition condition = getCondition( 0 ); if ( condition.isAtomic() ) { return simplify( condition, this ); } } boolean changed = false; for ( int i = 0; i < nrConditions(); i++ ) { Condition condition = getCondition( i ); changed |= condition.simplify(); if ( i == 0 ) { condition.setOperator( OPERATOR_NONE ); } } return changed; }
public void getUsedFields( Hashtable<String, String> fields ) { if ( isAtomic() ) { if ( getLeftValuename() != null ) { fields.put( getLeftValuename(), "-" ); } if ( getRightValuename() != null ) { fields.put( getRightValuename(), "-" ); } } else { for ( int i = 0; i < nrConditions(); i++ ) { Condition subc = getCondition( i ); subc.getUsedFields( fields ); } } }
public void removeCondition( int nr ) { if ( isComposite() ) { Condition c = list.get( nr ); list.remove( nr ); // Nothing left or only one condition left: move it to the parent: make it atomic. boolean moveUp = isAtomic() || nrConditions() == 1; if ( nrConditions() == 1 ) { c = getCondition( 0 ); } if ( moveUp ) { setLeftValuename( c.getLeftValuename() ); setFunction( c.getFunction() ); setRightValuename( c.getRightValuename() ); setRightExact( c.getRightExact() ); setNegated( isNegated() ^ c.isNegated() ); } } }
public ObjectId saveCondition( Condition condition, ObjectId id_condition_parent ) throws KettleException { try { condition.setObjectId( insertCondition( id_condition_parent, condition ) ); for ( int i = 0; i < condition.nrConditions(); i++ ) { Condition subc = condition.getCondition( i ); repository.saveCondition( subc, condition.getObjectId() ); } return condition.getObjectId(); } catch ( KettleException dbe ) { throw new KettleException( "Error saving condition to the repository.", dbe ); } }
@Override public Object clone() { Condition retval = null; retval = new Condition(); retval.negate = negate; retval.operator = operator; if ( isComposite() ) { for ( int i = 0; i < nrConditions(); i++ ) { Condition c = getCondition( i ); Condition cCopy = (Condition) c.clone(); retval.addCondition( cCopy ); } } else { retval.negate = negate; retval.left_valuename = left_valuename; retval.operator = operator; retval.right_valuename = right_valuename; retval.function = function; if ( right_exact != null ) { retval.right_exact = (ValueMetaAndData) right_exact.clone(); } else { retval.right_exact = null; } } return retval; }
private boolean simplify( Condition condition, Condition parent ) { // If condition is atomic // AND // if parent only contain a single child: simplify // if ( condition.isAtomic() && parent.nrConditions() == 1 ) { parent.setLeftValuename( condition.getLeftValuename() ); parent.setFunction( condition.getFunction() ); parent.setRightValuename( condition.getRightValuename() ); parent.setRightExact( condition.getRightExact() ); parent.setNegated( condition.isNegated() ^ parent.isNegated() ); parent.list.clear(); return true; } return false; }
drawNegated( gc, 0, 0, active_condition ); size_cond = new Rectangle[active_condition.nrConditions()]; size_oper = new Rectangle[active_condition.nrConditions()]; for ( int i = 0; i < active_condition.nrConditions(); i++ ) { Point to = drawCondition( gc, basex, basey, i, active_condition.getCondition( i ) ); basey += size_and_not.height + to.y + 15;
public String getXML( int level ) throws KettleValueException { String retval = ""; String indent1 = Const.rightPad( " ", level ); String indent2 = Const.rightPad( " ", level + 1 ); String indent3 = Const.rightPad( " ", level + 2 ); retval += indent1 + XMLHandler.openTag( XML_TAG ) + Const.CR; retval += indent2 + XMLHandler.addTagValue( "negated", isNegated() ); if ( getOperator() != OPERATOR_NONE ) { retval += indent2 + XMLHandler.addTagValue( "operator", Const.rtrim( getOperatorDesc() ) ); } if ( isAtomic() ) { retval += indent2 + XMLHandler.addTagValue( "leftvalue", getLeftValuename() ); retval += indent2 + XMLHandler.addTagValue( "function", getFunctionDesc() ); retval += indent2 + XMLHandler.addTagValue( "rightvalue", getRightValuename() ); if ( getRightExact() != null ) { retval += indent2 + getRightExact().getXML(); } } else { retval += indent2 + "<conditions>" + Const.CR; for ( int i = 0; i < nrConditions(); i++ ) { Condition c = getCondition( i ); retval += c.getXML( level + 2 ); } retval += indent3 + "</conditions>" + Const.CR; } retval += indent2 + XMLHandler.closeTag( XML_TAG ) + Const.CR; return retval; }
MenuItem miMoveDown = new MenuItem( mPop, SWT.CASCADE ); miMoveDown.setText( BaseMessages.getString( PKG, "ConditionEditor.MoveConditionDown" ) ); if ( cond_nr >= active_condition.nrConditions() - 1 ) { miMoveDown.setEnabled( false );