Revision: 4874
http://sourceforge.net/p/jump-pilot/code/4874
Author: michaudm
Date: 2016-03-28 16:00:05 +0000 (Mon, 28 Mar 2016)
Log Message:
-----------
Cleaning, formatting rewriting jump.util
Modified Paths:
--------------
core/trunk/src/com/vividsolutions/jump/util/CollectionWrapper.java
core/trunk/src/com/vividsolutions/jump/util/ImmutableFirstElementList.java
core/trunk/src/com/vividsolutions/jump/util/LangUtil.java
core/trunk/src/com/vividsolutions/jump/util/LazyList.java
core/trunk/src/com/vividsolutions/jump/util/ListWrapper.java
core/trunk/src/com/vividsolutions/jump/util/OrderedMap.java
core/trunk/src/com/vividsolutions/jump/util/UniqueList.java
Modified: core/trunk/src/com/vividsolutions/jump/util/CollectionWrapper.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/CollectionWrapper.java
2016-03-28 15:51:04 UTC (rev 4873)
+++ core/trunk/src/com/vividsolutions/jump/util/CollectionWrapper.java
2016-03-28 16:00:05 UTC (rev 4874)
@@ -3,9 +3,9 @@
import java.util.Collection;
import java.util.Iterator;
-public abstract class CollectionWrapper<T> implements Collection<T> {
+public abstract class CollectionWrapper<E> implements Collection<E> {
- public abstract Collection<T> getCollection();
+ public abstract Collection<E> getCollection();
public int size() {
return getCollection().size();
@@ -23,7 +23,7 @@
return getCollection().toArray();
}
- public boolean add(T o) {
+ public boolean add(E o) {
return getCollection().add(o);
}
@@ -35,7 +35,7 @@
return getCollection().remove(o);
}
- public boolean addAll(Collection<? extends T> c) {
+ public boolean addAll(Collection<? extends E> c) {
return getCollection().addAll(c);
}
@@ -51,7 +51,7 @@
return getCollection().retainAll(c);
}
- public Iterator<T> iterator() {
+ public Iterator<E> iterator() {
return getCollection().iterator();
}
Modified:
core/trunk/src/com/vividsolutions/jump/util/ImmutableFirstElementList.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/ImmutableFirstElementList.java
2016-03-28 15:51:04 UTC (rev 4873)
+++ core/trunk/src/com/vividsolutions/jump/util/ImmutableFirstElementList.java
2016-03-28 16:00:05 UTC (rev 4874)
@@ -41,11 +41,11 @@
/**
* Can't add, replace, or remove the first element in the list.
*/
-public class ImmutableFirstElementList<T> implements List<T> {
+public class ImmutableFirstElementList<E> implements List<E> {
- private List<T> list = new ArrayList<T>();
+ private List<E> list = new ArrayList<>();
- public ImmutableFirstElementList(T firstElement) {
+ public ImmutableFirstElementList(E firstElement) {
list.add(firstElement);
}
@@ -61,7 +61,7 @@
return list.contains(o);
}
- public Iterator<T> iterator() {
+ public Iterator<E> iterator() {
//Prevent Iterator#remove. [Jon Aquino]
return Collections.unmodifiableList(list).iterator();
}
@@ -74,7 +74,7 @@
return list.toArray(a);
}
- public boolean add(T o) {
+ public boolean add(E o) {
return list.add(o);
}
@@ -87,16 +87,16 @@
return list.containsAll(c);
}
- public boolean addAll(Collection<? extends T> c) {
+ public boolean addAll(Collection<? extends E> c) {
return list.addAll(c);
}
- public boolean addAll(int index, Collection c) {
+ public boolean addAll(int index, Collection<? extends E> c) {
return list.addAll(index == 0 ? 1 : index, c);
}
public boolean removeAll(Collection<?> c) {
- return list.subList(1, list.size()).remove(c);
+ return list.subList(1, list.size()).removeAll(c);
}
public boolean retainAll(Collection<?> c) {
@@ -107,22 +107,22 @@
list.subList(1, list.size()).clear();
}
- public T get(int index) {
+ public E get(int index) {
return list.get(index);
}
- public T set(int index, T element) {
+ public E set(int index, E element) {
if (index == 0) {
return get(0);
}
return list.set(index, element);
}
- public void add(int index, T element) {
+ public void add(int index, E element) {
list.add(index == 0 ? 1 : index, element);
}
- public T remove(int index) {
+ public E remove(int index) {
if (index == 0) { return get(0);
}
return list.remove(index);
@@ -136,17 +136,17 @@
return list.lastIndexOf(o);
}
- public ListIterator listIterator() {
+ public ListIterator<E> listIterator() {
//Prevent Iterator#remove. [Jon Aquino]
return Collections.unmodifiableList(list).listIterator();
}
- public ListIterator listIterator(int index) {
+ public ListIterator<E> listIterator(int index) {
//Prevent Iterator#remove. [Jon Aquino]
return Collections.unmodifiableList(list).listIterator(index);
}
- public List subList(int fromIndex, int toIndex) {
+ public List<E> subList(int fromIndex, int toIndex) {
if (fromIndex > 0) {
return list.subList(fromIndex, toIndex);
}
Modified: core/trunk/src/com/vividsolutions/jump/util/LangUtil.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/LangUtil.java 2016-03-28
15:51:04 UTC (rev 4873)
+++ core/trunk/src/com/vividsolutions/jump/util/LangUtil.java 2016-03-28
16:00:05 UTC (rev 4874)
@@ -70,7 +70,7 @@
}
public static Class toPrimitiveWrapperClass(Class primitiveClass) {
- return (Class) primitiveToWrapperMap.get(primitiveClass);
+ return primitiveToWrapperMap.get(primitiveClass);
}
public static boolean isPrimitive(Class c) {
Modified: core/trunk/src/com/vividsolutions/jump/util/LazyList.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/LazyList.java 2016-03-28
15:51:04 UTC (rev 4873)
+++ core/trunk/src/com/vividsolutions/jump/util/LazyList.java 2016-03-28
16:00:05 UTC (rev 4874)
@@ -3,18 +3,18 @@
import java.util.Collection;
import java.util.List;
-public class LazyList extends ListWrapper {
+public class LazyList<E> extends ListWrapper<E> {
private Block collectionFactory;
- private List list;
+ private List<E> list;
public LazyList(Block collectionFactory) {
this.collectionFactory = collectionFactory;
}
- public Collection getCollection() {
+ public Collection<E> getCollection() {
if (list == null) {
- list = (List) collectionFactory.yield();
+ list = (List<E>) collectionFactory.yield();
}
return list;
}
Modified: core/trunk/src/com/vividsolutions/jump/util/ListWrapper.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/ListWrapper.java
2016-03-28 15:51:04 UTC (rev 4873)
+++ core/trunk/src/com/vividsolutions/jump/util/ListWrapper.java
2016-03-28 16:00:05 UTC (rev 4874)
@@ -4,21 +4,21 @@
import java.util.List;
import java.util.ListIterator;
-public abstract class ListWrapper<T> extends CollectionWrapper<T> implements
List<T> {
+public abstract class ListWrapper<E> extends CollectionWrapper<E> implements
List<E> {
- public List<T> getList() {
- return (List<T>) getCollection();
+ public List<E> getList() {
+ return (List<E>) getCollection();
}
- public T get(int index) {
+ public E get(int index) {
return getList().get(index);
}
- public T remove(int index) {
+ public E remove(int index) {
return getList().remove(index);
}
- public void add(int index, T element) {
+ public void add(int index, E element) {
getList().add(index, element);
}
@@ -30,23 +30,23 @@
return getList().lastIndexOf(o);
}
- public boolean addAll(int index, Collection<? extends T> c) {
+ public boolean addAll(int index, Collection<? extends E> c) {
return getList().addAll(index, c);
}
- public List<T> subList(int fromIndex, int toIndex) {
+ public List<E> subList(int fromIndex, int toIndex) {
return getList().subList(fromIndex, toIndex);
}
- public ListIterator<T> listIterator() {
+ public ListIterator<E> listIterator() {
return getList().listIterator();
}
- public ListIterator<T> listIterator(int index) {
+ public ListIterator<E> listIterator(int index) {
return getList().listIterator(index);
}
- public T set(int index, T element) {
+ public E set(int index, E element) {
return getList().set(index, element);
}
}
\ No newline at end of file
Modified: core/trunk/src/com/vividsolutions/jump/util/OrderedMap.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/OrderedMap.java 2016-03-28
15:51:04 UTC (rev 4873)
+++ core/trunk/src/com/vividsolutions/jump/util/OrderedMap.java 2016-03-28
16:00:05 UTC (rev 4874)
@@ -39,15 +39,16 @@
/**
* A Map that preserves the order of its keys.
*/
-public class OrderedMap implements Map {
- private Map map;
- private List keyList;
+public class OrderedMap<U,V> implements Map<U,V> {
+ private Map<U,V> map;
+ private List<U> keyList;
+
/**
* Creates an OrderedMap backed by the given map.
* @param map a Map that will be this OrderedMap's underlying Map
*/
- public OrderedMap(List keyList, Map map) {
+ public OrderedMap(List<U> keyList, Map<U,V> map) {
this.keyList = keyList;
this.map = map;
}
@@ -56,11 +57,11 @@
* Creates an OrderedMap.
*/
public OrderedMap() {
- this(new HashMap());
+ this(new HashMap<U,V>());
}
- public OrderedMap(Map map) {
- this(new UniqueList(), map);
+ public OrderedMap(Map<U,V> map) {
+ this(new UniqueList<U>(), map);
}
public int size() {
@@ -79,23 +80,21 @@
return map.containsValue(value);
}
- public Object get(Object key) {
+ public V get(Object key) {
return map.get(key);
}
- public Object put(Object key, Object value) {
+ public V put(U key, V value) {
keyList.add(key);
-
return map.put(key, value);
}
- public Object remove(Object key) {
+ public V remove(Object key) {
keyList.remove(key);
-
return map.remove(key);
}
- public void putAll(Map t) {
+ public void putAll(Map<? extends U, ? extends V> t) {
keyList.addAll(t.keySet());
map.putAll(t);
}
@@ -105,7 +104,7 @@
map.clear();
}
- public Set keySet() {
+ public Set<U> keySet() {
return map.keySet();
}
@@ -113,7 +112,7 @@
* Returns the keys, in order.
* @return the keys in the order they were (first) added
*/
- public List keyList() {
+ public List<U> keyList() {
return keyList;
}
@@ -122,8 +121,8 @@
* @return the values in the same order as the keys
* @see #keyList()
*/
- public List valueList() {
- return (List) values();
+ public List<V> valueList() {
+ return (List<V>) values();
}
/**
@@ -131,22 +130,21 @@
* @return the values in the same order as the keys
* @see #keyList()
*/
- public Collection values() {
- ArrayList values = new ArrayList();
+ public Collection<V> values() {
+ List<V> values = new ArrayList<>();
- for (Iterator i = keyList.iterator(); i.hasNext();) {
- Object key = i.next();
+ for (U key : keyList) {
values.add(map.get(key));
}
return values;
}
- public Set entrySet() {
+ public Set<Map.Entry<U,V>> entrySet() {
return map.entrySet();
}
public boolean equals(Object o) {
- return map.equals(o);
+ return (o instanceof OrderedMap) && map.equals(o);
}
}
Modified: core/trunk/src/com/vividsolutions/jump/util/UniqueList.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/util/UniqueList.java 2016-03-28
15:51:04 UTC (rev 4873)
+++ core/trunk/src/com/vividsolutions/jump/util/UniqueList.java 2016-03-28
16:00:05 UTC (rev 4874)
@@ -40,21 +40,21 @@
* A List that ignores duplicates. Note: performance is not optimized - a
simple linear
* search is performed.
*/
-public class UniqueList implements List {
- private List list;
+public class UniqueList<E> implements List<E> {
+ private List<E> list;
/**
* Creates a UniqueList.
*/
public UniqueList() {
- this(new ArrayList());
+ this(new ArrayList<E>());
}
/**
* Creates a UniqueList backed by the given List.
* @param list a List that will be this UniqueList's underlying List
*/
- public UniqueList(List list) {
+ public UniqueList(List<E> list) {
this.list = list;
}
@@ -70,7 +70,7 @@
return list.contains(o);
}
- public Iterator iterator() {
+ public Iterator<E> iterator() {
return list.iterator();
}
@@ -78,11 +78,11 @@
return list.toArray();
}
- public Object[] toArray(Object[] a) {
+ public <T> T[] toArray(T[] a) {
return list.toArray(a);
}
- public boolean add(Object o) {
+ public boolean add(E o) {
if (list.contains(o)) {
return false;
}
@@ -94,25 +94,25 @@
return list.remove(o);
}
- public boolean containsAll(Collection c) {
+ public boolean containsAll(Collection<?> c) {
return list.containsAll(c);
}
- public boolean addAll(Collection c) {
+ public boolean addAll(Collection<? extends E> c) {
return addAll(size(), c);
}
- public boolean addAll(int index, Collection c) {
- ArrayList itemsToAdd = new ArrayList(c);
+ public boolean addAll(int index, Collection<? extends E> c) {
+ List<E> itemsToAdd = new ArrayList<>(c);
itemsToAdd.removeAll(this);
return list.addAll(index, itemsToAdd);
}
- public boolean removeAll(Collection c) {
+ public boolean removeAll(Collection<?> c) {
return list.removeAll(c);
}
- public boolean retainAll(Collection c) {
+ public boolean retainAll(Collection<?> c) {
return list.retainAll(c);
}
@@ -121,18 +121,18 @@
}
public boolean equals(Object o) {
- return list.equals(o);
+ return o instanceof UniqueList && list.equals(o);
}
- public Object get(int index) {
+ public E get(int index) {
return list.get(index);
}
- public Object set(int index, Object element) {
+ public E set(int index, E element) {
return list.set(index, element);
}
- public void add(int index, Object element) {
+ public void add(int index, E element) {
if (list.contains(element)) {
return;
}
@@ -140,7 +140,7 @@
list.add(index, element);
}
- public Object remove(int index) {
+ public E remove(int index) {
return list.remove(index);
}
@@ -152,15 +152,15 @@
return list.lastIndexOf(o);
}
- public ListIterator listIterator() {
+ public ListIterator<E> listIterator() {
return list.listIterator();
}
- public ListIterator listIterator(int index) {
+ public ListIterator<E> listIterator(int index) {
return list.listIterator(index);
}
- public List subList(int fromIndex, int toIndex) {
+ public List<E> subList(int fromIndex, int toIndex) {
return list.subList(fromIndex, toIndex);
}
}
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785471&iu=/4140
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel