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 2012/03/15 23:19:19 UTC
svn commit: r1301247 - in
/commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory:
CloningEntityFactory.java CompositeEntityFactory.java
Author: mbenson
Date: Thu Mar 15 22:19:19 2012
New Revision: 1301247
URL: http://svn.apache.org/viewvc?rev=1301247&view=rev
Log:
lang5 + minor cleanup including final members
Modified:
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CloningEntityFactory.java
commons/sandbox/flatfile/trunk/src/main/java/org/apache/commons/flatfile/entityfactory/CompositeEntityFactory.java
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=1301247&r1=1301246&r2=1301247&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 Thu Mar 15 22:19:19 2012
@@ -20,6 +20,8 @@ import java.util.Map;
import org.apache.commons.flatfile.Entity;
import org.apache.commons.flatfile.EntityFactory;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.Validate;
/**
* Stores prototype entities in a Map and returns cloned Entities.
@@ -33,18 +35,14 @@ public class CloningEntityFactory implem
* @param lookup lookup Map
*/
public CloningEntityFactory(Map<? extends Object, ? extends Entity> lookup) {
- if (lookup == null) {
- throw new IllegalArgumentException("null lookup Map");
- }
- this.lookup = lookup;
+ this.lookup = Validate.notNull(lookup);
}
/**
* {@inheritDoc}
*/
public Entity getEntity(Object cue) {
- Entity prototype = lookup.get(cue);
- return prototype == null ? null : prototype.clone();
+ return ObjectUtils.clone(lookup.get(cue));
}
}
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=1301247&r1=1301246&r2=1301247&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 Thu Mar 15 22:19:19 2012
@@ -25,22 +25,22 @@ import org.apache.commons.flatfile.Entit
*/
public class CompositeEntityFactory implements EntityFactory {
- private EntityFactory[] delegates;
+ private final EntityFactory[] delegates;
/**
* Create a new CompositeEntityFactory.
* @param delegates EntityFactory[]
*/
- public CompositeEntityFactory(EntityFactory[] delegates) {
- this.delegates = delegates;
+ public CompositeEntityFactory(EntityFactory... delegates) {
+ this.delegates = delegates == null ? new EntityFactory[0] : delegates;
}
/**
* {@inheritDoc}
*/
public Entity getEntity(Object cue) {
- for (int i = 0; delegates != null && i < delegates.length; i++) {
- Entity result = delegates[i].getEntity(cue);
+ for (EntityFactory delegate : delegates) {
+ Entity result = delegate.getEntity(cue);
if (result != null) {
return result;
}