From portal-commits at lists.jboss.org Sun Nov 11 17:31:48 2007 Content-Type: multipart/mixed; boundary="===============2316403308120817865==" MIME-Version: 1.0 From: portal-commits at lists.jboss.org To: portal-commits at lists.jboss.org Subject: [portal-commits] JBoss Portal SVN: r8869 - modules/common/trunk/common/src/main/java/org/jboss/portal/common/util. Date: Sun, 11 Nov 2007 17:31:48 -0500 Message-ID: --===============2316403308120817865== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: julien(a)jboss.com Date: 2007-11-11 17:31:47 -0500 (Sun, 11 Nov 2007) New Revision: 8869 Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/C= ollectionBuilder.java modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/M= apBuilder.java Log: refactored and generifed CollectionBuilder and MapBuilder Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common= /util/CollectionBuilder.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/= CollectionBuilder.java 2007-11-11 22:20:21 UTC (rev 8868) +++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/= CollectionBuilder.java 2007-11-11 22:31:47 UTC (rev 8869) @@ -33,37 +33,44 @@ * @author Julien Viet * @version $Revision: 7234 $ */ -public class CollectionBuilder +public class CollectionBuilder { = /** . */ - private ArrayList collection; + private Collection collection; = - public CollectionBuilder() + private CollectionBuilder(Collection collection) { - this.collection =3D new ArrayList(); + this.collection =3D collection; } = - /** - * Factory method to create a collection builder using a singleton. - * - * @param o the object to add - * @return the builder created - */ - public static CollectionBuilder singleton(Object o) + public static CollectionBuilder create(Collection collection) { - CollectionBuilder builder =3D new CollectionBuilder(); - builder.collection.add(o); - return builder; + return new CollectionBuilder(collection); } = + public static CollectionBuilder arrayList() + { + return new CollectionBuilder(new ArrayList()); + } + + public static CollectionBuilder linkedList() + { + return new CollectionBuilder(new LinkedList()); + } + + public static CollectionBuilder hashSet() + { + return new CollectionBuilder(new HashSet()); + } + /** * Add the object to the collection. * * @param o the object to add * @return the builder */ - public CollectionBuilder add(Object o) + public CollectionBuilder add(V o) { collection.add(o); return this; @@ -75,39 +82,14 @@ * @param all the objects to add * @return the builder */ - public CollectionBuilder addAll(Collection all) + public CollectionBuilder addAll(Collection all) { collection.addAll(all); return this; } = - /** - * Return a set build from the collection. - * - * @return a set - */ - public HashSet toHashSet() + public Collection get() { - return new HashSet(collection); + return collection; } - - /** - * Return a list build from the collection. - * - * @return a list - */ - public ArrayList toArrayList() - { - return new ArrayList(collection); - } - - /** - * Return a list build from the collection. - * - * @return a list - */ - public LinkedList toLinkedList() - { - return new LinkedList(collection); - } } Modified: modules/common/trunk/common/src/main/java/org/jboss/portal/common= /util/MapBuilder.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/= MapBuilder.java 2007-11-11 22:20:21 UTC (rev 8868) +++ modules/common/trunk/common/src/main/java/org/jboss/portal/common/util/= MapBuilder.java 2007-11-11 22:31:47 UTC (rev 8869) @@ -27,18 +27,18 @@ import java.util.Map; = /** - * An helper to build collection of object in a simple manner. + * An helper to build map in a simple manner. * * @author Julien Viet * @version $Revision: 7228 $ */ -public class MapBuilder +public class MapBuilder { = /** . */ - private final Map map; + private final Map map; = - private MapBuilder(Map map) + private MapBuilder(Map map) { if (map =3D=3D null) { @@ -52,9 +52,9 @@ * * @return a new instance */ - public static MapBuilder hashMap() + public static MapBuilder hashMap() { - return new MapBuilder(new HashMap()); + return new MapBuilder(new HashMap()); } = /** @@ -62,14 +62,14 @@ * * @return a new instance */ - public static MapBuilder linkedHashMap() + public static MapBuilder linkedHashMap() { - return new MapBuilder(new LinkedHashMap()); + return new MapBuilder(new LinkedHashMap()); } = - public static MapBuilder create(Map map) + public static MapBuilder create(Map map) { - return new MapBuilder(map); + return new MapBuilder(map); } = /** @@ -79,7 +79,7 @@ * @param value the value * @return the builder */ - public MapBuilder put(Object key, Object value) + public MapBuilder put(K key, V value) { map.put(key, value); return this; @@ -91,13 +91,13 @@ * @param all the entries to add * @return the builder */ - public MapBuilder putAll(Map all) + public MapBuilder putAll(Map all) { map.putAll(all); return this; } = - public Map get() + public Map get() { return map; } --===============2316403308120817865==--