com.im.df.api 5.9

com.im.df.api.dml
Class DFOperator

java.lang.Object
  extended by com.im.df.api.dml.DFOperator
Direct Known Subclasses:
Operators.AllDataOperator, Operators.SimpleFieldValuesOperator, Operators.SimpleLogicalOperator, Operators.StructureOperator

public abstract class DFOperator
extends Object

This class represents one operator used by DFTermExpression in DIF API. DFOperator is only extensible class which constitutes the complex terms used in query. It's supposed that new operators will be added to the system.


Constructor Summary
DFOperator(String displayName, int minOperands, int maxOperands)
          Creates new instance of the operator.
DFOperator(String displayName, String displayNameInExpression, int minOperands, int maxOperands)
          Creates new instance of the operator.
 
Method Summary
protected  boolean correctNumberOfOperands(List<DFTerm> operands)
          Test if the given operands number is acceptable.
 String getDisplayName()
          Return standalone operator's display name (usually the first character is upper case)
 String getDisplayNameInExpression()
          Return operator's display name which is used in expression (usually the first character is lower case).
 int getMaxOperands()
           
 int getMinOperands()
           
abstract  Class<? extends DFFieldDataTypeCapability> getReturnType(List<DFTerm> operands)
          Compute the return type of the term.
 String getToStringPart(List<DFTerm> operands, int index)
          Get the part of the complete toString(java.util.List) method result.
abstract  boolean isFieldAcceptableAsOperand(DFField field)
          This is just an utility method which must be implemented by subclasses.
abstract  Object[] parseOperands(DFField field, String operands)
           
 String toString()
           
 String toString(List<DFTerm> operands)
           
 void validate(DFDataTree dataTree, List<DFTerm> operands, Map<String,Object> options, TermErrors errors)
          Validate the operands in context of this operator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DFOperator

public DFOperator(String displayName,
                  int minOperands,
                  int maxOperands)
Creates new instance of the operator. Display name in expression is the same like standalone display name.

Parameters:
displayName - Operator's display name
minOperands - Minimum number of operands which is acceptable for this operator
maxOperands - Maximum number of operands which is acceptable for this operator

DFOperator

public DFOperator(String displayName,
                  String displayNameInExpression,
                  int minOperands,
                  int maxOperands)
Creates new instance of the operator.

Parameters:
displayName - Operator's display name (standalone) - e.g. "Is null"
displayNameInExpression - Operator's display name - when used in expression - e.g. "is null".
minOperands - Minimum number of operands which is acceptable for this operator
maxOperands - Maximum number of operands which is acceptable for this operator
Method Detail

getDisplayName

public String getDisplayName()
Return standalone operator's display name (usually the first character is upper case)


getDisplayNameInExpression

public String getDisplayNameInExpression()
Return operator's display name which is used in expression (usually the first character is lower case).


getMinOperands

public int getMinOperands()
Returns:
Minimum number of operands which is acceptable for this operator

getMaxOperands

public int getMaxOperands()
Returns:
Maximum number of operands which is acceptable for this operator

validate

public void validate(DFDataTree dataTree,
                     List<DFTerm> operands,
                     Map<String,Object> options,
                     TermErrors errors)
Validate the operands in context of this operator. It's up to operator to decide if it accepts the given operands or not. This method is called from DFTerm.validate(com.im.df.api.ddl.DFDataTree).

Parameters:
dataTree - The datatree where this operator will be used
operands - The list of operands
options - Options of this query term (DFTermExpression.getOptions()
errors - The errors object which contains the result of the validation

correctNumberOfOperands

protected boolean correctNumberOfOperands(List<DFTerm> operands)
Test if the given operands number is acceptable. The current implementation just compares the operands list size with min/max operands of this operator.

Parameters:
operands - The operands to test
Returns:
True if the number of operands is acceptable, otherwise false.

getReturnType

public abstract Class<? extends DFFieldDataTypeCapability> getReturnType(List<DFTerm> operands)
Compute the return type of the term. Can return null if it cannot be determined.

Parameters:
operands - The operands for the computation of return type. The result can be different for different set of operands.
Returns:
The class which is subclass of DFFieldDataTypeCapability or null

parseOperands

public abstract Object[] parseOperands(DFField field,
                                       String operands)
                                throws IllegalArgumentException
Throws:
IllegalArgumentException

toString

public String toString(List<DFTerm> operands)

getToStringPart

public String getToStringPart(List<DFTerm> operands,
                              int index)
Get the part of the complete toString(java.util.List) method result. This method can be overriden by subclasses so each operator can provide specific form of String representation.

For example for binary operator is this method called 3 times: for indexes 0, 1 and 2. The index=0 means it's string before the first operand, index=1 is string between operands and index=2 is after the second operand. For operator LESS_THAN it should return: index=0 => "", index=1 => " less than ", and for index=2 => "".

This method allow subclass to reuse the generic code from toString(java.util.List) and change the own notation (e.g. "[molW %lt; 15]" => "[%lt; moW, 15]" etc.).

Parameters:
operands - The list of all operands
index - The index of String [0..operands.size()]
Returns:
The indexed part of whole toString(java.util.List) method.

isFieldAcceptableAsOperand

public abstract boolean isFieldAcceptableAsOperand(DFField field)
This is just an utility method which must be implemented by subclasses. It test if the given field is acceptable as operand for this DFOperator. It can return true even for fields which are recognized as invalid later. This is just rough test in the beginning of validation to filter inappropriate fields.

For example some operator takes two operands of different types (text, integer,...), but both must be of the same type. In this case this method returns true for all text, integer etc. fields, but if you use combination of [text, integer] as operands, it will be invalid.

Parameters:
field - The field to be tested
Returns:
True if field seems to be acceptable, false otherwise.

toString

public String toString()
Overrides:
toString in class Object

com.im.df.api 5.9