[jboss-svn-commits] JBoss Common SVN: r1944 - trunk/src/main/org/jboss/util/collection
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Aug 11 11:41:11 EDT 2006
Author: adrian at jboss.org
Date: 2006-08-11 11:41:06 -0400 (Fri, 11 Aug 2006)
New Revision: 1944
Modified:
trunk/src/main/org/jboss/util/collection/CollectionsFactory.java
trunk/src/main/org/jboss/util/collection/LazyList.java
trunk/src/main/org/jboss/util/collection/LazyMap.java
trunk/src/main/org/jboss/util/collection/LazySet.java
Log:
Generification.
Modified: trunk/src/main/org/jboss/util/collection/CollectionsFactory.java
===================================================================
--- trunk/src/main/org/jboss/util/collection/CollectionsFactory.java 2006-08-10 19:03:11 UTC (rev 1943)
+++ trunk/src/main/org/jboss/util/collection/CollectionsFactory.java 2006-08-11 15:41:06 UTC (rev 1944)
@@ -1,40 +1,37 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
package org.jboss.util.collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CopyOnWriteArraySet;
-import org.jboss.util.collection.LazyList;
-import org.jboss.util.collection.LazyMap;
-import org.jboss.util.collection.LazySet;
-
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList;
-import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArraySet;
-
/**
- * Collections factory.
+ * TempCollectionsFactory.
+ *
+ * FIXME: Generise the common version
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision$
@@ -44,48 +41,48 @@
/**
* Defines the map implementation
*/
- public static final Map createLazyMap()
+ public static final <K, V> Map<K, V> createLazyMap()
{
- return new LazyMap();
+ return new LazyMap<K, V>();
}
/**
* Defines the list implementation
*/
- public static final List createLazyList()
+ public static final <T> List <T> createLazyList()
{
- return new LazyList();
+ return new LazyList<T>();
}
/**
* Defines the set implementation
*/
- public static final Set createLazySet()
+ public static final <T> Set<T> createLazySet()
{
- return new LazySet();
+ return new LazySet<T>();
}
/**
* Defines the concurrent map implementation
*/
- public static final Map createConcurrentReaderMap()
+ public static final <K, V> Map<K, V> createConcurrentReaderMap()
{
- return new ConcurrentReaderHashMap();
+ return new ConcurrentHashMap<K, V>();
}
/**
* Defines the concurrent list implementation
*/
- public static final List createCopyOnWriteList()
+ public static final <T> List<T> createCopyOnWriteList()
{
- return new CopyOnWriteArrayList();
+ return new CopyOnWriteArrayList<T>();
}
/**
* Defines the concurrent set implementation
*/
- public static final Set createCopyOnWriteSet()
+ public static final <T> Set<T> createCopyOnWriteSet()
{
- return new CopyOnWriteArraySet();
+ return new CopyOnWriteArraySet<T>();
}
}
Modified: trunk/src/main/org/jboss/util/collection/LazyList.java
===================================================================
--- trunk/src/main/org/jboss/util/collection/LazyList.java 2006-08-10 19:03:11 UTC (rev 1943)
+++ trunk/src/main/org/jboss/util/collection/LazyList.java 2006-08-11 15:41:06 UTC (rev 1944)
@@ -34,19 +34,19 @@
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision$
*/
-public class LazyList implements List
+public class LazyList<T> implements List<T>
{
/** The delegate list */
- private List delegate = Collections.EMPTY_LIST;
+ private List<T> delegate = Collections.emptyList();
- public void add(int index, Object element)
+ public void add(int index, T element)
{
if (delegate instanceof ArrayList == false)
- delegate = new ArrayList(delegate);
+ delegate = new ArrayList<T>(delegate);
delegate.add(index, element);
}
- public boolean add(Object o)
+ public boolean add(T o)
{
if (delegate == Collections.EMPTY_LIST)
{
@@ -56,28 +56,28 @@
else
{
if (delegate instanceof ArrayList == false)
- delegate = new ArrayList(delegate);
+ delegate = new ArrayList<T>(delegate);
return delegate.add(o);
}
}
- public boolean addAll(Collection c)
+ public boolean addAll(Collection<? extends T> c)
{
if (delegate instanceof ArrayList == false)
- delegate = new ArrayList(delegate);
+ delegate = new ArrayList<T>(delegate);
return delegate.addAll(c);
}
- public boolean addAll(int index, Collection c)
+ public boolean addAll(int index, Collection<? extends T> c)
{
if (delegate instanceof ArrayList == false)
- delegate = new ArrayList(delegate);
+ delegate = new ArrayList<T>(delegate);
return delegate.addAll(index, c);
}
public void clear()
{
- delegate = Collections.EMPTY_LIST;
+ delegate = Collections.emptyList();
}
public boolean contains(Object o)
@@ -85,12 +85,12 @@
return delegate.contains(o);
}
- public boolean containsAll(Collection c)
+ public boolean containsAll(Collection<?> c)
{
return delegate.containsAll(c);
}
- public Object get(int index)
+ public T get(int index)
{
return delegate.get(index);
}
@@ -105,7 +105,7 @@
return delegate.isEmpty();
}
- public Iterator iterator()
+ public Iterator<T> iterator()
{
return delegate.iterator();
}
@@ -115,48 +115,48 @@
return delegate.lastIndexOf(o);
}
- public ListIterator listIterator()
+ public ListIterator<T> listIterator()
{
return delegate.listIterator();
}
- public ListIterator listIterator(int index)
+ public ListIterator<T> listIterator(int index)
{
return delegate.listIterator(index);
}
- public Object remove(int index)
+ public T remove(int index)
{
if (delegate instanceof ArrayList == false)
- delegate = new ArrayList(delegate);
+ delegate = new ArrayList<T>(delegate);
return delegate.remove(index);
}
public boolean remove(Object o)
{
if (delegate instanceof ArrayList == false)
- delegate = new ArrayList(delegate);
+ delegate = new ArrayList<T>(delegate);
return delegate.remove(o);
}
- public boolean removeAll(Collection c)
+ public boolean removeAll(Collection<?> c)
{
if (delegate instanceof ArrayList == false)
- delegate = new ArrayList(delegate);
- return delegate.remove(c);
+ delegate = new ArrayList<T>(delegate);
+ return delegate.removeAll(c);
}
- public boolean retainAll(Collection c)
+ public boolean retainAll(Collection<?> c)
{
if (delegate instanceof ArrayList == false)
- delegate = new ArrayList(delegate);
+ delegate = new ArrayList<T>(delegate);
return delegate.retainAll(c);
}
- public Object set(int index, Object element)
+ public T set(int index, T element)
{
if (delegate instanceof ArrayList == false)
- delegate = new ArrayList(delegate);
+ delegate = new ArrayList<T>(delegate);
return delegate.set(index, element);
}
@@ -165,7 +165,7 @@
return delegate.size();
}
- public List subList(int fromIndex, int toIndex)
+ public List<T> subList(int fromIndex, int toIndex)
{
return delegate.subList(fromIndex, toIndex);
}
@@ -175,7 +175,7 @@
return delegate.toArray();
}
- public Object[] toArray(Object[] a)
+ public <T> T[] toArray(T[] a)
{
return delegate.toArray(a);
}
Modified: trunk/src/main/org/jboss/util/collection/LazyMap.java
===================================================================
--- trunk/src/main/org/jboss/util/collection/LazyMap.java 2006-08-10 19:03:11 UTC (rev 1943)
+++ trunk/src/main/org/jboss/util/collection/LazyMap.java 2006-08-11 15:41:06 UTC (rev 1944)
@@ -33,14 +33,14 @@
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision$
*/
-public class LazyMap implements Map
+public class LazyMap<K, V> implements Map<K, V>
{
/** The delegate map */
- private Map delegate = Collections.EMPTY_MAP;
+ private Map<K, V> delegate = Collections.emptyMap();
public void clear()
{
- delegate = Collections.EMPTY_MAP;
+ delegate = Collections.emptyMap();
}
public boolean containsKey(Object key)
@@ -53,12 +53,12 @@
return delegate.containsValue(value);
}
- public Set entrySet()
+ public Set<Map.Entry<K, V>> entrySet()
{
return delegate.entrySet();
}
- public Object get(Object key)
+ public V get(Object key)
{
return delegate.get(key);
}
@@ -68,12 +68,12 @@
return delegate.isEmpty();
}
- public Set keySet()
+ public Set<K> keySet()
{
return delegate.keySet();
}
- public Object put(Object key, Object value)
+ public V put(K key, V value)
{
if (delegate == Collections.EMPTY_MAP)
{
@@ -83,22 +83,22 @@
else
{
if (delegate instanceof HashMap == false)
- delegate = new HashMap(delegate);
+ delegate = new HashMap<K, V>(delegate);
return delegate.put(key, value);
}
}
- public void putAll(Map t)
+ public void putAll(Map<? extends K, ? extends V> t)
{
if (delegate instanceof HashMap == false)
- delegate = new HashMap(delegate);
+ delegate = new HashMap<K, V>(delegate);
delegate.putAll(t);
}
- public Object remove(Object key)
+ public V remove(Object key)
{
if (delegate instanceof HashMap == false)
- delegate = new HashMap(delegate);
+ delegate = new HashMap<K, V>(delegate);
return delegate.remove(key);
}
@@ -107,7 +107,7 @@
return delegate.size();
}
- public Collection values()
+ public Collection<V> values()
{
return delegate.values();
}
Modified: trunk/src/main/org/jboss/util/collection/LazySet.java
===================================================================
--- trunk/src/main/org/jboss/util/collection/LazySet.java 2006-08-10 19:03:11 UTC (rev 1943)
+++ trunk/src/main/org/jboss/util/collection/LazySet.java 2006-08-11 15:41:06 UTC (rev 1944)
@@ -33,12 +33,12 @@
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision$
*/
-public class LazySet implements Set
+public class LazySet<T> implements Set<T>
{
/** The delegate set */
- private Set delegate = Collections.EMPTY_SET;
+ private Set<T> delegate = Collections.emptySet();
- public boolean add(Object o)
+ public boolean add(T o)
{
if (delegate == Collections.EMPTY_SET)
{
@@ -48,21 +48,21 @@
else
{
if (delegate instanceof HashSet == false)
- delegate = new HashSet(delegate);
+ delegate = new HashSet<T>(delegate);
return delegate.add(o);
}
}
- public boolean addAll(Collection c)
+ public boolean addAll(Collection<? extends T> c)
{
if (delegate instanceof HashSet == false)
- delegate = new HashSet(delegate);
+ delegate = new HashSet<T>(delegate);
return delegate.addAll(c);
}
public void clear()
{
- delegate = Collections.EMPTY_SET;
+ delegate = Collections.emptySet();
}
public boolean contains(Object o)
@@ -70,7 +70,7 @@
return delegate.contains(o);
}
- public boolean containsAll(Collection c)
+ public boolean containsAll(Collection<?> c)
{
return delegate.containsAll(c);
}
@@ -80,7 +80,7 @@
return delegate.isEmpty();
}
- public Iterator iterator()
+ public Iterator<T> iterator()
{
return delegate.iterator();
}
@@ -88,21 +88,21 @@
public boolean remove(Object o)
{
if (delegate instanceof HashSet == false)
- delegate = new HashSet(delegate);
+ delegate = new HashSet<T>(delegate);
return delegate.remove(o);
}
- public boolean removeAll(Collection c)
+ public boolean removeAll(Collection<?> c)
{
if (delegate instanceof HashSet == false)
- delegate = new HashSet(delegate);
+ delegate = new HashSet<T>(delegate);
return delegate.removeAll(c);
}
- public boolean retainAll(Collection c)
+ public boolean retainAll(Collection<?> c)
{
if (delegate instanceof HashSet == false)
- delegate = new HashSet(delegate);
+ delegate = new HashSet<T>(delegate);
return delegate.retainAll(c);
}
@@ -116,7 +116,7 @@
return delegate.toArray();
}
- public Object[] toArray(Object[] a)
+ public <T> T[] toArray(T[] a)
{
return delegate.toArray(a);
}
More information about the jboss-svn-commits
mailing list