Author: jleroux
Date: Tue Jan 15 14:22:31 2019 New Revision: 1851363 URL: http://svn.apache.org/viewvc?rev=1851363&view=rev Log: Improved: ObjectType::doRealCompare returns null instead of a boolean in few places (OFBIZ-10812) While reviewing OFBIZ-10811 I found that I could improve ObjectType class on 2 points: doRealCompare returning null instead of a boolean simpleTypeOrObjectConvert Javadoc (2 other instance not documented) Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java?rev=1851363&r1=1851362&r2=1851363&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/ObjectType.java Tue Jan 15 14:22:31 2019 @@ -485,6 +485,7 @@ public class ObjectType { return isOrSubOf(objectClass, typeClass); } + /** See also {@link #simpleTypeOrObjectConvert(Object obj, String type, String format, TimeZone timeZone, Locale locale, boolean noTypeFail)}. */ public static Object simpleTypeOrObjectConvert(Object obj, String type, String format, Locale locale, boolean noTypeFail) throws GeneralException { return simpleTypeOrObjectConvert(obj, type, format, null, locale, noTypeFail); } @@ -496,8 +497,11 @@ public class ObjectType { * * Supported types: * - All primitives + * * - Simple types: String, Boolean, Double, Float, Long, Integer, BigDecimal. + * * - Other Objects: List, Map, Set, Calendar, Date (java.sql.Date), Time, Timestamp, TimeZone, Date (util.Date and sql.Date) + * * - Simple types (maybe) not handled: Short, BigInteger, Byte, Character, ObjectName and Void... * * @param obj Object to convert @@ -552,7 +556,6 @@ public class ObjectType { if (converter != null) { if (converter instanceof LocalizedConverter) { - @SuppressWarnings("rawtypes") LocalizedConverter<Object, Object> localizedConverter = (LocalizedConverter) converter; if (timeZone == null) { timeZone = TimeZone.getDefault(); @@ -588,6 +591,7 @@ public class ObjectType { return obj; } + /** See also {@link #simpleTypeOrObjectConvert(Object obj, String type, String format, TimeZone timeZone, Locale locale, boolean noTypeFail)}. */ public static Object simpleTypeOrObjectConvert(Object obj, String type, String format, Locale locale) throws GeneralException { return simpleTypeOrObjectConvert(obj, type, format, locale, true); } @@ -631,7 +635,7 @@ public class ObjectType { } catch (GeneralException e) { Debug.logError(e, module); messages.add("Could not convert value2 for comparison: " + e.getMessage()); - return null; + return Boolean.FALSE; } } @@ -647,7 +651,7 @@ public class ObjectType { } catch (GeneralException e) { Debug.logError(e, module); messages.add("Could not convert value1 for comparison: " + e.getMessage()); - return null; + return Boolean.FALSE; } // handle null values... @@ -661,11 +665,11 @@ public class ObjectType { } else { if (convertedValue1 == null) { messages.add("Left value is null, cannot complete compare for the operator " + operator); - return null; + return Boolean.FALSE; } if (convertedValue2 == null) { messages.add("Right value is null, cannot complete compare for the operator " + operator); - return null; + return Boolean.FALSE; } } } @@ -678,7 +682,7 @@ public class ObjectType { return str1.indexOf(str2) < 0 ? Boolean.FALSE : Boolean.TRUE; } messages.add("Error in XML file: cannot do a contains compare between a String and a non-String type"); - return null; + return Boolean.FALSE; } else if ("is-empty".equals(operator)) { if (convertedValue1 == null) { return Boolean.TRUE; @@ -720,7 +724,7 @@ public class ObjectType { return str1.length() == 0 && str2.length() == 0 ? Boolean.FALSE : Boolean.TRUE; } else { messages.add("ERROR: Could not do a compare between strings with one empty string for the operator " + operator); - return null; + return Boolean.FALSE; } } result = str1.compareTo(str2); @@ -767,7 +771,7 @@ public class ObjectType { } } else { messages.add("Can only compare Booleans using the operators 'equals' or 'not-equals'"); - return null; + return Boolean.FALSE; } } else if ("java.lang.Object".equals(type)) { if (convertedValue1.equals(convertedValue2)) { @@ -777,7 +781,7 @@ public class ObjectType { } } else { messages.add("Type \"" + type + "\" specified for compare not supported."); - return null; + return Boolean.FALSE; } if (verboseOn) { @@ -809,7 +813,7 @@ public class ObjectType { } } else { messages.add("Specified compare operator \"" + operator + "\" not known."); - return null; + return Boolean.FALSE; } if (verboseOn) { Modified: ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java?rev=1851363&r1=1851362&r2=1851363&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/entityext/src/main/java/org/apache/ofbiz/entityext/eca/EntityEcaCondition.java Tue Jan 15 14:22:31 2019 @@ -25,15 +25,15 @@ import java.util.Map; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.ObjectType; +import org.apache.ofbiz.base.util.UtilMisc; import org.apache.ofbiz.base.util.UtilValidate; import org.apache.ofbiz.entity.GenericEntity; import org.apache.ofbiz.entity.GenericEntityException; import org.apache.ofbiz.service.DispatchContext; import org.apache.ofbiz.service.GenericServiceException; -import org.w3c.dom.Element; -import org.apache.ofbiz.base.util.UtilMisc; import org.apache.ofbiz.service.LocalDispatcher; import org.apache.ofbiz.service.ServiceUtil; +import org.w3c.dom.Element; /** * EntityEcaCondition @@ -118,11 +118,7 @@ public final class EntityEcaCondition im Debug.logWarning((String) message, module); } } - if (cond != null) { - return cond; - } else { - return false; - } + return cond; } public String getLValue() { Modified: ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java?rev=1851363&r1=1851362&r2=1851363&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/service/src/main/java/org/apache/ofbiz/service/eca/ServiceEcaCondition.java Tue Jan 15 14:22:31 2019 @@ -184,12 +184,10 @@ public class ServiceEcaCondition impleme Debug.logWarning(message.toString(), module); } } - if (cond != null) { - return cond; - } else { + if (!cond) { Debug.logWarning("doRealCompare returned null, returning false", module); - return false; } + return cond; } @Override |
Free forum by Nabble | Edit this page |