[COLLECTIONS-473] Made field collection private and added setter for de-serialization.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1494280 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
74d39c4c4f
commit
0cba84e103
|
@ -132,6 +132,9 @@ New features
|
|||
Changed classes / methods
|
||||
-------------------------
|
||||
|
||||
o [COLLECTIONS-473] Made field "collection" in class "AbstractCollectionDecorator" private and added
|
||||
setter "setCollection(Collection)" with scope protected to set the decorated collection
|
||||
during de-serialization.
|
||||
o [COLLECTIONS-466] Replaced "Collection" with "Iterable" for method arguments where applicable.
|
||||
o [COLLECTIONS-460] Changed "IteratorChain" to use internally a "Queue" instead of a "List". Iterators are
|
||||
removed from the queue once used and can be garbage collected after being exhausted.
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
<body>
|
||||
|
||||
<release version="4.0" date="TBA" description="Next release">
|
||||
<action issue="COLLECTIONS-473" dev="tn" type="update" due-to="sebb">
|
||||
Made field "collection" in class "AbstractCollectionDecorator" private and added
|
||||
setter "setCollection(Collection)" with scope protected to set the decorated collection
|
||||
during de-serialization.
|
||||
</action>
|
||||
<action issue="COLLECTIONS-472" dev="tn" type="fix" due-to="Adrian Nistor">
|
||||
Improved performance of "AbstractMapBag#containsAll(Collection)" by returning immediately
|
||||
after a difference has been found.
|
||||
|
|
|
@ -69,7 +69,7 @@ public final class CompliantBag<E>
|
|||
*/
|
||||
private void writeObject(final ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
out.writeObject(collection);
|
||||
out.writeObject(decorated());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +83,7 @@ public final class CompliantBag<E>
|
|||
@SuppressWarnings("unchecked") // will throw CCE, see Javadoc
|
||||
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
collection = (Collection<E>) in.readObject();
|
||||
setCollection((Collection<E>) in.readObject());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -107,7 +107,7 @@ public class TransformedBag<E> extends TransformedCollection<E> implements Bag<E
|
|||
* @return the decorated bag
|
||||
*/
|
||||
protected Bag<E> getBag() {
|
||||
return (Bag<E>) collection;
|
||||
return (Bag<E>) decorated();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -108,7 +108,7 @@ public class TransformedSortedBag<E> extends TransformedBag<E> implements Sorted
|
|||
* @return the decorated bag
|
||||
*/
|
||||
protected SortedBag<E> getSortedBag() {
|
||||
return (SortedBag<E>) collection;
|
||||
return (SortedBag<E>) decorated();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -83,7 +83,7 @@ public final class UnmodifiableBag<E>
|
|||
*/
|
||||
private void writeObject(final ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
out.writeObject(collection);
|
||||
out.writeObject(decorated());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,7 +97,7 @@ public final class UnmodifiableBag<E>
|
|||
@SuppressWarnings("unchecked") // will throw CCE, see Javadoc
|
||||
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
collection = (Collection<E>) in.readObject();
|
||||
setCollection((Collection<E>) in.readObject());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -83,7 +83,7 @@ public final class UnmodifiableSortedBag<E>
|
|||
*/
|
||||
private void writeObject(final ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
out.writeObject(collection);
|
||||
out.writeObject(decorated());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,7 +97,7 @@ public final class UnmodifiableSortedBag<E>
|
|||
@SuppressWarnings("unchecked") // will throw CCE, see Javadoc
|
||||
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
collection = (Collection<E>) in.readObject();
|
||||
setCollection((Collection<E>) in.readObject());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -46,7 +46,7 @@ public abstract class AbstractCollectionDecorator<E>
|
|||
private static final long serialVersionUID = 6249888059822088500L;
|
||||
|
||||
/** The collection being decorated */
|
||||
protected Collection<E> collection;
|
||||
private Collection<E> collection;
|
||||
|
||||
/**
|
||||
* Constructor only used in deserialization, do not use otherwise.
|
||||
|
@ -79,6 +79,17 @@ public abstract class AbstractCollectionDecorator<E>
|
|||
return collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the collection being decorated.
|
||||
* <p>
|
||||
* <b>NOTE:</b> this method should only be used during deserialization
|
||||
*
|
||||
* @param coll the decorated collection
|
||||
*/
|
||||
protected void setCollection(final Collection<E> coll) {
|
||||
this.collection = coll;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
public boolean add(final E object) {
|
||||
|
|
|
@ -82,7 +82,7 @@ public final class UnmodifiableBoundedCollection<E> extends AbstractCollectionDe
|
|||
break; // normal loop exit
|
||||
}
|
||||
if (coll instanceof AbstractCollectionDecorator) {
|
||||
coll = ((AbstractCollectionDecorator<E>) coll).collection;
|
||||
coll = ((AbstractCollectionDecorator<E>) coll).decorated();
|
||||
} else if (coll instanceof SynchronizedCollection) {
|
||||
coll = ((SynchronizedCollection<E>) coll).decorated();
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public abstract class AbstractSerializableListDecorator<E>
|
|||
*/
|
||||
private void writeObject(final ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
out.writeObject(collection);
|
||||
out.writeObject(decorated());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,7 +68,7 @@ public abstract class AbstractSerializableListDecorator<E>
|
|||
@SuppressWarnings("unchecked")
|
||||
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
collection = (Collection<E>) in.readObject();
|
||||
setCollection((Collection<E>) in.readObject());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ public class TransformedList<E> extends TransformedCollection<E> implements List
|
|||
* @return the decorated list
|
||||
*/
|
||||
protected List<E> getList() {
|
||||
return (List<E>) collection;
|
||||
return (List<E>) decorated();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -121,13 +121,13 @@ abstract class AbstractInputCheckedMapDecorator<K, V>
|
|||
|
||||
@Override
|
||||
public Iterator<Map.Entry<K, V>> iterator() {
|
||||
return new EntrySetIterator(collection.iterator(), parent);
|
||||
return new EntrySetIterator(this.decorated().iterator(), parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object[] toArray() {
|
||||
final Object[] array = collection.toArray();
|
||||
final Object[] array = this.decorated().toArray();
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = new MapEntry((Map.Entry<K, V>) array[i], parent);
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ abstract class AbstractInputCheckedMapDecorator<K, V>
|
|||
// where another thread could access data before we decorate it
|
||||
result = (Object[]) Array.newInstance(array.getClass().getComponentType(), 0);
|
||||
}
|
||||
result = collection.toArray(result);
|
||||
result = this.decorated().toArray(result);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = new MapEntry((Map.Entry<K, V>) result[i], parent);
|
||||
}
|
||||
|
|
|
@ -103,13 +103,13 @@ public final class UnmodifiableEntrySet<K, V>
|
|||
//-----------------------------------------------------------------------
|
||||
@Override
|
||||
public Iterator<Map.Entry<K, V>> iterator() {
|
||||
return new UnmodifiableEntrySetIterator(collection.iterator());
|
||||
return new UnmodifiableEntrySetIterator(decorated().iterator());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object[] toArray() {
|
||||
final Object[] array = collection.toArray();
|
||||
final Object[] array = decorated().toArray();
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = new UnmodifiableEntry((Map.Entry<K, V>) array[i]);
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ public final class UnmodifiableEntrySet<K, V>
|
|||
// where another thread could access data before we decorate it
|
||||
result = (Object[]) Array.newInstance(array.getClass().getComponentType(), 0);
|
||||
}
|
||||
result = collection.toArray(result);
|
||||
result = decorated().toArray(result);
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = new UnmodifiableEntry((Map.Entry<K, V>) result[i]);
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ public class TransformedQueue<E> extends TransformedCollection<E> implements Que
|
|||
* @return the decorated queue
|
||||
*/
|
||||
protected Queue<E> getQueue() {
|
||||
return (Queue<E>) collection;
|
||||
return (Queue<E>) decorated();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -79,7 +79,7 @@ public final class UnmodifiableQueue<E>
|
|||
*/
|
||||
private void writeObject(final ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
out.writeObject(collection);
|
||||
out.writeObject(decorated());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,7 +92,7 @@ public final class UnmodifiableQueue<E>
|
|||
@SuppressWarnings("unchecked")
|
||||
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
collection = (Collection<E>) in.readObject();
|
||||
setCollection((Collection<E>) in.readObject());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -55,7 +55,7 @@ public abstract class AbstractSerializableSetDecorator<E>
|
|||
*/
|
||||
private void writeObject(final ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
out.writeObject(collection);
|
||||
out.writeObject(decorated());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,7 +68,7 @@ public abstract class AbstractSerializableSetDecorator<E>
|
|||
@SuppressWarnings("unchecked")
|
||||
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
collection = (Collection<E>) in.readObject();
|
||||
setCollection((Collection<E>) in.readObject());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -181,18 +181,18 @@ public class ListOrderedSet<E>
|
|||
// -----------------------------------------------------------------------
|
||||
@Override
|
||||
public void clear() {
|
||||
collection.clear();
|
||||
decorated().clear();
|
||||
setOrder.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderedIterator<E> iterator() {
|
||||
return new OrderedSetIterator<E>(setOrder.listIterator(), collection);
|
||||
return new OrderedSetIterator<E>(setOrder.listIterator(), decorated());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(final E object) {
|
||||
if (collection.add(object)) {
|
||||
if (decorated().add(object)) {
|
||||
setOrder.add(object);
|
||||
return true;
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ public class ListOrderedSet<E>
|
|||
|
||||
@Override
|
||||
public boolean remove(final Object object) {
|
||||
final boolean result = collection.remove(object);
|
||||
final boolean result = decorated().remove(object);
|
||||
if (result) {
|
||||
setOrder.remove(object);
|
||||
}
|
||||
|
@ -230,11 +230,11 @@ public class ListOrderedSet<E>
|
|||
public boolean retainAll(final Collection<?> coll) {
|
||||
final Set<Object> collectionRetainAll = new HashSet<Object>();
|
||||
for (final Object next : coll) {
|
||||
if (collection.contains(next)) {
|
||||
if (decorated().contains(next)) {
|
||||
collectionRetainAll.add(next);
|
||||
}
|
||||
}
|
||||
if (collectionRetainAll.size() == collection.size()) {
|
||||
if (collectionRetainAll.size() == decorated().size()) {
|
||||
return false;
|
||||
}
|
||||
if (collectionRetainAll.size() == 0) {
|
||||
|
@ -298,7 +298,7 @@ public class ListOrderedSet<E>
|
|||
*/
|
||||
public void add(final int index, final E object) {
|
||||
if (!contains(object)) {
|
||||
collection.add(object);
|
||||
decorated().add(object);
|
||||
setOrder.add(index, object);
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ public class ListOrderedSet<E>
|
|||
if (contains(e)) {
|
||||
continue;
|
||||
}
|
||||
collection.add(e);
|
||||
decorated().add(e);
|
||||
toAdd.add(e);
|
||||
changed = true;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ public class TransformedSortedSet<E> extends TransformedSet<E> implements Sorted
|
|||
* @return the decorated set
|
||||
*/
|
||||
protected SortedSet<E> getSortedSet() {
|
||||
return (SortedSet<E>) collection;
|
||||
return (SortedSet<E>) decorated();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -69,7 +69,7 @@ public final class UnmodifiableSortedSet<E>
|
|||
*/
|
||||
private void writeObject(final ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
out.writeObject(collection);
|
||||
out.writeObject(decorated());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,7 +82,7 @@ public final class UnmodifiableSortedSet<E>
|
|||
@SuppressWarnings("unchecked") // (1) should only fail if input stream is incorrect
|
||||
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
collection = (Collection<E>) in.readObject(); // (1)
|
||||
setCollection((Collection<E>) in.readObject()); // (1)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue