You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/03/10 10:02:28 UTC
[12/51] [abbrv] [partial] [OLINGO-192] rename java packages
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBinary.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBinary.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBinary.java
deleted file mode 100644
index f86b9fd..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBinary.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Binary.
- */
-public class EdmBinary extends SingletonPrimitiveType {
-
- private static final EdmBinary INSTANCE = new EdmBinary();
-
- {
- uriPrefix = "binary'";
- uriSuffix = "'";
- }
-
- public static EdmBinary getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return byte[].class;
- }
-
- @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);
- }
-
- 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);
- }
-
- @Override
- 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)");
- }
- if (!validateMaxLength(value, maxLength)) {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
- }
-
- final byte[] result = Base64.decodeBase64(value);
-
- if (returnType.isAssignableFrom(byte[].class)) {
- return returnType.cast(result);
- } else if (returnType.isAssignableFrom(Byte[].class)) {
- final Byte[] byteArray = new Byte[result.length];
- for (int i = 0; i < result.length; i++) {
- byteArray[i] = result[i];
- }
- return returnType.cast(byteArray);
- } else {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(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 {
-
- byte[] byteArrayValue;
- if (value instanceof byte[]) {
- byteArrayValue = (byte[]) value;
- } else if (value instanceof Byte[]) {
- final int length = ((Byte[]) value).length;
- byteArrayValue = new byte[length];
- for (int i = 0; i < length; i++) {
- byteArrayValue[i] = ((Byte[]) value)[i].byteValue();
- }
- } else {
- throw new EdmPrimitiveTypeException(
- "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)");
- }
-
- return Base64.encodeBase64URLSafeString(byteArrayValue);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBoolean.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBoolean.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBoolean.java
deleted file mode 100644
index e324000..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmBoolean.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Boolean.
- */
-public final class EdmBoolean extends SingletonPrimitiveType {
-
- private static final EdmBoolean INSTANCE = new EdmBoolean();
-
- public static EdmBoolean getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Boolean.class;
- }
-
- @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);
- }
-
- private static boolean validateLiteral(final String value) {
- return "true".equals(value) || "false".equals(value);
- }
-
- @Override
- 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)));
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
- }
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
- }
- }
-
- @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 {
-
- if (value instanceof Boolean) {
- return Boolean.toString((Boolean) value);
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmByte.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmByte.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmByte.java
deleted file mode 100644
index 711e9fa..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmByte.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.math.BigInteger;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Byte.
- */
-public final class EdmByte extends SingletonPrimitiveType {
-
- private static final EdmByte INSTANCE = new EdmByte();
-
- public static EdmByte getInstance() {
- return INSTANCE;
- }
-
- @Override
- public boolean isCompatible(final EdmPrimitiveType primitiveType) {
- return primitiveType instanceof Uint7
- || primitiveType instanceof EdmByte;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Short.class;
- }
-
- @Override
- 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);
- } catch (final NumberFormatException e) {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
- }
- if (valueShort < 0 || valueShort >= 1 << Byte.SIZE) {
- throw new EdmPrimitiveTypeException(
- "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");
- } catch (final ClassCastException e) {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
- }
- }
-
- @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 {
-
- 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)");
- }
- } else if (value instanceof BigInteger) {
- if (((BigInteger) value).compareTo(BigInteger.ZERO) >= 0
- && ((BigInteger) value).compareTo(BigInteger.valueOf(1 << Byte.SIZE)) < 0) {
- return value.toString();
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
- }
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDate.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDate.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDate.java
deleted file mode 100644
index e13fb7b..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDate.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.util.Calendar;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Date.
- */
-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();
-
- public static EdmDate getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Calendar.class;
- }
-
- @Override
- 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 Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
- dateTimeValue.clear();
-
- final Matcher matcher = PATTERN.matcher(value);
- if (!matcher.matches()) {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
- }
-
- dateTimeValue.set(
- 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);
- } catch (final IllegalArgumentException e) {
- 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");
- }
- }
-
- @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 {
-
- final Calendar dateTimeValue = EdmDateTimeOffset.createDateTime(value);
-
- 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);
- } else {
- EdmDateTimeOffset.appendTwoDigits(result, (year / 100) % 100);
- EdmDateTimeOffset.appendTwoDigits(result, year % 100);
- }
- result.append('-');
- EdmDateTimeOffset.appendTwoDigits(result, dateTimeValue.get(Calendar.MONTH) + 1); // month is zero-based
- result.append('-');
- EdmDateTimeOffset.appendTwoDigits(result, dateTimeValue.get(Calendar.DAY_OF_MONTH));
- return result.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDateTimeOffset.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDateTimeOffset.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDateTimeOffset.java
deleted file mode 100644
index d7c5ba8..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDateTimeOffset.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type DateTimeOffset.
- */
-public final class EdmDateTimeOffset extends SingletonPrimitiveType {
-
- private static final Pattern PATTERN = Pattern.compile(
- "(-?\\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();
-
- public static EdmDateTimeOffset getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Calendar.class;
- }
-
- @Override
- 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)");
- }
-
- final String timeZoneOffset = matcher.group(9) != null && matcher.group(10) != null
- && !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)");
- }
- 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)));
-
- 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)");
- }
- final String decimals = matcher.group(8);
- if (decimals.length() > (precision == null ? 0 : precision)) {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
- }
- final String milliSeconds = decimals + "000".substring(decimals.length());
- dateTimeValue.set(Calendar.MILLISECOND, Short.parseShort(milliSeconds));
- }
-
- try {
- return convertDateTime(dateTimeValue, returnType);
- } catch (final IllegalArgumentException e) {
- 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");
- }
- }
-
- /**
- * 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}
- * @return the converted value
- * @throws IllegalArgumentException if the Calendar value is not valid
- * @throws ClassCastException if the return type is not allowed
- */
- 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.
- // For strict checks, the lenient mode is switched off.
- dateTimeValue.setLenient(false);
-
- if (returnType.isAssignableFrom(Calendar.class)) {
- // Ensure that all fields are recomputed.
- dateTimeValue.get(Calendar.MILLISECOND); // may throw IllegalArgumentException
- // Reset the lenient mode to its default.
- dateTimeValue.setLenient(true);
- return returnType.cast(dateTimeValue);
- } else if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(dateTimeValue.getTimeInMillis()); // may throw IllegalArgumentException
- } else if (returnType.isAssignableFrom(Date.class)) {
- return returnType.cast(dateTimeValue.getTime()); // may throw IllegalArgumentException
- } else {
- throw new ClassCastException("unsupported return type " + returnType.getSimpleName());
- }
- }
-
- @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 {
-
- final Calendar dateTimeValue = createDateTime(value);
-
- 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);
- result.append('-');
- appendTwoDigits(result, dateTimeValue.get(Calendar.MONTH) + 1); // month is zero-based
- result.append('-');
- appendTwoDigits(result, dateTimeValue.get(Calendar.DAY_OF_MONTH));
- result.append('T');
- appendTwoDigits(result, dateTimeValue.get(Calendar.HOUR_OF_DAY));
- result.append(':');
- appendTwoDigits(result, dateTimeValue.get(Calendar.MINUTE));
- result.append(':');
- appendTwoDigits(result, dateTimeValue.get(Calendar.SECOND));
-
- try {
- appendMilliseconds(result, dateTimeValue.get(Calendar.MILLISECOND), precision);
- } catch (final IllegalArgumentException e) {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets), e");
- }
-
- final int offsetInMinutes = (dateTimeValue.get(Calendar.ZONE_OFFSET)
- + 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);
- result.append(offsetString);
-
- return result.toString();
- }
-
- /**
- * 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
- */
- protected static <T> Calendar createDateTime(final T value) throws EdmPrimitiveTypeException {
- Calendar dateTimeValue;
- if (value instanceof Date) {
- // Although java.util.Date, as stated in its documentation,
- // "is intended to reflect coordinated universal time (UTC)",
- // its toString() method uses the default time zone. And so do we.
- dateTimeValue = Calendar.getInstance();
- dateTimeValue.setTime((Date) value);
- } else if (value instanceof Calendar) {
- dateTimeValue = (Calendar) ((Calendar) value).clone();
- } else if (value instanceof Long) {
- dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
- dateTimeValue.setTimeInMillis((Long) value);
- } else {
- throw new EdmPrimitiveTypeException(
- "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.
- *
- * @param result a {@link StringBuilder}
- * @param number an integer that must satisfy <code>0 <= number <= 99</code>
- */
- protected static void appendTwoDigits(final StringBuilder result, final int number) {
- result.append((char) ('0' + number / 10));
- result.append((char) ('0' + number % 10));
- }
-
- /**
- * 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 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 int digits = milliseconds % 1000 == 0 ? 0 : milliseconds % 100 == 0 ? 1 : milliseconds % 10 == 0 ? 2 : 3;
- if (digits > 0) {
- result.append('.');
- for (int d = 100; d > 0; d /= 10) {
- final byte digit = (byte) (milliseconds % (d * 10) / d);
- if (digit > 0 || milliseconds % d > 0) {
- result.append((char) ('0' + digit));
- }
- }
-
- if (precision == null || precision < digits) {
- throw new IllegalArgumentException();
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDecimal.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDecimal.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDecimal.java
deleted file mode 100644
index 895d7e5..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDecimal.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Decimal.
- */
-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();
-
- public static EdmDecimal getInstance() {
- 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;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return BigDecimal.class;
- }
-
- @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);
- }
-
- private static boolean validateLiteral(final String value) {
- return PATTERN.matcher(value).matches();
- }
-
- 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();
- final int decimals = matcher.group(2) == null ? 0 : matcher.group(2).length();
- return (precision == null || precision >= significantIntegerDigits + decimals)
- && (decimals <= (scale == null ? 0 : scale));
- }
-
- @Override
- 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)");
- }
- if (!validatePrecisionAndScale(value, precision, scale)) {
- throw new EdmPrimitiveTypeException(
- "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");
- } catch (final ClassCastException e) {
- throw new EdmPrimitiveTypeException(
- "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 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)) {
- final double doubleValue = value.doubleValue();
- if (BigDecimal.valueOf(doubleValue).compareTo(value) == 0) {
- return returnType.cast(doubleValue);
- } else {
- throw new IllegalArgumentException();
- }
- } else if (returnType.isAssignableFrom(Float.class)) {
- final Float floatValue = value.floatValue();
- if (BigDecimal.valueOf(floatValue).compareTo(value) == 0) {
- return returnType.cast(floatValue);
- } else {
- throw new IllegalArgumentException();
- }
- } else {
- try {
- if (returnType.isAssignableFrom(BigInteger.class)) {
- return returnType.cast(value.toBigIntegerExact());
- } else if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(value.longValueExact());
- } else if (returnType.isAssignableFrom(Integer.class)) {
- return returnType.cast(value.intValueExact());
- } else if (returnType.isAssignableFrom(Short.class)) {
- return returnType.cast(value.shortValueExact());
- } else if (returnType.isAssignableFrom(Byte.class)) {
- return returnType.cast(value.byteValueExact());
- } else {
- throw new ClassCastException("unsupported return type " + returnType.getSimpleName());
- }
- } catch (final ArithmeticException e) {
- throw new IllegalArgumentException(e);
- }
- }
- }
-
- @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 {
-
- String result;
- if (value instanceof Long || value instanceof Integer || value instanceof Short
- || value instanceof Byte || value instanceof BigInteger) {
- result = value.toString();
- 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)");
- }
-
- } 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;
- } 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();
- 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)");
- }
-
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
- }
-
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDouble.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDouble.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDouble.java
deleted file mode 100644
index f5f46b3..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDouble.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.math.BigDecimal;
-import java.util.regex.Pattern;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Double.
- */
-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();
-
- public static EdmDouble getInstance() {
- 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;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Double.class;
- }
-
- @Override
- 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.
- if (value.equals(NEGATIVE_INFINITY)) {
- result = Double.NEGATIVE_INFINITY;
- } else if (value.equals(POSITIVE_INFINITY)) {
- result = Double.POSITIVE_INFINITY;
- } else if (value.equals(NaN)) {
- result = Double.NaN;
- } else {
- // Now only "normal" numbers remain.
- if (!PATTERN.matcher(value).matches()) {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
- }
-
- // The number format is checked above, so we don't have to catch NumberFormatException.
- bigDecimalValue = new BigDecimal(value);
- result = bigDecimalValue.doubleValue();
- // "Real" infinite values have been treated already above, so we can throw an exception
- // if the conversion to a double results in an infinite value.
- if (result.isInfinite() || BigDecimal.valueOf(result).compareTo(bigDecimalValue) != 0) {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
- }
- }
-
- if (returnType.isAssignableFrom(Double.class)) {
- return returnType.cast(result);
- } else if (result.isInfinite() || result.isNaN()) {
- if (returnType.isAssignableFrom(Float.class)) {
- return returnType.cast(result.floatValue());
- } else {
- throw new EdmPrimitiveTypeException(
- "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");
- } catch (final ClassCastException e) {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
- }
- }
- }
-
- @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 {
- if (value instanceof Long) {
- if (Math.abs((Long) value) < 1L << 51) {
- return value.toString();
- } else {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
- }
- } 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();
- } else if (value instanceof Float) {
- 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) {
- return ((BigDecimal) value).toString();
- } else {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
- }
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDuration.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDuration.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDuration.java
deleted file mode 100644
index 538c74d..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmDuration.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-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{Digit}+(?:\\.(?:\\p{Digit}+?)0*)?)S)?)?");
-
- private static final EdmDuration INSTANCE = new EdmDuration();
-
- {
- uriPrefix = "duration'";
- uriSuffix = "'";
- }
-
- public static EdmDuration getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return BigDecimal.class;
- }
-
- @Override
- 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()
- || matcher.group(1) == null && matcher.group(2) == null && matcher.group(3) == null
- && matcher.group(4) == null) {
- throw new EdmPrimitiveTypeException(
- "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)));
-
- 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)");
- }
-
- try {
- return EdmDecimal.convertDecimal(result, returnType);
- } catch (final IllegalArgumentException e) {
- throw new EdmPrimitiveTypeException(
- "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");
- }
- }
-
- @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 {
-
- BigDecimal valueDecimal;
- if (value instanceof BigDecimal) {
- valueDecimal = (BigDecimal) value;
- } else if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
- valueDecimal = BigDecimal.valueOf(((Number) value).longValue());
- } else if (value instanceof BigInteger) {
- valueDecimal = new BigDecimal((BigInteger) value);
- } else {
- throw new EdmPrimitiveTypeException(
- "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)");
- }
-
- final StringBuilder result = new StringBuilder();
- if (valueDecimal.signum() == -1) {
- result.append('-');
- valueDecimal = valueDecimal.negate();
- }
- result.append('P');
- BigInteger seconds = valueDecimal.toBigInteger();
- final BigInteger days = seconds.divide(BigInteger.valueOf(24 * 60 * 60));
- if (!days.equals(BigInteger.ZERO)) {
- result.append(days.toString());
- result.append('D');
- }
- result.append('T');
- seconds = seconds.subtract(days.multiply(BigInteger.valueOf(24 * 60 * 60)));
- final BigInteger hours = seconds.divide(BigInteger.valueOf(60 * 60));
- if (!hours.equals(BigInteger.ZERO)) {
- result.append(hours.toString());
- result.append('H');
- }
- seconds = seconds.subtract(hours.multiply(BigInteger.valueOf(60 * 60)));
- final BigInteger minutes = seconds.divide(BigInteger.valueOf(60));
- if (!minutes.equals(BigInteger.ZERO)) {
- result.append(minutes.toString());
- result.append('M');
- }
- result.append(valueDecimal.remainder(BigDecimal.valueOf(60)).toPlainString());
- result.append('S');
-
- return result.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmGuid.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmGuid.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmGuid.java
deleted file mode 100644
index cdcc0b8..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmGuid.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.util.UUID;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Guid.
- */
-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();
-
- public static EdmGuid getInstance() {
- return INSTANCE;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return UUID.class;
- }
-
- @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);
- }
-
- private boolean validateLiteral(final String value) {
- return value.matches(PATTERN);
- }
-
- @Override
- 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 {
-
- UUID result;
- if (validateLiteral(value)) {
- result = UUID.fromString(value);
- } else {
- throw new EdmPrimitiveTypeException(
- "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)");
- }
- }
-
- @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 {
-
- if (value instanceof UUID) {
- return ((UUID) value).toString();
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt16.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt16.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt16.java
deleted file mode 100644
index ee104cf..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt16.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.math.BigInteger;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Int16.
- */
-public final class EdmInt16 extends SingletonPrimitiveType {
-
- private static final EdmInt16 INSTANCE = new EdmInt16();
-
- public static EdmInt16 getInstance() {
- return INSTANCE;
- }
-
- @Override
- public boolean isCompatible(final EdmPrimitiveType primitiveType) {
- return primitiveType instanceof Uint7
- || primitiveType instanceof EdmByte
- || primitiveType instanceof EdmSByte
- || primitiveType instanceof EdmInt16;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Short.class;
- }
-
- @Override
- 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);
- } catch (final NumberFormatException e) {
- throw new EdmPrimitiveTypeException(
- "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");
- } catch (final ClassCastException e) {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
- }
- }
-
- @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 {
- if (value instanceof Byte || value instanceof Short) {
- return value.toString();
- } else if (value instanceof Integer || value instanceof Long) {
- if (((Number) value).longValue() >= Short.MIN_VALUE
- && ((Number) value).longValue() <= Short.MAX_VALUE) {
- return value.toString();
- } else {
- throw new EdmPrimitiveTypeException(
- "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)");
- }
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32.java
deleted file mode 100644
index 80b5313..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.math.BigInteger;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Int32.
- */
-public final class EdmInt32 extends SingletonPrimitiveType {
-
- private static final EdmInt32 INSTANCE = new EdmInt32();
-
- public static EdmInt32 getInstance() {
- 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;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Integer.class;
- }
-
- @Override
- 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);
- } catch (final NumberFormatException e) {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
- }
-
- try {
- return EdmInt64.convertNumber(valueInteger, returnType);
- } catch (final IllegalArgumentException e) {
- throw new EdmPrimitiveTypeException(
- "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");
- }
- }
-
- @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 {
-
- if (value instanceof Byte || value instanceof Short || value instanceof Integer) {
- return value.toString();
- } else if (value instanceof Long) {
- if ((Long) value >= Integer.MIN_VALUE && (Long) value <= Integer.MAX_VALUE) {
- return value.toString();
- } else {
- throw new EdmPrimitiveTypeException(
- "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)");
- }
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64.java
deleted file mode 100644
index 9661b2f..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.math.BigInteger;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Int64.
- */
-public final class EdmInt64 extends SingletonPrimitiveType {
-
- private static final EdmInt64 INSTANCE = new EdmInt64();
-
- public static EdmInt64 getInstance() {
- 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;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Long.class;
- }
-
- @Override
- 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);
- } catch (final NumberFormatException e) {
- throw new EdmPrimitiveTypeException(
- "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");
- } catch (final ClassCastException e) {
- throw new EdmPrimitiveTypeException(
- "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}
- * @return the converted value
- * @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 {
-
- if (returnType.isAssignableFrom(Long.class)) {
- return returnType.cast(value.longValue());
- } else if (returnType.isAssignableFrom(BigInteger.class)) {
- return returnType.cast(BigInteger.valueOf(value.longValue()));
- } else if (returnType.isAssignableFrom(Byte.class)) {
- if (value.longValue() >= Byte.MIN_VALUE && value.longValue() <= Byte.MAX_VALUE) {
- return returnType.cast(value.byteValue());
- } else {
- throw new IllegalArgumentException();
- }
- } else if (returnType.isAssignableFrom(Short.class)) {
- if (value.longValue() >= Short.MIN_VALUE && value.longValue() <= Short.MAX_VALUE) {
- return returnType.cast(value.shortValue());
- } else {
- throw new IllegalArgumentException();
- }
- } else if (returnType.isAssignableFrom(Integer.class)) {
- if (value.longValue() >= Integer.MIN_VALUE && value.longValue() <= Integer.MAX_VALUE) {
- return returnType.cast(value.intValue());
- } else {
- throw new IllegalArgumentException();
- }
- } else {
- throw new ClassCastException("unsupported return type " + returnType.getSimpleName());
- }
- }
-
- @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 {
-
- if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
- return value.toString();
- } else if (value instanceof BigInteger) {
- if (((BigInteger) value).bitLength() < Long.SIZE) {
- return value.toString();
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
- }
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNull.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNull.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNull.java
deleted file mode 100644
index b5b43cc..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNull.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-//TODO: Is this class still necessary?
-/**
- * Implementation of the simple type Null.
- */
-public final class EdmNull extends SingletonPrimitiveType {
-
- private static final EdmNull INSTANCE = new EdmNull();
-
- public static EdmNull getInstance() {
- return INSTANCE;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj || obj == null;
- }
-
- @Override
- public int hashCode() {
- return 0;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return null;
- }
-
- @Override
- 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;
- }
-
- @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 null;
- }
-
- @Override
- public String toUriLiteral(final String literal) {
- return "null";
- }
-
- @Override
- public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java
deleted file mode 100644
index 2b0b08f..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmPrimitiveTypeKind.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-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() {
- return new FullQualifiedName(EdmPrimitiveType.EDM_NAMESPACE, toString());
- }
-
- /**
- * 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);
- }
- }
-
- /**
- * Gets <tt>EdmPrimitiveTypeKind</tt> from a full string (e.g. 'Edm.Int32').
- *
- * @param value string value type.
- * @return <tt>EdmPrimitiveTypeKind</tt> object.
- */
- public static EdmPrimitiveTypeKind fromString(final String value) {
- final String noNsValue = value.substring(4);
- for (EdmPrimitiveTypeKind edmSimpleType : EdmPrimitiveTypeKind.values()) {
- if (edmSimpleType.name().equals(noNsValue)) {
- return edmSimpleType;
- }
- }
- throw new IllegalArgumentException(value);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByte.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByte.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByte.java
deleted file mode 100644
index 70ac12d..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByte.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.math.BigInteger;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type SByte.
- */
-public final class EdmSByte extends SingletonPrimitiveType {
-
- private static final EdmSByte INSTANCE = new EdmSByte();
-
- public static EdmSByte getInstance() {
- return INSTANCE;
- }
-
- @Override
- public boolean isCompatible(final EdmPrimitiveType primitiveType) {
- return primitiveType instanceof Uint7
- || primitiveType instanceof EdmSByte;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Byte.class;
- }
-
- @Override
- 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);
- } catch (final NumberFormatException e) {
- throw new EdmPrimitiveTypeException(
- "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");
- }
- }
-
- @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 {
-
- if (value instanceof Byte) {
- return value.toString();
- } else if (value instanceof Short || value instanceof Integer || value instanceof Long) {
- if (((Number) value).longValue() >= Byte.MIN_VALUE && ((Number) value).longValue() <= Byte.MAX_VALUE) {
- return value.toString();
- } else {
- throw new EdmPrimitiveTypeException(
- "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)");
- }
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/897db8ef/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingle.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingle.java b/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingle.java
deleted file mode 100644
index b2c0363..0000000
--- a/lib/commons-core/src/main/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingle.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.odata4.commons.core.edm.primitivetype;
-
-import java.math.BigDecimal;
-import java.util.regex.Pattern;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
-
-/**
- * Implementation of the EDM primitive type Single.
- */
-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();
-
- public static EdmSingle getInstance() {
- 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;
- }
-
- @Override
- public Class<?> getDefaultType() {
- return Float.class;
- }
-
- @Override
- 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.
- if (value.equals(EdmDouble.NEGATIVE_INFINITY)) {
- result = Float.NEGATIVE_INFINITY;
- } else if (value.equals(EdmDouble.POSITIVE_INFINITY)) {
- result = Float.POSITIVE_INFINITY;
- } else if (value.equals(EdmDouble.NaN)) {
- result = Float.NaN;
- } else {
- // Now only "normal" numbers remain.
- if (!PATTERN.matcher(value).matches()) {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
- }
-
- // The number format is checked above, so we don't have to catch NumberFormatException.
- bigDecimalValue = new BigDecimal(value);
- result = bigDecimalValue.floatValue();
- // "Real" infinite values have been treated already above, so we can throw an exception
- // if the conversion to a float results in an infinite value.
- if (result.isInfinite() || bigDecimalValue.compareTo(new BigDecimal(result.toString())) != 0) {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
- }
- }
-
- if (returnType.isAssignableFrom(Float.class)) {
- return returnType.cast(result);
- } else if (result.isInfinite() || result.isNaN()) {
- if (returnType.isAssignableFrom(Double.class)) {
- return returnType.cast(result.doubleValue());
- } else {
- throw new EdmPrimitiveTypeException(
- "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");
- } catch (final ClassCastException e) {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
- }
- }
- }
-
- @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 {
-
- if (value instanceof Long || value instanceof Integer) {
- if (Math.abs(((Number) value).longValue()) < 1L << 22) {
- return value.toString();
- } else {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
- }
- } else if (value instanceof Short || value instanceof Byte) {
- return value.toString();
- } else if (value instanceof Double) {
- if (((Double) value).isInfinite()) {
- return (Double) value == Double.NEGATIVE_INFINITY ? EdmDouble.NEGATIVE_INFINITY : EdmDouble.POSITIVE_INFINITY;
- } else {
- final String floatString = Float.toString(((Double) value).floatValue());
- if (floatString.equals(((Double) value).toString())) {
- return floatString;
- } else {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
- }
- }
- } else if (value instanceof Float) {
- 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) {
- return ((BigDecimal) value).toString();
- } else {
- throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
- }
- } else {
- throw new EdmPrimitiveTypeException(
- "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
- }
- }
-}