summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableArray.java
diff options
context:
space:
mode:
Diffstat (limited to 'projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableArray.java')
-rw-r--r--projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableArray.java94
1 files changed, 56 insertions, 38 deletions
diff --git a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableArray.java b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableArray.java
index c75de01..39f9fb1 100644
--- a/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableArray.java
+++ b/projects/net.wotonomy.foundation/src/main/java/net/wotonomy/foundation/NSMutableArray.java
@@ -30,17 +30,19 @@ import java.util.ListIterator;
* @author $Author: cgruber $
* @version $Revision: 893 $
*/
-public class NSMutableArray extends NSArray {
+public class NSMutableArray<T> extends NSArray<T> {
+ private static final long serialVersionUID = 2414783500843649556L;
+
/**
* Returns an NSArray backed by the specified List. This is useful to "protect"
* an internal representation that is returned by a method of return type
* NSArray.
*/
- public static NSMutableArray mutableArrayBackedByList(List aList) {
- return new NSMutableArray(aList, null);
+ public static <T> NSMutableArray<T> mutableArrayBackedByList(List<T> aList) {
+ return new NSMutableArray<>(aList, null);
}
- NSMutableArray(List aList, Object ignored) // differentiates
+ NSMutableArray(List<T> aList, Object ignored) // differentiates
{
super(aList, ignored);
}
@@ -64,7 +66,7 @@ public class NSMutableArray extends NSArray {
/**
* Produces an array containing only the specified object.
*/
- public NSMutableArray(Object anObject) {
+ public NSMutableArray(T anObject) {
super(anObject);
//System.out.println( "NSMutableArray: " + net.wotonomy.ui.swing.util.StackTraceInspector.getMyCaller() );
}
@@ -72,7 +74,7 @@ public class NSMutableArray extends NSArray {
/**
* Produces an array containing the specified objects.
*/
- public NSMutableArray(Object[] anArray) {
+ public NSMutableArray(T[] anArray) {
super(anArray);
//System.out.println( "NSMutableArray: " + net.wotonomy.ui.swing.util.StackTraceInspector.getMyCaller() );
}
@@ -80,7 +82,7 @@ public class NSMutableArray extends NSArray {
/**
* Produces an array containing the objects in the specified collection.
*/
- public NSMutableArray(Collection aCollection) {
+ public NSMutableArray(Collection<T> aCollection) {
super(aCollection);
//System.out.println( "NSMutableArray: " + net.wotonomy.ui.swing.util.StackTraceInspector.getMyCaller() );
}
@@ -102,7 +104,7 @@ public class NSMutableArray extends NSArray {
/**
* Adds all objects in the specified collection.
*/
- public void addObjectsFromArray(Collection aCollection) {
+ public void addObjectsFromArray(Collection<T> aCollection) {
list.addAll(aCollection);
}
@@ -117,7 +119,7 @@ public class NSMutableArray extends NSArray {
* Removes all objects equivalent to the specified object within the range of
* specified indices.
*/
- public void removeObject(Object anObject, NSRange aRange) {
+ public void removeObject(T anObject, NSRange aRange) {
if ((anObject == null) || (aRange == null))
return;
@@ -136,7 +138,7 @@ public class NSMutableArray extends NSArray {
* Removes all instances of the specified object within the range of specified
* indices, comparing by reference.
*/
- public void removeIdenticalObject(Object anObject, NSRange aRange) {
+ public void removeIdenticalObject(T anObject, NSRange aRange) {
if ((anObject == null) || (aRange == null))
return;
@@ -154,7 +156,7 @@ public class NSMutableArray extends NSArray {
/**
* Removes all objects in the specified collection from the array.
*/
- public void removeObjectsInArray(Collection aCollection) {
+ public void removeObjectsInArray(Collection<T> aCollection) {
list.removeAll(aCollection);
}
@@ -176,7 +178,7 @@ public class NSMutableArray extends NSArray {
* objects are removed. If otherRange is larger than currentRange, the extra
* objects are added.
*/
- public void replaceObjectsInRange(NSRange currentRange, List otherArray, NSRange otherRange) {
+ public void replaceObjectsInRange(NSRange currentRange, List<T> otherArray, NSRange otherRange) {
if ((currentRange == null) || (otherArray == null) || (otherRange == null))
return;
@@ -187,8 +189,7 @@ public class NSMutableArray extends NSArray {
otherRange = new NSRange(loc, otherArray.size() - loc);
}
- Object o;
- List subList = list.subList(currentRange.location(), currentRange.maxRange());
+ List<T> subList = list.subList(currentRange.location(), currentRange.maxRange());
int otherIndex = otherRange.location();
// TODO: Test this logic.
for (int i = 0; i < subList.size(); i++) {
@@ -210,7 +211,7 @@ public class NSMutableArray extends NSArray {
* Clears the current array and then populates it with the contents of the
* specified collection.
*/
- public void setArray(Collection aCollection) {
+ public void setArray(Collection<T> aCollection) {
list.clear();
list.addAll(aCollection);
}
@@ -233,8 +234,8 @@ public class NSMutableArray extends NSArray {
/**
* Removes all occurences of the specified object, comparing by reference.
*/
- public void removeIdenticalObject(Object anObject) {
- Iterator it = list.iterator();
+ public void removeIdenticalObject(T anObject) {
+ Iterator<T> it = list.iterator();
while (it.hasNext()) {
if (it.next() == anObject) {
it.remove();
@@ -245,91 +246,108 @@ public class NSMutableArray extends NSArray {
/**
* Inserts the specified object into this array at the specified index.
*/
- public void insertObjectAtIndex(Object anObject, int anIndex) {
+ public void insertObjectAtIndex(T anObject, int anIndex) {
list.add(anIndex, anObject);
}
/**
* Replaces the object at the specified index with the specified object.
*/
- public void replaceObjectAtIndex(int anIndex, Object anObject) {
+ public void replaceObjectAtIndex(int anIndex, T anObject) {
list.set(anIndex, anObject);
}
/**
* Adds the specified object to the end of this array.
*/
- public void addObject(Object anObject) {
+ public void addObject(T anObject) {
list.add(anObject);
}
+ @Override
public Object clone() {
- return new NSMutableArray(list);
+ return new NSMutableArray<>(list);
}
- public NSArray immutableClone() {
- return new NSArray(this);
+ @Override
+ public NSArray<T> immutableClone() {
+ return new NSArray<>(this);
}
- public NSMutableArray mutableClone() {
- return new NSMutableArray(this);
+ @Override
+ public NSMutableArray<T> mutableClone() {
+ return new NSMutableArray<>(this);
}
// interface List: mutators
- public void add(int index, Object element) {
+ @Override
+ public void add(int index, T element) {
list.add(index, element);
}
- public boolean add(Object o) {
+ @Override
+ public boolean add(T o) {
return list.add(o);
}
- public boolean addAll(Collection coll) {
+ @Override
+ public boolean addAll(Collection<? extends T> coll) {
return list.addAll(coll);
}
- public boolean addAll(int index, Collection c) {
+ @Override
+ public boolean addAll(int index, Collection<? extends T> c) {
return list.addAll(index, c);
}
+ @Override
public void clear() {
list.clear();
}
- public Iterator iterator() {
+ @Override
+ public Iterator<T> iterator() {
return list.iterator();
}
- public ListIterator listIterator() {
+ @Override
+ public ListIterator<T> listIterator() {
return list.listIterator();
}
- public ListIterator listIterator(int index) {
- return list.listIterator();
+ @Override
+ public ListIterator<T> listIterator(int index) {
+ return list.listIterator(index);
}
- public Object remove(int index) {
+ @Override
+ public T remove(int index) {
return list.remove(index);
}
+ @Override
public boolean remove(Object o) {
return list.remove(o);
}
- public boolean removeAll(Collection coll) {
+ @Override
+ public boolean removeAll(Collection<?> coll) {
return list.removeAll(coll);
}
- public boolean retainAll(Collection coll) {
+ @Override
+ public boolean retainAll(Collection<?> coll) {
return list.retainAll(coll);
}
- public Object set(int index, Object element) {
+ @Override
+ public T set(int index, T element) {
return list.set(index, element);
}
- public List subList(int fromIndex, int toIndex) {
+ @Override
+ public List<T> subList(int fromIndex, int toIndex) {
return list.subList(fromIndex, toIndex);
}