log = Logger.getLogger( FilterConditionParser.class.getCanonicalName() );
}
public static FilterCondition parse(String filterString) {
FilterCondition filter;
LinkedList<FilterCondition> filterStack = new LinkedList<FilterCondition>();
String[] splits = filterString.split( "\\s" );
for( int i = 0; i < splits.length; i++ ) {
if( splits[i].equalsIgnoreCase( "and" ) ) {
ConjunctionFilter and = ConjunctionFilter.and( filterStack );
filterStack.clear();
filterStack.add( and );
}
else if( splits[i].equalsIgnoreCase( "approved" ) ) {
filterStack.add( StatusFilter.APPROVED );
}
else if( splits[i].equalsIgnoreCase( "direct" ) ) {
filterStack.add( new SemanticsFilter( Semantics.DIRECT ) );
}
else if( splits[i].equalsIgnoreCase( "dl" ) ) {
filterStack.add( SatisfiedSyntaxConstraintFilter.DL );
}
else if( splits[i].equalsIgnoreCase( "!dl" ) ) {
filterStack.add( new UnsatisfiedSyntaxConstraintFilter( SyntaxConstraint.DL ) );
}
else if( splits[i].equalsIgnoreCase( "el" ) ) {
filterStack.add( SatisfiedSyntaxConstraintFilter.EL );
}
else if( splits[i].equalsIgnoreCase( "!el" ) ) {
filterStack.add( new UnsatisfiedSyntaxConstraintFilter( SyntaxConstraint.EL ) );
}
else if( splits[i].equalsIgnoreCase( "extracredit" ) ) {
filterStack.add( StatusFilter.EXTRACREDIT );
}
else if( splits[i].equalsIgnoreCase( "not" ) ) {
FilterCondition a = filterStack.removeLast();
filterStack.add( NegationFilter.not( a ) );
}
else if( splits[i].equalsIgnoreCase( "or" ) ) {
DisjunctionFilter or = DisjunctionFilter.or( filterStack );
filterStack.clear();