Class DFOperator

    • Constructor Summary

      Constructors 
      Constructor Description
      DFOperator​(java.lang.String persistName, java.lang.String displayName, int minOperands, int maxOperands)
      Creates new instance of the operator.
      DFOperator​(java.lang.String persistName, java.lang.String displayName, java.lang.String displayNameInExpression, int minOperands, int maxOperands)
      Creates new instance of the operator.
    • Constructor Detail

      • DFOperator

        public DFOperator​(java.lang.String persistName,
                          java.lang.String displayName,
                          int minOperands,
                          int maxOperands)
        Creates new instance of the operator. Display name in expression is the same like given standalone display name.
        Parameters:
        persistName - Name used to persist the operator
        displayName - Standalone display name - 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
        Since:
        14.10.27
      • DFOperator

        public DFOperator​(java.lang.String persistName,
                          java.lang.String displayName,
                          java.lang.String displayNameInExpression,
                          int minOperands,
                          int maxOperands)
        Creates new instance of the operator.
        Parameters:
        persistName - Name used to persist the operator
        displayName - Standalone display name - e.g. "Is null"
        displayNameInExpression - 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
        Since:
        14.10.27
    • Method Detail

      • getDisplayName

        public final java.lang.String getDisplayName()
        Return standalone operator's display name (usually the first character is upper case).
        Returns:
        display name
      • getDisplayNameInExpression

        public final java.lang.String getDisplayNameInExpression()
        Return operator's display name which is used in expression (usually the first character is lower case).
        Returns:
        display name in expression.
      • getPersistName

        public final java.lang.String getPersistName()
        The name used to persist the operator.
        Returns:
        name to persist.
        Since:
        14.10.27
      • getMinOperands

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

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

        public void validate​(DFDataTree dataTree,
                             java.util.List<DFTerm> operands,
                             java.util.Map<java.lang.String,​java.lang.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 final boolean correctNumberOfOperands​(java.util.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.
      • parseOperands

        public abstract java.lang.Object[] parseOperands​(DFField field,
                                                         java.lang.String operands)
                                                  throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • toString

        protected java.lang.String toString​(java.util.List<DFTerm> operands)
      • getToStringPart

        public java.lang.String getToStringPart​(java.util.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 < 15]" => "[< 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 tests 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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getStartingWithOperator

        public int getStartingWithOperator​(java.lang.String text)
        Calculates whether the input string is starting with the operator's String representation. If no, returns 0, if yes returns the position where the operator ends in the input text.

        By overriding this method you can define aliases for operator.
        To properly override this method you should call getStartingWith(java.lang.String, java.lang.String) for aliases and return the result if it is not 0. Return 0 if no alias returns number larger than 0.

        The method uses case insensitive strings.
        Parameters:
        text - input string to test.
        Returns:
        0 when the input is not starting with operator, otherwise the position, where the operator ends.
        Since:
        6.4
      • getStartingWith

        protected final int getStartingWith​(java.lang.String text,
                                            java.lang.String operator)
        Helper method to override getStartingWithOperator(java.lang.String).

        The method uses case insensitive Strings.
        Parameters:
        text - String to inspect whether starts with operator.
        operator - The operator's name.
        Returns:
        operator.length() if text starts with operator, otherwise 0.
        Since:
        6.4