uk.me.parabola.mkgmap.osmstyle.eval
Class LinkedOp

java.lang.Object
  extended by uk.me.parabola.mkgmap.osmstyle.eval.LinkedOp
All Implemented Interfaces:
Op
Direct Known Subclasses:
LinkedBinaryOp

public class LinkedOp
extends java.lang.Object
implements Op

This is used to implement OR expressions as if each term was a separate indexable expression.

So if you have:

 A=1 | B=1 | C=1 {set name='${name} ${A}' | '${B}'; }
 
This is represented by:
 A=1 {set name='${name} ${A}' | '${B}'; }
 B=1 {set name='${name} ${A}' | '${B}'; }
 C=1 {set name='${name} ${A}' | '${B}'; }
 
So that each term can be index separately. However we need to be able to prevent the second and/or third terms running if the first (or second) matches. That is what this class does. It acts in most respects like the operation it is wrapping, but when a successful evaluation is performed on an element, the test is suppressed for the subsequent terms in the chain.

Author:
Steve Ratcliffe

Field Summary
protected  Op wrapped
           
 
Fields inherited from interface uk.me.parabola.mkgmap.osmstyle.eval.Op
AND, CLOSE_PAREN, EQUALS, EXISTS, GT, GTE, LT, LTE, NOT, NOT_EQUALS, NOT_EXISTS, OPEN_PAREN, OR, REGEX, VALUE
 
Constructor Summary
protected LinkedOp(Op wrapped, boolean first)
           
 
Method Summary
static LinkedOp create(Op op, boolean first)
          Create either a LinkedOp or a LinkedBinaryOp as appropriate for the type of operation that is passed in.
 boolean eval(Element el)
          Evaluate the expression.
 Op getFirst()
          Get the first operand.
 char getType()
           
 boolean hasHigherPriority(Op other)
          Does this operation have a higher priority that the other one?
 boolean isType(char value)
           
 int priority()
           
 void setFirst(Op first)
           
 void setLink(LinkedOp link)
           
 java.lang.String toString()
           
 java.lang.String value()
          Get the value in a 'pure' form, without being quoted in any way.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

wrapped

protected final Op wrapped
Constructor Detail

LinkedOp

protected LinkedOp(Op wrapped,
                   boolean first)
Method Detail

eval

public boolean eval(Element el)
Description copied from interface: Op
Evaluate the expression.

Specified by:
eval in interface Op
Parameters:
el - The OSM element to be tested.
Returns:
True if the expression is true for the given element.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

priority

public int priority()
Specified by:
priority in interface Op

hasHigherPriority

public boolean hasHigherPriority(Op other)
Description copied from interface: Op
Does this operation have a higher priority that the other one?

Specified by:
hasHigherPriority in interface Op
Parameters:
other - The other operation.

getFirst

public Op getFirst()
Description copied from interface: Op
Get the first operand.

Specified by:
getFirst in interface Op

setFirst

public void setFirst(Op first)
Specified by:
setFirst in interface Op

getType

public char getType()
Specified by:
getType in interface Op

value

public java.lang.String value()
Description copied from interface: Op
Get the value in a 'pure' form, without being quoted in any way. If you want the expression in a form that can be printed and used in a style file, then use toString().

Specified by:
value in interface Op

isType

public boolean isType(char value)
Specified by:
isType in interface Op

setLink

public void setLink(LinkedOp link)

create

public static LinkedOp create(Op op,
                              boolean first)
Create either a LinkedOp or a LinkedBinaryOp as appropriate for the type of operation that is passed in.