Author: mbenson Date: Fri Oct 21 22:53:28 2016 New Revision: 1766167 URL: http://svn.apache.org/viewvc?rev=1766167&view=rev Log: modify interfaces to support type inference which included the introduction of a self-referential type parameter throughout the Entity type hierarchy
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/DynamicField.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/Entity.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityArray.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollection.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollectionSupport.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityFactory.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityMap.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntitySupport.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/Field.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/FieldSupport.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/ImmutableEntity.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/IndexedEntityCollection.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/NamedEntityCollection.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/PadJustifyFieldSupport.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/ParserEntityFactory.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CloningEntityFactory.java commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CompositeEntityFactory.java commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/BasicFunctionalityTest.java commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/DynamicFieldTest.java commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityArrayLifecycleTest.java commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityParserTestBase.java commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/FillerTest.java commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ImmutableTest.java commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/TypesTest.java commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ValuesTest.java commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/conversion/ConversionTestBase.java Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/DynamicField.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/DynamicField.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/DynamicField.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/DynamicField.java Fri Oct 21 22:53:28 2016 @@ -38,7 +38,7 @@ import org.apache.commons.flatfile.util. * field AND underflow == IGNORE. * @version $Revision$ $Date$ */ -public class DynamicField extends PadJustifyFieldSupport { +public class DynamicField extends PadJustifyFieldSupport<DynamicField> { /** * Bounds */ Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/Entity.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/Entity.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/Entity.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/Entity.java Fri Oct 21 22:53:28 2016 @@ -25,7 +25,7 @@ import java.io.Serializable; * Represents a record or field. * @version $Revision$ $Date$ */ -public interface Entity extends Cloneable, Serializable { +public interface Entity<E extends Entity<E>> extends Cloneable, Serializable { /** * Get the length of this Entity. * @return int @@ -50,7 +50,7 @@ public interface Entity extends Cloneabl * Clone oneself. * @return a deep (or otherwise "safe") copy of this Entity. */ - Entity clone(); + E clone(); /** * Fill this entity's value with all <code>b</code>. Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityArray.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityArray.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityArray.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityArray.java Fri Oct 21 22:53:28 2016 @@ -28,16 +28,15 @@ import org.apache.commons.lang3.Validate * and a prototypical child are assigned. The prototype child is cloned * <code>size</code> times, and these clones become the indexed child entities. */ -public class EntityArray extends EntityCollectionSupport implements - IndexedEntityCollection { +public class EntityArray extends EntityCollectionSupport<EntityArray> implements IndexedEntityCollection<EntityArray> { private static final long serialVersionUID = 8716199462287161060L; private int size = -1; private int minimumSize = 0; private int maximumSize = Integer.MAX_VALUE; private boolean resizable = false; - private List<Entity> children; - private Entity prototype; + private List<Entity<?>> children; + private Entity<?> prototype; /** * Create a new EntityArray. @@ -58,7 +57,7 @@ public class EntityArray extends EntityC * Create a new EntityArray with the specified prototype. * @param prototype Entity */ - public EntityArray(Entity prototype) { + public EntityArray(Entity<?> prototype) { setPrototype(prototype); } @@ -67,7 +66,7 @@ public class EntityArray extends EntityC * @param prototype Entity * @param size number of occurrences */ - public EntityArray(Entity prototype, int size) { + public EntityArray(Entity<?> prototype, int size) { this(prototype); setSize(size); } @@ -75,36 +74,40 @@ public class EntityArray extends EntityC /** * {@inheritDoc} */ - public Entity getChild(int index) { + public <C extends Entity<C>> C getChild(int index) { initialize(); - return (Entity) children.get(index); + @SuppressWarnings("unchecked") + final C result = (C) children.get(index); + return result; } /** * {@inheritDoc} */ - public synchronized Collection<Entity> getChildren() { + public synchronized <C extends Entity<C>> Collection<? extends C> getChildren() { initialize(); - return Collections.unmodifiableCollection(children); + @SuppressWarnings("unchecked") + final Collection<? extends C> result = (Collection<? extends C>) children; + return Collections.unmodifiableCollection(result); } /** * Get the prototype. - * @return Entity. + * @param <E> inferred result type + * @return E. */ - public synchronized Entity getPrototype() { - return prototype; + public synchronized <E extends Entity<E>> E getPrototype() { + @SuppressWarnings("unchecked") + final E result = (E) prototype; + return result; } /** * Set the prototype. * @param prototype The Entity prototype to set. */ - public synchronized void setPrototype(Entity prototype) { - if (prototype == null) { - throw new IllegalArgumentException("prototype Entity was null"); - } - this.prototype = prototype; + public synchronized void setPrototype(Entity<?> prototype) { + this.prototype = Validate.notNull(prototype, "prototype"); } /** @@ -143,10 +146,10 @@ public class EntityArray extends EntityC */ @Override public synchronized EntityArray clone() { - EntityArray result = (EntityArray) super.clone(); + final EntityArray result = super.clone(); if (children != null) { - result.children = new ArrayList<Entity>(); - for (Entity e : children) { + result.children = new ArrayList<Entity<?>>(); + for (Entity<?> e : children) { result.children.add(e.clone()); } } @@ -164,13 +167,13 @@ public class EntityArray extends EntityC throw new IllegalStateException("EntityArray size not set"); } if (size == 0) { - children = Collections.<Entity>emptyList(); + children = Collections.<Entity<?>> emptyList(); return; } if (prototype == null) { throw new IllegalStateException("Prototype child entity not set"); } - children = new ArrayList<Entity>(size); + children = new ArrayList<Entity<?>>(size); adjustSize(); } Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollection.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollection.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollection.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollection.java Fri Oct 21 22:53:28 2016 @@ -22,11 +22,12 @@ import java.util.Collection; * An entity that is a collection of child entities. * @version $Revision$ $Date$ */ -public interface EntityCollection extends Entity { +public interface EntityCollection<E extends EntityCollection<E>> extends Entity<E> { /** * Get the children. - * @return Collection<Entity>. + * @param <C> inferred collection element type + * @return Collection<? extends C>. */ - Collection<Entity> getChildren(); + <C extends Entity<C>> Collection<? extends C> getChildren(); } Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollectionSupport.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollectionSupport.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollectionSupport.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityCollectionSupport.java Fri Oct 21 22:53:28 2016 @@ -29,7 +29,8 @@ import org.apache.commons.lang3.ArrayUti * Implementation of common operations for an EntityCollection. * @version $Revision$ $Date$ */ -public abstract class EntityCollectionSupport extends EntitySupport implements EntityCollection { +public abstract class EntityCollectionSupport<E extends EntityCollectionSupport<E>> extends EntitySupport<E> + implements EntityCollection<E> { /** Serialization version */ private static final long serialVersionUID = 5902476686737324304L; @@ -44,8 +45,8 @@ public abstract class EntityCollectionSu */ public final synchronized int length() { int result = 0; - for (Iterator<Entity> it = getChildren().iterator(); it.hasNext();) { - Entity e = it.next(); + for (Iterator<? extends Entity<?>> it = getChildren().iterator(); it.hasNext();) { + final Entity<?> e = it.next(); if (shouldSuppress(e)) { continue; } @@ -61,8 +62,8 @@ public abstract class EntityCollectionSu * {@inheritDoc} */ public final synchronized void readFrom(InputStream is) throws IOException { - for (Iterator<Entity> it = getChildren().iterator(); it.hasNext();) { - Entity e = it.next(); + for (Iterator<? extends Entity<?>> it = getChildren().iterator(); it.hasNext();) { + final Entity<?> e = it.next(); if (shouldSuppress(e)) { continue; } @@ -77,8 +78,8 @@ public abstract class EntityCollectionSu * {@inheritDoc} */ public final synchronized void writeTo(OutputStream os) throws IOException { - for (Iterator<Entity> it = getChildren().iterator(); it.hasNext();) { - Entity e = it.next(); + for (Iterator<? extends Entity<?>> it = getChildren().iterator(); it.hasNext();) { + final Entity<?> e = it.next(); if (shouldSuppress(e)) { continue; } @@ -174,19 +175,11 @@ public abstract class EntityCollectionSu } /** - * {@inheritDoc} - */ - @Override - public EntityCollectionSupport clone() { - return (EntityCollectionSupport) super.clone(); - } - - /** * Learn whether the specified child should be suppressed. * @param child to check * @return boolean */ - protected boolean shouldSuppress(Entity child) { + protected boolean shouldSuppress(Entity<?> child) { return isSuppressEmptyChildren() && child.length() == 0; } Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityFactory.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityFactory.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityFactory.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityFactory.java Fri Oct 21 22:53:28 2016 @@ -24,9 +24,10 @@ public interface EntityFactory { /** * Get an Entity. + * @param <E> inferred result type * @param cue an Object that <u>may</u> provide a cue as to what type of Entity is required. - * @return Entity. + * @return E. */ - Entity getEntity(Object cue); + <E extends Entity<E>> E getEntity(Object cue); } Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityMap.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityMap.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityMap.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntityMap.java Fri Oct 21 22:53:28 2016 @@ -35,7 +35,7 @@ import org.apache.commons.lang3.Validate * Basic implementation of NamedEntityCollection. * @version $Revision$ $Date$ */ -public class EntityMap extends EntityCollectionSupport implements NamedEntityCollection { +public class EntityMap extends EntityCollectionSupport<EntityMap> implements NamedEntityCollection<EntityMap> { private static final long serialVersionUID = 3162898927743996952L; @@ -46,14 +46,14 @@ public class EntityMap extends EntityCol private final String name; @SuppressWarnings("PMD.UnusedPrivateField") // false positive; this field is used in EntityMap#clone() - private final Entity entity; + private final Entity<?> entity; /** * Create a new Child instance. * @param name of child * @param entity child */ - public Child(String name, Entity entity) { + public Child(String name, Entity<?> entity) { this.name = name; if (entity == null) { throw new IllegalArgumentException(); @@ -67,13 +67,13 @@ public class EntityMap extends EntityCol * Expose the Child list as List<Entity>. This is necessary because we permit nameless children, * which we want to account for in a layout but have no need of referencing later. */ - private static class ChildrenList extends AbstractList<Entity> implements Serializable { + private static class ChildrenList extends AbstractList<Entity<?>> implements Serializable { private static final long serialVersionUID = -954784669450571284L; - private static final Transformer<Child, Entity> CHILD_TO_ENTITY = new Transformer<Child, Entity>() { + private static final Transformer<Child, Entity<?>> CHILD_TO_ENTITY = new Transformer<Child, Entity<?>>() { - public Entity transform(Child input) { + public Entity<?> transform(Child input) { return input.entity; } }; @@ -93,15 +93,15 @@ public class EntityMap extends EntityCol * {@inheritDoc} */ @Override - public Entity get(int index) { - return CHILD_TO_ENTITY.transform(wrapped.get(index)); + public Entity<?> get(int index) { + return wrapped.get(index).entity; } /** * {@inheritDoc} */ @Override - public Iterator<Entity> iterator() { + public Iterator<Entity<?>> iterator() { return IteratorUtils.transformedIterator(wrapped.iterator(), CHILD_TO_ENTITY); } @@ -116,22 +116,22 @@ public class EntityMap extends EntityCol private List<Child> children; /** contains mapped children only */ - private Map<String, Entity> childMap; + private Map<String, Entity<?>> childMap; - private List<Entity> exposeChildrenList; + private List<Entity<?>> exposeChildrenList; /** * Add a child. * @param name if {@code null} filler element * @param child non-null child Entity */ - public synchronized void add(String name, Entity child) { + public synchronized void add(String name, Entity<?> child) { Validate.notNull(child, "child entity is null"); if (children == null) { children = new ArrayList<Child>(); exposeChildrenList = new ChildrenList(children); - childMap = new LinkedHashMap<String, Entity>(); + childMap = new LinkedHashMap<String, Entity<?>>(); } if (childMap.containsKey(name)) { throw new IllegalArgumentException("cannot add > 1 child entity '" + name + "'"); @@ -146,8 +146,8 @@ public class EntityMap extends EntityCol * Get a map of the children. * @return Map<String, Entity> */ - public synchronized Map<String, Entity> getChildMap() { - return childMap == null ? Collections.<String, Entity> emptyMap() : Collections.unmodifiableMap(childMap); + public synchronized Map<String, Entity<?>> getChildMap() { + return childMap == null ? Collections.<String, Entity<?>> emptyMap() : Collections.unmodifiableMap(childMap); } /** @@ -161,8 +161,10 @@ public class EntityMap extends EntityCol /** * {@inheritDoc} */ - public Entity getChild(String name) { - return getChildMap().get(name); + public <C extends Entity<C>> C getChild(String name) { + @SuppressWarnings("unchecked") + final C result = (C) getChildMap().get(name); + return result; } /** @@ -175,8 +177,9 @@ public class EntityMap extends EntityCol /** * {@inheritDoc} */ - public synchronized Collection<Entity> getChildren() { - return children == null ? Collections.<Entity> emptyList() : Collections.unmodifiableList(exposeChildrenList); + public synchronized Collection<Entity<?>> getChildren() { + return children == null ? Collections.<Entity<?>> emptyList() + : Collections.unmodifiableList(exposeChildrenList); } /** @@ -184,7 +187,7 @@ public class EntityMap extends EntityCol */ @Override public synchronized EntityMap clone() { - EntityMap result = (EntityMap) super.clone(); + final EntityMap result = super.clone(); result.children = null; result.childMap = null; result.exposeChildrenList = null; Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntitySupport.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntitySupport.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntitySupport.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/EntitySupport.java Fri Oct 21 22:53:28 2016 @@ -24,7 +24,7 @@ import org.apache.commons.flatfile.util. * Generic entity support stuff. * @version $Revision$ $Date$ */ -public abstract class EntitySupport implements Entity { +public abstract class EntitySupport<E extends EntitySupport<E>> implements Entity<E> { /** Serialization version */ private static final long serialVersionUID = 1067918863342682612L; @@ -39,9 +39,11 @@ public abstract class EntitySupport impl /** * {@inheritDoc} */ - public EntitySupport clone() { + public E clone() { try { - return (EntitySupport) super.clone(); + @SuppressWarnings("unchecked") + final E result = (E) super.clone(); + return result; } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/Field.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/Field.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/Field.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/Field.java Fri Oct 21 22:53:28 2016 @@ -24,7 +24,7 @@ import java.io.OutputStream; * Stores string representations of objects in a (fixed-length) byte array. * @version $Revision$ $Date$ */ -public class Field extends PadJustifyFieldSupport { +public class Field extends PadJustifyFieldSupport<Field> { private static final long serialVersionUID = 3939293448043882440L; Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/FieldSupport.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/FieldSupport.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/FieldSupport.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/FieldSupport.java Fri Oct 21 22:53:28 2016 @@ -25,7 +25,7 @@ import org.apache.commons.lang3.Validate * Support and basic field options. * @version $Revision$ $Date$ */ -public abstract class FieldSupport extends EntitySupport { +public abstract class FieldSupport<E extends FieldSupport<E>> extends EntitySupport<E> { /** Serialization version */ private static final long serialVersionUID = -8940832296518637934L; Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/ImmutableEntity.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/ImmutableEntity.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/ImmutableEntity.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/ImmutableEntity.java Fri Oct 21 22:53:28 2016 @@ -32,7 +32,7 @@ import org.apache.commons.lang3.ClassUti * @version $Revision$ $Date$ */ public class ImmutableEntity { - private static class ImmutableEntityInvocationHandler implements InvocationHandler { + private static class ImmutableEntityInvocationHandler<E extends Entity<E>> implements InvocationHandler { // make sure this array stays sorted: private static final String[] ALLOWED_VOID = { "readFrom", "writeTo" }; private static final String CLONE = "clone"; @@ -44,13 +44,13 @@ public class ImmutableEntity { private static final byte[] READ_BUFFER = new byte[1024]; private static final int BUF_LEN = READ_BUFFER.length; - private Entity delegate; + private E delegate; /** * Create a new ImmutableEntityInvocationHandler instance. * @param delegate Entity */ - private ImmutableEntityInvocationHandler(Entity delegate) { + private ImmutableEntityInvocationHandler(E delegate) { this.delegate = delegate; } @@ -59,10 +59,9 @@ public class ImmutableEntity { */ // TODO could we simplify/future-proof proxy definition by breaking Entity into smaller interfaces? public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - String name = method.getName(); + final String name = method.getName(); - // check allowed void methods; most would be intended to trigger a - // change on the target + // check allowed void methods; most would be intended to trigger a change on the target if (method.getReturnType() == Void.TYPE && Arrays.binarySearch(ALLOWED_VOID, name) < 0) { return null; } @@ -80,8 +79,7 @@ public class ImmutableEntity { return null; } if (CLONE.equals(name)) { - // it should be safe to return the proxy itself as the clone of - // an IMMUTABLE entity + // it should be safe to return the proxy itself as the clone of an IMMUTABLE entity return proxy; } if (EQUALS.equals(name)) { @@ -92,10 +90,11 @@ public class ImmutableEntity { } Object result = method.invoke(delegate, args); if (GET_CHILD.equals(name)) { // return immutable children - result = of((Entity) result); + @SuppressWarnings({ "rawtypes", "unchecked" }) + final Entity immutableChild = of((Entity) result); + return immutableChild; } - // if delegate returns same result 2x, that indicates it's the true - // buffer, which we protect by copying: + // if delegate returns same result 2x, that indicates it's the true buffer, which we protect by copying: if (GET_VALUE.equals(name)) { byte[] test = (byte[]) method.invoke(delegate, args); if (result == test) { @@ -107,7 +106,7 @@ public class ImmutableEntity { } } - private static final Map<Entity, Entity> PROXIES = new WeakHashMap<Entity, Entity>(); + private static final Map<Entity<?>, Entity<?>> PROXIES = new WeakHashMap<Entity<?>, Entity<?>>(); /** * Create a new ImmutableEntity instance. @@ -117,14 +116,16 @@ public class ImmutableEntity { /** * Get an immutable instance of <code>e</code>. + * @param <E> type of {@code e} * @param e Entity delegate - * @return immutable Entity + * @return immutable E */ - public static Entity of(Entity e) { - Entity result = PROXIES.get(e); + @SuppressWarnings("unchecked") + public static <E extends Entity<E>> E of(E e) { + E result = (E) PROXIES.get(e); if (result == null) { - result = (Entity) Proxy.newProxyInstance(e.getClass().getClassLoader(), - getInterfaces(e), new ImmutableEntityInvocationHandler(e)); + result = (E) Proxy.newProxyInstance(e.getClass().getClassLoader(), + getInterfaces(e), new ImmutableEntityInvocationHandler<E>(e)); PROXIES.put(e, result); } return result; Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/IndexedEntityCollection.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/IndexedEntityCollection.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/IndexedEntityCollection.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/IndexedEntityCollection.java Fri Oct 21 22:53:28 2016 @@ -20,7 +20,7 @@ package org.apache.commons.flatfile; * EntityCollection whose children are indexed. * @version $Revision$ $Date$ */ -public interface IndexedEntityCollection extends EntityCollection { +public interface IndexedEntityCollection<E extends IndexedEntityCollection<E>> extends EntityCollection<E> { /** * Get the size (# of child elements) of this IndexedEntityCollection. * @return int @@ -29,10 +29,11 @@ public interface IndexedEntityCollection /** * Get the child at the specified index. + * @param <C> inferred result type * @param index int - * @return Entity + * @return C */ - Entity getChild(int index); + <C extends Entity<C>> C getChild(int index); /** * Learn whether the size of this object can be set. @@ -43,7 +44,7 @@ public interface IndexedEntityCollection /** * Set new size of this object. * @param size to set - * @throws IllegalStateException if {@link #isSizable()} <code>== false</code> + * @throws IllegalStateException if {@link #isSizable()} {@code == false} */ - void setSize(int size) throws IllegalStateException; + void setSize(int size); } Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/NamedEntityCollection.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/NamedEntityCollection.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/NamedEntityCollection.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/NamedEntityCollection.java Fri Oct 21 22:53:28 2016 @@ -20,7 +20,7 @@ package org.apache.commons.flatfile; * EntityCollection whose children are mapped to a name. * @version $Revision$ $Date$ */ -public interface NamedEntityCollection extends EntityCollection { +public interface NamedEntityCollection<E extends NamedEntityCollection<E>> extends EntityCollection<E> { /** * Learn whether this NamedEntityCollection has a child of the specified name. * @param name to find @@ -30,10 +30,11 @@ public interface NamedEntityCollection e /** * Get the specified child. + * @param <C> inferred result type * @param name to find - * @return Entity + * @return C */ - Entity getChild(String name); + <C extends Entity<C>> C getChild(String name); /** * Get the child entities' names. Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/PadJustifyFieldSupport.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/PadJustifyFieldSupport.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/PadJustifyFieldSupport.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/PadJustifyFieldSupport.java Fri Oct 21 22:53:28 2016 @@ -26,7 +26,7 @@ import org.apache.commons.flatfile.util. * Support for fields with pad/justify. * @version $Revision$ $Date$ */ -public abstract class PadJustifyFieldSupport extends FieldSupport { +public abstract class PadJustifyFieldSupport<E extends PadJustifyFieldSupport<E>> extends FieldSupport<E> { /** Serialization version */ private static final long serialVersionUID = -4953059253157670418L; @@ -44,7 +44,7 @@ public abstract class PadJustifyFieldSup /** * {@inheritDoc} */ - protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest) { + protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport<?> dest) { final InputStream is = new ByteArrayInputStream(src); final int dlen = dest.getPadJustifyLength(); return dlen <= src.length ? is : new ConcatenatedInputStream( @@ -58,7 +58,7 @@ public abstract class PadJustifyFieldSup /** * {@inheritDoc} */ - protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest) { + protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport<?> dest) { final int dlen = dest.getPadJustifyLength(); if (dlen < src.length) { return new ByteArrayInputStream(src, src.length - dlen, @@ -76,7 +76,7 @@ public abstract class PadJustifyFieldSup /** * {@inheritDoc} */ - protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest) { + protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport<?> dest) { final int dlen = dest.getPadJustifyLength(); // it would be odd and therefore hopefully rare to center a // field that allowed overflow, but we'll provide for it: @@ -102,7 +102,7 @@ public abstract class PadJustifyFieldSup * @param dest PadJustifyFieldSupport * @return InputStream */ - protected abstract InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest); + protected abstract InputStream getInputStream(byte[] src, PadJustifyFieldSupport<?> dest); } private byte pad = DEFAULT_PAD; Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/ParserEntityFactory.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/ParserEntityFactory.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/ParserEntityFactory.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/ParserEntityFactory.java Fri Oct 21 22:53:28 2016 @@ -54,7 +54,7 @@ public class ParserEntityFactory impleme private class EntityHolder { private final EntityDefinition definition; - private Entity prototype; + private Entity<?> prototype; /** * Create a new EntityHolder instance. @@ -68,12 +68,12 @@ public class ParserEntityFactory impleme * Get the prototypical entity from this {@link EntityHolder}. * @return Entity */ - Entity getPrototype() { + Entity<?> getPrototype() { synchronized (this) { if (prototype == null) { - prototype = doWithPooledTreeParser(new Transformer<EntityTreeParser, Entity>() { + prototype = doWithPooledTreeParser(new Transformer<EntityTreeParser, Entity<?>>() { - public Entity transform(EntityTreeParser input) { + public Entity<?> transform(EntityTreeParser input) { return input.createEntity(definition); } }); @@ -126,12 +126,14 @@ public class ParserEntityFactory impleme /** * {@inheritDoc} */ - public final Entity getEntity(Object cue) { + public final <E extends Entity<E>> E getEntity(Object cue) { EntityHolder holder = getEntityMap().get(getEntityNameStrategy().getEntityName(cue)); if (holder != null) { - return holder.getPrototype().clone(); + @SuppressWarnings("unchecked") + final E result = (E) holder.getPrototype().clone(); + return result; } - return getParent() == null ? null : getParent().getEntity(cue); + return getParent() == null ? null : getParent().<E> getEntity(cue); } /** @@ -265,7 +267,7 @@ public class ParserEntityFactory impleme * @param type associated field type * @return e */ - private <E extends Entity> E applyDefaultOptions(E e, String type) { + private <E extends Entity<E>> E applyDefaultOptions(E e, String type) { Map<String, ? extends Object> m = defaultOptionMaps.get(type); return m == null ? e : ApplyOptions.apply(e, m); } Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CloningEntityFactory.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CloningEntityFactory.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CloningEntityFactory.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CloningEntityFactory.java Fri Oct 21 22:53:28 2016 @@ -20,7 +20,6 @@ import java.util.Map; import org.apache.commons.flatfile.Entity; import org.apache.commons.flatfile.EntityFactory; -import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.Validate; /** @@ -28,21 +27,23 @@ import org.apache.commons.lang3.Validate * @version $Revision$ $Date$ */ public class CloningEntityFactory implements EntityFactory { - private Map<? extends Object, ? extends Entity> lookup; + private Map<? extends Object, ? extends Entity<?>> lookup; /** * Create a new CloningEntityFactory. * @param lookup lookup Map */ - public CloningEntityFactory(Map<? extends Object, ? extends Entity> lookup) { + public CloningEntityFactory(Map<? extends Object, ? extends Entity<?>> lookup) { this.lookup = Validate.notNull(lookup); } /** * {@inheritDoc} */ - public Entity getEntity(Object cue) { - return ObjectUtils.clone(lookup.get(cue)); + public <E extends Entity<E>> E getEntity(Object cue) { + @SuppressWarnings("unchecked") + final E prototype = (E) lookup.get(cue); + return prototype == null ? null : prototype.clone(); } } Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CompositeEntityFactory.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CompositeEntityFactory.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CompositeEntityFactory.java (original) +++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CompositeEntityFactory.java Fri Oct 21 22:53:28 2016 @@ -38,9 +38,9 @@ public class CompositeEntityFactory impl /** * {@inheritDoc} */ - public Entity getEntity(Object cue) { + public <E extends Entity<E>> E getEntity(Object cue) { for (EntityFactory delegate : delegates) { - Entity result = delegate.getEntity(cue); + final E result = delegate.getEntity(cue); if (result != null) { return result; } Modified: commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/BasicFunctionalityTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/BasicFunctionalityTest.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/BasicFunctionalityTest.java (original) +++ commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/BasicFunctionalityTest.java Fri Oct 21 22:53:28 2016 @@ -18,6 +18,7 @@ package org.apache.commons.flatfile; import static org.junit.Assert.assertEquals; +import org.junit.Before; import org.junit.Test; /** @@ -25,29 +26,50 @@ import org.junit.Test; */ public class BasicFunctionalityTest extends EntityParserTestBase { + protected String getSource() { + return "basic.test"; + } + + private EntityMap test1; + + @Before + public void setup() { + test1 = entityFactory.getEntity("basic"); + } + @Test - public void testBasicFunctionality() throws Exception { - EntityMap test1 = (EntityMap) entityFactory.getEntity("basic"); + public void testBasicMap() throws Exception { assertEquals(1, test1.getChild("foo").length()); assertEquals(2, test1.getChild("bar").length()); assertEquals(3, test1.getChild("baz").length()); - EntityArray simpleArray = (EntityArray) test1.getChild("simpleArray"); + } + + @Test + public void testSimpleArray() throws Exception { + EntityArray simpleArray = test1.getChild("simpleArray"); int sz = simpleArray.size(); assertEquals(3, sz); for (int i = 0; i < sz; i++) { assertEquals(1, simpleArray.getChild(i).length()); } - EntityMap complex = (EntityMap) test1.getChild("complex"); + } + + @Test + public void testComplexMap() throws Exception { + EntityMap complex = test1.getChild("complex"); assertEquals(3, complex.getChildMap().size()); assertEquals(1, complex.getChild("foo").length()); assertEquals(2, complex.getChild("bar").length()); assertEquals(3, complex.getChild("baz").length()); + } - EntityArray complexArray = (EntityArray) test1.getChild("complexArray"); - sz = complexArray.size(); + @Test + public void testComplexArray() throws Exception { + EntityArray complexArray = test1.getChild("complexArray"); + int sz = complexArray.size(); assertEquals(3, sz); for (int i = 0; i < sz; i++) { - EntityMap child = (EntityMap) complexArray.getChild(i); + EntityMap child = complexArray.getChild(i); assertEquals(6, child.length()); assertEquals(1, child.getChild("foo").length()); assertEquals(2, child.getChild("bar").length()); @@ -55,7 +77,4 @@ public class BasicFunctionalityTest exte } } - protected String getSource() { - return "basic.test"; - } } Modified: commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/DynamicFieldTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/DynamicFieldTest.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/DynamicFieldTest.java (original) +++ commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/DynamicFieldTest.java Fri Oct 21 22:53:28 2016 @@ -42,7 +42,7 @@ public class DynamicFieldTest extends En @Test public void test1() throws Exception { - DynamicField df = get("df1"); + DynamicField df = entityFactory.getEntity("df1"); assertEquals(0, df.length()); assertBounds(df, 0, 1); assertLoad(df); @@ -50,7 +50,7 @@ public class DynamicFieldTest extends En @Test public void test2() throws Exception { - DynamicField df = get("df2"); + DynamicField df = entityFactory.getEntity("df2"); assertEquals(0, df.length()); assertBounds(df, DynamicField.Bounds.DEFAULT.getMinimum(), 1); assertLoad(df); @@ -58,7 +58,7 @@ public class DynamicFieldTest extends En @Test public void test3() throws Exception { - DynamicField df = get("df3"); + DynamicField df = entityFactory.getEntity("df3"); assertEquals(0, df.length()); assertBounds(df, 0, DynamicField.Bounds.DEFAULT.getMaximum()); assertLoad(df); @@ -66,7 +66,7 @@ public class DynamicFieldTest extends En @Test public void test4() throws Exception { - DynamicField df = get("df4"); + DynamicField df = entityFactory.getEntity("df4"); assertEquals(0, df.length()); assertBounds(df, DynamicField.Bounds.DEFAULT); assertLoad(df); @@ -74,7 +74,7 @@ public class DynamicFieldTest extends En @Test public void test5() throws Exception { - DynamicField df = get("df5"); + DynamicField df = entityFactory.getEntity("df5"); assertEquals(3, df.length()); byte[] foo = "foo".getBytes(); assertArrayEquals(foo, df.getValue()); @@ -84,7 +84,7 @@ public class DynamicFieldTest extends En @Test public void test6() throws Exception { - DynamicField df = get("df6"); + DynamicField df = entityFactory.getEntity("df6"); assertEquals(0, df.length()); assertBounds(df, 0, 0); assertLoad(df); @@ -92,7 +92,7 @@ public class DynamicFieldTest extends En @Test public void test7() throws Exception { - DynamicField df = get("df7"); + DynamicField df = entityFactory.getEntity("df7"); assertEquals(0, df.length()); assertBounds(df, DynamicField.Bounds.DEFAULT.getMinimum(), 0); assertLoad(df); @@ -100,7 +100,7 @@ public class DynamicFieldTest extends En @Test public void test8() throws Exception { - DynamicField df = get("df8"); + DynamicField df = entityFactory.getEntity("df8"); assertBounds(df, 1, 1); assertArrayEquals(new byte[] { ' ' }, df.getValue()); assertLoad(df); @@ -108,7 +108,7 @@ public class DynamicFieldTest extends En @Test public void test9() throws Exception { - DynamicField df = get("df9"); + DynamicField df = entityFactory.getEntity("df9"); assertBounds(df, 1, 3); assertArrayEquals(" ".getBytes(), df.getValue()); assertLoad(df); @@ -116,7 +116,7 @@ public class DynamicFieldTest extends En @Test public void testUnboundedArray() throws Exception { - EntityArray a = (EntityArray) entityFactory.getEntity("unboundedArray"); + EntityArray a = entityFactory.getEntity("unboundedArray"); assertEquals(0, a.length()); a.getChild(1).setValue("foo".getBytes()); assertArrayEquals("foo".getBytes(), a.getValue()); @@ -124,8 +124,7 @@ public class DynamicFieldTest extends En @Test public void testUnboundedDelimitedArray() throws Exception { - EntityArray a = (EntityArray) entityFactory - .getEntity("unboundedDelimitedArray"); + EntityArray a = entityFactory.getEntity("unboundedDelimitedArray"); assertArrayEquals("---".getBytes(), a.getValue()); a.getChild(1).setValue("foo".getBytes()); assertArrayEquals("-foo--".getBytes(), a.getValue()); @@ -133,7 +132,7 @@ public class DynamicFieldTest extends En @Test public void testBoundedArray() throws Exception { - EntityArray a = (EntityArray) entityFactory.getEntity("boundedArray"); + EntityArray a = entityFactory.getEntity("boundedArray"); assertArrayEquals(" ".getBytes(), a.getValue()); a.getChild(1).setValue("foo".getBytes()); assertArrayEquals(" foo ".getBytes(), a.getValue()); @@ -141,8 +140,7 @@ public class DynamicFieldTest extends En @Test public void testBoundedDelimitedArray() throws Exception { - EntityArray a = (EntityArray) entityFactory - .getEntity("boundedDelimitedArray"); + EntityArray a = entityFactory.getEntity("boundedDelimitedArray"); assertArrayEquals(" \n \n \n".getBytes(), a.getValue()); a.getChild(1).setValue("foo".getBytes()); assertArrayEquals(" \nfoo\n \n".getBytes(), a.getValue()); @@ -151,8 +149,7 @@ public class DynamicFieldTest extends En @Test public void testNestedUncertainty() throws Exception { - EntityArray a = (EntityArray) entityFactory - .getEntity("nestedUncertainty"); + EntityArray a = entityFactory.getEntity("nestedUncertainty"); assertTrue(a.isSizable()); a.setSize(10); assertArrayEquals(SMALL_BYTES, a.getValue()); @@ -211,10 +208,6 @@ public class DynamicFieldTest extends En } } - private DynamicField get(String name) { - return (DynamicField) entityFactory.getEntity(name); - } - protected String getSource() { return "dynamicField.test"; } Modified: commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityArrayLifecycleTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityArrayLifecycleTest.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityArrayLifecycleTest.java (original) +++ commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityArrayLifecycleTest.java Fri Oct 21 22:53:28 2016 @@ -27,7 +27,7 @@ public class EntityArrayLifecycleTest ex @Test public void testMe() throws Exception { - EntityArray e = (EntityArray) entityFactory.getEntity("hypo"); + EntityArray e = entityFactory.getEntity("hypo"); try { e.getValue(); fail("should fail"); @@ -38,37 +38,37 @@ public class EntityArrayLifecycleTest ex e.setSize(5); e.fill((byte) 'a'); assertValue("aaaaaaaaaa", e); - e = (EntityArray) entityFactory.getEntity("hypo"); + e = entityFactory.getEntity("hypo"); assertTrue(e.isSizable()); e.setSize(2); e.fill((byte) 'b'); assertValue("bbbb", e); - e = (EntityArray) entityFactory.getEntity("complete"); + e = entityFactory.getEntity("complete"); assertFalse(e.isSizable()); expectInvalidSize(e, e.size() + 1, "should fail to set size of completed entity", IllegalStateException.class); e.setSize(e.size()); - e = (EntityArray) entityFactory.getEntity("rangeMin1"); + e = entityFactory.getEntity("rangeMin1"); assertTrue(e.isSizable()); expectInvalidSize(e, 0, "should fail to set size < 1", IllegalArgumentException.class); e.setSize(665); assertEquals(665, e.size()); - e = (EntityArray) entityFactory.getEntity("explicitRange"); + e = entityFactory.getEntity("explicitRange"); expectInvalidSize(e, 0, "should fail to set size < 1", IllegalArgumentException.class); expectInvalidSize(e, 4, "should fail to set size > 4", IllegalArgumentException.class); e.setSize(3); assertEquals(3, e.size()); - e = (EntityArray) entityFactory.getEntity("optional"); + e = entityFactory.getEntity("optional"); assertEquals(0, e.getMinimumSize()); assertEquals(1, e.getMaximumSize()); e.setSize(0); assertEquals(0, e.size()); assertEquals(0, e.getValue().length); - e = (EntityArray) entityFactory.getEntity("optional2"); + e = entityFactory.getEntity("optional2"); assertEquals(0, e.getMinimumSize()); assertEquals(1, e.getMaximumSize()); e.setSize(0); Modified: commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityParserTestBase.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityParserTestBase.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityParserTestBase.java (original) +++ commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityParserTestBase.java Fri Oct 21 22:53:28 2016 @@ -30,13 +30,12 @@ public abstract class EntityParserTestBa @Before public void setUp() throws Exception { - entityFactory = new ParserEntityFactory(getClass().getResourceAsStream( - getSource())); + entityFactory = new ParserEntityFactory(getClass().getResourceAsStream(getSource())); } protected abstract String getSource(); - protected void assertValue(String s, Entity e) { + protected void assertValue(String s, Entity<?> e) { assertEquals(s, new String(e.getValue())); } Modified: commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/FillerTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/FillerTest.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/FillerTest.java (original) +++ commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/FillerTest.java Fri Oct 21 22:53:28 2016 @@ -27,8 +27,7 @@ public class FillerTest extends EntityPa @Test public void testFiller() throws Exception { - EntityMap withFiller = (EntityMap) entityFactory - .getEntity("withFiller"); + EntityMap withFiller = entityFactory.getEntity("withFiller"); assertEquals(3, withFiller.getChildMap().size()); assertValue("foo bar---nothing-goes-here---baz", withFiller); } Modified: commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ImmutableTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ImmutableTest.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ImmutableTest.java (original) +++ commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ImmutableTest.java Fri Oct 21 22:53:28 2016 @@ -26,7 +26,7 @@ import org.junit.Test; public class ImmutableTest extends EntityParserTestBase { @Test public void test1() throws Exception { - Entity test1 = entityFactory.getEntity("test1"); + Entity<?> test1 = entityFactory.getEntity("test1"); assertValue("FOOxBARxBAZ", test1); test1.fill((byte) 'y'); assertValue("FOOyBARyBAZ", test1); @@ -34,7 +34,7 @@ public class ImmutableTest extends Entit @Test public void test2() throws Exception { - Entity test2 = entityFactory.getEntity("test2"); + Entity<?> test2 = entityFactory.getEntity("test2"); assertTrue(test2 instanceof IndexedEntityCollection); test2.fill((byte) '0'); assertValue("submarine", test2); @@ -42,8 +42,8 @@ public class ImmutableTest extends Entit @Test public void test3() throws Exception { - NamedEntityCollection test3 = (NamedEntityCollection) entityFactory - .getEntity("test3"); + @SuppressWarnings({ "rawtypes", "unchecked" }) + NamedEntityCollection test3 = entityFactory.getEntity("test3"); // verify the immutable children are still Entities: test3.getChild("a"); test3.getChild("c"); Modified: commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/TypesTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/TypesTest.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/TypesTest.java (original) +++ commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/TypesTest.java Fri Oct 21 22:53:28 2016 @@ -28,71 +28,71 @@ public class TypesTest extends EntityPar @Test public void testTypes() throws Exception { // test typedefs - EntityMap test2 = (EntityMap) entityFactory.getEntity("types"); + EntityMap test2 = entityFactory.getEntity("types"); assertEquals(49, test2.length()); - EntityArray foo = (EntityArray) test2.getChild("foo"); + EntityArray foo = test2.getChild("foo"); assertEquals(8, foo.length()); int sz = foo.size(); assertEquals(4, sz); for (int i = 1; i < sz; i++) { - Field fooI = (Field) foo.getChild(i); + Field fooI = foo.getChild(i); assertEquals(2, fooI.length()); } for (int i = 1; i <= 2; i++) { - Field fooI = (Field) test2.getChild("foo" + i); + Field fooI = test2.getChild("foo" + i); assertEquals(2, fooI.length()); } for (int i = 1; i <= 2; i++) { - EntityArray barI = (EntityArray) test2.getChild("bar" + i); + EntityArray barI = test2.getChild("bar" + i); assertEquals(4, barI.length()); sz = barI.size(); assertEquals(2, sz); for (int j = 0; j < sz; j++) { - Field child = (Field) barI.getChild(j); + Field child = barI.getChild(j); assertEquals(2, child.length()); } } - EntityArray baz = (EntityArray) test2.getChild("baz"); + EntityArray baz = test2.getChild("baz"); assertEquals(9, baz.length()); sz = baz.size(); assertEquals(3, sz); for (int i = 0; i < sz; i++) { - EntityMap child = (EntityMap) baz.getChild(i); + EntityMap child = baz.getChild(i); assertEquals(3, child.length()); assertEquals(2, child.getChildren().size()); - Field a = (Field) child.getChild("a"); + Field a = child.getChild("a"); assertEquals(1, a.length()); - Field b = (Field) child.getChild("b"); + Field b = child.getChild("b"); assertEquals(2, b.length()); } - EntityMap nest = (EntityMap) test2.getChild("nest"); + EntityMap nest = test2.getChild("nest"); assertEquals(19, nest.length()); assertEquals(4, nest.getChildren().size()); - Field nestFoo = (Field) nest.getChild("foo"); + Field nestFoo = nest.getChild("foo"); assertEquals(2, nestFoo.length()); char[] barChar = new char[] { 'A', 'B' }; for (int i = 0; i < barChar.length; i++) { - EntityArray bar = (EntityArray) nest.getChild("bar" + barChar[i]); + EntityArray bar = nest.getChild("bar" + barChar[i]); assertEquals(4, bar.length()); int barSize = bar.size(); assertEquals(2, barSize); for (int j = 0; j < barSize; j++) { - Field child = (Field) bar.getChild(j); + Field child = bar.getChild(j); assertEquals(2, child.length()); } } - EntityArray nestBaz = (EntityArray) test2.getChild("baz"); + EntityArray nestBaz = test2.getChild("baz"); assertEquals(9, nestBaz.length()); int nestBazSize = nestBaz.size(); assertEquals(3, nestBazSize); for (int i = 0; i < nestBazSize; i++) { - EntityMap child = (EntityMap) nestBaz.getChild(i); + EntityMap child = nestBaz.getChild(i); assertEquals(3, child.length()); assertEquals(2, child.getChildren().size()); - Field a = (Field) child.getChild("a"); + Field a = child.getChild("a"); assertEquals(1, a.length()); - Field b = (Field) child.getChild("b"); + Field b = child.getChild("b"); assertEquals(2, b.length()); } Modified: commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ValuesTest.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ValuesTest.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ValuesTest.java (original) +++ commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ValuesTest.java Fri Oct 21 22:53:28 2016 @@ -27,7 +27,7 @@ public class ValuesTest extends EntityPa @Test public void testValues() throws Exception { - EntityMap values = (EntityMap) entityFactory.getEntity("values"); + EntityMap values = entityFactory.getEntity("values"); assertValue("A", values.getChild("A")); assertValue("BB", values.getChild("BB")); assertValue("CCC", values.getChild("CCC")); @@ -36,9 +36,8 @@ public class ValuesTest extends EntityPa assertValue("BBBB", values.getChild("B4")); assertValue("CCCC", values.getChild("C4")); assertValue("DDDD", values.getChild("D4")); - testArray((EntityArray) ((EntityMap) values.getChild("initarray")) - .getChild("array")); - testArray((EntityArray) values.getChild("array")); + testArray(values.<EntityMap> getChild("initarray").<EntityArray> getChild("array")); + testArray(values.<EntityArray> getChild("array")); assertValue("twv", values.getChild("x")); assertValue("vwt", values.getChild("y")); assertValue("123123", values.getChild("z")); @@ -54,14 +53,14 @@ public class ValuesTest extends EntityPa @Test public void testImplicitLength() throws Exception { - Entity e = entityFactory.getEntity("implicitLength"); + Entity<?> e = entityFactory.getEntity("implicitLength"); assertEquals(12, e.length()); assertValue("foo-bar-baz!", e); } @Test public void testOverrideChildren() throws Exception { - Entity e = entityFactory.getEntity("overrideChildren"); + Entity<?> e = entityFactory.getEntity("overrideChildren"); assertEquals(45, e.length()); assertEquals("", new String(e.getValue()).trim()); } Modified: commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/conversion/ConversionTestBase.java URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/conversion/ConversionTestBase.java?rev=1766167&r1=1766166&r2=1766167&view=diff ============================================================================== --- commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/conversion/ConversionTestBase.java (original) +++ commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/conversion/ConversionTestBase.java Fri Oct 21 22:53:28 2016 @@ -23,7 +23,6 @@ import net.sf.morph.transform.Transforme import net.sf.morph.transform.copiers.PropertyNameMatchingCopier; import net.sf.morph.transform.transformers.SimpleDelegatingTransformer; -//import com.pgac.fixedlength.morph.EntityInstantiatingReflector; import org.apache.commons.flatfile.Entity; import org.apache.commons.flatfile.EntityParserTestBase; import org.apache.commons.flatfile.dsl.DefaultEntityNameStrategy; @@ -87,7 +86,7 @@ public abstract class ConversionTestBase } protected void assertConversion(TestPair pair) { - Entity e = (Entity) converter.convert(Entity.class, pair + Entity<?> e = (Entity<?>) converter.convert(Entity.class, pair .getModelObject()); assertValue(pair.getEntityValue(), e); }