Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  * either express or implied. See the License for the specific language
  * governing permissions and limitations under the License.
  */
 package org.dbflute.cbean.cvalue;
 
 import java.util.Map;
 
The value of condition.

Author(s):
jflute
 
 public class ConditionValue implements Serializable {
 
     // ===================================================================================
     //                                                                          Definition
     //                                                                          ==========
     
The serial version UID for object serialization. (Default)
 
     private static final long serialVersionUID = 1L;
 
     public static final String FIXED_KEY_QUERY = "query";
     public static final String FIXED_KEY_INLINE = "inline";
     public static final String FIXED_KEY_ONCLAUSE = "onClause";
 
     // ===================================================================================
     //                                                                           Attribute
     //                                                                           =========
     
The map of fixed values. map:{[query or inline or onClause] = map:{[condition-key] = [value]}}
 
     protected Map<StringMap<StringObject>> _fixedValueMap;

    
The map of varying values. map:{[condition-key] = map:{[varying-key] = [value]}}
 
     protected Map<StringMap<StringObject>> _varyingValueMap;
 
     // temporary query modes:
     protected boolean _orScopeQuery// completely independent
     protected boolean _inline;
     protected boolean _onClause// can be true, when in-line is true
 
     // ===================================================================================
     //                                                                               Equal
     //                                                                               =====
     protected String _equalLatestLocation;
     protected transient ValueHandler _equalValueHandler;
 
     protected ValueHandler getEqualValueHandler() {
         if ( == null) {
              = new StandardValueHandler(.);
         }
         return ;
     }

    
Does it has the value of equal?

Returns:
The determination, true or false. (NotNull)
 
     public boolean hasEqual() {
         return getEqualValueHandler().hasValue();
     }

    
Does the value equal the value of equal?

Parameters:
value The value of equal. (NullAllowed)
Returns:
The determination, true or false. (NotNull)
 
     public boolean equalEqual(Object value) {
         return getEqualValueHandler().equalValue(value);
     }

    
Override the value of equal.

Parameters:
value The value of equal. (NullAllowed)
 
     public void overrideEqual(Object value) {
         getEqualValueHandler().overrideValue(value);
     }

    
Set up the value of equal.

Parameters:
value The value of equal. (NullAllowed)
location The base location of equal. (NotNull)
 
    public void setupEqual(Object valueString location) {
         = location + "." + getEqualValueHandler().setValue(value);
    }

    
Get the latest location of equal.

Returns:
The latest location of equal. (NullAllowed)
    public String getEqualLatestLocation() {
        return ;
    }
    // ===================================================================================
    //                                                                           Not Equal
    //                                                                           =========
    protected String _notEqualLatestLocation;
    protected transient ValueHandler _notEqualValueHandler;
    protected ValueHandler getNotEqualValueHandler() {
        if ( == null) {
        }
        return ;
    }

    
Does it has the value of notEqual?

Returns:
The determination, true or false. (NotNull)
    public boolean hasNotEqual() {
        return getNotEqualValueHandler().hasValue();
    }

    
Does the value equal the value of notEqual?

Parameters:
value The value of notEqual. (NullAllowed)
Returns:
The determination, true or false. (NotNull)
    public boolean equalNotEqual(Object value) {
        return getNotEqualValueHandler().equalValue(value);
    }

    
Override the value of notEqual.

Parameters:
value The value of notEqual. (NullAllowed)
    public void overrideNotEqual(Object value) {
        getNotEqualValueHandler().overrideValue(value);
    }

    
Set up the value of notEqual.

Parameters:
value The value of notEqual. (NullAllowed)
location The base location of notEqual. (NotNull)
    public void setupNotEqual(Object valueString location) {
         = location + "." + getNotEqualValueHandler().setValue(value);
    }

    
Get the latest location of notEqual.

Returns:
The latest location of notEqual. (NullAllowed)
    public String getNotEqualLatestLocation() {
        return ;
    }
    // ===================================================================================
    //                                                                        Greater Than
    //                                                                        ============
    protected transient ValueHandler _greaterThanValueHandler;
        if ( == null) {
        }
        return ;
    }

    
Does it has the value of greaterThan?

Returns:
The determination, true or false. (NotNull)
    public boolean hasGreaterThan() {
        return getGreaterThanValueHandler().hasValue();
    }

    
Does the value equal the value of greaterThan?

Parameters:
value The value of greaterThan. (NullAllowed)
Returns:
The determination, true or false. (NotNull)
    public boolean equalGreaterThan(Object value) {
        return getGreaterThanValueHandler().equalValue(value);
    }

    
Override the value of greaterThan.

Parameters:
value The value of greaterThan. (NullAllowed)
    public void overrideGreaterThan(Object value) {
    }

    
Set up the value of greaterThan.

Parameters:
value The value of greaterThan. (NullAllowed)
location The base location of greaterThan. (NotNull)
    public void setupGreaterThan(Object valueString location) {
         = location + "." + getGreaterThanValueHandler().setValue(value);
    }

    
Get the latest location of greaterThan.

Returns:
The latest location of greaterThan. (NullAllowed)
        return ;
    }
    // ===================================================================================
    //                                                                           Less Than
    //                                                                           =========
    protected String _lessThanLatestLocation;
    protected transient ValueHandler _lessThanValueHandler;
    protected ValueHandler getLessThanValueHandler() {
        if ( == null) {
        }
        return ;
    }

    
Does it has the value of lessThan?

Returns:
The determination, true or false. (NotNull)
    public boolean hasLessThan() {
        return getLessThanValueHandler().hasValue();
    }

    
Does the value equal the value of lessThan?

Parameters:
value The value of lessThan. (NullAllowed)
Returns:
The determination, true or false. (NotNull)
    public boolean equalLessThan(Object value) {
        return getLessThanValueHandler().equalValue(value);
    }

    
Override the value of lessThan.

Parameters:
value The value of lessThan. (NullAllowed)
    public void overrideLessThan(Object value) {
        getLessThanValueHandler().overrideValue(value);
    }

    
Set up the value of lessThan.

Parameters:
value The value of lessThan. (NullAllowed)
location The base location of lessThan. (NotNull)
    public void setupLessThan(Object valueString location) {
         = location + "." + getLessThanValueHandler().setValue(value);
    }

    
Get the latest location of lessThan.

Returns:
The latest location of lessThan. (NullAllowed)
    public String getLessThanLatestLocation() {
        return ;
    }
    // ===================================================================================
    //                                                                       Greater Equal
    //                                                                       =============
    protected transient ValueHandler _greaterEqualValueHandler;
        if ( == null) {
        }
        return ;
    }

    
Does it has the value of greaterEqual?

Returns:
The determination, true or false. (NotNull)
    public boolean hasGreaterEqual() {
        return getGreaterEqualValueHandler().hasValue();
    }

    
Does the value equal the value of greaterEqual?

Parameters:
value The value of greaterEqual. (NullAllowed)
Returns:
The determination, true or false. (NotNull)
    public boolean equalGreaterEqual(Object value) {
        return getGreaterEqualValueHandler().equalValue(value);
    }

    
Override the value of greaterEqual.

Parameters:
value The value of greaterEqual. (NullAllowed)
    public void overrideGreaterEqual(Object value) {
    }

    
Set up the value of greaterEqual.

Parameters:
value The value of greaterEqual. (NullAllowed)
location The base location of greaterEqual. (NotNull)
    public void setupGreaterEqual(Object valueString location) {
         = location + "." + getGreaterEqualValueHandler().setValue(value);
    }

    
Get the latest location of greaterEqual.

Returns:
The latest location of greaterEqual. (NullAllowed)
        return ;
    }
    // ===================================================================================
    //                                                                          Less Equal
    //                                                                          ==========
    protected String _lessEqualLatestLocation;
    protected transient ValueHandler _lessEqualValueHandler;
    protected ValueHandler getLessEqualValueHandler() {
        if ( == null) {
        }
        return ;
    }

    
Does it has the value of lessEqual?

Returns:
The determination, true or false. (NotNull)
    public boolean hasLessEqual() {
        return getLessEqualValueHandler().hasValue();
    }

    
Does the value equal the value of lessEqual?

Parameters:
value The value of lessEqual. (NullAllowed)
Returns:
The determination, true or false. (NotNull)
    public boolean equalLessEqual(Object value) {
        return getLessEqualValueHandler().equalValue(value);
    }

    
Override the value of lessEqual.

Parameters:
value The value of lessEqual. (NullAllowed)
    public void overrideLessEqual(Object value) {
        getLessEqualValueHandler().overrideValue(value);
    }

    
Set up the value of lessEqual.

Parameters:
value The value of lessEqual. (NullAllowed)
location The base location of lessEqual. (NotNull)
    public void setupLessEqual(Object valueString location) {
         = location + "." + getLessEqualValueHandler().setValue(value);
    }

    
Get the latest location of lessEqual.

Returns:
The latest location of lessEqual. (NullAllowed)
        return ;
    }
    // ===================================================================================
    //                                                                            In Scope
    //                                                                            ========
    protected String _inScopeLatestLocation;
    protected transient ValueHandler _inScopeValueHandler;
    protected ValueHandler getInScopeValueHandler() {
        if ( == null) {
        }
        return ;
    }

    
Set up the value of inScope.

Parameters:
value The value of inScope. (NullAllowed)
location The base location of inScope. (NotNull)
    public void setupInScope(Object valueString location) {
        final String key = getInScopeValueHandler().setValue(value);
         = location + "." + key;
    }

    
Get the latest location of inScope.

Returns:
The latest location of inScope. (NullAllowed)
    public String getInScopeLatestLocation() {
        return ;
    }
    // ===================================================================================
    //                                                                        Not In Scope
    //                                                                        ============
    protected transient ValueHandler _notInScopeValueHandler;
        if ( == null) {
        }
        return ;
    }

    
Set up the value of notInScope.

Parameters:
value The value of notInScope. (NullAllowed)
location The base location of notInScope. (NotNull)
    public void setupNotInScope(Object valueString location) {
        final String key = getNotInScopeValueHandler().setValue(value);
         = location + "." + key;
    }

    
Get the latest location of notInScope.

Returns:
The latest location of notInScope. (NullAllowed)
        return ;
    }
    // ===================================================================================
    //                                                                         Like Search
    //                                                                         ===========
    protected transient VaryingValueHandler _likeSearchValueHandler;
        if ( == null) {
        }
        return ;
    }

    
Set up the value of likeSearch.

Parameters:
value The value of likeSearch. (NullAllowed)
option The option of likeSearch. (NotNull)
location The base location of likeSearch. (NotNull)
    public void setupLikeSearch(String valuefinal LikeSearchOption optionString location) {
        final String key = getLikeSearchValueHandler().setValue(option.generateRealValue(value));
         = location + "." + key;
    }

    
Get the latest location of likeSearch.

Returns:
The latest location of likeSearch. (NullAllowed)
        return ;
    }
    // ===================================================================================
    //                                                                     Not Like Search
    //                                                                     ===============
    protected transient VaryingValueHandler _notLikeSearchValueHandler;
        if ( == null) {
        }
        return ;
    }

    
Set up the value of notLikeSearch.

Parameters:
value The value of notLikeSearch. (NullAllowed)
option The option of notLikeSearch. (NotNull)
location The base location of notLikeSearch. (NotNull)
    public void setupNotLikeSearch(String valuefinal LikeSearchOption optionString location) {
        final String key = getNotLikeSearchValueHandler().setValue(option.generateRealValue(value));
         = location + "." + key;
    }

    
Get the latest location of notLikeSearch.

Returns:
The latest location of notLikeSearch. (NullAllowed)
        return ;
    }
    // ===================================================================================
    //                                                                         Is Not Null
    //                                                                         ===========
    protected transient ValueHandler _isNotNullValueHandler;
    protected ValueHandler getIsNotNullValueHandler() {
        if ( == null) {
        }
        return ;
    }

    
Set the value of isNotNull.

Parameters:
value The value of isNotNull. (NullAllowed)
Returns:
The key of value. (NotNull)
    public String setIsNotNull(Object value) {
        return getIsNotNullValueHandler().setValue(value);
    }

    
Does it has the value of isNotNull?

Returns:
The determination, true or false. (NotNull)
    public boolean hasIsNotNull() {
        return getIsNotNullValueHandler().hasValue();
    }
    // ===================================================================================
    //                                                                             Is Null
    //                                                                             =======
    protected transient ValueHandler _isNullValueHandler;
    protected ValueHandler getIsNullValueHandler() {
        if ( == null) {
        }
        return ;
    }

    
Set the value of isNull.

Parameters:
value The value of isNull. (NullAllowed)
Returns:
The key of value. (NotNull)
    public String setIsNull(Object value) {
        return getIsNullValueHandler().setValue(value);
    }

    
Does it has the value of isNull?

Returns:
The determination, true or false. (NotNull)
    public boolean hasIsNull() {
        return getIsNullValueHandler().hasValue();
    }
    // ===================================================================================
    //                                                                      Value Handling
    //                                                                      ==============
    // -----------------------------------------------------
    //                                                 Fixed
    //                                                 -----
    protected Object getFixedValue(ConditionKey conditionKey) {
        if (!hasFixedValue(conditionKey)) {
            return null;
        }
        return .get(getFixedValueKey()).get(conditionKey.getConditionKey());
    }
    protected String setupFixedValue(ConditionKey conditionKeyObject value) {
        if ( == null) {
            // query or in-line or on-clause
             = new HashMap<StringMap<StringObject>>(3);
        }
        final String fixedValueKey = getFixedValueKey();
        Map<StringObjectelementMap = .get(fixedValueKey);
        if (elementMap == null) {
            elementMap = new HashMap<StringObject>(8);
            .put(fixedValueKeyelementMap);
        }
        final String key = conditionKey.getConditionKey();
        elementMap.put(keyvalue);
        return "fixed." + fixedValueKey + "." + key;
    }
    protected String getFixedValueKey() {
        if () {
            if () {
                return ;
            } else {
                return ;
            }
        } else { // normal query
            return ;
        }
    }
    protected boolean hasFixedValue(ConditionKey conditionKey) {
        if ( == null) {
            return false;
        }
        final Map<StringObjectelementMap = .get(getFixedValueKey());
        if (elementMap == null) {
            return false;
        }
        return elementMap.containsKey(conditionKey.getConditionKey());
    }
    // -----------------------------------------------------
    //                                               Varying
    //                                               -------
    protected Object getVaryingValue(ConditionKey conditionKey) {
        throw new IllegalStateException();
    }
    protected String setupVaryingValue(ConditionKey conditionKeyObject value) {
        if ( == null) {
             = new HashMap<StringMap<StringObject>>(4);
        }
        final String key = conditionKey.getConditionKey();
        Map<StringObjectelementMap = .get(key);
        if (elementMap == null) {
            elementMap = new LinkedHashMap<StringObject>();
            .put(keyelementMap);
        }
        final String elementKey = key + elementMap.size();
        elementMap.put(elementKeyvalue);
        return "varying." + key + "." + elementKey;
    }
    protected boolean hasVaryingValue(ConditionKey conditionKey) {
        throw new IllegalStateException();
    }
    // -----------------------------------------------------
    //                                               Handler
    //                                               -------
    protected static interface ValueHandler {
        Object getValue();
        String setValue(Object value);
        boolean hasValue();
        boolean equalValue(Object value);
        void overrideValue(Object value);
    }
    protected class StandardValueHandler implements ValueHandler {
        protected final ConditionKey _conditionKey;
        public StandardValueHandler(ConditionKey conditionKey) {
             = conditionKey;
        }
        public Object getValue() {
            return getStandardValue();
        }
        public String setValue(Object value) {
            return setupStandardValue(value);
        }
        public boolean hasValue() {
            return hasStandardValue();
        }
        public boolean equalValue(Object value) {
            return hasValue() ? getValue().equals(value) : value == null;
        }
        public void overrideValue(Object value) {
            setValue(value);
        }
        protected Object getStandardValue(ConditionKey conditionKey) {
            return  ? getVaryingValue(conditionKey) : getFixedValue(conditionKey);
        }
        protected String setupStandardValue(ConditionKey conditionKeyObject value) {
            if () {
                return setupVaryingValue(conditionKeyvalue);
            } else {
                return setupFixedValue(conditionKeyvalue);
            }
        }
        protected boolean hasStandardValue(ConditionKey conditionKey) {
            return  ? hasVaryingValue(conditionKey) : hasFixedValue(conditionKey);
        }
    }
    protected class VaryingValueHandler implements ValueHandler {
        protected final ConditionKey _conditionKey;
        public VaryingValueHandler(ConditionKey conditionKey) {
             = conditionKey;
        }
        public Object getValue() {
            return getVaryingValue();
        }
        public String setValue(Object value) {
            return setupVaryingValue(value);
        }
        public boolean hasValue() {
            return hasVaryingValue();
        }
        public boolean equalValue(Object value) {
            return hasValue() ? getValue().equals(value) : value == null;
        }
        public void overrideValue(Object value) {
            setValue(value);
        }
    }
    // ===================================================================================
    //                                                                             Process
    //                                                                             =======
    public static interface CallbackProcessor<RESULT> {
        RESULT process();
        QueryModeProvider getProvider();
    }
    public static interface QueryModeProvider {
        boolean isOrScopeQuery(); // completely independent
        boolean isInline();
        boolean isOnClause(); // can be true, when in-line is true
    }
    public <RESULT> RESULT process(CallbackProcessor<RESULT> processor) {
        try {
            final QueryModeProvider provider = processor.getProvider();
             = provider.isOrScopeQuery();
             = provider.isInline();
             = provider.isOnClause();
            return processor.process();
        } finally {
             = false;
             = false;
             = false;
        }
    }
    // ===================================================================================
    //                                                                      Basic Override
    //                                                                      ==============
    @Override
    public String toString() {
        final String title = DfTypeUtil.toClassTitle(this);
        final StringBuilder sb = new StringBuilder();
        sb.append(title).append(":{");
        sb.append("fixed=").append();
        sb.append(", varying=").append();
        sb.append("}");
        return sb.toString();
    }
    // ===================================================================================
    //                                                                            Accessor
    //                                                                            ========
    public boolean isFixedQuery() {
        // only or-scope query is NOT fixed
        return !;
    }

    
Get the map of fixed values. {basically for parameter-comment}

Returns:
The map of fixed values. map:{[query or inline or onClause] = map:{[condition-key] = [value]}} (NullAllowed)
    public Map<StringMap<StringObject>> getFixed() {
        return ;
    }

    
Get the map of fixed values for query. {basically for internal tests}

Returns:
The map of query. map:{[condition-key] = [value]} (NullAllowed)
    public Map<StringObjectgetFixedQuery() {
        return  != null ? .get() : null;
    }

    
Get the map of fixed values for in-line. {basically for internal tests}

Returns:
The map of in-line query. map:{[condition-key] = [value]} (NullAllowed)
    public Map<StringObjectgetFixedInline() {
        return  != null ? .get() : null;
    }

    
Get the map of fixed values for on-clause. {basically for internal tests}

Returns:
The map of on-clause query. map:{[condition-key] = [value]} (NullAllowed)
    public Map<StringObjectgetFixedOnClause() {
        return  != null ? .get() : null;
    }

    
Get the map of varying values. {basically for parameter-comment}

Returns:
The map of varying values. map:{[condition-key] = map:{[varying-key] = [value]}} (NullAllowed)
    public Map<StringMap<StringObject>> getVarying() {
        return ;
    }
New to GrepCode? Check out our FAQ X