Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2016-01-11 20:07:01 +0000
committerThomas Watson2016-01-11 21:12:46 +0000
commitc39f725ba260b275d818714bb3fa45334c967b62 (patch)
treec8dc4434b3d737e1a739bd28b2e81c6746ac5a82 /bundles/org.eclipse.osgi/felix
parent131f07ce89bdab182d6e6203dcc5afd9bcc4a4a2 (diff)
downloadrt.equinox.framework-c39f725ba260b275d818714bb3fa45334c967b62.tar.gz
rt.equinox.framework-c39f725ba260b275d818714bb3fa45334c967b62.tar.xz
rt.equinox.framework-c39f725ba260b275d818714bb3fa45334c967b62.zip
Bug 485217 - Update resolver implementation and default to using batch resolves with a timeout
Fix felix resolver to implement add methods for List impl
Diffstat (limited to 'bundles/org.eclipse.osgi/felix')
-rwxr-xr-xbundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/CopyOnWriteList.java90
1 files changed, 68 insertions, 22 deletions
diff --git a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/CopyOnWriteList.java b/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/CopyOnWriteList.java
index b6044341d..50eeb421f 100755
--- a/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/CopyOnWriteList.java
+++ b/bundles/org.eclipse.osgi/felix/src/org/apache/felix/resolver/util/CopyOnWriteList.java
@@ -19,14 +19,10 @@
package org.apache.felix.resolver.util;
import java.lang.reflect.Array;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
+import java.util.*;
@SuppressWarnings("NullableProblems")
-public class CopyOnWriteList<E> implements List<E>, Cloneable {
+public class CopyOnWriteList<E> implements List<E>, Cloneable, RandomAccess {
Object[] data;
@@ -100,19 +96,65 @@ public class CopyOnWriteList<E> implements List<E>, Cloneable {
}
public Iterator<E> iterator() {
- return new Iterator<E>() {
- int idx = 0;
- public boolean hasNext() {
- return idx < data.length;
- }
- @SuppressWarnings("unchecked")
- public E next() {
- return (E) data[idx++];
+ return new CopyOnWriteListIterator(0);
+ }
+
+ class CopyOnWriteListIterator implements ListIterator<E> {
+ int idx;
+ CopyOnWriteListIterator(int idx) {
+ this.idx = idx;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return idx < data.length;
+ }
+
+ @Override
+ public E next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
}
- public void remove() {
- CopyOnWriteList.this.remove(--idx);
+ return (E) data[idx++];
+ }
+
+ @Override
+ public boolean hasPrevious() {
+ return idx >= 0;
+ }
+
+ @Override
+ public E previous() {
+ if (!hasPrevious()) {
+ throw new NoSuchElementException();
}
- };
+ return (E) data[idx--];
+ }
+
+ @Override
+ public int nextIndex() {
+ return idx;
+ }
+
+ @Override
+ public int previousIndex() {
+ return idx - 1;
+ }
+
+ @Override
+ public void remove() {
+ CopyOnWriteList.this.remove(--idx);
+ }
+
+ @Override
+ public void set(E e) {
+ new UnsupportedOperationException();
+ }
+
+ @Override
+ public void add(E e) {
+ CopyOnWriteList.this.add(idx, e);
+ }
}
public Object[] toArray() {
@@ -132,7 +174,8 @@ public class CopyOnWriteList<E> implements List<E>, Cloneable {
}
public boolean add(E e) {
- throw new UnsupportedOperationException();
+ add(size(), e);
+ return true;
}
public boolean remove(Object o) {
@@ -170,11 +213,14 @@ public class CopyOnWriteList<E> implements List<E>, Cloneable {
}
public boolean addAll(Collection<? extends E> c) {
- throw new UnsupportedOperationException();
+ return addAll(size(), c);
}
public boolean addAll(int index, Collection<? extends E> c) {
- throw new UnsupportedOperationException();
+ for (E e : c) {
+ add(index++, e);
+ }
+ return !(c.isEmpty());
}
public boolean removeAll(Collection<?> c) {
@@ -215,11 +261,11 @@ public class CopyOnWriteList<E> implements List<E>, Cloneable {
}
public ListIterator<E> listIterator() {
- throw new UnsupportedOperationException();
+ return new CopyOnWriteListIterator(0);
}
public ListIterator<E> listIterator(int index) {
- throw new UnsupportedOperationException();
+ return new CopyOnWriteListIterator(index);
}
public List<E> subList(int fromIndex, int toIndex) {

Back to the top