Class MapStringExpression

  • All Implemented Interfaces:
    Serializable, Cloneable, Expression

    public class MapStringExpression
    extends AbstractExpression
    Maps a string read from a column into an other string. The possible mappings are given as (key, text) pairs. If the string from the column is null or matches none of the defined keys, a fallback value is returned.

    If the fallback value is undefined, the original value is returned instead.

    Author:
    Thomas Morgner
    See Also:
    Serialized Form
    • Constructor Detail

      • MapStringExpression

        public MapStringExpression()
        Default Constructor.
    • Method Detail

      • getField

        public String getField()
        Returns the name of the field from where to read the key value.
        Returns:
        the field name.
      • setField

        public void setField​(String field)
        Defines the name of the field from where to read the key value.
        Parameters:
        field - the field name.
      • getNullValue

        public String getNullValue()
        Returns the value that is returned if the key-field evaluates to null.
        Returns:
        the null-value.
      • setNullValue

        public void setNullValue​(String nullValue)
        Defines the value that is returned if the key-field evaluates to null.
        Parameters:
        nullValue - the null-value.
      • getFallbackValue

        public String getFallbackValue()
        Returns the value that is returned if none of the predefined keys matches the lookup-value.
        Returns:
        the fallback value.
      • setFallbackValue

        public void setFallbackValue​(String fallbackValue)
        Defines the value that is returned if none of the predefined keys matches the lookup-value.
        Parameters:
        fallbackValue - the fallback value.
      • setKey

        public void setKey​(int index,
                           String key)
        Defines a key value to which the lookup-field's value is compared. If the key is defined, a matching value must be defined too.
        Parameters:
        index - the index position of the key in the list.
        key - the key value.
      • getKey

        public String getKey​(int index)
        Returns a key value at the given index.
        Parameters:
        index - the index position of the key in the list.
        Returns:
        the key value.
      • getKeyCount

        public int getKeyCount()
        Returns the number of keys defined in the expression.
        Returns:
        the number of keys.
      • getKey

        public String[] getKey()
        Returns all defined keys as string array.
        Returns:
        all defined keys.
      • setKey

        public void setKey​(String[] keys)
        Defines all keys using the values from the string array.
        Parameters:
        keys - all defined keys.
      • setText

        public void setText​(int index,
                            String value)
        Defines the mapped text for the key at the given position. This text is returned if the key matches the value read from the lookup-field column.
        Parameters:
        index - the index of the entry.
        value - the text that is returned if the key is selected.
      • getText

        public String getText​(int index)
        Returns the mapped text for the key at the given position. This text is returned if the key matches the value read from the lookup-field column.
        Parameters:
        index - the index of the entry.
        Returns:
        the text that is returned if the key is selected.
      • getTextCount

        public int getTextCount()
        Returns the number of replacement text defined in this expression. This should match the number of keys defined.
        Returns:
        the number of texts defined.
      • getText

        public String[] getText()
        Returns all defined texts as string-array.
        Returns:
        all texts.
      • setText

        public void setText​(String[] texts)
        Defines all texts by using the values from the given text-array.
        Parameters:
        texts - the new text-values.
      • isIgnoreCase

        public boolean isIgnoreCase()
        Returns, whether the key-lookup should be case-insensitive.
        Returns:
        true, if the key comparison is case-insensitive, false otherwise.
      • setIgnoreCase

        public void setIgnoreCase​(boolean ignoreCase)
        Defines, whether the key-lookup should be case-insensitive.
        Parameters:
        ignoreCase - true, if the key comparison is case-insensitive, false otherwise.
      • getInstance

        public Expression getInstance()
        Return a completly separated copy of this function. The copy does no longer share any changeable objects with the original function.
        Specified by:
        getInstance in interface Expression
        Overrides:
        getInstance in class AbstractExpression
        Returns:
        a copy of this function.
      • getValue

        public Object getValue()
        Performs the lookup by first querying the given field, and then returning the defined text for the key-position.
        Returns:
        the value of the function.