bb.util
Class Unmodifiables.UnmodifiableMap.UnmodifiableEntrySet<K,V>

java.lang.Object
  extended by bb.util.Unmodifiables.UnmodifiableCollection<E>
      extended by bb.util.Unmodifiables.UnmodifiableSet<Map.Entry<K,V>>
          extended by bb.util.Unmodifiables.UnmodifiableMap.UnmodifiableEntrySet<K,V>
All Implemented Interfaces:
Serializable, Iterable<Map.Entry<K,V>>, Collection<Map.Entry<K,V>>, Set<Map.Entry<K,V>>
Enclosing class:
Unmodifiables.UnmodifiableMap<K,V>

static class Unmodifiables.UnmodifiableMap.UnmodifiableEntrySet<K,V>
extends Unmodifiables.UnmodifiableSet<Map.Entry<K,V>>

We need this class in addition to UnmodifiableSet as Map.Entries themselves permit modification of the backing Map via their setValue operation. This class is subtle: there are many possible attacks that must be thwarted.

See Also:
Serialized Form

Nested Class Summary
private static class Unmodifiables.UnmodifiableMap.UnmodifiableEntrySet.UnmodifiableEntry<K,V>
          This "wrapper class" serves two purposes: it prevents the client from modifying the backing Map, by short-circuiting the setValue method, and it protects the backing Map against an ill-behaved Map.Entry that attempts to modify another Map Entry when asked to perform an equality check.
 
Field Summary
private static long serialVersionUID
           
 
Fields inherited from class bb.util.Unmodifiables.UnmodifiableCollection
c
 
Constructor Summary
Unmodifiables.UnmodifiableMap.UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K,? extends V>> s)
           
 
Method Summary
 boolean contains(Object o)
          This method is overridden to protect the backing set against an object with a nefarious equals function that senses that the equality-candidate is Map.Entry and calls its setValue method.
 boolean containsAll(Collection<?> coll)
          The next two methods are overridden to protect against an unscrupulous List whose contains(Object o) method senses when o is a Map.Entry, and calls o.setValue.
 boolean equals(Object o)
           
 Iterator<Map.Entry<K,V>> iterator()
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 
Methods inherited from class bb.util.Unmodifiables.UnmodifiableSet
hashCode
 
Methods inherited from class bb.util.Unmodifiables.UnmodifiableCollection
add, addAll, clear, isEmpty, remove, removeAll, retainAll, size, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, isEmpty, remove, removeAll, retainAll, size
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

Unmodifiables.UnmodifiableMap.UnmodifiableEntrySet

Unmodifiables.UnmodifiableMap.UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K,? extends V>> s)
Method Detail

iterator

public Iterator<Map.Entry<K,V>> iterator()
Specified by:
iterator in interface Iterable<Map.Entry<K,V>>
Specified by:
iterator in interface Collection<Map.Entry<K,V>>
Specified by:
iterator in interface Set<Map.Entry<K,V>>
Overrides:
iterator in class Unmodifiables.UnmodifiableCollection<Map.Entry<K,V>>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<Map.Entry<K,V>>
Specified by:
toArray in interface Set<Map.Entry<K,V>>
Overrides:
toArray in class Unmodifiables.UnmodifiableCollection<Map.Entry<K,V>>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<Map.Entry<K,V>>
Specified by:
toArray in interface Set<Map.Entry<K,V>>
Overrides:
toArray in class Unmodifiables.UnmodifiableCollection<Map.Entry<K,V>>

contains

public boolean contains(Object o)
This method is overridden to protect the backing set against an object with a nefarious equals function that senses that the equality-candidate is Map.Entry and calls its setValue method.

Specified by:
contains in interface Collection<Map.Entry<K,V>>
Specified by:
contains in interface Set<Map.Entry<K,V>>
Overrides:
contains in class Unmodifiables.UnmodifiableCollection<Map.Entry<K,V>>

containsAll

public boolean containsAll(Collection<?> coll)
The next two methods are overridden to protect against an unscrupulous List whose contains(Object o) method senses when o is a Map.Entry, and calls o.setValue.

Specified by:
containsAll in interface Collection<Map.Entry<K,V>>
Specified by:
containsAll in interface Set<Map.Entry<K,V>>
Overrides:
containsAll in class Unmodifiables.UnmodifiableCollection<Map.Entry<K,V>>

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<Map.Entry<K,V>>
Specified by:
equals in interface Set<Map.Entry<K,V>>
Overrides:
equals in class Unmodifiables.UnmodifiableSet<Map.Entry<K,V>>