You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2009/03/22 23:12:29 UTC
svn commit: r757266 [1/2] - in /commons/sandbox/flatfile/trunk/src:
main/antlr/ main/java/org/apache/commons/flatfile/
main/java/org/apache/commons/flatfile/dsl/
main/java/org/apache/commons/flatfile/entityfactory/
main/java/org/apache/commons/flatfile...
Author: mbenson
Date: Sun Mar 22 22:12:27 2009
New Revision: 757266
URL: http://svn.apache.org/viewvc?rev=757266&view=rev
Log:
Java 1.5
Removed:
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/EmptyArray.java
Modified:
commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g
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/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/PadJustifyFieldSupport.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/DefaultEntityNameStrategy.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/EntityDefinition.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/EntityNameStrategy.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/morph/BaseEntityCollectionReflector.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/ByteArrayToEntityCopier.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/ContainerToIndexedEntityCollectionCopier.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityCollectionReflector.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityInstantiatingReflector.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityToByteArrayConverter.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/FieldOptionConstantConverter.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/IndexedEntityCollectionInstantiatingReflector.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/IndexedEntityCollectionReflector.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/NamedEntityCollectionReflector.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/TextToByteConverter.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/TextToEntityCopier.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ApplyOptions.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/BasicFilterFactory.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ConcatenatedInputStream.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/FilterFactory.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/RepeatingInputStream.java
commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/EntityArrayLifecycleTest.java
Modified: commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g (original)
+++ commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g Sun Mar 22 22:12:27 2009
@@ -39,7 +39,7 @@
{
private ParserEntityFactory entityFactory;
- private Stack stk = new Stack();
+ private Stack<String> stk = new Stack<String>();
public synchronized Entity createEntity(EntityDefinition def) {
String name = def.getName();
@@ -54,7 +54,7 @@
} catch (ANTLRException e) {
throw new RuntimeException(e);
} finally {
- Object x = stk.pop();
+ String x = stk.pop();
if (!x.equals(def.getName())) {
throw new IllegalStateException("Stack out of balance; encountered " + x);
}
@@ -66,8 +66,7 @@
}
private void runChecks(EntityDefinition def, Entity e) {
- for (Iterator it = def.getChecks().iterator(); it.hasNext();) {
- AST check = (AST) it.next();
+ for (AST check : def.getChecks()) {
switch (check.getType()) {
case LENGTH :
int expected = Integer.parseInt(check.getText());
@@ -83,6 +82,7 @@
}
}
+//TODO support other encodings
private byte[] getBytes(String s) {
try {
return s.getBytes("UTF-8");
@@ -94,20 +94,20 @@
}
/* public */ load
-{ List checks = new ArrayList(); String name = null; }
+{ List<AST> checks = new ArrayList<AST>(); String name = null; }
: #( ROOT
( defaultOptions )*
( #( ASSIGN name=name e:. )
(
CHECK c:. {
checks.add(c);
- }
+ }
)*
{
EntityDefinition ed = new EntityDefinition(name, e);
if (!checks.isEmpty()) {
- ed.setChecks(checks);
- checks = new ArrayList();
+ ed.setChecks(new ArrayList<AST>(checks));
+ checks.clear();
}
entityFactory.add(name, ed);
}
@@ -116,7 +116,7 @@
;
protected defaultOptions
-{ HashMap m = new HashMap(); String key = null, value = null; }
+{ HashMap<String, String> m = new HashMap<String, String>(); String key = null, value = null; }
: #( o:OPTIONS
( #( ASSIGN key=optionKV value=optionKV { m.put(key, value); } ) )+
) { entityFactory.setDefaultOptions(o.getText(), m); }
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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -110,8 +110,8 @@
* @param maximum int
*/
public void setMaximum(int maximum) {
- Validate.isTrue(maximum <= ALL_VALID.getMaximum(),
- "maximum value > " + ALL_VALID.getMaximum(), maximum);
+ Validate.isTrue(maximum <= ALL_VALID.getMaximum(), "maximum value > "
+ + ALL_VALID.getMaximum(), maximum);
this.maximum = maximum;
}
@@ -128,8 +128,8 @@
* @param minimum int
*/
public void setMinimum(int minimum) {
- Validate.isTrue(minimum >= ALL_VALID.getMinimum(),
- "minimum value < " + ALL_VALID.getMinimum(), minimum);
+ Validate.isTrue(minimum >= ALL_VALID.getMinimum(), "minimum value < "
+ + ALL_VALID.getMinimum(), minimum);
this.minimum = minimum;
}
@@ -144,16 +144,14 @@
return false;
}
Bounds ob = (Bounds) o;
- return ob.getMaximum() == getMaximum()
- && ob.getMinimum() == getMinimum();
+ return ob.getMaximum() == getMaximum() && ob.getMinimum() == getMinimum();
}
/**
* {@inheritDoc}
*/
public int hashCode() {
- return new HashCodeBuilder().append(minimum).append(maximum)
- .toHashCode();
+ return new HashCodeBuilder().append(minimum).append(maximum).toHashCode();
}
/**
@@ -167,6 +165,7 @@
}
}
+ /** Serialization version */
private static final long serialVersionUID = -319053179741813727L;
private Bounds bounds;
@@ -189,20 +188,16 @@
setBounds(bounds);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#getValue()
+ /**
+ * {@inheritDoc}
*/
public synchronized byte[] getValue() {
initialize(ArrayUtils.EMPTY_BYTE_ARRAY);
return buffer.toByteArray();
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#length()
+ /**
+ * {@inheritDoc}
*/
public int length() {
initialize(ArrayUtils.EMPTY_BYTE_ARRAY);
@@ -220,14 +215,11 @@
public synchronized void readFrom(InputStream is) throws IOException {
initialize();
buffer.reset();
- IOUtils.copy(new ThresholdingInputStream(is, getBounds().getMaximum()),
- buffer);
+ IOUtils.copy(new ThresholdingInputStream(is, getBounds().getMaximum()), buffer);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#setValue(byte[])
+ /**
+ * {@inheritDoc}
*/
public synchronized void setValue(byte[] b) {
getBounds().validate(b, this);
@@ -235,10 +227,8 @@
iSetValue(b);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#writeTo(java.io.OutputStream)
+ /**
+ * {@inheritDoc}
*/
public synchronized void writeTo(OutputStream os) throws IOException {
initialize(ArrayUtils.EMPTY_BYTE_ARRAY);
@@ -277,20 +267,15 @@
this.underflow = underflow;
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
+ /**
+ * {@inheritDoc}
*/
public int hashCode() {
- return new HashCodeBuilder().append(getBounds()).append(getValue())
- .toHashCode();
+ return new HashCodeBuilder().append(getBounds()).append(getValue()).toHashCode();
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
public boolean equals(Object other) {
if (other == this) {
@@ -304,10 +289,8 @@
&& Arrays.equals(odf.getValue(), getValue());
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.PadJustifyFieldSupport#getPadJustifyLength()
+ /**
+ * {@inheritDoc}
*/
protected int getPadJustifyLength() {
return getBounds().getMinimum();
@@ -321,12 +304,10 @@
super.setValue(value);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.EntitySupport#clone()
+ /**
+ * {@inheritDoc}
*/
- public Object clone() {
+ public DynamicField clone() {
DynamicField result = (DynamicField) super.clone();
result.setBounds(new Bounds(getBounds()));
result.buffer = null;
@@ -334,16 +315,31 @@
return result;
}
- private synchronized void writeObject(ObjectOutputStream out)
- throws IOException {
+ /**
+ * Get the bounds.
+ * @return Bounds
+ */
+ public Bounds getBounds() {
+ return bounds;
+ }
+
+ /**
+ * Set the bounds.
+ * @param bounds Bounds
+ */
+ public void setBounds(Bounds bounds) {
+ Validate.notNull(bounds, "bounds cannot be null");
+ this.bounds = bounds;
+ }
+
+ private synchronized void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(getBounds());
initialize(ArrayUtils.EMPTY_BYTE_ARRAY);
out.write(buffer.size());
buffer.writeTo(out);
}
- private void readObject(ObjectInputStream in) throws IOException,
- ClassNotFoundException {
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
setBounds((Bounds) in.readObject());
int n = in.read();
initialize();
@@ -365,20 +361,4 @@
}
}
- /**
- * Get the bounds.
- * @return Bounds
- */
- public Bounds getBounds() {
- return bounds;
- }
-
- /**
- * Set the bounds.
- * @param bounds Bounds
- */
- public void setBounds(Bounds bounds) {
- Validate.notNull(bounds, "bounds cannot be null");
- this.bounds = 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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -50,7 +50,7 @@
* Clone oneself.
* @return a deep (or otherwise "safe") copy of this Entity.
*/
- Object clone();
+ Entity 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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
/**
@@ -34,7 +33,7 @@
private int minimumSize = 0;
private int maximumSize = Integer.MAX_VALUE;
private boolean resizable = false;
- private List children;
+ private List<Entity> children;
private Entity prototype;
/**
@@ -80,12 +79,10 @@
return (Entity) children.get(index);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.EntityCollection#getChildren()
+ /**
+ * {@inheritDoc}
*/
- public synchronized Collection getChildren() {
+ public synchronized Collection<Entity> getChildren() {
initialize();
return Collections.unmodifiableCollection(children);
}
@@ -148,12 +145,13 @@
* Clone this EntityArray.
* @return new EntityArray
*/
- public synchronized Object clone() {
+ @Override
+ public synchronized EntityArray clone() {
EntityArray result = (EntityArray) super.clone();
if (children != null) {
- result.children = new ArrayList();
- for (Iterator iter = children.iterator(); iter.hasNext();) {
- result.children.add(((Entity) iter.next()).clone());
+ result.children = new ArrayList<Entity>();
+ for (Entity e : children) {
+ result.children.add(e.clone());
}
}
return result;
@@ -167,13 +165,13 @@
throw new IllegalStateException("EntityArray size not set");
}
if (size == 0) {
- children = Collections.EMPTY_LIST;
+ children = Collections.<Entity>emptyList();
return;
}
if (prototype == null) {
throw new IllegalStateException("Prototype child entity not set");
}
- children = new ArrayList(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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -28,5 +28,5 @@
* Get the children.
* @return Collection<Entity>.
*/
- Collection getChildren();
+ Collection<Entity> 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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -29,22 +29,23 @@
* Implementation of common operations for an EntityCollection.
* @version $Revision$ $Date$
*/
-public abstract class EntityCollectionSupport extends EntitySupport implements
- EntityCollection {
+public abstract class EntityCollectionSupport extends EntitySupport implements EntityCollection {
+ /** Serialization version */
+ private static final long serialVersionUID = 5902476686737324304L;
+
private static final byte[] DEFAULT_DELIMITER = ArrayUtils.EMPTY_BYTE_ARRAY;
+
private byte[] delim = DEFAULT_DELIMITER;
private boolean delimAfter = true;
private boolean suppressEmptyChildren = true;
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#length()
+ /**
+ * {@inheritDoc}
*/
public final synchronized int length() {
int result = 0;
- for (Iterator it = getChildren().iterator(); it.hasNext();) {
- Entity e = (Entity) it.next();
+ for (Iterator<Entity> it = getChildren().iterator(); it.hasNext();) {
+ Entity e = it.next();
if (shouldSuppress(e)) {
continue;
}
@@ -56,14 +57,12 @@
return result;
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#readFrom(java.io.InputStream)
+ /**
+ * {@inheritDoc}
*/
public final synchronized void readFrom(InputStream is) throws IOException {
- for (Iterator it = getChildren().iterator(); it.hasNext();) {
- Entity e = (Entity) it.next();
+ for (Iterator<Entity> it = getChildren().iterator(); it.hasNext();) {
+ Entity e = it.next();
if (shouldSuppress(e)) {
continue;
}
@@ -76,14 +75,12 @@
}
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#writeTo(java.io.OutputStream)
+ /**
+ * {@inheritDoc}
*/
public final synchronized void writeTo(OutputStream os) throws IOException {
- for (Iterator it = getChildren().iterator(); it.hasNext();) {
- Entity e = (Entity) it.next();
+ for (Iterator<Entity> it = getChildren().iterator(); it.hasNext();) {
+ Entity e = it.next();
if (shouldSuppress(e)) {
continue;
}
@@ -94,10 +91,8 @@
}
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#getValue()
+ /**
+ * {@inheritDoc}
*/
public final synchronized byte[] getValue() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -109,10 +104,8 @@
return baos.toByteArray();
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#setValue(byte[])
+ /**
+ * {@inheritDoc}
*/
public final synchronized void setValue(byte[] b) {
try {
@@ -124,7 +117,6 @@
/**
* {@inheritDoc}
- * @see com.pgac.flatfile.EntitySupport#setValue(byte[], int, int)
*/
public final void setValue(byte[] b, int offset, int length) {
try {
@@ -184,6 +176,14 @@
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public EntityCollectionSupport clone() {
+ return (EntityCollectionSupport) super.clone();
+ }
+
+ /**
* Learn whether the specified child should be suppressed.
* @param child
* @return boolean
@@ -191,4 +191,5 @@
protected boolean shouldSuppress(Entity child) {
return isSuppressEmptyChildren() && child.length() == 0;
}
+
}
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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -16,10 +16,10 @@
*/
package org.apache.commons.flatfile;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -27,24 +27,48 @@
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.list.AbstractSerializableListDecorator;
+import org.apache.commons.collections.map.ListOrderedMap;
-import org.apache.commons.flatfile.util.EmptyArray;
+import org.apache.commons.lang.ArrayUtils;
/**
* Basic implementation of NamedEntityCollection.
* @version $Revision$ $Date$
*/
-public class EntityMap extends EntityCollectionSupport implements
- NamedEntityCollection {
+public class EntityMap extends EntityCollectionSupport implements NamedEntityCollection {
private static final long serialVersionUID = 3162898927743996952L;
+ private class Child implements Serializable {
+
+ /** Serialization version */
+ private static final long serialVersionUID = 2347729609002856564L;
+
+ private String name;
+ private Entity entity;
+
+ /**
+ * Create a new Child instance.
+ * @param name
+ * @param entity
+ */
+ public Child(String name, Entity entity) {
+ this.name = name;
+ if (entity == null) {
+ throw new IllegalArgumentException();
+ }
+ this.entity = entity;
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
private class ChildrenList extends AbstractSerializableListDecorator {
private static final long serialVersionUID = 3241482030276238909L;
private Transformer t = new Transformer() {
public Object transform(Object o) {
- return o instanceof Entity ? o : getChildMap().get(o);
+ return ((Child) o).entity;
}
};
@@ -52,52 +76,54 @@
super(children);
}
- public Object get(int index) {
- return t.transform(super.get(index));
+ public Entity get(int index) {
+ return (Entity) t.transform(super.get(index));
}
- public Iterator iterator() {
+ public Iterator<Entity> iterator() {
return IteratorUtils.transformedIterator(super.iterator(), t);
}
+
}
- /** contains names of mapped children OR the children themselves for unmapped children */
- private List children;
+ /** All children */
+ private List<Child> children;
/** contains mapped children only */
- private Map childMap;
+ private Map<String, Entity> childMap;
- private List exposeChildrenList;
+ private List<Entity> exposeChildrenList;
/**
* Add a child.
* @param name if null filler element
* @param child non-null child Entity
*/
+ @SuppressWarnings("unchecked")
public synchronized void add(String name, Entity child) {
if (child == null) {
throw new IllegalArgumentException("child entity is null");
}
if (children == null) {
- children = new ArrayList();
- childMap = new HashMap();
+ children = new ArrayList<Child>();
+ exposeChildrenList = new ChildrenList();
+ childMap = new ListOrderedMap();
}
if (childMap.containsKey(name)) {
- throw new IllegalArgumentException("cannot add > 1 child entity '"
- + name + "'");
+ throw new IllegalArgumentException("cannot add > 1 child entity '" + name + "'");
}
if (name != null) {
childMap.put(name, child);
}
- children.add(name == null ? (Object) child : name);
+ children.add(new Child(name, child));
}
/**
* Get a map of the children.
- * @return
+ * @return Map<String, Entity>
*/
- public synchronized Map getChildMap() {
- return childMap == null ? Collections.EMPTY_MAP : Collections
+ public synchronized Map<String, Entity> getChildMap() {
+ return childMap == null ? Collections.<String, Entity> emptyMap() : Collections
.unmodifiableMap(childMap);
}
@@ -106,8 +132,8 @@
* @see com.pgac.flatfile.NamedEntityCollection#getChildNames()
*/
public synchronized String[] getChildNames() {
- return childMap == null ? EmptyArray.STRING : (String[]) childMap
- .keySet().toArray(new String[childMap.size()]);
+ return childMap == null ? ArrayUtils.EMPTY_STRING_ARRAY : childMap.keySet().toArray(
+ new String[childMap.size()]);
}
/**
@@ -115,7 +141,7 @@
* @see com.pgac.flatfile.NamedEntityCollection#getChild(java.lang.String)
*/
public Entity getChild(String name) {
- return (Entity) getChildMap().get(name);
+ return getChildMap().get(name);
}
/**
@@ -130,31 +156,23 @@
* {@inheritDoc}
* @see com.pgac.flatfile.EntityCollection#getChildren()
*/
- public synchronized Collection getChildren() {
- if (children == null) {
- return Collections.EMPTY_LIST;
- }
- if (exposeChildrenList == null) {
- exposeChildrenList = new ChildrenList();
- }
- return exposeChildrenList;
+ public synchronized Collection<Entity> getChildren() {
+ return children == null ? Collections.<Entity> emptyList() : Collections
+ .unmodifiableList(exposeChildrenList);
}
/**
* {@inheritDoc}
* @see com.pgac.flatfile.EntitySupport#clone()
*/
- public synchronized Object clone() {
+ public synchronized EntityMap clone() {
EntityMap result = (EntityMap) super.clone();
result.children = null;
result.childMap = null;
result.exposeChildrenList = null;
if (children != null) {
- for (Iterator iter = children.iterator(); iter.hasNext();) {
- Object o = iter.next();
- String name = o instanceof String ? (String) o : null;
- Entity e = (Entity) (o instanceof Entity ? o : childMap.get(o));
- result.add(name, (Entity) e.clone());
+ for (Child child : children) {
+ result.add(child.name, child.entity.clone());
}
}
return result;
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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -26,23 +26,22 @@
*/
public abstract class EntitySupport implements Entity {
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#fill(byte)
+ /** Serialization version */
+ private static final long serialVersionUID = 1067918863342682612L;
+
+ /**
+ * {@inheritDoc}
*/
public void fill(byte b) throws IOException {
readFrom(RepeatingInputStream.getInstance(b));
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#clone()
+ /**
+ * {@inheritDoc}
*/
- public Object clone() {
+ public EntitySupport clone() {
try {
- return super.clone();
+ return (EntitySupport) super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
@@ -50,7 +49,6 @@
/**
* {@inheritDoc}
- * @see com.pgac.flatfile.Entity#getValue(int, int)
*/
public byte[] getValue(int offset, int length) {
if (offset + length > length()) {
@@ -64,7 +62,6 @@
/**
* {@inheritDoc}
- * @see com.pgac.flatfile.Entity#setValue(byte[], int, int)
*/
public void setValue(byte[] b, int offset, int length) {
if (offset + length > b.length) {
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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -33,7 +33,7 @@
/**
* Create a new Field.
- * @param size
+ * @param size of field
*/
public Field(int size) {
this(new byte[size]);
@@ -47,58 +47,46 @@
this.buffer = buffer;
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#length()
+ /**
+ * {@inheritDoc}
*/
public int length() {
return buffer.length;
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#readFrom(java.io.InputStream)
+ /**
+ * {@inheritDoc}
*/
public synchronized void readFrom(InputStream is) throws IOException {
is.read(buffer);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#writeTo(java.io.OutputStream)
+ /**
+ * {@inheritDoc}
*/
public synchronized void writeTo(OutputStream os) throws IOException {
os.write(buffer);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#setValue(byte[])
+ /**
+ * {@inheritDoc}
*/
public void setValue(byte[] b) {
getOverflow().check(b, buffer.length);
super.setValue(b);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#getValue()
+ /**
+ * {@inheritDoc}
*/
public byte[] getValue() {
return buffer;
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.Entity#clone()
+ /**
+ * {@inheritDoc}
*/
- public Object clone() {
+ public Field clone() {
Field result = (Field) super.clone();
result.buffer = new byte[buffer.length];
System.arraycopy(buffer, 0, result.buffer, 0, buffer.length);
@@ -121,10 +109,8 @@
this.overflow = overflow;
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.PadJustifyFieldSupport#getPadJustifyLength()
+ /**
+ * {@inheritDoc}
*/
protected int getPadJustifyLength() {
return length();
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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -25,71 +25,54 @@
*/
public abstract class FieldSupport extends EntitySupport {
+ /** Serialization version */
+ private static final long serialVersionUID = -8940832296518637934L;
+
/**
- * Overflow enumerated type.
+ * Overflow behavior enumerated type.
*/
- public static abstract class Overflow implements FieldOption {
+ public static enum Overflow implements FieldOption {
/** Error on overflow */
- public static final Overflow ERROR = new Overflow() {
- private static final long serialVersionUID = -7441509026880178410L;
-
+ ERROR() {
protected void check(byte[] b, int len) {
if (b.length > len) {
- throw new IllegalArgumentException(new String(b)
- + " too large for field (" + len + ")");
+ throw new IllegalArgumentException(new String(b) + " too large for field ("
+ + len + ")");
}
}
- };
-
- /** Ignore on overflow */
- public static final Overflow IGNORE = new Overflow() {
- private static final long serialVersionUID = -904459454393715111L;
-
- protected void check(byte[] b, int len) {
- // ignore
- }
- };
+ },
- /** Field-specific backwards compatible IGNORE alias */
- public static final Overflow TRUNCATE = IGNORE;
+ /** Truncate on overflow (same as IGNORE) */
+ TRUNCATE,
- private Overflow() {
- }
+ /** Ignore overflow (same as TRUNCATE) */
+ IGNORE;
/** Check the given aspect of the field */
- protected abstract void check(byte[] b, int len);
+ protected void check(byte[] b, int len) {
+ }
}
/**
- * Underflow enumerated type.
+ * Underflow behavior enumerated type.
*/
- public static abstract class Underflow implements FieldOption {
+ public static enum Underflow implements FieldOption {
/** Error on Underflow */
- public static final Underflow ERROR = new Underflow() {
- private static final long serialVersionUID = 6868582529171417983L;
-
+ ERROR() {
protected void check(byte[] b, int len) {
if (b.length < len) {
- throw new IllegalArgumentException(new String(b)
- + " too small for field (" + len + ")");
+ throw new IllegalArgumentException(new String(b) + " too small for field ("
+ + len + ")");
}
}
- };
-
- /** Ignore on Underflow */
- public static final Underflow IGNORE = new Underflow() {
- private static final long serialVersionUID = -8423193000820647264L;
+ },
- protected void check(byte[] b, int len) {
- // ignore
- }
- };
-
- private Underflow() {
- }
+ /** Ignore Underflow */
+ IGNORE;
/** Check the given aspect of the field */
- protected abstract void check(byte[] b, int len);
+ protected void check(byte[] b, int len) {
+ }
}
/**
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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -25,13 +25,14 @@
import java.util.Map;
import java.util.WeakHashMap;
+import org.apache.commons.lang.ArrayUtils;
+
/**
* Immutable Entity factory, using Java 1.3 proxies.
* @version $Revision$ $Date$
*/
public class ImmutableEntity {
- private static class ImmutableEntityInvocationHandler implements
- InvocationHandler {
+ private static class ImmutableEntityInvocationHandler implements InvocationHandler {
// make sure this array stays sorted:
private static final String[] ALLOWED_VOID = { "readFrom", "writeTo" };
private static final String CLONE = "clone";
@@ -51,18 +52,16 @@
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
* java.lang.reflect.Method, java.lang.Object[])
*/
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String name = method.getName();
// 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) {
+ if (method.getReturnType() == Void.TYPE && Arrays.binarySearch(ALLOWED_VOID, name) < 0) {
return null;
}
if (READ_FROM.equals(name)) {
@@ -106,8 +105,7 @@
}
}
- private static final Map PROXIES = new WeakHashMap();
- private static final Class[] NO_CLASS = new Class[0];
+ private static final Map<Entity, Entity> PROXIES = new WeakHashMap<Entity, Entity>();
private ImmutableEntity() {
}
@@ -115,20 +113,19 @@
public static Entity getInstance(Entity e) {
Entity result = (Entity) PROXIES.get(e);
if (result == null) {
- result = (Entity) Proxy.newProxyInstance(e.getClass()
- .getClassLoader(), getInterfaces(e),
- new ImmutableEntityInvocationHandler(e));
+ result = (Entity) Proxy.newProxyInstance(e.getClass().getClassLoader(),
+ getInterfaces(e), new ImmutableEntityInvocationHandler(e));
PROXIES.put(e, result);
}
return result;
}
- private static Class[] getInterfaces(Object o) {
- HashSet set = new HashSet();
- for (Class c = o.getClass(); c != null; c = c.getSuperclass()) {
- set.addAll(Arrays.asList(c.getInterfaces()));
+ private static Class<?>[] getInterfaces(Object o) {
+ HashSet<Class<?>> set = new HashSet<Class<?>>();
+ for (Class<?> c = o.getClass(); c != null; c = c.getSuperclass()) {
+ set.addAll(Arrays.<Class<?>> asList(c.getInterfaces()));
}
- return set.isEmpty() ? NO_CLASS : (Class[]) set.toArray(new Class[set
- .size()]);
+ return set.isEmpty() ? ArrayUtils.EMPTY_CLASS_ARRAY : (Class<?>[]) set
+ .toArray(new Class[set.size()]);
}
}
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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -28,81 +28,67 @@
* @version $Revision$ $Date$
*/
public abstract class PadJustifyFieldSupport extends FieldSupport {
+ /** Serialization version */
+ private static final long serialVersionUID = -4953059253157670418L;
+
/**
* Justify enumerated type.
*/
- public static abstract class Justify implements FieldOption {
+ public static enum Justify implements FieldOption {
/** Left-justify */
- public static final Justify LEFT = new Justify() {
- private static final long serialVersionUID = 9080286767796807220L;
-
- protected InputStream getInputStream(byte[] src,
- PadJustifyFieldSupport dest) {
+ LEFT {
+ protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest) {
InputStream is = new ByteArrayInputStream(src);
int dlen = dest.getPadJustifyLength();
- return dlen <= src.length ? is : new ConcatenatedInputStream(
- is, RepeatingInputStream.getInstance(dest.getPad(),
- dlen - src.length));
+ return dlen <= src.length ? is : new ConcatenatedInputStream(is,
+ RepeatingInputStream.getInstance(dest.getPad(), dlen - src.length));
}
- };
+ },
/** Right-justify */
- public static final Justify RIGHT = new Justify() {
- private static final long serialVersionUID = -5793503470625462046L;
-
- protected InputStream getInputStream(byte[] src,
- PadJustifyFieldSupport dest) {
+ RIGHT {
+ protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest) {
int dlen = dest.getPadJustifyLength();
if (dlen < src.length) {
- return new ByteArrayInputStream(src, src.length - dlen,
- dlen);
+ return new ByteArrayInputStream(src, src.length - dlen, dlen);
}
InputStream is = new ByteArrayInputStream(src);
- return dlen == src.length ? is : new ConcatenatedInputStream(
- RepeatingInputStream.getInstance(dest.getPad(), dlen
- - src.length), is);
+ return dlen == src.length ? is : new ConcatenatedInputStream(RepeatingInputStream
+ .getInstance(dest.getPad(), dlen - src.length), is);
}
- };
+ },
/** Center */
- public static final Justify CENTER = new Justify() {
- private static final long serialVersionUID = -5301921606809471697L;
+ CENTER {
- protected InputStream getInputStream(byte[] src,
- PadJustifyFieldSupport dest) {
+ protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest) {
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:
if (dlen < src.length) {
- return new ByteArrayInputStream(src,
- (src.length - dlen) / 2, dlen);
+ return new ByteArrayInputStream(src, (src.length - dlen) / 2, dlen);
}
InputStream is = new ByteArrayInputStream(src);
if (dlen == src.length) {
return is;
}
- ArrayList l = new ArrayList(3);
+ ArrayList<InputStream> l = new ArrayList<InputStream>(3);
byte pad = dest.getPad();
- l.add(RepeatingInputStream.getInstance(pad,
- (dlen - src.length) / 2));
+ l.add(RepeatingInputStream.getInstance(pad, (dlen - src.length) / 2));
l.add(is);
l.add(RepeatingInputStream.getInstance(pad));
return new ConcatenatedInputStream(l);
}
};
- private Justify() {
- }
-
/**
* Get an InputStream for the specified parameters.
* @param src byte[] value
* @param dest PadJustifyFieldSupport
* @return InputStream
*/
- protected abstract InputStream getInputStream(byte[] src,
- PadJustifyFieldSupport dest);
+ protected abstract InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest);
}
private byte pad = 0x20;
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/DefaultEntityNameStrategy.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/DefaultEntityNameStrategy.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/DefaultEntityNameStrategy.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/DefaultEntityNameStrategy.java Sun Mar 22 22:12:27 2009
@@ -33,6 +33,7 @@
* @param o Object.
* @return String entity name.
*/
+ @SuppressWarnings("unchecked")
public String getEntityName(Object o) {
if (o == null) {
return NULL;
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/EntityDefinition.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/EntityDefinition.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/EntityDefinition.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/EntityDefinition.java Sun Mar 22 22:12:27 2009
@@ -28,7 +28,7 @@
public class EntityDefinition {
private String name;
private AST ast;
- private Collection checks;
+ private Collection<AST> checks;
/**
* Create a new EntityDefinition.
@@ -60,15 +60,15 @@
* Get the checks.
* @return Collection.
*/
- public synchronized Collection getChecks() {
- return checks == null ? Collections.EMPTY_LIST : checks;
+ public synchronized Collection<AST> getChecks() {
+ return checks == null ? Collections.<AST>emptyList() : checks;
}
/**
* Set the checks.
* @param checks The Collection checks to set.
*/
- public synchronized void setChecks(Collection checks) {
+ public synchronized void setChecks(Collection<AST> checks) {
this.checks = checks;
}
}
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/EntityNameStrategy.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/EntityNameStrategy.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/EntityNameStrategy.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/EntityNameStrategy.java Sun Mar 22 22:12:27 2009
@@ -21,5 +21,10 @@
* @version $Revision$ $Date$
*/
public interface EntityNameStrategy {
+ /**
+ * Get the Entity name to associate with the argument.
+ * @param o to resolve
+ * @return String entity name
+ */
String getEntityName(Object o);
}
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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -20,7 +20,6 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.apache.commons.lang.ObjectUtils;
@@ -53,16 +52,16 @@
private static final EntityNameStrategy DEFAULT_NAME_STRATEGY = new DefaultEntityNameStrategy();
private EntityNameStrategy entityNameStrategy;
- private ThreadLocal treeParser = new ThreadLocal() {
- protected Object initialValue() {
+ private ThreadLocal<EntityTreeParser> treeParser = new ThreadLocal<EntityTreeParser>() {
+ protected EntityTreeParser initialValue() {
EntityTreeParser result = new EntityTreeParser();
result.setEntityFactory(ParserEntityFactory.this);
return result;
}
};
- private Map entityMap;
- private Map defaultOptionMaps = new HashMap();
+ private Map<String, Object> entityMap;
+ private Map<String, Map<String, ? extends Object>> defaultOptionMaps = new HashMap<String, Map<String, ? extends Object>>();
private boolean checked;
private InputStream[] sources;
private EntityFactory parent;
@@ -91,7 +90,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see com.pgac.fixedlength.EntityFactory#getEntity(java.lang.Object)
*/
public final Entity getEntity(Object cue) {
@@ -101,8 +100,7 @@
return e;
}
}
- Object o = getEntityMap().get(
- getEntityNameStrategy().getEntityName(cue));
+ Object o = getEntityMap().get(getEntityNameStrategy().getEntityName(cue));
if (o == null) {
return null;
}
@@ -115,7 +113,7 @@
prototype = tp.createEntity(def);
entityMap.put(def.getName(), prototype);
}
- return (Entity) prototype.clone();
+ return prototype.clone();
}
/**
@@ -125,8 +123,8 @@
if (checked) {
return;
}
- for (Iterator it = getEntityMap().keySet().iterator(); it.hasNext();) {
- getEntity((String) it.next());
+ for (String name : getEntityMap().keySet()) {
+ getEntity(name);
}
}
@@ -135,16 +133,14 @@
* @return EntityNameStrategy.
*/
public synchronized EntityNameStrategy getEntityNameStrategy() {
- return entityNameStrategy == null ? DEFAULT_NAME_STRATEGY
- : entityNameStrategy;
+ return entityNameStrategy == null ? DEFAULT_NAME_STRATEGY : entityNameStrategy;
}
/**
* Set the entityNameStrategy.
* @param entityNameStrategy The EntityNameStrategy entityNameStrategy to set.
*/
- public synchronized void setEntityNameStrategy(
- EntityNameStrategy entityNameStrategy) {
+ public synchronized void setEntityNameStrategy(EntityNameStrategy entityNameStrategy) {
this.entityNameStrategy = entityNameStrategy;
}
@@ -194,16 +190,16 @@
}
/* package-private */
- void setDefaultOptions(String type, Map options) {
- Object old = defaultOptionMaps.put(type, options);
+ void setDefaultOptions(String type, Map<String, ? extends Object> options) {
+ Map<String, ? extends Object> old = defaultOptionMaps.put(type, options);
if (!ObjectUtils.equals(old, options)) {
LOG.warn("Overriding " + type + " options");
}
}
/* package-private */
- Map getDefaultOptions(String type) {
- return (Map) defaultOptionMaps.get(type);
+ Map<String, ? extends Object> getDefaultOptions(String type) {
+ return defaultOptionMaps.get(type);
}
/* package-private */
@@ -222,20 +218,20 @@
}
private Entity applyDefaultOptions(Entity e, String type) {
- Map m = (Map) defaultOptionMaps.get(type);
- return m == null ? e : (Entity) ApplyOptions.apply(e, m);
+ Map<String, ? extends Object> m = defaultOptionMaps.get(type);
+ return m == null ? e : ApplyOptions.apply(e, m);
}
private EntityTreeParser getTreeParser() {
return (EntityTreeParser) treeParser.get();
}
- private synchronized Map getEntityMap() {
+ private synchronized Map<String, Object> getEntityMap() {
if (entityMap == null) {
- entityMap = new HashMap();
+ entityMap = new HashMap<String, Object>();
try {
EntityParser p = null;
- ArrayList trees = new ArrayList();
+ ArrayList<AST> trees = new ArrayList<AST>();
InputStream[] is = getSources();
for (int i = 0; i < is.length; i++) {
TokenBuffer tb = new TokenBuffer(new EntityLexer(is[i]));
@@ -247,8 +243,8 @@
p.parse();
trees.add(p.getAST());
}
- for (Iterator it = trees.iterator(); it.hasNext();) {
- getTreeParser().load((AST) it.next());
+ for (AST ast : trees) {
+ getTreeParser().load(ast);
}
} catch (Exception e) {
throw e instanceof RuntimeException ? (RuntimeException) e
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=757266&r1=757265&r2=757266&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 Sun Mar 22 22:12:27 2009
@@ -26,27 +26,25 @@
* @version $Revision$ $Date$
*/
public class CloningEntityFactory implements EntityFactory {
- private Map lookup;
+ private Map<? extends Object, ? extends Entity> lookup;
/**
* Create a new CloningEntityFactory.
* @param lookup lookup Map
*/
- public CloningEntityFactory(Map lookup) {
+ public CloningEntityFactory(Map<? extends Object, ? extends Entity> lookup) {
if (lookup == null) {
throw new IllegalArgumentException("null lookup Map");
}
this.lookup = lookup;
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.EntityFactory#getEntity(java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
public Entity getEntity(Object cue) {
- Entity prototype = (Entity) lookup.get(cue);
- return prototype == null ? null : (Entity) prototype.clone();
+ Entity prototype = lookup.get(cue);
+ return prototype == null ? null : prototype.clone();
}
}
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/BaseEntityCollectionReflector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/BaseEntityCollectionReflector.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/BaseEntityCollectionReflector.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/BaseEntityCollectionReflector.java Sun Mar 22 22:12:27 2009
@@ -46,14 +46,14 @@
this.propertyName = propertyName;
}
- final Class getTypeFrom(Object bean) throws Exception {
+ final Class<?> getTypeFrom(Object bean) throws Exception {
if (isEntity(bean, propertyName)) {
return getEntityType(getEntity(bean, propertyName));
}
return FALLBACK.getType(bean, propertyName);
}
- abstract Class getEntityType(Entity e) throws Exception;
+ abstract Class<?> getEntityType(Entity e) throws Exception;
final Object getFrom(Object bean) throws Exception {
if (isEntity(bean, propertyName)) {
@@ -92,7 +92,7 @@
super(propertyName.substring(TYPE_OVERRIDE.length()));
}
- Class getEntityType(Entity e) {
+ Class<?> getEntityType(Entity e) {
return ClassUtils.getClass(e);
}
@@ -111,7 +111,7 @@
super(propertyName);
}
- Class getEntityType(Entity e) {
+ Class<?> getEntityType(Entity e) {
return e instanceof EntityCollection ? EntityCollection.class
: String.class;
}
@@ -150,58 +150,50 @@
this.trimStrings = trimStrings;
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getContainedTypeImpl(java.lang.Class)
+ /**
+ * {@inheritDoc}
*/
- protected Class getContainedTypeImpl(Class c) throws Exception {
+ @SuppressWarnings("unchecked")
+ protected Class<?> getContainedTypeImpl(Class c) throws Exception {
return Entity.class;
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getIteratorImpl(java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
- protected Iterator getIteratorImpl(Object o) throws Exception {
+ protected Iterator<Entity> getIteratorImpl(Object o) throws Exception {
return ((EntityCollection) o).getChildren().iterator();
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getSizeImpl(java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
protected int getSizeImpl(Object o) throws Exception {
return ((EntityCollection) o).getChildren().size();
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getTypeImpl(java.lang.Object,
- * java.lang.String)
+ /**
+ * {@inheritDoc}
*/
- protected Class getTypeImpl(Object bean, String propertyName)
+ protected Class<?> getTypeImpl(Object bean, String propertyName)
throws Exception {
return getPropertyStrategy(propertyName).getTypeFrom(bean);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getImpl(java.lang.Object,
- * int)
+ /**
+ * {@inheritDoc}
*/
protected Object getImpl(Object container, int index) throws Exception {
Entity e = getEntity(container, index);
return e instanceof EntityCollection ? (Object) e : getString(e);
}
+ /**
+ * {@inheritDoc}
+ */
/*
* (non-Javadoc)
- *
+ *
* @see net.sf.morph.reflect.reflectors.BaseReflector#getImpl(java.lang.Object,
* java.lang.String)
*/
@@ -209,22 +201,16 @@
return getPropertyStrategy(propertyName).getFrom(bean);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#setImpl(java.lang.Object,
- * java.lang.String, java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
protected void setImpl(Object bean, String propertyName, Object value)
throws Exception {
getPropertyStrategy(propertyName).setOn(bean, value);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#setImpl(java.lang.Object,
- * int, java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
protected Object setImpl(Object container, int index, Object propertyValue)
throws Exception {
@@ -235,6 +221,7 @@
}
/**
+ * Set the value of an Entity
* @param value Object Set the value of <code>e</code> by converting <code>value</code> to a byte[]
* @param e Entity
* @throws Exception
@@ -243,13 +230,11 @@
e.setValue((byte[]) getToTextConverter().convert(byte[].class, value));
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getPropertyNamesImpl(java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
protected String[] getPropertyNamesImpl(Object bean) throws Exception {
- HashSet result = new HashSet();
+ HashSet<String> result = new HashSet<String>();
if (this instanceof IndexedContainerReflector) {
result.addAll(Arrays.asList(super.getPropertyNamesImpl(bean)));
}
@@ -261,7 +246,7 @@
result.add("@" + fallback[i]);
}
}
- return (String[]) result.toArray(new String[result.size()]);
+ return result.toArray(new String[result.size()]);
}
/**
@@ -297,22 +282,16 @@
throw new UnsupportedOperationException();
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#isReadableImpl(java.lang.Object,
- * java.lang.String)
+ /**
+ * {@inheritDoc}
*/
protected boolean isReadableImpl(Object bean, String propertyName)
throws Exception {
return getPropertyStrategy(propertyName).isReadableOn(bean);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#isWriteableImpl(java.lang.Object,
- * java.lang.String)
+ /**
+ * {@inheritDoc}
*/
protected boolean isWriteableImpl(Object bean, String propertyName)
throws Exception {
@@ -320,6 +299,7 @@
}
/**
+ * Get the to-text {@link DecoratedConverter} assigned.
* @return the toTextConverter
*/
public synchronized DecoratedConverter getToTextConverter() {
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/ByteArrayToEntityCopier.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/ByteArrayToEntityCopier.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/ByteArrayToEntityCopier.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/ByteArrayToEntityCopier.java Sun Mar 22 22:12:27 2009
@@ -32,32 +32,22 @@
public class ByteArrayToEntityCopier extends BaseTransformer implements
DecoratedConverter, DecoratedCopier {
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#copyImpl(java.lang.Object,
- * java.lang.Object, java.util.Locale, java.lang.Integer)
- */
protected void copyImpl(Object destination, Object source, Locale locale,
Integer preferredTransformationType) throws Exception {
((Entity) destination).setValue((byte[]) source);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#getSourceClassesImpl()
+ /**
+ * {@inheritDoc}
*/
- protected Class[] getSourceClassesImpl() throws Exception {
+ protected Class<?>[] getSourceClassesImpl() throws Exception {
return new Class[] { byte[].class };
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#getDestinationClassesImpl()
+ /**
+ * {@inheritDoc}
*/
- protected Class[] getDestinationClassesImpl() throws Exception {
+ protected Class<?>[] getDestinationClassesImpl() throws Exception {
return new Class[] { Entity.class };
}
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/ContainerToIndexedEntityCollectionCopier.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/ContainerToIndexedEntityCollectionCopier.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/ContainerToIndexedEntityCollectionCopier.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/ContainerToIndexedEntityCollectionCopier.java Sun Mar 22 22:12:27 2009
@@ -40,14 +40,11 @@
* @version $Revision$ $Date$
*/
public class ContainerToIndexedEntityCollectionCopier extends ContainerCopier {
- private static final Class[] DEST_CLASSES = new Class[] { IndexedEntityCollection.class };
+ private static final Class<?>[] DEST_CLASSES = new Class[] { IndexedEntityCollection.class };
- private static class SizeOneReflector extends ObjectReflector implements
- SizableReflector {
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getSizeImpl(java.lang.Object)
+ private static class SizeOneReflector extends ObjectReflector implements SizableReflector {
+ /**
+ * {@inheritDoc}
*/
protected int getSizeImpl(Object container) throws Exception {
return 1;
@@ -59,72 +56,58 @@
*/
public ContainerToIndexedEntityCollectionCopier() {
setReflector(new SimpleDelegatingReflector(new Reflector[] {
- new EntityCollectionReflector(), new ListReflector(),
- new SortedSetReflector(), new SetReflector(),
- new EnumerationReflector(), new IteratorReflector(),
- new ArrayReflector(), new CollectionReflector(),
- new SizeOneReflector() }));
+ new EntityCollectionReflector(), new ListReflector(), new SortedSetReflector(),
+ new SetReflector(), new EnumerationReflector(), new IteratorReflector(),
+ new ArrayReflector(), new CollectionReflector(), new SizeOneReflector() }));
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#setSourceClasses(java.lang.Class[])
+ /**
+ * {@inheritDoc}
*/
+ @SuppressWarnings("unchecked")
public synchronized void setSourceClasses(Class[] sourceClasses) {
super.setSourceClasses(sourceClasses);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.copiers.ContainerCopier#getSourceClassesImpl()
- */
- protected Class[] getSourceClassesImpl() throws Exception {
- Class[] c = getBeanReflector().getReflectableClasses();
- Class[] result = new Class[c.length + 1];
+ /**
+ * {@inheritDoc}
+ */
+ protected Class<?>[] getSourceClassesImpl() throws Exception {
+ Class<?>[] c = getBeanReflector().getReflectableClasses();
+ Class<?>[] result = new Class[c.length + 1];
System.arraycopy(c, 0, result, 0, c.length);
return result;
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#setDestinationClasses(java.lang.Class[])
+ /**
+ * {@inheritDoc}
*/
+ @SuppressWarnings("unchecked")
public synchronized void setDestinationClasses(Class[] destinationClasses) {
super.setDestinationClasses(destinationClasses);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.copiers.ContainerCopier#getDestinationClassesImpl()
+ /**
+ * {@inheritDoc}
*/
- protected Class[] getDestinationClassesImpl() throws Exception {
+ protected Class<?>[] getDestinationClassesImpl() throws Exception {
return DEST_CLASSES;
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.copiers.ContainerCopier#copyImpl(java.lang.Object,
- * java.lang.Object, java.util.Locale, java.lang.Integer)
+ /**
+ * {@inheritDoc}
*/
protected void copyImpl(Object destination, Object source, Locale locale,
Integer preferredTransformationType) throws TransformationException {
int size = source == null ? 0 : getBeanReflector().getSize(source);
((IndexedEntityCollection) destination).setSize(size);
if (size > 0) {
- super.copyImpl(destination, source, locale,
- preferredTransformationType);
+ super.copyImpl(destination, source, locale, preferredTransformationType);
}
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#isAutomaticallyHandlingNulls()
+ /**
+ * {@inheritDoc}
*/
protected boolean isAutomaticallyHandlingNulls() {
return false;
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityCollectionReflector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityCollectionReflector.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityCollectionReflector.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityCollectionReflector.java Sun Mar 22 22:12:27 2009
@@ -32,10 +32,8 @@
// default
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.SimpleDelegatingReflector#createDefaultComponents()
+ /**
+ * {@inheritDoc}
*/
protected synchronized Reflector[] createDefaultComponents() {
return new Reflector[] { new IndexedEntityCollectionReflector(),
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityInstantiatingReflector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityInstantiatingReflector.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityInstantiatingReflector.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityInstantiatingReflector.java Sun Mar 22 22:12:27 2009
@@ -56,12 +56,10 @@
setEntityFactory(entityFactory);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getReflectableClassesImpl()
+ /**
+ * {@inheritDoc}
*/
- protected Class[] getReflectableClassesImpl() throws Exception {
+ protected Class<?>[] getReflectableClassesImpl() throws Exception {
return new Class[] { Entity.class };
}
@@ -81,12 +79,10 @@
this.entityFactory = entityFactory;
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#newInstanceImpl(java.lang.Class,
- * java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
+ @SuppressWarnings("unchecked")
protected Object newInstanceImpl(Class destType, Object source)
throws Exception {
Entity e = getEntityFactory().getEntity(source);
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityToByteArrayConverter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityToByteArrayConverter.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityToByteArrayConverter.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/EntityToByteArrayConverter.java Sun Mar 22 22:12:27 2009
@@ -29,30 +29,24 @@
*/
public class EntityToByteArrayConverter extends BaseTransformer implements
DecoratedConverter {
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#getDestinationClassesImpl()
+ /**
+ * {@inheritDoc}
*/
- protected Class[] getDestinationClassesImpl() throws Exception {
+ protected Class<?>[] getDestinationClassesImpl() throws Exception {
return new Class[] { byte[].class };
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#getSourceClassesImpl()
+ /**
+ * {@inheritDoc}
*/
- protected Class[] getSourceClassesImpl() throws Exception {
+ protected Class<?>[] getSourceClassesImpl() throws Exception {
return new Class[] { Entity.class };
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#convertImpl(java.lang.Class,
- * java.lang.Object, java.util.Locale)
+ /**
+ * {@inheritDoc}
*/
+ @SuppressWarnings("unchecked")
protected Object convertImpl(Class destType, Object source, Locale locale)
throws Exception {
return ((Entity) source).getValue();
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/FieldOptionConstantConverter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/FieldOptionConstantConverter.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/FieldOptionConstantConverter.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/FieldOptionConstantConverter.java Sun Mar 22 22:12:27 2009
@@ -28,38 +28,35 @@
* Convert text to FieldOption instances from class constants.
* @version $Revision$ $Date$
*/
+@SuppressWarnings("unchecked")
public class FieldOptionConstantConverter extends BaseTransformer implements
DecoratedConverter {
private DecoratedConverter textConverter;
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#getDestinationClassesImpl()
+ /**
+ * {@inheritDoc}
*/
protected Class[] getDestinationClassesImpl() throws Exception {
return new Class[] { FieldOption.class };
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#getSourceClassesImpl()
+ /**
+ * {@inheritDoc}
*/
protected Class[] getSourceClassesImpl() throws Exception {
return getTextConverter().getSourceClasses();
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#convertImpl(java.lang.Class,
- * java.lang.Object, java.util.Locale)
+ /**
+ * {@inheritDoc}
*/
protected Object convertImpl(Class destinationClass, Object source,
Locale locale) throws Exception {
String constant = (String) getTextConverter().convert(String.class,
source, locale);
+ if (destinationClass.isEnum()) {
+ return Enum.valueOf(destinationClass, constant);
+ }
// return static field
return destinationClass.getField(constant).get(null);
}
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/IndexedEntityCollectionInstantiatingReflector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/IndexedEntityCollectionInstantiatingReflector.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/IndexedEntityCollectionInstantiatingReflector.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/IndexedEntityCollectionInstantiatingReflector.java Sun Mar 22 22:12:27 2009
@@ -41,12 +41,10 @@
private InstantiatingReflector componentReflector;
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getReflectableClassesImpl()
+ /**
+ * {@inheritDoc}
*/
- protected Class[] getReflectableClassesImpl() throws Exception {
+ protected Class<?>[] getReflectableClassesImpl() throws Exception {
return new Class[] { IndexedEntityCollection.class };
}
@@ -67,12 +65,10 @@
this.componentReflector = componentReflector;
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.reflectors.BaseEntityCollectionReflector#newInstanceImpl(java.lang.Class,
- * java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
+ @SuppressWarnings("unchecked")
protected Object newInstanceImpl(Class destType, Object source)
throws Exception {
int size = CONTAINER_REFLECTOR.getSize(source);
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/IndexedEntityCollectionReflector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/IndexedEntityCollectionReflector.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/IndexedEntityCollectionReflector.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/IndexedEntityCollectionReflector.java Sun Mar 22 22:12:27 2009
@@ -36,30 +36,22 @@
*/
public static final String IMPLICIT_PROPERTY_PROTOTYPE = "prototype";
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.reflect.BaseEntityCollectionReflector#getEntity(java.lang.Object,
- * int)
+ /**
+ * {@inheritDoc}
*/
protected Entity getEntity(Object container, int index) throws Exception {
return ((IndexedEntityCollection) container).getChild(index);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getReflectableClassesImpl()
+ /**
+ * {@inheritDoc}
*/
- protected Class[] getReflectableClassesImpl() throws Exception {
+ protected Class<?>[] getReflectableClassesImpl() throws Exception {
return new Class[] { IndexedEntityCollection.class };
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.morph.BaseEntityCollectionReflector#isEntity(java.lang.Object,
- * java.lang.String)
+ /**
+ * {@inheritDoc}
*/
protected boolean isEntity(Object bean, String propertyName)
throws Exception {
@@ -76,11 +68,8 @@
return false;
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.morph.BaseEntityCollectionReflector#getImpl(java.lang.Object,
- * java.lang.String)
+ /**
+ * {@inheritDoc}
*/
protected Object getImpl(Object bean, String propertyName) throws Exception {
return super.getImpl(bean, propertyName);
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/NamedEntityCollectionReflector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/NamedEntityCollectionReflector.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/NamedEntityCollectionReflector.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/NamedEntityCollectionReflector.java Sun Mar 22 22:12:27 2009
@@ -31,22 +31,17 @@
*/
public class NamedEntityCollectionReflector extends
BaseEntityCollectionReflector implements BeanReflector {
- private static final Class[] REFLECTABLE_CLASSES = { NamedEntityCollection.class };
+ private static final Class<?>[] REFLECTABLE_CLASSES = { NamedEntityCollection.class };
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getReflectableClassesImpl()
+ /**
+ * {@inheritDoc}
*/
- protected Class[] getReflectableClassesImpl() throws Exception {
+ protected Class<?>[] getReflectableClassesImpl() throws Exception {
return REFLECTABLE_CLASSES;
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.morph.BaseEntityCollectionReflector#isEntity(java.lang.Object,
- * java.lang.String)
+ /**
+ * {@inheritDoc}
*/
protected boolean isEntity(Object bean, String propertyName)
throws Exception {
@@ -54,28 +49,23 @@
.getChildNames(), propertyName);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.reflect.BaseEntityCollectionReflector#getEntity(java.lang.Object,
- * java.lang.String)
+ /**
+ * {@inheritDoc}
*/
protected Entity getEntity(Object bean, String propertyName)
throws Exception {
return ((NamedEntityCollection) bean).getChild(propertyName);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getPropertyNamesImpl(java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
protected String[] getPropertyNamesImpl(Object bean) throws Exception {
- HashSet result = new HashSet(Arrays.asList(super
+ HashSet<String> result = new HashSet<String>(Arrays.asList(super
.getPropertyNamesImpl(bean)));
result.addAll(Arrays.asList(((NamedEntityCollection) bean)
.getChildNames()));
- return (String[]) result.toArray(new String[result.size()]);
+ return result.toArray(new String[result.size()]);
}
}
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/TextToByteConverter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/TextToByteConverter.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/TextToByteConverter.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/TextToByteConverter.java Sun Mar 22 22:12:27 2009
@@ -17,6 +17,7 @@
package org.apache.commons.flatfile.morph;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
@@ -33,12 +34,10 @@
DecoratedConverter {
private DecoratedConverter textConverter;
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#convertImpl(java.lang.Class,
- * java.lang.Object, java.util.Locale)
+ /**
+ * {@inheritDoc}
*/
+ @SuppressWarnings("unchecked")
protected Object convertImpl(Class destinationClass, Object source,
Locale locale) throws Exception {
if (isByte(destinationClass)) {
@@ -51,38 +50,32 @@
return getTextConverter().convert(destinationClass, b, locale);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#getDestinationClassesImpl()
- */
- protected Class[] getDestinationClassesImpl() throws Exception {
- HashSet s = new HashSet();
- s.addAll(Arrays.asList(getTextConverter().getDestinationClasses()));
+ /**
+ * {@inheritDoc}
+ */
+ protected Class<?>[] getDestinationClassesImpl() throws Exception {
+ HashSet<Class<?>> s = new HashSet<Class<?>>();
+ s.addAll(Arrays.asList((Class<?>[]) getTextConverter().getDestinationClasses()));
s.add(byte.class);
s.add(Byte.class);
- return (Class[]) s.toArray(new Class[s.size()]);
+ return s.toArray(new Class[s.size()]);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#getSourceClassesImpl()
+ /**
+ * {@inheritDoc}
*/
- protected Class[] getSourceClassesImpl() throws Exception {
- HashSet s = new HashSet();
- s.addAll(Arrays.asList(getTextConverter().getSourceClasses()));
+ protected Class<?>[] getSourceClassesImpl() throws Exception {
+ HashSet<Class<?>> s = new HashSet<Class<?>>();
+ s.addAll(Arrays.asList((Class<?>[]) getTextConverter().getSourceClasses()));
s.add(byte.class);
s.add(Byte.class);
- return (Class[]) s.toArray(new Class[s.size()]);
+ return s.toArray(new Class[s.size()]);
}
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.transform.transformers.BaseTransformer#isTransformableImpl(java.lang.Class,
- * java.lang.Class)
+ /**
+ * {@inheritDoc}
*/
+ @SuppressWarnings("unchecked")
protected boolean isTransformableImpl(Class destinationType,
Class sourceType) throws Exception {
DecoratedConverter cnv = getTextConverter();
@@ -92,6 +85,7 @@
.getSourceClasses(), sourceType));
}
+ @SuppressWarnings("unchecked")
private boolean isByte(Class c) {
return c == byte.class || c == Byte.class;
}
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/TextToEntityCopier.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/TextToEntityCopier.java?rev=757266&r1=757265&r2=757266&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/TextToEntityCopier.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/morph/TextToEntityCopier.java Sun Mar 22 22:12:27 2009
@@ -48,6 +48,7 @@
* {@inheritDoc}
* @see net.sf.morph.transform.transformers.BaseTransformer#setSourceClasses(java.lang.Class[])
*/
+ @SuppressWarnings("unchecked")
public synchronized void setSourceClasses(Class[] sourceClasses) {
super.setSourceClasses(sourceClasses);
}
@@ -56,6 +57,7 @@
* {@inheritDoc}
* @see net.sf.morph.transform.transformers.BaseTransformer#setDestinationClasses(java.lang.Class[])
*/
+ @SuppressWarnings("unchecked")
public synchronized void setDestinationClasses(Class[] destinationClasses) {
super.setDestinationClasses(destinationClasses);
}
@@ -64,7 +66,7 @@
* {@inheritDoc}
* @see net.sf.morph.transform.transformers.BaseTransformer#getDestinationClassesImpl()
*/
- protected Class[] getDestinationClassesImpl() throws Exception {
+ protected Class<?>[] getDestinationClassesImpl() throws Exception {
return new Class[] { Entity.class };
}
@@ -72,7 +74,7 @@
* {@inheritDoc}
* @see net.sf.morph.transform.transformers.BaseTransformer#getSourceClassesImpl()
*/
- protected Class[] getSourceClassesImpl() throws Exception {
+ protected Class<?>[] getSourceClassesImpl() throws Exception {
return getTextConverter().getSourceClasses();
}