Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added more to the avian classpath for the collection interface as well as the list interface #55

Merged
merged 2 commits into from

1 participant

@jentfoo

Added to collection:
public boolean containsAll(Collection<?> c);
public boolean removeAll(Collection<?> c);

Added to list:
public boolean addAll(int startIndex, Collection<? extends T> c);

Also where possible for inner classes I made them extend the abstract version instead of just implement the interface. This helps reduce code duplication where possible.

These changes were necessary to support protobuf 2.5.0

Mike Jensen added some commits
Mike Jensen Added more to the avian classpath for the collection interface as wel…
…l as the list interface

Added to collection:
public boolean containsAll(Collection<?> c);
public boolean removeAll(Collection<?> c);

Added to list:
public boolean addAll(int startIndex, Collection<? extends T> c);

Also where possible for inner classes I made them extend the abstract version instead of just implement the interface.  This helps reduce code duplication where possible.

These changes were necessary to support protobuf 2.5.0
a41f8c0
Mike Jensen Merge branch 'master' of https://github.com/ReadyTalk/avian bd2ebfc
@jentfoo jentfoo merged commit f052c77 into ReadyTalk:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 29, 2013
  1. Added more to the avian classpath for the collection interface as wel…

    Mike Jensen authored
    …l as the list interface
    
    Added to collection:
    public boolean containsAll(Collection<?> c);
    public boolean removeAll(Collection<?> c);
    
    Added to list:
    public boolean addAll(int startIndex, Collection<? extends T> c);
    
    Also where possible for inner classes I made them extend the abstract version instead of just implement the interface.  This helps reduce code duplication where possible.
    
    These changes were necessary to support protobuf 2.5.0
This page is out of date. Refresh to see the latest.
View
30 classpath/java/util/AbstractCollection.java
@@ -51,6 +51,21 @@ public boolean contains(Object element) {
return false;
}
+ public boolean containsAll(Collection<?> c) {
+ if (c == null) {
+ throw new NullPointerException("Collection is null");
+ }
+
+ Iterator<?> it = c.iterator();
+ while (it.hasNext()) {
+ if (! contains(it.next())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
public boolean isEmpty() {
return size() == 0;
}
@@ -60,6 +75,21 @@ public boolean remove(Object element) {
+ this.getClass().getName());
}
+ public boolean removeAll(Collection<?> c) {
+ if (c == null) {
+ throw new NullPointerException("Collection is null");
+ }
+
+ boolean changed = false;
+
+ Iterator<?> it = c.iterator();
+ while (it.hasNext()) {
+ changed = remove(it.next()) || changed;
+ }
+
+ return changed;
+ }
+
public abstract int size();
public Object[] toArray() {
View
21 classpath/java/util/AbstractList.java
@@ -20,6 +20,27 @@ public boolean add(T o) {
return true;
}
+ public boolean addAll(Collection<? extends T> c) {
+ return addAll(size(), c);
+ }
+
+ public boolean addAll(int startIndex, Collection<? extends T> c) {
+ if (c == null) {
+ throw new NullPointerException("Collection is null");
+ }
+
+ int index = startIndex;
+ boolean changed = false;
+
+ Iterator<? extends T> it = c.iterator();
+ while (it.hasNext()) {
+ add(index++, it.next());
+ changed = true;
+ }
+
+ return changed;
+ }
+
public Iterator<T> iterator() {
return listIterator();
}
View
55 classpath/java/util/Arrays.java
@@ -91,36 +91,15 @@ public static boolean equals(Object[] a, Object[] b) {
}
public static <T> List<T> asList(final T ... array) {
- return new List<T>() {
- public String toString() {
- return Collections.toString(this);
- }
-
+ return new AbstractList<T>() {
public int size() {
return array.length;
}
- public boolean add(T element) {
- throw new UnsupportedOperationException();
- }
-
- public boolean addAll(Collection<? extends T> collection) {
- throw new UnsupportedOperationException();
- }
-
public void add(int index, T element) {
throw new UnsupportedOperationException();
}
-
- public boolean contains(Object element) {
- for (int i = 0; i < array.length; ++i) {
- if (equal(element, array[i])) {
- return true;
- }
- }
- return false;
- }
-
+
public int indexOf(Object element) {
for (int i = 0; i < array.length; ++i) {
if (equal(element, array[i])) {
@@ -138,7 +117,7 @@ public int lastIndexOf(Object element) {
}
return -1;
}
-
+
public T get(int index) {
return array[index];
}
@@ -147,41 +126,13 @@ public T set(int index, T value) {
throw new UnsupportedOperationException();
}
- public Object[] toArray() {
- return toArray(new Object[size()]);
- }
-
- public <S> S[] toArray(S[] a) {
- return (S[])array;
- }
-
- public boolean isEmpty() {
- return size() == 0;
- }
-
public T remove(int index) {
- throw new UnsupportedOperationException();
- }
-
- public boolean remove(Object element) {
throw new UnsupportedOperationException();
}
- public void clear() {
- throw new UnsupportedOperationException();
- }
-
- public Iterator<T> iterator() {
- return listIterator();
- }
-
public ListIterator<T> listIterator(int index) {
return new Collections.ArrayListIterator(this, index);
}
-
- public ListIterator<T> listIterator() {
- return listIterator(0);
- }
};
}
View
4 classpath/java/util/Collection.java
@@ -17,12 +17,16 @@
public boolean contains(Object element);
+ public boolean containsAll(Collection<?> c);
+
public boolean add(T element);
public boolean addAll(Collection<? extends T> collection);
public boolean remove(Object element);
+ public boolean removeAll(Collection<?> c);
+
public Object[] toArray();
public <S> S[] toArray(S[] array);
View
28 classpath/java/util/Collections.java
@@ -170,6 +170,14 @@ public void clear() {
public Iterator<T> iterator() {
return new SynchronizedIterator(lock, collection.iterator());
}
+
+ public boolean containsAll(Collection<?> c) {
+ synchronized (lock) { return collection.containsAll(c); }
+ }
+
+ public boolean removeAll(Collection<?> c) {
+ synchronized (lock) { return collection.removeAll(c); }
+ }
}
static class SynchronizedMap<K,V> implements Map<K,V> {
@@ -393,6 +401,18 @@ public boolean addAll(Collection<? extends T> collection) {
public void clear() {
throw new UnsupportedOperationException("not supported");
}
+
+ public boolean removeAll(Collection<?> c) {
+ throw new UnsupportedOperationException("not supported");
+ }
+
+ public boolean addAll(int startIndex, Collection<? extends T> c) {
+ throw new UnsupportedOperationException("not supported");
+ }
+
+ public boolean containsAll(Collection<?> c) {
+ return inner.containsAll(c);
+ }
}
public static <K,V> Map<K,V> unmodifiableMap(Map<K,V> m) {
@@ -500,6 +520,14 @@ public int size() {
public <S> S[] toArray(S[] array) {
return inner.toArray(array);
+ }
+
+ public boolean containsAll(Collection<?> c) {
+ return inner.containsAll(c);
+ }
+
+ public boolean removeAll(Collection<?> c) {
+ throw new UnsupportedOperationException("not supported");
}
}
View
35 classpath/java/util/HashMap.java
@@ -303,7 +303,7 @@ public boolean equal(K a, K b) {
}
}
- private class EntrySet implements Set<Entry<K, V>> {
+ private class EntrySet extends AbstractSet<Entry<K, V>> {
public int size() {
return HashMap.this.size();
}
@@ -321,12 +321,6 @@ public boolean add(Entry<K, V> e) {
return putCell(e.getKey(), e.getValue()) != null;
}
- public boolean addAll(Collection<? extends Entry<K, V>> collection) {
- boolean change = false;
- for (Entry<K, V> e: collection) if (add(e)) change = true;
- return change;
- }
-
public boolean remove(Object o) {
return (o instanceof Entry<?,?>) && remove((Entry<?,?>)o);
}
@@ -352,7 +346,7 @@ public void clear() {
}
}
- private class KeySet implements Set<K> {
+ private class KeySet extends AbstractSet<K> {
public int size() {
return HashMap.this.size();
}
@@ -369,12 +363,6 @@ public boolean add(K key) {
return putCell(key, null) != null;
}
- public boolean addAll(Collection<? extends K> collection) {
- boolean change = false;
- for (K k: collection) if (add(k)) change = true;
- return change;
- }
-
public boolean remove(Object key) {
return removeCell(key) != null;
}
@@ -409,6 +397,21 @@ public boolean contains(Object value) {
return containsValue(value);
}
+ public boolean containsAll(Collection<?> c) {
+ if (c == null) {
+ throw new NullPointerException("collection is null");
+ }
+
+ Iterator<?> it = c.iterator();
+ while (it.hasNext()) {
+ if (! contains(it.next())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
public boolean add(V value) {
throw new UnsupportedOperationException();
}
@@ -421,6 +424,10 @@ public boolean remove(Object value) {
throw new UnsupportedOperationException();
}
+ public boolean removeAll(Collection<?> c) {
+ throw new UnsupportedOperationException();
+ }
+
public Object[] toArray() {
return toArray(new Object[size()]);
}
View
2  classpath/java/util/List.java
@@ -21,6 +21,8 @@
public void add(int index, T element);
+ public boolean addAll(int startIndex, Collection<? extends T> c);
+
public int indexOf(Object value);
public int lastIndexOf(Object value);
View
21 classpath/java/util/TreeMap.java
@@ -120,7 +120,7 @@ public V setValue(V value) {
}
- private class KeySet implements Set<K> {
+ private class KeySet extends AbstractSet<K> {
public int size() {
return TreeMap.this.size();
}
@@ -177,6 +177,21 @@ public boolean contains(Object value) {
return containsValue(value);
}
+ public boolean containsAll(Collection<?> c) {
+ if (c == null) {
+ throw new NullPointerException("collection is null");
+ }
+
+ Iterator<?> it = c.iterator();
+ while (it.hasNext()) {
+ if (! contains(it.next())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
public boolean add(V value) {
throw new UnsupportedOperationException();
}
@@ -189,6 +204,10 @@ public boolean remove(Object value) {
throw new UnsupportedOperationException();
}
+ public boolean removeAll(Collection<?> c) {
+ throw new UnsupportedOperationException();
+ }
+
public Object[] toArray() {
return toArray(new Object[size()]);
}
Something went wrong with that request. Please try again.