From 3cee9228d904fb01102bb71a2021d513ac3e8a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Thu, 20 Feb 2014 11:28:04 +0100 Subject: [PATCH] White noise: formatting, some missing final, etc --- .../edm/constants/ODataServiceVersion.java | 2 - .../{EdmImpl.java => AbstractEdmImpl.java} | 109 +++++++++++------- .../odata4/commons/core/edm/ActionMapKey.java | 15 ++- .../commons/core/edm/FunctionMapKey.java | 38 +++--- .../primitivetype/AbstractPrimitiveType.java | 35 +++--- .../core/edm/primitivetype/EdmBinary.java | 44 +++---- .../core/edm/primitivetype/EdmBoolean.java | 25 ++-- .../core/edm/primitivetype/EdmByte.java | 30 ++--- .../core/edm/primitivetype/EdmDate.java | 30 ++--- .../edm/primitivetype/EdmDateTimeOffset.java | 70 ++++++----- .../core/edm/primitivetype/EdmDecimal.java | 76 ++++++------ .../core/edm/primitivetype/EdmDouble.java | 49 ++++---- .../core/edm/primitivetype/EdmDuration.java | 47 ++++---- .../core/edm/primitivetype/EdmGuid.java | 27 +++-- .../core/edm/primitivetype/EdmInt16.java | 30 ++--- .../core/edm/primitivetype/EdmInt32.java | 32 ++--- .../core/edm/primitivetype/EdmInt64.java | 40 ++++--- .../core/edm/primitivetype/EdmNull.java | 14 ++- .../primitivetype/EdmPrimitiveTypeKind.java | 71 ++++++------ .../core/edm/primitivetype/EdmSByte.java | 26 +++-- .../core/edm/primitivetype/EdmSingle.java | 41 ++++--- .../core/edm/primitivetype/EdmString.java | 24 ++-- .../core/edm/primitivetype/EdmTimeOfDay.java | 29 ++--- .../commons/core/edm/primitivetype/Uint7.java | 21 ++-- .../commons/core/edm/ActionMapKeyTest.java | 3 +- .../commons/core/edm/EdmImplCachingTest.java | 11 +- .../core/edm/EdmImplCallCreateTest.java | 11 +- .../commons/core/edm/FunctionMapKeyTest.java | 1 + .../core/edm/primitivetype/EdmSingleTest.java | 12 +- .../edm/primitivetype/EdmTimeOfDayTest.java | 2 +- .../primitivetype/PrimitiveTypeBaseTest.java | 38 +++--- .../core/edm/provider/EdmProviderImpl.java | 4 +- .../core/edm/provider/EdmReturnTypeImpl.java | 6 +- 33 files changed, 561 insertions(+), 452 deletions(-) rename odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/{EdmImpl.java => AbstractEdmImpl.java} (70%) diff --git a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/constants/ODataServiceVersion.java b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/constants/ODataServiceVersion.java index bbd2b1c35..9c6a3fa8e 100644 --- a/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/constants/ODataServiceVersion.java +++ b/odata4-lib/odata4-commons-api/src/main/java/org/apache/olingo/odata4/commons/api/edm/constants/ODataServiceVersion.java @@ -23,8 +23,6 @@ import java.util.regex.Pattern; /** * This class is a container for the supported ODataServiceVersions. - * - * */ public class ODataServiceVersion { diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmImpl.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmImpl.java similarity index 70% rename from odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmImpl.java rename to odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmImpl.java index d52a02f9d..29d9b0434 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/EdmImpl.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/AbstractEdmImpl.java @@ -33,25 +33,42 @@ import org.apache.olingo.odata4.commons.api.edm.EdmServiceMetadata; import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -public abstract class EdmImpl implements Edm { +public abstract class AbstractEdmImpl implements Edm { + + private final Map entityContainers + = new HashMap(); + + private final Map enumTypes + = new HashMap(); + + private final Map typeDefinitions + = new HashMap(); + + private final Map entityTypes + = new HashMap(); + + private final Map complexTypes + = new HashMap(); + + private final Map unboundActions + = new HashMap(); + + private final Map unboundFunctions + = new HashMap(); + + private final Map boundActions + = new HashMap(); + + private final Map boundFunctions + = new HashMap(); - private final Map entityContainers = - new HashMap(); - private final Map enumTypes = new HashMap(); - private final Map typeDefinitions = - new HashMap(); - private final Map entityTypes = new HashMap(); - private final Map complexTypes = new HashMap(); - private final Map unboundActions = new HashMap(); - private final Map unboundFunctions = new HashMap(); - private final Map boundActions = new HashMap(); - private final Map boundFunctions = new HashMap(); private EdmServiceMetadata serviceMetadata; + private Map aliasToNamespaceInfo; @Override public EdmEntityContainer getEntityContainer(final FullQualifiedName namespaceOrAliasFQN) { - FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); + final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); EdmEntityContainer container = entityContainers.get(fqn); if (container == null) { container = createEntityContainer(fqn); @@ -67,7 +84,7 @@ public abstract class EdmImpl implements Edm { @Override public EdmEnumType getEnumType(final FullQualifiedName namespaceOrAliasFQN) { - FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); + final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); EdmEnumType enumType = enumTypes.get(fqn); if (enumType == null) { enumType = createEnumType(fqn); @@ -80,7 +97,7 @@ public abstract class EdmImpl implements Edm { @Override public EdmTypeDefinition getTypeDefinition(final FullQualifiedName namespaceOrAliasFQN) { - FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); + final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); EdmTypeDefinition typeDefinition = typeDefinitions.get(fqn); if (typeDefinition == null) { typeDefinition = createTypeDefinition(fqn); @@ -93,7 +110,7 @@ public abstract class EdmImpl implements Edm { @Override public EdmEntityType getEntityType(final FullQualifiedName namespaceOrAliasFQN) { - FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); + final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); EdmEntityType entityType = entityTypes.get(fqn); if (entityType == null) { entityType = createEntityType(fqn); @@ -106,7 +123,7 @@ public abstract class EdmImpl implements Edm { @Override public EdmComplexType getComplexType(final FullQualifiedName namespaceOrAliasFQN) { - FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); + final FullQualifiedName fqn = resolvePossibleAlias(namespaceOrAliasFQN); EdmComplexType complexType = complexTypes.get(fqn); if (complexType == null) { complexType = createComplexType(fqn); @@ -119,61 +136,67 @@ public abstract class EdmImpl implements Edm { @Override public EdmAction getAction(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName, - final Boolean isBindingParameterCollection) { - FullQualifiedName actionFqn = resolvePossibleAlias(actionName); + final Boolean isBindingParameterCollection) { + + EdmAction action = null; + + final FullQualifiedName actionFqn = resolvePossibleAlias(actionName); if (bindingParameterTypeName == null) { - EdmAction action = unboundActions.get(actionName); + action = unboundActions.get(actionName); if (action == null) { action = createUnboundAction(actionFqn); if (action != null) { unboundActions.put(actionName, action); } } - return action; } else { - FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName); - ActionMapKey key = new ActionMapKey(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection); - EdmAction action = boundActions.get(key); + final FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName); + final ActionMapKey key = new ActionMapKey(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection); + action = boundActions.get(key); if (action == null) { action = createBoundAction(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection); if (action != null) { boundActions.put(key, action); } } - return action; } + + return action; } @Override public EdmFunction getFunction(final FullQualifiedName functionName, - final FullQualifiedName bindingParameterTypeName, - final Boolean isBindingParameterCollection, final List parameterNames) { - FullQualifiedName functionFqn = resolvePossibleAlias(functionName); + final FullQualifiedName bindingParameterTypeName, + final Boolean isBindingParameterCollection, final List parameterNames) { + + EdmFunction function = null; + + final FullQualifiedName functionFqn = resolvePossibleAlias(functionName); if (bindingParameterTypeName == null) { - FunctionMapKey key = - new FunctionMapKey(functionFqn, bindingParameterTypeName, isBindingParameterCollection, parameterNames); - EdmFunction function = unboundFunctions.get(key); + final FunctionMapKey key = new FunctionMapKey( + functionFqn, bindingParameterTypeName, isBindingParameterCollection, parameterNames); + function = unboundFunctions.get(key); if (function == null) { function = createUnboundFunction(functionFqn, parameterNames); if (function != null) { unboundFunctions.put(key, function); } } - return function; } else { - FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName); - FunctionMapKey key = - new FunctionMapKey(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, parameterNames); - EdmFunction function = boundFunctions.get(key); + final FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName); + final FunctionMapKey key + = new FunctionMapKey(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, parameterNames); + function = boundFunctions.get(key); if (function == null) { function = createBoundFunction(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, - parameterNames); + parameterNames); if (function != null) { boundFunctions.put(key, function); } } - return function; } + + return function; } @Override @@ -190,7 +213,7 @@ public abstract class EdmImpl implements Edm { } FullQualifiedName finalFQN = null; if (namespaceOrAliasFQN != null) { - String namespace = aliasToNamespaceInfo.get(namespaceOrAliasFQN.getNamespace()); + final String namespace = aliasToNamespaceInfo.get(namespaceOrAliasFQN.getNamespace()); // If not contained in info it must be a namespace if (namespace == null) { finalFQN = namespaceOrAliasFQN; @@ -218,12 +241,12 @@ public abstract class EdmImpl implements Edm { protected abstract EdmFunction createUnboundFunction(FullQualifiedName functionName, List parameterNames); protected abstract EdmAction createBoundAction(FullQualifiedName actionName, - FullQualifiedName bindingParameterTypeName, - Boolean isBindingParameterCollection); + FullQualifiedName bindingParameterTypeName, + Boolean isBindingParameterCollection); protected abstract EdmFunction createBoundFunction(FullQualifiedName functionName, - FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection, - List parameterNames); + FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection, + List parameterNames); protected abstract EdmServiceMetadata createServiceMetadata(); } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/ActionMapKey.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/ActionMapKey.java index dbb454d27..cbecb09da 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/ActionMapKey.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/ActionMapKey.java @@ -22,15 +22,19 @@ import org.apache.olingo.odata4.commons.api.edm.EdmException; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; public class ActionMapKey { + private final FullQualifiedName actionName; + private final FullQualifiedName bindingParameterTypeName; + private final Boolean isBindingParameterCollection; public ActionMapKey(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName, - final Boolean isBindingParameterCollection) { + final Boolean isBindingParameterCollection) { + if (actionName == null || bindingParameterTypeName == null || isBindingParameterCollection == null) { - throw new EdmException( - "Action name, binding parameter type and binding parameter collection must not be null for bound actions"); + throw new EdmException("Action name, binding parameter type and binding parameter collection " + + "must not be null for bound actions"); } this.actionName = actionName; this.bindingParameterTypeName = bindingParameterTypeName; @@ -39,8 +43,9 @@ public class ActionMapKey { @Override public int hashCode() { - String forHash = - actionName.toString() + bindingParameterTypeName.toString() + isBindingParameterCollection.toString(); + final String forHash = actionName.toString() + + bindingParameterTypeName.toString() + + isBindingParameterCollection.toString(); return forHash.hashCode(); } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/FunctionMapKey.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/FunctionMapKey.java index f4f7a4c0c..3cb96a262 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/FunctionMapKey.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/FunctionMapKey.java @@ -28,16 +28,20 @@ import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; public class FunctionMapKey { private final FullQualifiedName functionName; + private final FullQualifiedName bindingParameterTypeName; + private final Boolean isBindingParameterCollection; + private final List parameterNames; public FunctionMapKey(final FullQualifiedName functionName, final FullQualifiedName bindingParameterTypeName, - final Boolean isBindingParameterCollection, final List parameterNames) { + final Boolean isBindingParameterCollection, final List parameterNames) { + this.functionName = functionName; if (bindingParameterTypeName != null && isBindingParameterCollection == null) { throw new EdmException( - "Indicator that the bindingparameter is a collection must not be null if its an bound function."); + "Indicator that the bindingparameter is a collection must not be null if its an bound function."); } this.bindingParameterTypeName = bindingParameterTypeName; this.isBindingParameterCollection = isBindingParameterCollection; @@ -85,23 +89,23 @@ public class FunctionMapKey { } final FunctionMapKey other = (FunctionMapKey) obj; - if (functionName.equals(other.functionName)) { - if ((bindingParameterTypeName == null && other.bindingParameterTypeName == null) - || (bindingParameterTypeName != null && bindingParameterTypeName.equals(other.bindingParameterTypeName))) { - if ((isBindingParameterCollection == null && other.isBindingParameterCollection == null) - || (isBindingParameterCollection != null && isBindingParameterCollection - .equals(other.isBindingParameterCollection))) { - if (parameterNames == null && other.parameterNames == null) { - return true; - } else if (parameterNames.size() == other.parameterNames.size()) { - for (String name : parameterNames) { - if (!other.parameterNames.contains(name)) { - return false; - } - } - return true; + if (functionName.equals(other.functionName) + && (bindingParameterTypeName == null && other.bindingParameterTypeName == null) + || (bindingParameterTypeName != null && bindingParameterTypeName.equals(other.bindingParameterTypeName)) + && (isBindingParameterCollection == null + && other.isBindingParameterCollection == null) + || (isBindingParameterCollection != null + && isBindingParameterCollection.equals(other.isBindingParameterCollection))) { + + if (parameterNames == null && other.parameterNames == null) { + return true; + } else if (parameterNames.size() == other.parameterNames.size()) { + for (String name : parameterNames) { + if (!other.parameterNames.contains(name)) { + return false; } } + return true; } } return false; diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/AbstractPrimitiveType.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/AbstractPrimitiveType.java index d7e331f54..bb4c5c95e 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/AbstractPrimitiveType.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/AbstractPrimitiveType.java @@ -28,6 +28,7 @@ import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; abstract class AbstractPrimitiveType implements EdmPrimitiveType { protected String uriPrefix = ""; + protected String uriSuffix = ""; @Override @@ -37,8 +38,9 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType { @Override public boolean validate(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, - final Boolean isUnicode) { + final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, + final Boolean isUnicode) { + try { valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, getDefaultType()); return true; @@ -49,9 +51,10 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType { @Override public final T valueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) - throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) + throws EdmPrimitiveTypeException { + if (value == null) { if (isNullable != null && !isNullable) { throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); @@ -62,13 +65,13 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType { } protected abstract T internalValueOfString(String value, - Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode, - Class returnType) throws EdmPrimitiveTypeException; + Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode, + Class returnType) throws EdmPrimitiveTypeException; @Override public final String valueToString(final Object value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (value == null) { if (isNullable != null && !isNullable) { throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); @@ -79,13 +82,16 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType { } protected abstract String internalValueToString(T value, - Boolean isNullable, Integer maxLength, Integer precision, Integer scale, - Boolean isUnicode) throws EdmPrimitiveTypeException; + Boolean isNullable, Integer maxLength, Integer precision, Integer scale, + Boolean isUnicode) throws EdmPrimitiveTypeException; @Override public String toUriLiteral(final String literal) { - return literal == null ? null : - uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix; + return literal == null + ? null + : uriPrefix.isEmpty() && uriSuffix.isEmpty() + ? literal + : uriPrefix + literal + uriSuffix; } @Override @@ -95,7 +101,8 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType { } else if (uriPrefix.isEmpty() && uriSuffix.isEmpty()) { return literal; } else if (literal.length() >= uriPrefix.length() + uriSuffix.length() - && literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) { + && literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) { + return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length()); } else { throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)"); diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBinary.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBinary.java index a738d5d6b..f86b9fd5a 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBinary.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBinary.java @@ -26,14 +26,15 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; */ public class EdmBinary extends SingletonPrimitiveType { - private static final EdmBinary instance = new EdmBinary(); + private static final EdmBinary INSTANCE = new EdmBinary(); + { uriPrefix = "binary'"; uriSuffix = "'"; } public static EdmBinary getInstance() { - return instance; + return INSTANCE; } @Override @@ -43,31 +44,33 @@ public class EdmBinary extends SingletonPrimitiveType { @Override public boolean validate(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) { - return value == null ? - isNullable == null || isNullable : - Base64.isBase64(value) && validateMaxLength(value, maxLength); + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) { + + return value == null + ? isNullable == null || isNullable + : Base64.isBase64(value) && validateMaxLength(value, maxLength); } private static boolean validateMaxLength(final String value, final Integer maxLength) { - return maxLength == null ? true : - // Every three bytes are represented as four base-64 characters. - // Additionally, there could be up to two padding "=" characters - // if the number of bytes is not a multiple of three. - maxLength >= value.length() * 3 / 4 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0); + return maxLength == null ? true + : // Every three bytes are represented as four base-64 characters. + // Additionally, there could be up to two padding "=" characters + // if the number of bytes is not a multiple of three. + maxLength >= value.length() * 3 / 4 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0); } @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + if (!Base64.isBase64(value)) { throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); } if (!validateMaxLength(value, maxLength)) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); } final byte[] result = Base64.decodeBase64(value); @@ -75,7 +78,7 @@ public class EdmBinary extends SingletonPrimitiveType { if (returnType.isAssignableFrom(byte[].class)) { return returnType.cast(result); } else if (returnType.isAssignableFrom(Byte[].class)) { - Byte[] byteArray = new Byte[result.length]; + final Byte[] byteArray = new Byte[result.length]; for (int i = 0; i < result.length; i++) { byteArray[i] = result[i]; } @@ -87,8 +90,9 @@ public class EdmBinary extends SingletonPrimitiveType { @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + byte[] byteArrayValue; if (value instanceof byte[]) { byteArrayValue = (byte[]) value; @@ -100,12 +104,12 @@ public class EdmBinary extends SingletonPrimitiveType { } } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } if (maxLength != null && byteArrayValue.length > maxLength) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); + "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); } return Base64.encodeBase64URLSafeString(byteArrayValue); diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBoolean.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBoolean.java index 68298f398..e32400083 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBoolean.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBoolean.java @@ -25,10 +25,10 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; */ public final class EdmBoolean extends SingletonPrimitiveType { - private static final EdmBoolean instance = new EdmBoolean(); + private static final EdmBoolean INSTANCE = new EdmBoolean(); public static EdmBoolean getInstance() { - return instance; + return INSTANCE; } @Override @@ -38,8 +38,9 @@ public final class EdmBoolean extends SingletonPrimitiveType { @Override public boolean validate(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) { + return value == null ? isNullable == null || isNullable : validateLiteral(value); } @@ -49,30 +50,32 @@ public final class EdmBoolean extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + if (validateLiteral(value)) { if (returnType.isAssignableFrom(Boolean.class)) { return returnType.cast(Boolean.valueOf("true".equals(value))); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); } } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + if (value instanceof Boolean) { return Boolean.toString((Boolean) value); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } } } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmByte.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmByte.java index ff4121452..711e9fa9f 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmByte.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmByte.java @@ -28,16 +28,16 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; */ public final class EdmByte extends SingletonPrimitiveType { - private static final EdmByte instance = new EdmByte(); + private static final EdmByte INSTANCE = new EdmByte(); public static EdmByte getInstance() { - return instance; + return INSTANCE; } @Override public boolean isCompatible(final EdmPrimitiveType primitiveType) { return primitiveType instanceof Uint7 - || primitiveType instanceof EdmByte; + || primitiveType instanceof EdmByte; } @Override @@ -47,41 +47,43 @@ public final class EdmByte extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + Short valueShort; try { valueShort = Short.parseShort(value); } catch (final NumberFormatException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); } if (valueShort < 0 || valueShort >= 1 << Byte.SIZE) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); } try { return EdmInt64.convertNumber(valueShort, returnType); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) { if (((Number) value).longValue() >= 0 && ((Number) value).longValue() < 1 << Byte.SIZE) { return value.toString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); } } else if (value instanceof BigInteger) { if (((BigInteger) value).compareTo(BigInteger.ZERO) >= 0 @@ -89,11 +91,11 @@ public final class EdmByte extends SingletonPrimitiveType { return value.toString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); } } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } } } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDate.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDate.java index d3523ea5b..e13fb7b44 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDate.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDate.java @@ -30,12 +30,12 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; */ public final class EdmDate extends SingletonPrimitiveType { - private static final Pattern PATTERN = Pattern.compile( - "(-?\\p{Digit}{4,})-(\\p{Digit}{2})-(\\p{Digit}{2})"); - private static final EdmDate instance = new EdmDate(); + private static final Pattern PATTERN = Pattern.compile("(-?\\p{Digit}{4,})-(\\p{Digit}{2})-(\\p{Digit}{2})"); + + private static final EdmDate INSTANCE = new EdmDate(); public static EdmDate getInstance() { - return instance; + return INSTANCE; } @Override @@ -45,9 +45,10 @@ public final class EdmDate extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { - Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + + final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT")); dateTimeValue.clear(); final Matcher matcher = PATTERN.matcher(value); @@ -56,9 +57,9 @@ public final class EdmDate extends SingletonPrimitiveType { } dateTimeValue.set( - Integer.parseInt(matcher.group(1)), - Byte.parseByte(matcher.group(2)) - 1, // month is zero-based - Byte.parseByte(matcher.group(3))); + Integer.parseInt(matcher.group(1)), + Byte.parseByte(matcher.group(2)) - 1, // month is zero-based + Byte.parseByte(matcher.group(3))); try { return EdmDateTimeOffset.convertDateTime(dateTimeValue, returnType); @@ -66,17 +67,18 @@ public final class EdmDate extends SingletonPrimitiveType { throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Calendar dateTimeValue = EdmDateTimeOffset.createDateTime(value); - StringBuilder result = new StringBuilder(10); // Ten characters are enough for "normal" dates. + final StringBuilder result = new StringBuilder(10); // Ten characters are enough for "normal" dates. final int year = dateTimeValue.get(Calendar.YEAR); if (year < 0 || year >= 10000) { result.append(year); diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDateTimeOffset.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDateTimeOffset.java index 4bde6321e..d7c5ba88d 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDateTimeOffset.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDateTimeOffset.java @@ -32,13 +32,14 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; public final class EdmDateTimeOffset extends SingletonPrimitiveType { private static final Pattern PATTERN = Pattern.compile( - "(-?\\p{Digit}{4,})-(\\p{Digit}{2})-(\\p{Digit}{2})" + "(-?\\p{Digit}{4,})-(\\p{Digit}{2})-(\\p{Digit}{2})" + "T(\\p{Digit}{2}):(\\p{Digit}{2})(?::(\\p{Digit}{2})(\\.(\\p{Digit}{0,3}?)0*)?)?" + "(Z|([-+]\\p{Digit}{2}:\\p{Digit}{2}))?"); - private static final EdmDateTimeOffset instance = new EdmDateTimeOffset(); + + private static final EdmDateTimeOffset INSTANCE = new EdmDateTimeOffset(); public static EdmDateTimeOffset getInstance() { - return instance; + return INSTANCE; } @Override @@ -48,39 +49,40 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Matcher matcher = PATTERN.matcher(value); if (!matcher.matches()) { throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); } final String timeZoneOffset = matcher.group(9) != null && matcher.group(10) != null - && !matcher.group(10).matches("[-+]0+:0+") ? matcher.group(10) : null; - Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT" + timeZoneOffset)); + && !matcher.group(10).matches("[-+]0+:0+") ? matcher.group(10) : null; + final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT" + timeZoneOffset)); if (dateTimeValue.get(Calendar.ZONE_OFFSET) == 0 && timeZoneOffset != null) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); } dateTimeValue.clear(); dateTimeValue.set( - Short.parseShort(matcher.group(1)), - Byte.parseByte(matcher.group(2)) - 1, // month is zero-based - Byte.parseByte(matcher.group(3)), - Byte.parseByte(matcher.group(4)), - Byte.parseByte(matcher.group(5)), - matcher.group(6) == null ? 0 : Byte.parseByte(matcher.group(6))); + Short.parseShort(matcher.group(1)), + Byte.parseByte(matcher.group(2)) - 1, // month is zero-based + Byte.parseByte(matcher.group(3)), + Byte.parseByte(matcher.group(4)), + Byte.parseByte(matcher.group(5)), + matcher.group(6) == null ? 0 : Byte.parseByte(matcher.group(6))); if (matcher.group(7) != null) { if (matcher.group(7).length() == 1 || matcher.group(7).length() > 13) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); } final String decimals = matcher.group(8); if (decimals.length() > (precision == null ? 0 : precision)) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); } final String milliSeconds = decimals + "000".substring(decimals.length()); dateTimeValue.set(Calendar.MILLISECOND, Short.parseShort(milliSeconds)); @@ -90,15 +92,16 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { return convertDateTime(dateTimeValue, returnType); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e"); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } /** * Converts a {@link Calendar} value into the requested return type if possible. + * * @param dateTimeValue the value * @param returnType the class of the returned value; it must be one of {@link Calendar}, {@link Long}, or * {@link Date} @@ -107,7 +110,8 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { * @throws ClassCastException if the return type is not allowed */ protected static T convertDateTime(final Calendar dateTimeValue, final Class returnType) - throws IllegalArgumentException, ClassCastException { + throws IllegalArgumentException, ClassCastException { + // The Calendar class does not check any values until a get method is called, // so we do just that to validate the fields that may have been set, // not because we want to return something else. @@ -131,11 +135,12 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Calendar dateTimeValue = createDateTime(value); - StringBuilder result = new StringBuilder(23); // 23 characters are enough for millisecond precision. + final StringBuilder result = new StringBuilder(23); // 23 characters are enough for millisecond precision. final int year = dateTimeValue.get(Calendar.YEAR); appendTwoDigits(result, year / 100); appendTwoDigits(result, year % 100); @@ -154,11 +159,11 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { appendMilliseconds(result, dateTimeValue.get(Calendar.MILLISECOND), precision); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets), e"); + "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets), e"); } final int offsetInMinutes = (dateTimeValue.get(Calendar.ZONE_OFFSET) - + dateTimeValue.get(Calendar.DST_OFFSET)) / 60 / 1000; + + dateTimeValue.get(Calendar.DST_OFFSET)) / 60 / 1000; final int offsetHours = offsetInMinutes / 60; final int offsetMinutes = Math.abs(offsetInMinutes % 60); final String offsetString = offsetInMinutes == 0 ? "Z" : String.format("%+03d:%02d", offsetHours, offsetMinutes); @@ -169,6 +174,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { /** * Creates a date/time value from the given value. + * * @param value the value as {@link Calendar}, {@link Date}, or {@link Long} * @return the value as {@link Calendar} * @throws EdmPrimitiveTypeException if the type of the value is not supported @@ -188,14 +194,15 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { dateTimeValue.setTimeInMillis((Long) value); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } return dateTimeValue; } /** - * Appends the given number to the given string builder, - * assuming that the number has at most two digits, performance-optimized. + * Appends the given number to the given string builder, assuming that the number has at most two digits, + * performance-optimized. + * * @param result a {@link StringBuilder} * @param number an integer that must satisfy 0 <= number <= 99 */ @@ -205,14 +212,15 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType { } /** - * Appends the given number of milliseconds to the given string builder, - * assuming that the number has at most three digits, performance-optimized. + * Appends the given number of milliseconds to the given string builder, assuming that the number has at most three + * digits, performance-optimized. + * * @param result a {@link StringBuilder} - * @param milliseconds an integer that must satisfy 0 <= milliseconds <= 999 + * @param milliseconds an integer that must satisfy 0 <= milliseconds <= 999 * @param precision the upper limit for decimal digits (optional, defaults to zero) */ protected static void appendMilliseconds(final StringBuilder result, final long milliseconds, - final Integer precision) throws IllegalArgumentException { + final Integer precision) throws IllegalArgumentException { final int digits = milliseconds % 1000 == 0 ? 0 : milliseconds % 100 == 0 ? 1 : milliseconds % 10 == 0 ? 2 : 3; if (digits > 0) { result.append('.'); diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDecimal.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDecimal.java index 5ce58ac66..895d7e57c 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDecimal.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDecimal.java @@ -32,23 +32,24 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; public final class EdmDecimal extends SingletonPrimitiveType { private static final Pattern PATTERN = Pattern.compile("(?:\\+|-)?(?:0*(\\p{Digit}+?))(?:\\.(\\p{Digit}+?)0*)?"); - private static final EdmDecimal instance = new EdmDecimal(); + + private static final EdmDecimal INSTANCE = new EdmDecimal(); public static EdmDecimal getInstance() { - return instance; + return INSTANCE; } @Override public boolean isCompatible(final EdmPrimitiveType primitiveType) { return primitiveType instanceof Uint7 - || primitiveType instanceof EdmByte - || primitiveType instanceof EdmSByte - || primitiveType instanceof EdmInt16 - || primitiveType instanceof EdmInt32 - || primitiveType instanceof EdmInt64 - || primitiveType instanceof EdmSingle - || primitiveType instanceof EdmDouble - || primitiveType instanceof EdmDecimal; + || primitiveType instanceof EdmByte + || primitiveType instanceof EdmSByte + || primitiveType instanceof EdmInt16 + || primitiveType instanceof EdmInt32 + || primitiveType instanceof EdmInt64 + || primitiveType instanceof EdmSingle + || primitiveType instanceof EdmDouble + || primitiveType instanceof EdmDecimal; } @Override @@ -58,11 +59,12 @@ public final class EdmDecimal extends SingletonPrimitiveType { @Override public boolean validate(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) { - return value == null ? - isNullable == null || isNullable : - validateLiteral(value) && validatePrecisionAndScale(value, precision, scale); + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) { + + return value == null + ? isNullable == null || isNullable + : validateLiteral(value) && validatePrecisionAndScale(value, precision, scale); } private static boolean validateLiteral(final String value) { @@ -70,50 +72,53 @@ public final class EdmDecimal extends SingletonPrimitiveType { } private static final boolean validatePrecisionAndScale(final String value, final Integer precision, - final Integer scale) { + final Integer scale) { + final Matcher matcher = PATTERN.matcher(value); matcher.matches(); final int significantIntegerDigits = matcher.group(1).equals("0") ? 0 : matcher.group(1).length(); final int decimals = matcher.group(2) == null ? 0 : matcher.group(2).length(); return (precision == null || precision >= significantIntegerDigits + decimals) - && (decimals <= (scale == null ? 0 : scale)); + && (decimals <= (scale == null ? 0 : scale)); } @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + if (!validateLiteral(value)) { throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); } if (!validatePrecisionAndScale(value, precision, scale)) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); } try { return convertDecimal(new BigDecimal(value), returnType); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } /** * Converts a {@link BigDecimal} value into the requested return type if possible. + * * @param value the value * @param returnType the class of the returned value; it must be one of {@link BigDecimal}, {@link Double}, * {@link Float}, {@link BigInteger}, {@link Long}, {@link Integer}, {@link Short}, or {@link Byte} * @return the converted value - * @throws IllegalArgumentException if the conversion is not possible - * or would lead to loss of data + * @throws IllegalArgumentException if the conversion is not possible or would lead to loss of data * @throws ClassCastException if the return type is not allowed */ protected static T convertDecimal(final BigDecimal value, final Class returnType) - throws IllegalArgumentException, ClassCastException { + throws IllegalArgumentException, ClassCastException { + if (returnType.isAssignableFrom(BigDecimal.class)) { return returnType.cast(value); } else if (returnType.isAssignableFrom(Double.class)) { @@ -153,8 +158,9 @@ public final class EdmDecimal extends SingletonPrimitiveType { @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + String result; if (value instanceof Long || value instanceof Integer || value instanceof Short || value instanceof Byte || value instanceof BigInteger) { @@ -162,31 +168,31 @@ public final class EdmDecimal extends SingletonPrimitiveType { final int digits = result.startsWith("-") ? result.length() - 1 : result.length(); if (precision != null && precision < digits) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); + "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); } } else if (value instanceof Double || value instanceof Float || value instanceof BigDecimal) { BigDecimal bigDecimalValue; try { - bigDecimalValue = value instanceof Double ? BigDecimal.valueOf((Double) value) : - value instanceof Float ? BigDecimal.valueOf((Float) value) : (BigDecimal) value; + bigDecimalValue = value instanceof Double ? BigDecimal.valueOf((Double) value) + : value instanceof Float ? BigDecimal.valueOf((Float) value) : (BigDecimal) value; } catch (final NumberFormatException e) { throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)", e); } - final int digits = bigDecimalValue.scale() >= 0 ? - Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) : - bigDecimalValue.precision() - bigDecimalValue.scale(); + final int digits = bigDecimalValue.scale() >= 0 + ? Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) + : bigDecimalValue.precision() - bigDecimalValue.scale(); if ((precision == null || precision >= digits) && (bigDecimalValue.scale() <= (scale == null ? 0 : scale))) { result = bigDecimalValue.toPlainString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); + "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); } } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } return result; diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDouble.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDouble.java index 13d706dca..f5f46b377 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDouble.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDouble.java @@ -30,26 +30,30 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; public final class EdmDouble extends SingletonPrimitiveType { protected static final String NEGATIVE_INFINITY = "-INF"; + protected static final String POSITIVE_INFINITY = "INF"; + protected static final String NaN = "NaN"; + private static final Pattern PATTERN = Pattern.compile( - "(?:\\+|-)?\\p{Digit}{1,17}(?:\\.\\p{Digit}{1,17})?(?:(?:E|e)(?:\\+|-)?\\p{Digit}{1,3})?"); - private static final EdmDouble instance = new EdmDouble(); + "(?:\\+|-)?\\p{Digit}{1,17}(?:\\.\\p{Digit}{1,17})?(?:(?:E|e)(?:\\+|-)?\\p{Digit}{1,3})?"); + + private static final EdmDouble INSTANCE = new EdmDouble(); public static EdmDouble getInstance() { - return instance; + return INSTANCE; } @Override public boolean isCompatible(final EdmPrimitiveType primitiveType) { return primitiveType instanceof Uint7 - || primitiveType instanceof EdmByte - || primitiveType instanceof EdmSByte - || primitiveType instanceof EdmInt16 - || primitiveType instanceof EdmInt32 - || primitiveType instanceof EdmInt64 - || primitiveType instanceof EdmSingle - || primitiveType instanceof EdmDouble; + || primitiveType instanceof EdmByte + || primitiveType instanceof EdmSByte + || primitiveType instanceof EdmInt16 + || primitiveType instanceof EdmInt32 + || primitiveType instanceof EdmInt64 + || primitiveType instanceof EdmSingle + || primitiveType instanceof EdmDouble; } @Override @@ -59,8 +63,9 @@ public final class EdmDouble extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + Double result = null; BigDecimal bigDecimalValue = null; // Handle special values first. @@ -93,25 +98,25 @@ public final class EdmDouble extends SingletonPrimitiveType { return returnType.cast(result.floatValue()); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)"); } } else { try { return EdmDecimal.convertDecimal(bigDecimalValue, returnType); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (value instanceof Long) { if (Math.abs((Long) value) < 1L << 51) { return value.toString(); @@ -121,11 +126,11 @@ public final class EdmDouble extends SingletonPrimitiveType { } else if (value instanceof Integer || value instanceof Short || value instanceof Byte) { return value.toString(); } else if (value instanceof Double) { - return (Double) value == Double.NEGATIVE_INFINITY ? NEGATIVE_INFINITY : - (Double) value == Double.POSITIVE_INFINITY ? POSITIVE_INFINITY : value.toString(); + return (Double) value == Double.NEGATIVE_INFINITY ? NEGATIVE_INFINITY + : (Double) value == Double.POSITIVE_INFINITY ? POSITIVE_INFINITY : value.toString(); } else if (value instanceof Float) { - return (Float) value == Float.NEGATIVE_INFINITY ? NEGATIVE_INFINITY : - (Float) value == Float.POSITIVE_INFINITY ? POSITIVE_INFINITY : value.toString(); + return (Float) value == Float.NEGATIVE_INFINITY ? NEGATIVE_INFINITY + : (Float) value == Float.POSITIVE_INFINITY ? POSITIVE_INFINITY : value.toString(); } else if (value instanceof BigDecimal) { final double doubleValue = ((BigDecimal) value).doubleValue(); if (!Double.isInfinite(doubleValue) && BigDecimal.valueOf(doubleValue).compareTo((BigDecimal) value) == 0) { @@ -135,7 +140,7 @@ public final class EdmDouble extends SingletonPrimitiveType { } } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } } } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDuration.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDuration.java index 4afcaa8b1..538c74df9 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDuration.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDuration.java @@ -28,16 +28,18 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; public final class EdmDuration extends SingletonPrimitiveType { private static final Pattern PATTERN = Pattern.compile( - "[-+]?P(?:(\\p{Digit}+)D)?(?:T(?:(\\p{Digit}+)H)?(?:(\\p{Digit}+)M)?" + "[-+]?P(?:(\\p{Digit}+)D)?(?:T(?:(\\p{Digit}+)H)?(?:(\\p{Digit}+)M)?" + "(?:(\\p{Digit}+(?:\\.(?:\\p{Digit}+?)0*)?)S)?)?"); - private static final EdmDuration instance = new EdmDuration(); + + private static final EdmDuration INSTANCE = new EdmDuration(); + { uriPrefix = "duration'"; uriSuffix = "'"; } public static EdmDuration getInstance() { - return instance; + return INSTANCE; } @Override @@ -47,46 +49,47 @@ public final class EdmDuration extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { final Matcher matcher = PATTERN.matcher(value); if (!matcher.matches() || matcher.group(1) == null && matcher.group(2) == null && matcher.group(3) == null - && matcher.group(4) == null) { + && matcher.group(4) == null) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)"); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)"); } - BigDecimal result = (matcher.group(1) == null ? BigDecimal.ZERO : - new BigDecimal(matcher.group(1)).multiply(BigDecimal.valueOf(24 * 60 * 60))) - .add(matcher.group(2) == null ? BigDecimal.ZERO : - new BigDecimal(matcher.group(2)).multiply(BigDecimal.valueOf(60 * 60))) - .add(matcher.group(3) == null ? BigDecimal.ZERO : - new BigDecimal(matcher.group(3)).multiply(BigDecimal.valueOf(60))) - .add(matcher.group(4) == null ? BigDecimal.ZERO : new BigDecimal(matcher.group(4))); + BigDecimal result = (matcher.group(1) == null ? BigDecimal.ZERO + : new BigDecimal(matcher.group(1)).multiply(BigDecimal.valueOf(24 * 60 * 60))). + add(matcher.group(2) == null ? BigDecimal.ZERO + : new BigDecimal(matcher.group(2)).multiply(BigDecimal.valueOf(60 * 60))). + add(matcher.group(3) == null ? BigDecimal.ZERO + : new BigDecimal(matcher.group(3)).multiply(BigDecimal.valueOf(60))). + add(matcher.group(4) == null ? BigDecimal.ZERO : new BigDecimal(matcher.group(4))); if (result.scale() <= (precision == null ? 0 : precision)) { result = value.startsWith("-") ? result.negate() : result; } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(literal, facets)"); + "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(literal, facets)"); } try { return EdmDecimal.convertDecimal(result, returnType); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + BigDecimal valueDecimal; if (value instanceof BigDecimal) { valueDecimal = (BigDecimal) value; @@ -96,15 +99,15 @@ public final class EdmDuration extends SingletonPrimitiveType { valueDecimal = new BigDecimal((BigInteger) value); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } if (valueDecimal.scale() > (precision == null ? 0 : precision)) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); + "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); } - StringBuilder result = new StringBuilder(); + final StringBuilder result = new StringBuilder(); if (valueDecimal.signum() == -1) { result.append('-'); valueDecimal = valueDecimal.negate(); diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmGuid.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmGuid.java index 298e1601f..cdcc0b8fb 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmGuid.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmGuid.java @@ -28,10 +28,11 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; public final class EdmGuid extends SingletonPrimitiveType { private static final String PATTERN = "\\p{XDigit}{8}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{4}-\\p{XDigit}{12}"; - private static final EdmGuid instance = new EdmGuid(); + + private static final EdmGuid INSTANCE = new EdmGuid(); public static EdmGuid getInstance() { - return instance; + return INSTANCE; } @Override @@ -41,8 +42,8 @@ public final class EdmGuid extends SingletonPrimitiveType { @Override public boolean validate(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) { return value == null ? isNullable == null || isNullable : validateLiteral(value); } @@ -52,34 +53,36 @@ public final class EdmGuid extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, - final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, + final Class returnType) throws EdmPrimitiveTypeException { + UUID result; if (validateLiteral(value)) { result = UUID.fromString(value); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); } if (returnType.isAssignableFrom(UUID.class)) { return returnType.cast(result); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + if (value instanceof UUID) { return ((UUID) value).toString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } } } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt16.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt16.java index 4f5197e73..ee104cf51 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt16.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt16.java @@ -28,18 +28,18 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; */ public final class EdmInt16 extends SingletonPrimitiveType { - private static final EdmInt16 instance = new EdmInt16(); + private static final EdmInt16 INSTANCE = new EdmInt16(); public static EdmInt16 getInstance() { - return instance; + return INSTANCE; } @Override public boolean isCompatible(final EdmPrimitiveType primitiveType) { return primitiveType instanceof Uint7 - || primitiveType instanceof EdmByte - || primitiveType instanceof EdmSByte - || primitiveType instanceof EdmInt16; + || primitiveType instanceof EdmByte + || primitiveType instanceof EdmSByte + || primitiveType instanceof EdmInt16; } @Override @@ -49,31 +49,31 @@ public final class EdmInt16 extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { Short valueShort; try { valueShort = Short.parseShort(value); } catch (final NumberFormatException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); } try { return EdmInt64.convertNumber(valueShort, returnType); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (value instanceof Byte || value instanceof Short) { return value.toString(); } else if (value instanceof Integer || value instanceof Long) { @@ -82,18 +82,18 @@ public final class EdmInt16 extends SingletonPrimitiveType { return value.toString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); } } else if (value instanceof BigInteger) { if (((BigInteger) value).bitLength() < Short.SIZE) { return value.toString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); } } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } } } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32.java index addc65b30..80b531316 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32.java @@ -28,19 +28,19 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; */ public final class EdmInt32 extends SingletonPrimitiveType { - private static final EdmInt32 instance = new EdmInt32(); + private static final EdmInt32 INSTANCE = new EdmInt32(); public static EdmInt32 getInstance() { - return instance; + return INSTANCE; } @Override public boolean isCompatible(final EdmPrimitiveType primitiveType) { return primitiveType instanceof Uint7 - || primitiveType instanceof EdmByte - || primitiveType instanceof EdmSByte - || primitiveType instanceof EdmInt16 - || primitiveType instanceof EdmInt32; + || primitiveType instanceof EdmByte + || primitiveType instanceof EdmSByte + || primitiveType instanceof EdmInt16 + || primitiveType instanceof EdmInt32; } @Override @@ -50,8 +50,9 @@ public final class EdmInt32 extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + Integer valueInteger; try { valueInteger = Integer.parseInt(value); @@ -63,17 +64,18 @@ public final class EdmInt32 extends SingletonPrimitiveType { return EdmInt64.convertNumber(valueInteger, returnType); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + if (value instanceof Byte || value instanceof Short || value instanceof Integer) { return value.toString(); } else if (value instanceof Long) { @@ -81,18 +83,18 @@ public final class EdmInt32 extends SingletonPrimitiveType { return value.toString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); } } else if (value instanceof BigInteger) { if (((BigInteger) value).bitLength() < Integer.SIZE) { return value.toString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); } } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } } } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64.java index a01fbb3d1..9661b2f9c 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64.java @@ -28,20 +28,20 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; */ public final class EdmInt64 extends SingletonPrimitiveType { - private static final EdmInt64 instance = new EdmInt64(); + private static final EdmInt64 INSTANCE = new EdmInt64(); public static EdmInt64 getInstance() { - return instance; + return INSTANCE; } @Override public boolean isCompatible(final EdmPrimitiveType primitiveType) { return primitiveType instanceof Uint7 - || primitiveType instanceof EdmByte - || primitiveType instanceof EdmSByte - || primitiveType instanceof EdmInt16 - || primitiveType instanceof EdmInt32 - || primitiveType instanceof EdmInt64; + || primitiveType instanceof EdmByte + || primitiveType instanceof EdmSByte + || primitiveType instanceof EdmInt16 + || primitiveType instanceof EdmInt32 + || primitiveType instanceof EdmInt64; } @Override @@ -51,29 +51,31 @@ public final class EdmInt64 extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + Long valueLong; try { valueLong = Long.parseLong(value); } catch (final NumberFormatException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); } try { return convertNumber(valueLong, returnType); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } /** * Converts a whole {@link Number} value into the requested return type if possible. + * * @param value the value * @param returnType the class of the returned value; it must be one of {@link BigInteger}, {@link Long}, * {@link Integer}, {@link Short}, or {@link Byte} @@ -81,8 +83,9 @@ public final class EdmInt64 extends SingletonPrimitiveType { * @throws IllegalArgumentException if the conversion is not possible * @throws ClassCastException if the return type is not allowed */ - public static T convertNumber(final Number value, final Class returnType) throws IllegalArgumentException, - ClassCastException { + public static T convertNumber(final Number value, final Class returnType) + throws IllegalArgumentException, ClassCastException { + if (returnType.isAssignableFrom(Long.class)) { return returnType.cast(value.longValue()); } else if (returnType.isAssignableFrom(BigInteger.class)) { @@ -112,8 +115,9 @@ public final class EdmInt64 extends SingletonPrimitiveType { @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) { return value.toString(); } else if (value instanceof BigInteger) { @@ -121,11 +125,11 @@ public final class EdmInt64 extends SingletonPrimitiveType { return value.toString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); } } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } } } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNull.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNull.java index 8f67cc08f..b5b43ccfa 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNull.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNull.java @@ -26,10 +26,10 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; */ public final class EdmNull extends SingletonPrimitiveType { - private static final EdmNull instance = new EdmNull(); + private static final EdmNull INSTANCE = new EdmNull(); public static EdmNull getInstance() { - return instance; + return INSTANCE; } @Override @@ -49,15 +49,17 @@ public final class EdmNull extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + return null; } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + return null; } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java index a0d3d11bc..88f4379ec 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java @@ -23,11 +23,13 @@ import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; //TODO: Should we delete this typekind and use a facade? public enum EdmPrimitiveTypeKind { + Binary, Boolean, Byte, Date, DateTimeOffset, Decimal, Double, Duration, Guid, Int16, Int32, Int64, SByte, Single, String, TimeOfDay; /** * Returns the {@link FullQualifiedName} for this type kind. + * * @return {@link FullQualifiedName} */ public FullQualifiedName getFullQualifiedName() { @@ -36,44 +38,45 @@ public enum EdmPrimitiveTypeKind { /** * Returns an instance for this {@link EdmPrimitiveTypeKind} in the form of {@link EdmPrimitiveType}. + * * @return {@link EdmPrimitiveType} instance */ public EdmPrimitiveType getEdmPrimitiveTypeInstance() { switch (this) { - case Binary: - return EdmBinary.getInstance(); - case Boolean: - return EdmBoolean.getInstance(); - case Byte: - return EdmByte.getInstance(); - case Date: - return EdmDate.getInstance(); - case DateTimeOffset: - return EdmDateTimeOffset.getInstance(); - case Decimal: - return EdmDecimal.getInstance(); - case Double: - return EdmDouble.getInstance(); - case Duration: - return EdmDuration.getInstance(); - case Guid: - return EdmGuid.getInstance(); - case Int16: - return EdmInt16.getInstance(); - case Int32: - return EdmInt32.getInstance(); - case Int64: - return EdmInt64.getInstance(); - case SByte: - return EdmSByte.getInstance(); - case Single: - return EdmSingle.getInstance(); - case String: - return EdmString.getInstance(); - case TimeOfDay: - return EdmTimeOfDay.getInstance(); - default: - throw new RuntimeException("Wrong type:" + this); + case Binary: + return EdmBinary.getInstance(); + case Boolean: + return EdmBoolean.getInstance(); + case Byte: + return EdmByte.getInstance(); + case Date: + return EdmDate.getInstance(); + case DateTimeOffset: + return EdmDateTimeOffset.getInstance(); + case Decimal: + return EdmDecimal.getInstance(); + case Double: + return EdmDouble.getInstance(); + case Duration: + return EdmDuration.getInstance(); + case Guid: + return EdmGuid.getInstance(); + case Int16: + return EdmInt16.getInstance(); + case Int32: + return EdmInt32.getInstance(); + case Int64: + return EdmInt64.getInstance(); + case SByte: + return EdmSByte.getInstance(); + case Single: + return EdmSingle.getInstance(); + case String: + return EdmString.getInstance(); + case TimeOfDay: + return EdmTimeOfDay.getInstance(); + default: + throw new RuntimeException("Wrong type:" + this); } } } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByte.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByte.java index a64befffe..70ac12d8d 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByte.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByte.java @@ -28,16 +28,16 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; */ public final class EdmSByte extends SingletonPrimitiveType { - private static final EdmSByte instance = new EdmSByte(); + private static final EdmSByte INSTANCE = new EdmSByte(); public static EdmSByte getInstance() { - return instance; + return INSTANCE; } @Override public boolean isCompatible(final EdmPrimitiveType primitiveType) { return primitiveType instanceof Uint7 - || primitiveType instanceof EdmSByte; + || primitiveType instanceof EdmSByte; } @Override @@ -47,28 +47,30 @@ public final class EdmSByte extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + Byte valueByte; try { valueByte = Byte.parseByte(value); } catch (final NumberFormatException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e); } try { return EdmInt64.convertNumber(valueByte, returnType); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + if (value instanceof Byte) { return value.toString(); } else if (value instanceof Short || value instanceof Integer || value instanceof Long) { @@ -76,18 +78,18 @@ public final class EdmSByte extends SingletonPrimitiveType { return value.toString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); } } else if (value instanceof BigInteger) { if (((BigInteger) value).bitLength() < Byte.SIZE) { return value.toString(); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); + "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)"); } } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } } } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingle.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingle.java index 540c4eafb..b2c0363c0 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingle.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingle.java @@ -30,22 +30,23 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; public final class EdmSingle extends SingletonPrimitiveType { private static final Pattern PATTERN = Pattern.compile( - "(?:\\+|-)?\\p{Digit}{1,9}(?:\\.\\p{Digit}{1,9})?(?:(?:E|e)(?:\\+|-)?\\p{Digit}{1,2})?"); - private static final EdmSingle instance = new EdmSingle(); + "(?:\\+|-)?\\p{Digit}{1,9}(?:\\.\\p{Digit}{1,9})?(?:(?:E|e)(?:\\+|-)?\\p{Digit}{1,2})?"); + + private static final EdmSingle INSTANCE = new EdmSingle(); public static EdmSingle getInstance() { - return instance; + return INSTANCE; } @Override public boolean isCompatible(final EdmPrimitiveType primitiveType) { return primitiveType instanceof Uint7 - || primitiveType instanceof EdmByte - || primitiveType instanceof EdmSByte - || primitiveType instanceof EdmInt16 - || primitiveType instanceof EdmInt32 - || primitiveType instanceof EdmInt64 - || primitiveType instanceof EdmSingle; + || primitiveType instanceof EdmByte + || primitiveType instanceof EdmSByte + || primitiveType instanceof EdmInt16 + || primitiveType instanceof EdmInt32 + || primitiveType instanceof EdmInt64 + || primitiveType instanceof EdmSingle; } @Override @@ -55,8 +56,9 @@ public final class EdmSingle extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + Float result = null; BigDecimal bigDecimalValue = null; // Handle special values first. @@ -89,25 +91,26 @@ public final class EdmSingle extends SingletonPrimitiveType { return returnType.cast(result.doubleValue()); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)"); } } else { try { return EdmDecimal.convertDecimal(bigDecimalValue, returnType); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + if (value instanceof Long || value instanceof Integer) { if (Math.abs(((Number) value).longValue()) < 1L << 22) { return value.toString(); @@ -128,8 +131,8 @@ public final class EdmSingle extends SingletonPrimitiveType { } } } else if (value instanceof Float) { - return (Float) value == Float.NEGATIVE_INFINITY ? EdmDouble.NEGATIVE_INFINITY : - (Float) value == Float.POSITIVE_INFINITY ? EdmDouble.POSITIVE_INFINITY : value.toString(); + return (Float) value == Float.NEGATIVE_INFINITY ? EdmDouble.NEGATIVE_INFINITY + : (Float) value == Float.POSITIVE_INFINITY ? EdmDouble.POSITIVE_INFINITY : value.toString(); } else if (value instanceof BigDecimal) { final float floatValue = ((BigDecimal) value).floatValue(); if (!Float.isInfinite(floatValue) && BigDecimal.valueOf(floatValue).compareTo((BigDecimal) value) == 0) { @@ -139,7 +142,7 @@ public final class EdmSingle extends SingletonPrimitiveType { } } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())"); } } } diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmString.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmString.java index c9fcc09ff..8edbc1c75 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmString.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmString.java @@ -28,14 +28,16 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; public final class EdmString extends SingletonPrimitiveType { private static final Pattern PATTERN_ASCII = Pattern.compile("\\p{ASCII}*"); - private static final EdmString instance = new EdmString(); + + private static final EdmString INSTANCE = new EdmString(); + { uriPrefix = "'"; uriSuffix = "'"; } public static EdmString getInstance() { - return instance; + return INSTANCE; } @Override @@ -45,32 +47,34 @@ public final class EdmString extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(value).matches() || maxLength != null && maxLength < value.length()) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); } if (returnType.isAssignableFrom(String.class)) { return returnType.cast(value); } else { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)"); } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final String result = value instanceof String ? (String) value : String.valueOf(value); if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(result).matches() || maxLength != null && maxLength < result.length()) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); + "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)"); } return result; @@ -84,7 +88,7 @@ public final class EdmString extends SingletonPrimitiveType { final int length = literal.length(); - StringBuilder uriLiteral = new StringBuilder(length + 2); + final StringBuilder uriLiteral = new StringBuilder(length + 2); uriLiteral.append(uriPrefix); for (int i = 0; i < length; i++) { final char c = literal.charAt(i); diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDay.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDay.java index 98d49825d..9605fa0ca 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDay.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDay.java @@ -28,11 +28,12 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; public final class EdmTimeOfDay extends SingletonPrimitiveType { private static final Pattern PATTERN = Pattern.compile( - "(\\p{Digit}{2}):(\\p{Digit}{2})(?::(\\p{Digit}{2})(\\.(\\p{Digit}{0,3}?)0*)?)?"); - private static final EdmTimeOfDay instance = new EdmTimeOfDay(); + "(\\p{Digit}{2}):(\\p{Digit}{2})(?::(\\p{Digit}{2})(\\.(\\p{Digit}{0,3}?)0*)?)?"); + + private static final EdmTimeOfDay INSTANCE = new EdmTimeOfDay(); public static EdmTimeOfDay getInstance() { - return instance; + return INSTANCE; } @Override @@ -42,14 +43,15 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + final Matcher matcher = PATTERN.matcher(value); if (!matcher.matches()) { throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)"); } - Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT")); dateTimeValue.clear(); dateTimeValue.set(Calendar.HOUR_OF_DAY, Byte.parseByte(matcher.group(1))); dateTimeValue.set(Calendar.MINUTE, Byte.parseByte(matcher.group(2))); @@ -62,7 +64,7 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType { final String decimals = matcher.group(5); if (decimals.length() > (precision == null ? 0 : precision)) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); + "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)"); } final String milliSeconds = decimals + "000".substring(decimals.length()); dateTimeValue.set(Calendar.MILLISECOND, Short.parseShort(milliSeconds)); @@ -72,20 +74,21 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType { return EdmDateTimeOffset.convertDateTime(dateTimeValue, returnType); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e"); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value), e"); } catch (final ClassCastException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e"); } } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + final Calendar dateTimeValue = EdmDateTimeOffset.createDateTime(value); - StringBuilder result = new StringBuilder(8); // Eight characters are enough for "normal" times. + final StringBuilder result = new StringBuilder(8); // Eight characters are enough for "normal" times. EdmDateTimeOffset.appendTwoDigits(result, dateTimeValue.get(Calendar.HOUR_OF_DAY)); result.append(':'); EdmDateTimeOffset.appendTwoDigits(result, dateTimeValue.get(Calendar.MINUTE)); @@ -96,7 +99,7 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType { EdmDateTimeOffset.appendMilliseconds(result, dateTimeValue.get(Calendar.MILLISECOND), precision); } catch (final IllegalArgumentException e) { throw new EdmPrimitiveTypeException( - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets), e"); + "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets), e"); } return result.toString(); diff --git a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/Uint7.java b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/Uint7.java index 5f55cb94d..3f189653e 100644 --- a/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/Uint7.java +++ b/odata4-lib/odata4-commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/Uint7.java @@ -25,10 +25,10 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; */ public final class Uint7 extends SingletonPrimitiveType { - private static final Uint7 instance = new Uint7(); + private static final Uint7 INSTANCE = new Uint7(); public static Uint7 getInstance() { - return instance; + return INSTANCE; } @Override @@ -48,16 +48,19 @@ public final class Uint7 extends SingletonPrimitiveType { @Override protected T internalValueOfString(final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { - return EdmSByte.getInstance().internalValueOfString(value, isNullable, maxLength, precision, scale, isUnicode, - returnType); + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType) throws EdmPrimitiveTypeException { + + return EdmSByte.getInstance().internalValueOfString( + value, isNullable, maxLength, precision, scale, isUnicode, returnType); } @Override protected String internalValueToString(final T value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { - return EdmSByte.getInstance().internalValueToString(value, isNullable, maxLength, precision, scale, isUnicode); + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { + + return EdmSByte.getInstance().internalValueToString( + value, isNullable, maxLength, precision, scale, isUnicode); } } diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/ActionMapKeyTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/ActionMapKeyTest.java index 51d312643..339b9be56 100644 --- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/ActionMapKeyTest.java +++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/ActionMapKeyTest.java @@ -29,6 +29,7 @@ import org.junit.Test; public class ActionMapKeyTest { private final FullQualifiedName fqn = new FullQualifiedName("namespace", "name"); + private final FullQualifiedName fqnType = new FullQualifiedName("namespace2", "name2"); @Test @@ -44,7 +45,7 @@ public class ActionMapKeyTest { } private void createAndCheckForEdmException(final FullQualifiedName fqn, final FullQualifiedName typeName, - final Boolean collection) { + final Boolean collection) { try { new ActionMapKey(fqn, typeName, collection); } catch (EdmException e) { diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/EdmImplCachingTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/EdmImplCachingTest.java index 8fd439ac6..2888c16ca 100644 --- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/EdmImplCachingTest.java +++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/EdmImplCachingTest.java @@ -46,7 +46,9 @@ import org.junit.Test; public class EdmImplCachingTest { private final FullQualifiedName NAME1 = new FullQualifiedName("testNamespace1", "testName1"); + private final FullQualifiedName NAME2 = new FullQualifiedName("testNamespace2", "testName2"); + private Edm edm; @Test @@ -244,7 +246,8 @@ public class EdmImplCachingTest { edm = new LocalEdm(); } - private class LocalEdm extends EdmImpl { + private class LocalEdm extends AbstractEdmImpl { + @Override public EdmEntityContainer createEntityContainer(final FullQualifiedName fqn) { if (NAME1.equals(fqn) || fqn == null) { @@ -307,7 +310,7 @@ public class EdmImplCachingTest { @Override public EdmAction createBoundAction(final FullQualifiedName fqn, final FullQualifiedName bindingParameterTypeName, - final Boolean isBindingParameterCollection) { + final Boolean isBindingParameterCollection) { if (NAME1.equals(fqn)) { EdmAction action = mock(EdmAction.class); when(action.getNamespace()).thenReturn(fqn.getNamespace()); @@ -324,8 +327,8 @@ public class EdmImplCachingTest { @Override public EdmFunction createBoundFunction(final FullQualifiedName fqn, - final FullQualifiedName bindingParameterTypeName, - final Boolean isBindingParameterCollection, final List bindingParameterNames) { + final FullQualifiedName bindingParameterTypeName, + final Boolean isBindingParameterCollection, final List bindingParameterNames) { if (NAME1.equals(fqn)) { EdmFunction function = mock(EdmFunction.class); when(function.getNamespace()).thenReturn(fqn.getNamespace()); diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/EdmImplCallCreateTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/EdmImplCallCreateTest.java index 657e1e8c9..f4f30f3f7 100644 --- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/EdmImplCallCreateTest.java +++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/EdmImplCallCreateTest.java @@ -46,7 +46,9 @@ import org.junit.Test; public class EdmImplCallCreateTest { private final FullQualifiedName FQN = new FullQualifiedName("testNamespace", "testName"); + private final FullQualifiedName WRONG_FQN = new FullQualifiedName("wrong", "wrong"); + private Edm edm; @Test @@ -148,7 +150,8 @@ public class EdmImplCallCreateTest { edm = new LocalEdm(); } - private class LocalEdm extends EdmImpl { + private class LocalEdm extends AbstractEdmImpl { + @Override public EdmEntityContainer createEntityContainer(final FullQualifiedName fqn) { if (fqn == null || FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) { @@ -206,7 +209,7 @@ public class EdmImplCallCreateTest { @Override public EdmAction createBoundAction(final FullQualifiedName fqn, final FullQualifiedName bindingParameterTypeName, - final Boolean isBindingParameterCollection) { + final Boolean isBindingParameterCollection) { if (FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) { EdmAction action = mock(EdmAction.class); when(action.getNamespace()).thenReturn(fqn.getNamespace()); @@ -218,8 +221,8 @@ public class EdmImplCallCreateTest { @Override public EdmFunction createBoundFunction(final FullQualifiedName fqn, - final FullQualifiedName bindingParameterTypeName, - final Boolean isBindingParameterCollection, final List bindingParameterNames) { + final FullQualifiedName bindingParameterTypeName, + final Boolean isBindingParameterCollection, final List bindingParameterNames) { if (FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) { EdmFunction function = mock(EdmFunction.class); when(function.getNamespace()).thenReturn(fqn.getNamespace()); diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/FunctionMapKeyTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/FunctionMapKeyTest.java index 21139a0bd..640be3958 100644 --- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/FunctionMapKeyTest.java +++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/FunctionMapKeyTest.java @@ -30,6 +30,7 @@ import org.junit.Test; public class FunctionMapKeyTest { private final FullQualifiedName fqn = new FullQualifiedName("namespace", "name"); + private final FullQualifiedName fqnType = new FullQualifiedName("namespace2", "name2"); @Test diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingleTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingleTest.java index 99a7fe1ed..366a7a61d 100644 --- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingleTest.java +++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingleTest.java @@ -86,23 +86,23 @@ public class EdmSingleTest extends PrimitiveTypeBaseTest { assertEquals(Float.valueOf(42.0F), instance.valueOfString("42", null, null, null, null, null, Float.class)); assertEquals(Float.valueOf(2.2E38F), instance.valueOfString("22E37", null, null, null, null, null, Float.class)); assertEquals(Float.valueOf(1.23E-38F), instance.valueOfString("12.3E-39", null, null, null, null, null, - Float.class)); + Float.class)); assertEquals(BigDecimal.TEN, instance.valueOfString("10", null, null, null, null, null, BigDecimal.class)); assertEquals(Byte.valueOf((byte) 0), instance.valueOfString("0", null, null, null, null, null, Byte.class)); assertEquals(Short.valueOf((short) 1), instance.valueOfString("1.00", null, null, null, null, null, Short.class)); assertEquals(Integer.valueOf(42), instance.valueOfString("4.2E1", null, null, null, null, null, Integer.class)); assertEquals(Long.valueOf(12345678), instance.valueOfString("12345.678E+03", null, null, null, null, null, - Long.class)); + Long.class)); assertEquals(Float.valueOf(Float.NaN), instance.valueOfString("NaN", null, null, null, null, null, Float.class)); assertEquals(Float.valueOf(Float.NEGATIVE_INFINITY), instance.valueOfString("-INF", null, null, null, null, null, - Float.class)); + Float.class)); assertEquals(Float.valueOf(Float.POSITIVE_INFINITY), instance.valueOfString("INF", null, null, null, null, null, - Float.class)); + Float.class)); assertEquals(Double.valueOf(Double.NaN), instance.valueOfString("NaN", null, null, null, null, null, - Double.class)); + Double.class)); assertEquals(Double.valueOf(Double.NEGATIVE_INFINITY), instance.valueOfString("-INF", null, null, null, null, null, - Double.class)); + Double.class)); expectContentErrorInValueOfString(instance, "0."); expectContentErrorInValueOfString(instance, ".0"); diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDayTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDayTest.java index 96e8dfac9..ae342f45c 100644 --- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDayTest.java +++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDayTest.java @@ -69,7 +69,7 @@ public class EdmTimeOfDayTest extends PrimitiveTypeBaseTest { assertEquals(dateTime, instance.valueOfString("00:00", null, null, null, null, null, Calendar.class)); assertEquals(dateTime, instance.valueOfString("00:00:00", null, null, null, null, null, Calendar.class)); assertEquals(dateTime, instance.valueOfString("00:00:00.000000000000", null, null, null, null, null, - Calendar.class)); + Calendar.class)); dateTime.set(Calendar.MILLISECOND, 999); assertEquals(dateTime, instance.valueOfString("00:00:00.999", null, null, 3, null, null, Calendar.class)); diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java index c107aa685..a1949ea6b 100644 --- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java +++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java @@ -28,9 +28,9 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException; public abstract class PrimitiveTypeBaseTest { private void expectErrorInValueToString(final EdmPrimitiveType instance, - final Object value, final Boolean isNullable, final Integer maxLength, - final Integer precision, final Integer scale, final Boolean isUnicode, - final String messageReferenceString) { + final Object value, final Boolean isNullable, final Integer maxLength, + final Integer precision, final Integer scale, final Boolean isUnicode, + final String messageReferenceString) { try { instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode); fail("Expected exception not thrown"); @@ -41,7 +41,7 @@ public abstract class PrimitiveTypeBaseTest { } private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value, - final String messageReference) { + final String messageReference) { expectErrorInValueToString(instance, value, null, null, null, null, null, messageReference); } @@ -54,20 +54,22 @@ public abstract class PrimitiveTypeBaseTest { } protected void expectFacetsErrorInValueToString(final EdmPrimitiveType instance, final Object value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) { expectErrorInValueToString(instance, value, isNullable, maxLength, precision, scale, isUnicode, - "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED"); + "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED"); } protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) { expectErrorInValueToString(instance, null, false, null, null, null, null, - "EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); + "EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED"); } private void expectErrorInValueOfString(final EdmPrimitiveType instance, - final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode, final Class returnType, final String messageReferenceString) { + final String value, final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode, final Class returnType, + final String messageReferenceString) { + try { instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType); fail("Expected exception not thrown"); @@ -79,30 +81,30 @@ public abstract class PrimitiveTypeBaseTest { protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) { expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class, - "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED"); + "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED"); } protected void expectUnconvertibleErrorInValueOfString(final EdmPrimitiveType instance, final String value, - final Class type) { + final Class type) { expectErrorInValueOfString(instance, value, null, null, null, null, null, type, - "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE"); + "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE"); } protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) { expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(), - "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT"); + "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT"); } protected void expectFacetsErrorInValueOfString(final EdmPrimitiveType instance, final String value, - final Boolean isNullable, final Integer maxLength, final Integer precision, - final Integer scale, final Boolean isUnicode) { + final Boolean isNullable, final Integer maxLength, final Integer precision, + final Integer scale, final Boolean isUnicode) { expectErrorInValueOfString(instance, value, isNullable, maxLength, precision, scale, isUnicode, - instance.getDefaultType(), "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED"); + instance.getDefaultType(), "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED"); } protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) { expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(), - "EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); + "EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED"); } protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) { diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java index 3a2442e49..49a14fc5c 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmProviderImpl.java @@ -35,7 +35,7 @@ import org.apache.olingo.odata4.commons.api.edm.EdmFunction; import org.apache.olingo.odata4.commons.api.edm.EdmServiceMetadata; import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -import org.apache.olingo.odata4.commons.core.edm.EdmImpl; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmImpl; import org.apache.olingo.odata4.server.api.edm.provider.Action; import org.apache.olingo.odata4.server.api.edm.provider.AliasInfo; import org.apache.olingo.odata4.server.api.edm.provider.ComplexType; @@ -47,7 +47,7 @@ import org.apache.olingo.odata4.server.api.edm.provider.Function; import org.apache.olingo.odata4.server.api.edm.provider.Parameter; import org.apache.olingo.odata4.server.api.edm.provider.TypeDefinition; -public class EdmProviderImpl extends EdmImpl { +public class EdmProviderImpl extends AbstractEdmImpl { private final EdmProvider provider; private final Map> actionsMap = new HashMap>(); diff --git a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java index 7ea2fc31e..e94d8a0b6 100644 --- a/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java +++ b/odata4-lib/odata4-server-core/src/main/java/org/apache/olingo/odata4/server/core/edm/provider/EdmReturnTypeImpl.java @@ -23,17 +23,17 @@ import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType; import org.apache.olingo.odata4.commons.api.edm.EdmReturnType; import org.apache.olingo.odata4.commons.api.edm.EdmType; import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName; -import org.apache.olingo.odata4.commons.core.edm.EdmImpl; +import org.apache.olingo.odata4.commons.core.edm.AbstractEdmImpl; import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind; import org.apache.olingo.odata4.server.api.edm.provider.ReturnType; public class EdmReturnTypeImpl implements EdmReturnType { - private final EdmImpl edm; + private final AbstractEdmImpl edm; private final ReturnType returnType; private EdmType typeImpl; - public EdmReturnTypeImpl(final EdmImpl edm, final ReturnType returnType) { + public EdmReturnTypeImpl(final AbstractEdmImpl edm, final ReturnType returnType) { this.edm = edm; this.returnType = returnType; }