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/24 22:09:22 UTC
svn commit: r758023 - in /commons/sandbox/flatfile/trunk/src:
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/morph/ main/java/...
Author: mbenson
Date: Tue Mar 24 21:09:19 2009
New Revision: 758023
URL: http://svn.apache.org/viewvc?rev=758023&view=rev
Log:
checkstyle
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/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/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/InputFilteringDynamicField.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/ConstantEntityNameStrategy.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/ParserEntityFactory.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CompositeEntityFactory.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/EntityInstantiatingReflector.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/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/main/java/org/apache/commons/flatfile/util/ThresholdingInputStream.java
commons/sandbox/flatfile/trunk/src/test/java/org/apache/commons/flatfile/ImmutableTest.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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -82,18 +82,25 @@
/**
* Create a new Bounds.
- * @param minimum
- * @param maximum
+ * @param minimum size
+ * @param maximum size
*/
public Bounds(int minimum, int maximum) {
setMinimum(minimum);
setMaximum(maximum);
}
+ /**
+ * Create a new Bounds instance.
+ * @param example to copy
+ */
private Bounds(Bounds example) {
this(example.getMinimum(), example.getMaximum());
}
+ /**
+ * Create a new Bounds instance.
+ */
private Bounds() {
}
@@ -332,6 +339,11 @@
this.bounds = bounds;
}
+ /**
+ * Serialization
+ * @param out to write to
+ * @throws IOException on error
+ */
private synchronized void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(getBounds());
initialize(ArrayUtils.EMPTY_BYTE_ARRAY);
@@ -339,6 +351,12 @@
buffer.writeTo(out);
}
+ /**
+ * Serialization
+ * @param in to read from
+ * @throws IOException on error
+ * @throws ClassNotFoundException if Object class not found
+ */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
setBounds((Bounds) in.readObject());
int n = in.read();
@@ -348,10 +366,17 @@
}
}
+ /**
+ * Intitialize this {@link DynamicField}.
+ */
private void initialize() {
initialize(null);
}
+ /**
+ * Initialize this {@link DynamicField} from a given byte[].
+ * @param value byte[]
+ */
private synchronized void initialize(byte[] value) {
if (buffer == null) {
buffer = new ByteArrayOutputStream();
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -34,15 +34,15 @@
/**
* Read value from an InputStream.
- * @param is
- * @throws IOException
+ * @param is to read
+ * @throws IOException on error
*/
void readFrom(InputStream is) throws IOException;
/**
* Write value to an OutputStream.
- * @param os
- * @throws IOException
+ * @param os to write to
+ * @throws IOException on error
*/
void writeTo(OutputStream os) throws IOException;
@@ -54,8 +54,8 @@
/**
* Fill this entity's value with all <code>b</code>.
- * @param b
- * @throws IOException
+ * @param b value
+ * @throws IOException on error
*/
void fill(byte b) throws IOException;
@@ -67,8 +67,8 @@
/**
* Get a subset of this Entity's value.
- * @param offset
- * @param length
+ * @param offset to start
+ * @param length to extend
* @return byte[]
*/
byte[] getValue(int offset, int length);
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -45,7 +45,7 @@
/**
* Create a new IndexedEntityCollection.
- * @param size
+ * @param size number of occurrences of the prototypical Entity
*/
public EntityArray(int size) {
setSize(size);
@@ -53,7 +53,7 @@
/**
* Create a new EntityArray with the specified prototype.
- * @param prototype
+ * @param prototype Entity
*/
public EntityArray(Entity prototype) {
setPrototype(prototype);
@@ -61,8 +61,8 @@
/**
* Create a new IndexedEntityCollection.
- * @param prototype
- * @param size
+ * @param prototype Entity
+ * @param size number of occurrences
*/
public EntityArray(Entity prototype, int size) {
this(prototype);
@@ -71,7 +71,7 @@
/**
* Get the child at the specified index.
- * @param index int
+ * @param index to return
* @return Entity
*/
public Entity getChild(int index) {
@@ -107,8 +107,8 @@
}
/**
- * Set the size.
- * @param size the size to set.
+ * {@inheritDoc}
+ * @throws IllegalArgumentException if <code>size</code> is not valid.
*/
public synchronized void setSize(int size) {
if (this.size >= 0 && !isResizable()) {
@@ -135,7 +135,7 @@
/**
* Learn whether this EntityArray's size can be set.
- * @return
+ * @return boolean
*/
public synchronized boolean isSizable() {
return size == -1 || isResizable();
@@ -157,6 +157,9 @@
return result;
}
+ /**
+ * Initialize this EntityArray.
+ */
private synchronized void initialize() {
if (children != null) {
return;
@@ -175,6 +178,9 @@
adjustSize();
}
+ /**
+ * Adjust the size of this EntityArray.
+ */
private synchronized void adjustSize() {
if (children.size() > size) {
children.subList(size, children.size()).clear();
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -185,7 +185,7 @@
/**
* Learn whether the specified child should be suppressed.
- * @param child
+ * @param child to check
* @return boolean
*/
protected boolean shouldSuppress(Entity child) {
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -49,8 +49,8 @@
/**
* Create a new Child instance.
- * @param name
- * @param entity
+ * @param name of child
+ * @param entity child
*/
public Child(String name, Entity entity) {
this.name = name;
@@ -62,6 +62,9 @@
}
+ /**
+ * Expose the Child list as List<Entity>.
+ */
@SuppressWarnings("unchecked")
private class ChildrenList extends AbstractSerializableListDecorator {
private static final long serialVersionUID = 3241482030276238909L;
@@ -72,14 +75,23 @@
}
};
+ /**
+ * Create our ChildrenList instance.
+ */
private ChildrenList() {
super(children);
}
+ /**
+ * {@inheritDoc}
+ */
public Entity get(int index) {
return (Entity) t.transform(super.get(index));
}
+ /**
+ * {@inheritDoc}
+ */
public Iterator<Entity> iterator() {
return IteratorUtils.transformedIterator(super.iterator(), t);
}
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -34,6 +34,9 @@
public static enum Overflow implements FieldOption {
/** Error on overflow */
ERROR() {
+ /**
+ * {@inheritDoc}
+ */
protected void check(byte[] b, int len) {
if (b.length > len) {
throw new IllegalArgumentException(new String(b) + " too large for field ("
@@ -48,7 +51,11 @@
/** Ignore overflow (same as TRUNCATE) */
IGNORE;
- /** Check the given aspect of the field */
+ /**
+ * Check the overflow of the field
+ * @param b value
+ * @param len field length
+ */
protected void check(byte[] b, int len) {
}
}
@@ -59,6 +66,9 @@
public static enum Underflow implements FieldOption {
/** Error on Underflow */
ERROR() {
+ /**
+ * {@inheritDoc}
+ */
protected void check(byte[] b, int len) {
if (b.length < len) {
throw new IllegalArgumentException(new String(b) + " too small for field ("
@@ -70,7 +80,11 @@
/** Ignore Underflow */
IGNORE;
- /** Check the given aspect of the field */
+ /**
+ * Check the underflow of the field
+ * @param b value
+ * @param len field length
+ */
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -21,11 +21,11 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
-import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
-import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.ClassUtils;
/**
* Immutable Entity factory, using Java 1.3 proxies.
@@ -46,15 +46,16 @@
private Entity delegate;
+ /**
+ * Create a new ImmutableEntityInvocationHandler instance.
+ * @param delegate Entity
+ */
private ImmutableEntityInvocationHandler(Entity delegate) {
this.delegate = delegate;
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
- * java.lang.reflect.Method, java.lang.Object[])
+ /**
+ * {@inheritDoc}
*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String name = method.getName();
@@ -107,9 +108,17 @@
private static final Map<Entity, Entity> PROXIES = new WeakHashMap<Entity, Entity>();
+ /**
+ * Create a new ImmutableEntity instance.
+ */
private ImmutableEntity() {
}
+ /**
+ * Get an immutable instance of <code>e</code>.
+ * @param e Entity delegate
+ * @return immutable Entity
+ */
public static Entity getInstance(Entity e) {
Entity result = (Entity) PROXIES.get(e);
if (result == null) {
@@ -120,12 +129,14 @@
return result;
}
+ /**
+ * Get the interfaces implemented by <code>o</code>.
+ * @param o to inspect.
+ * @return interface array
+ */
+ @SuppressWarnings("unchecked")
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() ? ArrayUtils.EMPTY_CLASS_ARRAY : (Class<?>[]) set
- .toArray(new Class[set.size()]);
+ List<Class<?>> interfaces = ClassUtils.getAllInterfaces(o.getClass());
+ return interfaces.toArray(new Class[interfaces.size()]);
}
}
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -36,13 +36,14 @@
/**
* Learn whether the size of this object can be set.
- * @return
+ * @return boolean
*/
boolean isSizable();
/**
* Set new size of this object.
- * @param size
+ * @param size to set
+ * @throws IllegalStateException if {@link #isSizable()} <code>== false</code>
*/
- void setSize(int size);
+ void setSize(int size) throws IllegalStateException;
}
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/InputFilteringDynamicField.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/InputFilteringDynamicField.java?rev=758023&r1=758022&r2=758023&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/InputFilteringDynamicField.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/InputFilteringDynamicField.java Tue Mar 24 21:09:19 2009
@@ -67,10 +67,8 @@
setFilterFactory(filterFactory);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.DynamicField#readFrom(java.io.InputStream)
+ /**
+ * {@inheritDoc}
*/
public synchronized void readFrom(InputStream is) throws IOException {
if (filterFactory == null) {
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -23,14 +23,14 @@
public interface NamedEntityCollection extends EntityCollection {
/**
* Learn whether this NamedEntityCollection has a child of the specified name.
- * @param name
+ * @param name to find
* @return boolean
*/
boolean hasChild(String name);
/**
* Get the specified child.
- * @param name
+ * @param name to find
* @return Entity
*/
Entity getChild(String name);
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -37,6 +37,9 @@
public static enum Justify implements FieldOption {
/** Left-justify */
LEFT {
+ /**
+ * {@inheritDoc}
+ */
protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest) {
InputStream is = new ByteArrayInputStream(src);
int dlen = dest.getPadJustifyLength();
@@ -47,6 +50,9 @@
/** Right-justify */
RIGHT {
+ /**
+ * {@inheritDoc}
+ */
protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest) {
int dlen = dest.getPadJustifyLength();
if (dlen < src.length) {
@@ -60,7 +66,9 @@
/** Center */
CENTER {
-
+ /**
+ * {@inheritDoc}
+ */
protected InputStream getInputStream(byte[] src, PadJustifyFieldSupport dest) {
int dlen = dest.getPadJustifyLength();
// it would be odd and therefore hopefully rare to center a
@@ -128,6 +136,7 @@
/**
* Implement pad/justify.
+ * @param b value set
*/
public void setValue(byte[] b) {
dieOnExceptionRead(getJustify().getInputStream(b, this));
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/ConstantEntityNameStrategy.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/ConstantEntityNameStrategy.java?rev=758023&r1=758022&r2=758023&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/ConstantEntityNameStrategy.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/dsl/ConstantEntityNameStrategy.java Tue Mar 24 21:09:19 2009
@@ -23,10 +23,8 @@
public class ConstantEntityNameStrategy implements EntityNameStrategy {
private String entityName;
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.reflectors.EntityNameStrategy#getEntityName(java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
public String getEntityName(Object o) {
return getEntityName();
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -32,8 +32,8 @@
/**
* Create a new EntityDefinition.
- * @param name
- * @param ast
+ * @param name of this Entity
+ * @param ast AST holding the parsed Entity
*/
public EntityDefinition(String name, AST ast) {
this.name = name;
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -16,7 +16,6 @@
*/
package org.apache.commons.flatfile.dsl;
-import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
@@ -33,9 +32,6 @@
import org.apache.commons.flatfile.Entity;
import org.apache.commons.flatfile.EntityFactory;
import org.apache.commons.flatfile.Field;
-import org.apache.commons.flatfile.dsl.EntityLexer;
-import org.apache.commons.flatfile.dsl.EntityParser;
-import org.apache.commons.flatfile.dsl.EntityTreeParser;
import org.apache.commons.flatfile.util.ApplyOptions;
/**
@@ -61,7 +57,8 @@
};
private Map<String, Object> entityMap;
- private Map<String, Map<String, ? extends Object>> defaultOptionMaps = new HashMap<String, Map<String, ? extends Object>>();
+ private Map<String, Map<String, ? extends Object>> defaultOptionMaps
+ = new HashMap<String, Map<String, ? extends Object>>();
private boolean checked;
private InputStream[] sources;
private EntityFactory parent;
@@ -74,7 +71,7 @@
/**
* Create a new ParserEntityFactory.
- * @param source
+ * @param source to read
*/
public ParserEntityFactory(InputStream source) {
setSource(source);
@@ -82,16 +79,14 @@
/**
* Create a new ParserEntityFactory.
- * @param sources
+ * @param sources to read
*/
public ParserEntityFactory(InputStream[] sources) {
setSources(sources);
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.EntityFactory#getEntity(java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
public final Entity getEntity(Object cue) {
if (parent != null) {
@@ -148,7 +143,7 @@
* Get the InputStream[] sources.
* @return InputStream[]
*/
- public InputStream[] getSources() throws IOException {
+ public InputStream[] getSources() {
return sources;
}
@@ -162,7 +157,7 @@
/**
* Convenience setter for a single InputStream source.
- * @param source
+ * @param source to set
*/
public void setSource(InputStream source) {
setSources(new InputStream[] { source });
@@ -184,12 +179,20 @@
this.parent = parent;
}
- /* package-private */
+ /**
+ * Add an EntityDefinition
+ * @param name to associate
+ * @param def to add
+ */
void add(String name, EntityDefinition def) {
entityMap.put(name, def);
}
- /* package-private */
+ /**
+ * Set the default options for a given entity "type".
+ * @param type String key
+ * @param options option Map
+ */
void setDefaultOptions(String type, Map<String, ? extends Object> options) {
Map<String, ? extends Object> old = defaultOptionMaps.put(type, options);
if (!ObjectUtils.equals(old, options)) {
@@ -197,35 +200,69 @@
}
}
- /* package-private */
+ /**
+ * Get the default option map for a given entity "type".
+ * @param type String key
+ * @return option Map
+ */
Map<String, ? extends Object> getDefaultOptions(String type) {
return defaultOptionMaps.get(type);
}
- /* package-private */
- Entity createField(int length) {
+ // TODO make field creation pluggable
+ // TODO tie default options to class rather than mnemonic
+
+ /**
+ * Create a Field of a particular length, applying default options.
+ * @param length of field
+ * @return Field
+ */
+ Field createField(int length) {
return applyDefaultOptions(new Field(length), OPTION_FIELD);
}
- /* package-private */
- Entity createDynamicField() {
+ /**
+ * Create a dynamic field, applying default options.
+ * @return DynamicField
+ */
+ DynamicField createDynamicField() {
return applyDefaultOptions(new DynamicField(), OPTION_DYNAMIC_FIELD);
}
- /* package-private */
- Entity createField(byte[] value) {
+ /**
+ * Create a field of a particular value, applying default options.
+ * @param value of the field.
+ * @return Field
+ */
+ Field createField(byte[] value) {
return applyDefaultOptions(new Field(value), OPTION_FIELD);
}
- private Entity applyDefaultOptions(Entity e, String type) {
+ /**
+ * Apply the default options of the specified type to the specified Entity.
+ * @param <E> Entity subtype
+ * @param e E
+ * @param type associated field type
+ * @return e
+ */
+ private <E extends Entity> E applyDefaultOptions(E e, String type) {
Map<String, ? extends Object> m = defaultOptionMaps.get(type);
return m == null ? e : ApplyOptions.apply(e, m);
}
+ /**
+ * Get this thread's {@link EntityTreeParser}
+ * @return {@link EntityTreeParser}
+ */
private EntityTreeParser getTreeParser() {
- return (EntityTreeParser) treeParser.get();
+ return treeParser.get();
}
+ // TODO come up with a single wrapper to get the Entity for the value.
+ /**
+ * Return our entity map, initializing if necessary.
+ * @return Map<String, Object> - value may be an EntityDefinition or an Entity.
+ */
private synchronized Map<String, Object> getEntityMap() {
if (entityMap == null) {
entityMap = new HashMap<String, Object>();
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -35,10 +35,8 @@
this.delegates = delegates;
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.EntityFactory#getEntity(java.lang.Object)
+ /**
+ * {@inheritDoc}
*/
public Entity getEntity(Object cue) {
for (int i = 0; delegates != null && i < delegates.length; i++) {
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -34,18 +34,31 @@
* Base EntityCollection reflector.
* @version $Revision$ $Date$
*/
-public abstract class BaseEntityCollectionReflector extends
- BaseContainerReflector {
+public abstract class BaseEntityCollectionReflector extends BaseContainerReflector {
+ //TODO make PropertyStrategy an enum; this would require factoring out the propertyName property
/**
* Entity property strategy base class.
*/
protected abstract class PropertyStrategy {
+ /**
+ * Property name to find
+ */
protected String propertyName;
+ /**
+ * Create a new PropertyStrategy instance.
+ * @param propertyName to find
+ */
protected PropertyStrategy(String propertyName) {
this.propertyName = propertyName;
}
+ /**
+ * Get the property type of <code>bean</code>.
+ * @param bean to inspect
+ * @return Class<?>
+ * @throws Exception on error
+ */
final Class<?> getTypeFrom(Object bean) throws Exception {
if (isEntity(bean, propertyName)) {
return getEntityType(getEntity(bean, propertyName));
@@ -53,8 +66,20 @@
return FALLBACK.getType(bean, propertyName);
}
- abstract Class<?> getEntityType(Entity e) throws Exception;
-
+ /**
+ * Strategy template method.
+ * @param entity to inspect
+ * @return Class<?>
+ * @throws Exception on error
+ */
+ abstract Class<?> getEntityType(Entity entity) throws Exception;
+
+ /**
+ * Read the property.
+ * @param bean to read
+ * @return value
+ * @throws Exception on error
+ */
final Object getFrom(Object bean) throws Exception {
if (isEntity(bean, propertyName)) {
return getEntityValue(getEntity(bean, propertyName));
@@ -62,71 +87,128 @@
return FALLBACK.get(bean, propertyName);
}
- abstract Object getEntityValue(Entity e) throws Exception;
-
+ /**
+ * Get the value of the specified Entity.
+ * @param entity to read
+ * @return Object value
+ * @throws Exception on error
+ */
+ abstract Object getEntityValue(Entity entity) throws Exception;
+
+ /**
+ * Set the property.
+ * @param bean target
+ * @param propertyValue to set
+ * @throws Exception on error
+ */
final void setOn(Object bean, Object propertyValue) throws Exception {
if (isEntity(bean, propertyName)) {
- setEntityValueOn(bean, getEntity(bean, propertyName),
- propertyValue);
+ setEntityValueOn(bean, getEntity(bean, propertyName), propertyValue);
} else {
FALLBACK.set(bean, propertyName, propertyValue);
}
}
- abstract void setEntityValueOn(Object bean, Entity e,
- Object propertyValue) throws Exception;
-
+ /**
+ * Set the entity value.
+ * @param bean target
+ * @param e Entity
+ * @param propertyValue value
+ * @throws Exception on error
+ */
+ abstract void setEntityValueOn(Object bean, Entity e, Object propertyValue)
+ throws Exception;
+
+ /**
+ * Learn whether our property can be read from a given target.
+ * @param bean to inspect
+ * @return boolean
+ * @throws Exception on error
+ */
final boolean isReadableOn(Object bean) throws Exception {
- return isEntity(bean, propertyName)
- || FALLBACK.isReadable(bean, propertyName);
+ return isEntity(bean, propertyName) || FALLBACK.isReadable(bean, propertyName);
}
+ /**
+ * Learn whether our property can be written to a given target.
+ * @param bean to inspect
+ * @return boolean
+ * @throws Exception on error
+ */
final boolean isWriteableOn(Object bean) throws Exception {
- return isEntity(bean, propertyName)
- || FALLBACK.isWriteable(bean, propertyName);
+ return isEntity(bean, propertyName) || FALLBACK.isWriteable(bean, propertyName);
}
}
+ /**
+ * Override the default strategy to treat an Entity as an ordinary javabean.
+ */
private class OverrideStrategy extends PropertyStrategy {
+ /**
+ * Create a new OverrideStrategy instance.
+ * @param propertyName String
+ */
public OverrideStrategy(String propertyName) {
super(propertyName.substring(TYPE_OVERRIDE.length()));
}
+ /**
+ * {@inheritDoc}
+ */
Class<?> getEntityType(Entity e) {
return ClassUtils.getClass(e);
}
+ /**
+ * {@inheritDoc}
+ */
Object getEntityValue(Entity e) {
return e;
}
- void setEntityValueOn(Object bean, Entity e, Object propertyValue)
- throws Exception {
+ /**
+ * {@inheritDoc}
+ */
+ void setEntityValueOn(Object bean, Entity e, Object propertyValue) throws Exception {
FALLBACK.set(bean, propertyName, propertyValue);
}
}
+ /**
+ * Default {@link PropertyStrategy}
+ */
private class DefaultStrategy extends PropertyStrategy {
+ /**
+ * Create a new DefaultStrategy instance.
+ * @param propertyName String
+ */
public DefaultStrategy(String propertyName) {
super(propertyName);
}
+ /**
+ * {@inheritDoc}
+ */
Class<?> getEntityType(Entity e) {
- return e instanceof EntityCollection ? EntityCollection.class
- : String.class;
+ return e instanceof EntityCollection ? EntityCollection.class : String.class;
}
+ /**
+ * {@inheritDoc}
+ */
Object getEntityValue(Entity e) {
return e instanceof EntityCollection ? (Object) e : getString(e);
}
- void setEntityValueOn(Object bean, Entity e, Object propertyValue)
- throws Exception {
+ /**
+ * {@inheritDoc}
+ */
+ void setEntityValueOn(Object bean, Entity e, Object propertyValue) throws Exception {
setEntityValue(e, propertyValue);
}
}
- /** Property name prefix indicating to return runtime Entity type rather than String even for non-collection Entities. */
+ /** Property name prefix indicating to treat Entities as beans. */
public static final String TYPE_OVERRIDE = "@";
private static final ObjectReflector FALLBACK = new ObjectReflector();
@@ -175,8 +257,7 @@
/**
* {@inheritDoc}
*/
- protected Class<?> getTypeImpl(Object bean, String propertyName)
- throws Exception {
+ protected Class<?> getTypeImpl(Object bean, String propertyName) throws Exception {
return getPropertyStrategy(propertyName).getTypeFrom(bean);
}
@@ -191,12 +272,6 @@
/**
* {@inheritDoc}
*/
- /*
- * (non-Javadoc)
- *
- * @see net.sf.morph.reflect.reflectors.BaseReflector#getImpl(java.lang.Object,
- * java.lang.String)
- */
protected Object getImpl(Object bean, String propertyName) throws Exception {
return getPropertyStrategy(propertyName).getFrom(bean);
}
@@ -204,16 +279,14 @@
/**
* {@inheritDoc}
*/
- protected void setImpl(Object bean, String propertyName, Object value)
- throws Exception {
+ protected void setImpl(Object bean, String propertyName, Object value) throws Exception {
getPropertyStrategy(propertyName).setOn(bean, value);
}
/**
* {@inheritDoc}
*/
- protected Object setImpl(Object container, int index, Object propertyValue)
- throws Exception {
+ protected Object setImpl(Object container, int index, Object propertyValue) throws Exception {
Entity e = getEntity(container, index);
byte[] result = e.getValue();
setEntityValue(e, propertyValue);
@@ -224,7 +297,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
+ * @throws Exception on error
*/
protected void setEntityValue(Entity e, Object value) throws Exception {
e.setValue((byte[]) getToTextConverter().convert(byte[].class, value));
@@ -251,32 +324,31 @@
/**
* Learn whether the specified property refers to an Entity child.
- * @param bean
- * @param propertyName
- * @return
- * @throws Exception
- */
- protected abstract boolean isEntity(Object bean, String propertyName)
- throws Exception;
-
- /**
- * Get the named child entity
- * @param bean
- * @param propertyName
- * @return
- * @throws Exception
+ * @param bean to inspect
+ * @param propertyName to read
+ * @return boolean
+ * @throws Exception on error
+ */
+ protected abstract boolean isEntity(Object bean, String propertyName) throws Exception;
+
+ /**
+ * Get the named child entity.
+ * @param bean to read
+ * @param propertyName to read
+ * @return Entity
+ * @throws Exception on error
*/
- protected Entity getEntity(Object bean, String propertyName)
- throws Exception {
+ protected Entity getEntity(Object bean, String propertyName) throws Exception {
return getEntity(bean, Integer.parseInt(propertyName));
}
/**
* Get the child entity at index <code>index</code>.
- * @param container
- * @param index
- * @return
- * @throws Exception
+ * Base implementation throws {@link UnsupportedOperationException}.
+ * @param container to read
+ * @param index to get
+ * @return Entity
+ * @throws Exception on error
*/
protected Entity getEntity(Object container, int index) throws Exception {
throw new UnsupportedOperationException();
@@ -285,16 +357,14 @@
/**
* {@inheritDoc}
*/
- protected boolean isReadableImpl(Object bean, String propertyName)
- throws Exception {
+ protected boolean isReadableImpl(Object bean, String propertyName) throws Exception {
return getPropertyStrategy(propertyName).isReadableOn(bean);
}
/**
* {@inheritDoc}
*/
- protected boolean isWriteableImpl(Object bean, String propertyName)
- throws Exception {
+ protected boolean isWriteableImpl(Object bean, String propertyName) throws Exception {
return getPropertyStrategy(propertyName).isWriteableOn(bean);
}
@@ -310,21 +380,21 @@
}
/**
- * @param toTextConverter the toTextConverter to set
+ * Set the to-text {@link DecoratedConverter}.
+ * @param toTextConverter to set
*/
- public synchronized void setToTextConverter(
- DecoratedConverter toTextConverter) {
+ public synchronized void setToTextConverter(DecoratedConverter toTextConverter) {
this.toTextConverter = toTextConverter;
}
/**
* Get the strategy instance to handle this property.
- * @param propertyName
+ * @param propertyName to handle
+ * @return PropertyStrategy
*/
protected PropertyStrategy getPropertyStrategy(String propertyName) {
return propertyName.startsWith(TYPE_OVERRIDE) ? (PropertyStrategy) new OverrideStrategy(
- propertyName)
- : new DefaultStrategy(propertyName);
+ propertyName) : new DefaultStrategy(propertyName);
}
/**
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -32,6 +32,9 @@
public class ByteArrayToEntityCopier extends BaseTransformer implements
DecoratedConverter, DecoratedCopier {
+ /**
+ * {@inheritDoc}
+ */
protected void copyImpl(Object destination, Object source, Locale locale,
Integer preferredTransformationType) throws Exception {
((Entity) destination).setValue((byte[]) source);
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -50,7 +50,7 @@
/**
* Create a new EntityInstantiatingReflector.
- * @param entityFactory
+ * @param entityFactory to use
*/
public EntityInstantiatingReflector(EntityFactory entityFactory) {
setEntityFactory(entityFactory);
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -17,7 +17,6 @@
package org.apache.commons.flatfile.morph;
import java.util.Arrays;
-import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
@@ -85,8 +84,12 @@
.getSourceClasses(), sourceType));
}
- @SuppressWarnings("unchecked")
- private boolean isByte(Class c) {
+ /**
+ * Learn whether the given class is Byte or byte.
+ * @param c to check
+ * @return boolean
+ */
+ 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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -35,7 +35,6 @@
/**
* {@inheritDoc}
- * @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 {
@@ -46,7 +45,6 @@
/**
* {@inheritDoc}
- * @see net.sf.morph.transform.transformers.BaseTransformer#setSourceClasses(java.lang.Class[])
*/
@SuppressWarnings("unchecked")
public synchronized void setSourceClasses(Class[] sourceClasses) {
@@ -55,7 +53,6 @@
/**
* {@inheritDoc}
- * @see net.sf.morph.transform.transformers.BaseTransformer#setDestinationClasses(java.lang.Class[])
*/
@SuppressWarnings("unchecked")
public synchronized void setDestinationClasses(Class[] destinationClasses) {
@@ -64,7 +61,6 @@
/**
* {@inheritDoc}
- * @see net.sf.morph.transform.transformers.BaseTransformer#getDestinationClassesImpl()
*/
protected Class<?>[] getDestinationClassesImpl() throws Exception {
return new Class[] { Entity.class };
@@ -72,7 +68,6 @@
/**
* {@inheritDoc}
- * @see net.sf.morph.transform.transformers.BaseTransformer#getSourceClassesImpl()
*/
protected Class<?>[] getSourceClassesImpl() throws Exception {
return getTextConverter().getSourceClasses();
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/BasicFilterFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/BasicFilterFactory.java?rev=758023&r1=758022&r2=758023&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/BasicFilterFactory.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/BasicFilterFactory.java Tue Mar 24 21:09:19 2009
@@ -32,7 +32,8 @@
private Constructor<? extends InputStream> constructor;
/**
- * Create a new BasicFilterFactory.
+ * Create a new BasicFilterFactory instance.
+ * @param clazz (Filter)InputStream type to instantiate.
*/
public BasicFilterFactory(Class<? extends InputStream> clazz) {
if (!InputStream.class.isAssignableFrom(clazz)) {
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ConcatenatedInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ConcatenatedInputStream.java?rev=758023&r1=758022&r2=758023&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ConcatenatedInputStream.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ConcatenatedInputStream.java Tue Mar 24 21:09:19 2009
@@ -19,7 +19,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
-import java.util.List;
import org.apache.commons.collections.IteratorUtils;
@@ -43,9 +42,9 @@
/**
* Create a new ConcatenatedInputStream.
- * @param src
+ * @param src InputStreams
*/
- public ConcatenatedInputStream(List<InputStream>src) {
+ public ConcatenatedInputStream(Iterable<InputStream> src) {
if (src == null) {
throw new IllegalArgumentException(NO_NULL);
}
@@ -55,8 +54,8 @@
/**
* Convenience constructor.
- * @param is0
- * @param is1
+ * @param is0 first InputStream
+ * @param is1 next InputStream
*/
@SuppressWarnings("unchecked")
public ConcatenatedInputStream(InputStream is0, InputStream is1) {
@@ -80,7 +79,10 @@
return n;
}
+ /**
+ * Position to the next InputStream
+ */
private void next() {
- current = iter.hasNext() ? (InputStream) iter.next() : AT_EOF;
+ current = iter.hasNext() ? iter.next() : AT_EOF;
}
}
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/FilterFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/FilterFactory.java?rev=758023&r1=758022&r2=758023&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/FilterFactory.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/FilterFactory.java Tue Mar 24 21:09:19 2009
@@ -20,8 +20,6 @@
import java.io.InputStream;
import java.io.Serializable;
-import org.apache.commons.flatfile.InputFilteringDynamicField;
-
/**
* Filter factory interface designed for use with {@link InputFilteringDynamicField}.
* @version $Revision$ $Date$
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/RepeatingInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/RepeatingInputStream.java?rev=758023&r1=758022&r2=758023&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/RepeatingInputStream.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/RepeatingInputStream.java Tue Mar 24 21:09:19 2009
@@ -27,26 +27,46 @@
*/
public abstract class RepeatingInputStream {
+ /**
+ * An InputStream that repeats a single byte forever.
+ */
private static class RepeatOneByte extends InputStream {
private byte b;
+ /**
+ * Create a new RepeatOneByte instance.
+ * @param b byte to repeat
+ */
private RepeatOneByte(byte b) {
this.b = b;
}
+ /**
+ * {@inheritDoc}
+ */
public int read() throws IOException {
return b;
}
}
+ /**
+ * An InputStream that repeats a byte[] forever.
+ */
private static class RepeatArray extends InputStream {
private byte[] b;
private int pos;
+ /**
+ * Create a new RepeatArray instance.
+ * @param b byte[] to repeat
+ */
private RepeatArray(byte[] b) {
this.b = b;
}
+ /**
+ * {@inheritDoc}
+ */
public synchronized int read() throws IOException {
try {
return b[pos++];
@@ -58,6 +78,9 @@
}
}
+ /**
+ * InputStream that limits the content of another InputStream.
+ */
private static class LimitedOutput extends InputStream {
private static final int EOF = -1;
@@ -65,11 +88,19 @@
private int bytesToReturn;
private int bytesReturned;
+ /**
+ * Create a new LimitedOutput instance.
+ * @param source wrapped InputStream
+ * @param bytesToReturn int max
+ */
private LimitedOutput(InputStream source, int bytesToReturn) {
this.source = source;
this.bytesToReturn = bytesToReturn;
}
+ /**
+ * {@inheritDoc}
+ */
public int read() throws IOException {
if (bytesReturned == bytesToReturn) {
return EOF;
@@ -90,7 +121,7 @@
/**
* Get an InputStream that will return the specified byte forever.
- * @param b
+ * @param b byte to repeat
* @return InputStream
*/
public static synchronized InputStream getInstance(byte b) {
@@ -105,7 +136,7 @@
/**
* Get an InputStream that will return the specified byte[] forever.
- * @param b
+ * @param b byte[] to repeat
* @return InputStream
*/
public static InputStream getInstance(byte[] b) {
@@ -114,8 +145,9 @@
/**
* Get an InputStream that will return a single byte a limited number of times.
- * @param b
- * @param bytesToReturn
+ * @param b byte to repeat
+ * @param bytesToReturn int
+ * @return InputStream
*/
public static synchronized InputStream getInstance(byte b, int bytesToReturn) {
return new LimitedOutput(getInstance(b), bytesToReturn);
@@ -124,8 +156,9 @@
/**
* Get an InputStream that will return the specified byte sequence
* until a total of <code>bytesToReturn</code> bytes have been returned.
- * @param b
- * @param bytesToReturn
+ * @param b byte[] to repeat
+ * @param bytesToReturn int
+ * @return InputStream
*/
public static synchronized InputStream getInstance(byte[] b,
int bytesToReturn) {
Modified: commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ThresholdingInputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ThresholdingInputStream.java?rev=758023&r1=758022&r2=758023&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ThresholdingInputStream.java (original)
+++ commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/util/ThresholdingInputStream.java Tue Mar 24 21:09:19 2009
@@ -34,6 +34,7 @@
/**
* Create a new ThresholdingInputStream.
* @param in the filtered stream
+ * @param maximum length
*/
public ThresholdingInputStream(InputStream in, int maximum) {
super(in);
@@ -45,10 +46,8 @@
* super methods are called
*/
- /*
- * (non-Javadoc)
- *
- * @see org.apache.commons.io.input.CountingInputStream#read()
+ /**
+ * {@inheritDoc}
*/
public synchronized int read() throws IOException {
assertNotClosed();
@@ -58,11 +57,8 @@
return super.read();
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.commons.io.input.CountingInputStream#read(byte[], int,
- * int)
+ /**
+ * {@inheritDoc}
*/
public synchronized int read(byte[] b, int off, int len) throws IOException {
assertNotClosed();
@@ -70,11 +66,8 @@
return n == 0 ? EOF : super.read(b, off, n < len ? n : len);
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.commons.io.input.CountingInputStream#read(byte[], int,
- * int)
+ /**
+ * {@inheritDoc}
*/
public synchronized int read(byte[] b) throws IOException {
assertNotClosed();
@@ -94,16 +87,18 @@
return super.read(b);
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.commons.io.input.ProxyInputStream#close()
+ /**
+ * {@inheritDoc}
*/
public synchronized void close() throws IOException {
this.closed = true;
super.close();
}
+ /**
+ * Make sure the stream is not closed.
+ * @throws IOException if stream has been closed.
+ */
private synchronized void assertNotClosed() throws IOException {
if (closed) {
throw new IOException("Stream closed");
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=758023&r1=758022&r2=758023&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 Tue Mar 24 21:09:19 2009
@@ -51,13 +51,10 @@
assertValue("xxxxxxxxxx", entityFactory.getEntity("test4"));
}
- /*
- * (non-Javadoc)
- *
- * @see com.pgac.fixedlength.EntityParserTestBase#getSource()
+ /**
+ * {@inheritDoc}
*/
protected String getSource() {
- // TODO Auto-generated method stub
return "immutable.test";
}
}