From 4c4f82ee5f0c7e2f063bb992333699b682c6395f Mon Sep 17 00:00:00 2001 From: Michael Bolz Date: Mon, 30 Jun 2014 09:18:51 +0200 Subject: [PATCH] [OLINGO-317] Code clean up --- .../commons/ComplexInvocationHandler.java | 11 ++-------- .../serialization/v4/ODataBinderImpl.java | 1 + .../core/serialization/AtomDeserializer.java | 1 + .../core/serialization/JsonDeserializer.java | 21 +++++++++---------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java index 658bf656c..2a71f2e81 100644 --- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/ComplexInvocationHandler.java @@ -24,7 +24,6 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -44,8 +43,6 @@ import org.apache.olingo.ext.proxy.utils.CoreUtils; public class ComplexInvocationHandler extends AbstractStructuredInvocationHandler { - private static final long serialVersionUID = 2629912294765040037L; - private static Pair, Class> init( final CommonEdmEnabledODataClient client, final Class reference) { @@ -151,8 +148,7 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle } } - for (final Iterator itor = getComplex().iterator(); itor.hasNext();) { - final CommonODataProperty property = itor.next(); + for (final CommonODataProperty property : getComplex()) { if (!propertyNames.contains(property.getName())) { res.add(property.getName()); } @@ -180,10 +176,7 @@ public class ComplexInvocationHandler extends AbstractStructuredInvocationHandle if (value == null) { toBeAdded = null; } else if (Collection.class.isAssignableFrom(value.getClass())) { - toBeAdded = new ArrayList(); - for (Object obj : (Collection) value) { - Collection.class.cast(toBeAdded).add(obj); - } + toBeAdded = new ArrayList((Collection) value); } else { toBeAdded = value; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java index 231e4fb3b..4f8fb0123 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/serialization/v4/ODataBinderImpl.java @@ -216,6 +216,7 @@ public class ODataBinderImpl extends AbstractODataBinder implements ODataBinder } @Override + @SuppressWarnings("unchecked") protected Object getValue(final ODataValue value) { Object valueResource; if (value instanceof org.apache.olingo.commons.api.domain.v4.ODataValue diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java index 11aaa356b..47a373fc2 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/AtomDeserializer.java @@ -122,6 +122,7 @@ public class AtomDeserializer extends AbstractAtomDealer implements ODataDeseria return value; } + @SuppressWarnings("unchecked") private Object fromComplexOrEnum(final XMLEventReader reader, final StartElement start) throws XMLStreamException, EdmPrimitiveTypeException { diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java index d52a87c71..1d830d68b 100755 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/serialization/JsonDeserializer.java @@ -145,7 +145,7 @@ public class JsonDeserializer implements ODataDeserializer { link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString()); EntitySet entitySet = new EntitySetImpl(); - Iterator entries = ((ArrayNode) inline).elements(); + Iterator entries = inline.elements(); while (entries.hasNext()) { entitySet.getEntities().add( entityDeserializer.doDeserialize(entries.next().traverse(codec)).getPayload()); @@ -326,25 +326,24 @@ public class JsonDeserializer implements ODataDeserializer { private Object fromComplex(final ObjectNode node, final ObjectCodec codec) throws IOException, EdmPrimitiveTypeException { - final Object value = version.compareTo(ODataServiceVersion.V40) < 0 ? - new ArrayList() : - new LinkedComplexValueImpl(); - if (value instanceof LinkedComplexValue) { + if (version.compareTo(ODataServiceVersion.V40) < 0) { + List properties = new ArrayList(); + populate(null, properties, node, codec); + return properties; + } else { + LinkedComplexValue linkComplexValue = new LinkedComplexValueImpl(); final Set toRemove = new HashSet(); for (final Iterator> itor = node.fields(); itor.hasNext();) { final Map.Entry field = itor.next(); - links(field, (LinkedComplexValue) value, toRemove, node, codec); + links(field, linkComplexValue, toRemove, node, codec); } node.remove(toRemove); - populate((LinkedComplexValue) value, ((LinkedComplexValue) value).getValue(), node, codec); - } else { - populate(null, (List) value, node, codec); + populate(linkComplexValue, linkComplexValue.getValue(), node, codec); + return linkComplexValue; } - - return value; } private void fromCollection(Valuable valuable, final Iterator nodeItor, final EdmTypeInfo typeInfo,