mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-07 00:59:08 +00:00
White noise: formatting, some missing final, etc
This commit is contained in:
parent
1ef04b3249
commit
3cee9228d9
@ -23,8 +23,6 @@ import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* This class is a container for the supported ODataServiceVersions.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ODataServiceVersion {
|
||||
|
||||
|
@ -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<FullQualifiedName, EdmEntityContainer> entityContainers
|
||||
= new HashMap<FullQualifiedName, EdmEntityContainer>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmEnumType> enumTypes
|
||||
= new HashMap<FullQualifiedName, EdmEnumType>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmTypeDefinition> typeDefinitions
|
||||
= new HashMap<FullQualifiedName, EdmTypeDefinition>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmEntityType> entityTypes
|
||||
= new HashMap<FullQualifiedName, EdmEntityType>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmComplexType> complexTypes
|
||||
= new HashMap<FullQualifiedName, EdmComplexType>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmAction> unboundActions
|
||||
= new HashMap<FullQualifiedName, EdmAction>();
|
||||
|
||||
private final Map<FunctionMapKey, EdmFunction> unboundFunctions
|
||||
= new HashMap<FunctionMapKey, EdmFunction>();
|
||||
|
||||
private final Map<ActionMapKey, EdmAction> boundActions
|
||||
= new HashMap<ActionMapKey, EdmAction>();
|
||||
|
||||
private final Map<FunctionMapKey, EdmFunction> boundFunctions
|
||||
= new HashMap<FunctionMapKey, EdmFunction>();
|
||||
|
||||
private final Map<FullQualifiedName, EdmEntityContainer> entityContainers =
|
||||
new HashMap<FullQualifiedName, EdmEntityContainer>();
|
||||
private final Map<FullQualifiedName, EdmEnumType> enumTypes = new HashMap<FullQualifiedName, EdmEnumType>();
|
||||
private final Map<FullQualifiedName, EdmTypeDefinition> typeDefinitions =
|
||||
new HashMap<FullQualifiedName, EdmTypeDefinition>();
|
||||
private final Map<FullQualifiedName, EdmEntityType> entityTypes = new HashMap<FullQualifiedName, EdmEntityType>();
|
||||
private final Map<FullQualifiedName, EdmComplexType> complexTypes = new HashMap<FullQualifiedName, EdmComplexType>();
|
||||
private final Map<FullQualifiedName, EdmAction> unboundActions = new HashMap<FullQualifiedName, EdmAction>();
|
||||
private final Map<FunctionMapKey, EdmFunction> unboundFunctions = new HashMap<FunctionMapKey, EdmFunction>();
|
||||
private final Map<ActionMapKey, EdmAction> boundActions = new HashMap<ActionMapKey, EdmAction>();
|
||||
private final Map<FunctionMapKey, EdmFunction> boundFunctions = new HashMap<FunctionMapKey, EdmFunction>();
|
||||
private EdmServiceMetadata serviceMetadata;
|
||||
|
||||
private Map<String, String> 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);
|
||||
@ -120,51 +137,56 @@ public abstract class EdmImpl implements Edm {
|
||||
@Override
|
||||
public EdmAction getAction(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName,
|
||||
final Boolean isBindingParameterCollection) {
|
||||
FullQualifiedName actionFqn = resolvePossibleAlias(actionName);
|
||||
|
||||
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<String> parameterNames) {
|
||||
FullQualifiedName functionFqn = resolvePossibleAlias(functionName);
|
||||
|
||||
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);
|
||||
@ -172,8 +194,9 @@ public abstract class EdmImpl implements Edm {
|
||||
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;
|
@ -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) {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -28,12 +28,16 @@ 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<String> parameterNames;
|
||||
|
||||
public FunctionMapKey(final FullQualifiedName functionName, final FullQualifiedName bindingParameterTypeName,
|
||||
final Boolean isBindingParameterCollection, final List<String> parameterNames) {
|
||||
|
||||
this.functionName = functionName;
|
||||
if (bindingParameterTypeName != null && isBindingParameterCollection == null) {
|
||||
throw new EdmException(
|
||||
@ -85,12 +89,14 @@ 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 (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()) {
|
||||
@ -102,8 +108,6 @@ public class FunctionMapKey {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
@ -39,6 +40,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
|
||||
public boolean validate(final String value,
|
||||
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;
|
||||
@ -52,6 +54,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType)
|
||||
throws EdmPrimitiveTypeException {
|
||||
|
||||
if (value == null) {
|
||||
if (isNullable != null && !isNullable) {
|
||||
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED");
|
||||
@ -84,8 +87,11 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
|
||||
|
||||
@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
|
||||
@ -96,6 +102,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
|
||||
return literal;
|
||||
} else if (literal.length() >= uriPrefix.length() + uriSuffix.length()
|
||||
&& 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)");
|
||||
|
@ -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
|
||||
@ -45,14 +46,15 @@ public class EdmBinary extends SingletonPrimitiveType {
|
||||
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);
|
||||
|
||||
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.
|
||||
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);
|
||||
@ -62,6 +64,7 @@ public class EdmBinary extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (!Base64.isBase64(value)) {
|
||||
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(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];
|
||||
}
|
||||
@ -89,6 +92,7 @@ public class EdmBinary extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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;
|
||||
|
@ -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
|
||||
@ -40,6 +40,7 @@ public final class EdmBoolean extends SingletonPrimitiveType {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -51,6 +52,7 @@ public final class EdmBoolean extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (validateLiteral(value)) {
|
||||
if (returnType.isAssignableFrom(Boolean.class)) {
|
||||
return returnType.cast(Boolean.valueOf("true".equals(value)));
|
||||
@ -68,6 +70,7 @@ public final class EdmBoolean extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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 {
|
||||
|
@ -28,10 +28,10 @@ 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
|
||||
@ -49,6 +49,7 @@ public final class EdmByte extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
Short valueShort;
|
||||
try {
|
||||
valueShort = Short.parseShort(value);
|
||||
@ -76,6 +77,7 @@ public final class EdmByte extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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();
|
||||
|
@ -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
|
||||
@ -47,7 +47,8 @@ public final class EdmDate extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
||||
dateTimeValue.clear();
|
||||
|
||||
final Matcher matcher = PATTERN.matcher(value);
|
||||
@ -74,9 +75,10 @@ public final class EdmDate extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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);
|
||||
|
@ -35,10 +35,11 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
||||
"(-?\\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
|
||||
@ -50,6 +51,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
final Matcher matcher = PATTERN.matcher(value);
|
||||
if (!matcher.matches()) {
|
||||
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
|
||||
@ -57,7 +59,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
||||
|
||||
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));
|
||||
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)");
|
||||
@ -99,6 +101,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
||||
|
||||
/**
|
||||
* 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}
|
||||
@ -108,6 +111,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
||||
*/
|
||||
protected static <T> T convertDateTime(final Calendar dateTimeValue, final Class<T> returnType)
|
||||
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.
|
||||
@ -133,9 +137,10 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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);
|
||||
@ -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
|
||||
@ -194,8 +200,9 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 <code>0 <= number <= 99</code>
|
||||
*/
|
||||
@ -205,10 +212,11 @@ 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 <code>0 <= milliseconds <= 999</code>
|
||||
* @param milliseconds an integer that must satisfy <code>0 <= milliseconds <= 999</code>
|
||||
* @param precision the upper limit for decimal digits (optional, defaults to zero)
|
||||
*/
|
||||
protected static void appendMilliseconds(final StringBuilder result, final long milliseconds,
|
||||
|
@ -32,10 +32,11 @@ 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
|
||||
@ -60,9 +61,10 @@ public final class EdmDecimal extends SingletonPrimitiveType {
|
||||
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);
|
||||
|
||||
return value == null
|
||||
? isNullable == null || isNullable
|
||||
: validateLiteral(value) && validatePrecisionAndScale(value, precision, scale);
|
||||
}
|
||||
|
||||
private static boolean validateLiteral(final String value) {
|
||||
@ -71,6 +73,7 @@ public final class EdmDecimal extends SingletonPrimitiveType {
|
||||
|
||||
private static final boolean validatePrecisionAndScale(final String value, final Integer precision,
|
||||
final Integer scale) {
|
||||
|
||||
final Matcher matcher = PATTERN.matcher(value);
|
||||
matcher.matches();
|
||||
final int significantIntegerDigits = matcher.group(1).equals("0") ? 0 : matcher.group(1).length();
|
||||
@ -83,6 +86,7 @@ public final class EdmDecimal extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (!validateLiteral(value)) {
|
||||
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
|
||||
}
|
||||
@ -104,16 +108,17 @@ public final class EdmDecimal extends SingletonPrimitiveType {
|
||||
|
||||
/**
|
||||
* 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> T convertDecimal(final BigDecimal value, final Class<T> returnType)
|
||||
throws IllegalArgumentException, ClassCastException {
|
||||
|
||||
if (returnType.isAssignableFrom(BigDecimal.class)) {
|
||||
return returnType.cast(value);
|
||||
} else if (returnType.isAssignableFrom(Double.class)) {
|
||||
@ -155,6 +160,7 @@ public final class EdmDecimal extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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) {
|
||||
@ -168,15 +174,15 @@ public final class EdmDecimal extends SingletonPrimitiveType {
|
||||
} 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 {
|
||||
|
@ -30,14 +30,18 @@ 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();
|
||||
|
||||
private static final EdmDouble INSTANCE = new EdmDouble();
|
||||
|
||||
public static EdmDouble getInstance() {
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,6 +65,7 @@ public final class EdmDouble extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
Double result = null;
|
||||
BigDecimal bigDecimalValue = null;
|
||||
// Handle special values first.
|
||||
@ -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) {
|
||||
|
@ -30,14 +30,16 @@ 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{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
|
||||
@ -57,13 +59,13 @@ public final class EdmDuration extends SingletonPrimitiveType {
|
||||
"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;
|
||||
@ -87,6 +89,7 @@ public final class EdmDuration extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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;
|
||||
@ -104,7 +107,7 @@ public final class EdmDuration extends SingletonPrimitiveType {
|
||||
"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();
|
||||
|
@ -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
|
||||
@ -55,6 +56,7 @@ public final class EdmGuid extends SingletonPrimitiveType {
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode,
|
||||
final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
UUID result;
|
||||
if (validateLiteral(value)) {
|
||||
result = UUID.fromString(value);
|
||||
@ -75,6 +77,7 @@ public final class EdmGuid extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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 {
|
||||
|
@ -28,10 +28,10 @@ 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
|
||||
|
@ -28,10 +28,10 @@ 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
|
||||
@ -52,6 +52,7 @@ public final class EdmInt32 extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
Integer valueInteger;
|
||||
try {
|
||||
valueInteger = Integer.parseInt(value);
|
||||
@ -74,6 +75,7 @@ public final class EdmInt32 extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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) {
|
||||
|
@ -28,10 +28,10 @@ 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
|
||||
@ -53,6 +53,7 @@ public final class EdmInt64 extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
Long valueLong;
|
||||
try {
|
||||
valueLong = Long.parseLong(value);
|
||||
@ -74,6 +75,7 @@ public final class EdmInt64 extends SingletonPrimitiveType {
|
||||
|
||||
/**
|
||||
* 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> T convertNumber(final Number value, final Class<T> returnType) throws IllegalArgumentException,
|
||||
ClassCastException {
|
||||
public static <T> T convertNumber(final Number value, final Class<T> returnType)
|
||||
throws IllegalArgumentException, ClassCastException {
|
||||
|
||||
if (returnType.isAssignableFrom(Long.class)) {
|
||||
return returnType.cast(value.longValue());
|
||||
} else if (returnType.isAssignableFrom(BigInteger.class)) {
|
||||
@ -114,6 +117,7 @@ public final class EdmInt64 extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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) {
|
||||
|
@ -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
|
||||
@ -51,6 +51,7 @@ public final class EdmNull extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -58,6 +59,7 @@ public final class EdmNull extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -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,6 +38,7 @@ public enum EdmPrimitiveTypeKind {
|
||||
|
||||
/**
|
||||
* Returns an instance for this {@link EdmPrimitiveTypeKind} in the form of {@link EdmPrimitiveType}.
|
||||
*
|
||||
* @return {@link EdmPrimitiveType} instance
|
||||
*/
|
||||
public EdmPrimitiveType getEdmPrimitiveTypeInstance() {
|
||||
|
@ -28,10 +28,10 @@ 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
|
||||
@ -49,6 +49,7 @@ public final class EdmSByte extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
Byte valueByte;
|
||||
try {
|
||||
valueByte = Byte.parseByte(value);
|
||||
@ -69,6 +70,7 @@ public final class EdmSByte extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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) {
|
||||
|
@ -31,10 +31,11 @@ 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();
|
||||
|
||||
private static final EdmSingle INSTANCE = new EdmSingle();
|
||||
|
||||
public static EdmSingle getInstance() {
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,6 +58,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
Float result = null;
|
||||
BigDecimal bigDecimalValue = null;
|
||||
// Handle special values first.
|
||||
@ -108,6 +110,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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) {
|
||||
|
@ -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
|
||||
@ -47,6 +49,7 @@ public final class EdmString extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
|
||||
if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(value).matches()
|
||||
|| maxLength != null && maxLength < value.length()) {
|
||||
throw new EdmPrimitiveTypeException(
|
||||
@ -65,6 +68,7 @@ public final class EdmString extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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()
|
||||
@ -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);
|
||||
|
@ -29,10 +29,11 @@ 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();
|
||||
|
||||
private static final EdmTimeOfDay INSTANCE = new EdmTimeOfDay();
|
||||
|
||||
public static EdmTimeOfDay getInstance() {
|
||||
return instance;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,12 +45,13 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> 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)));
|
||||
@ -83,9 +85,10 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
|
||||
protected <T> String internalValueToString(final T value,
|
||||
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));
|
||||
|
@ -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
|
||||
@ -50,14 +50,17 @@ public final class Uint7 extends SingletonPrimitiveType {
|
||||
protected <T> T internalValueOfString(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
|
||||
return EdmSByte.getInstance().internalValueOfString(value, isNullable, maxLength, precision, scale, isUnicode,
|
||||
returnType);
|
||||
|
||||
return EdmSByte.getInstance().internalValueOfString(
|
||||
value, isNullable, maxLength, precision, scale, isUnicode, returnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> 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);
|
||||
|
||||
return EdmSByte.getInstance().internalValueToString(
|
||||
value, isNullable, maxLength, precision, scale, isUnicode);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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())) {
|
||||
|
@ -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
|
||||
|
@ -67,7 +67,9 @@ public abstract class PrimitiveTypeBaseTest {
|
||||
|
||||
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 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");
|
||||
|
@ -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<FullQualifiedName, List<Action>> actionsMap = new HashMap<FullQualifiedName, List<Action>>();
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user