Java Reference
In-Depth Information
1 /**
2 * Abstract class to model a view (either key or value view).
3 * Implements size and clear methods, but not iterator method.
4 * View delegates to underlying map.
5 */
6 private abstract class ViewClass<AnyType> extends AbstractCollection<AnyType>
7 {
8 public int size( )
9 { return MapImpl.this.size( ); }
10
11 public void clear( )
12 { MapImpl.this.clear( ); }
13 }
14
15 /**
16 * Class to model the key set view.
17 * remove is overridden (otherwise a sequential search is used).
18 * iterator gives a KeySetIterator (see Figure 19.81).
19 * getMatch, the nonstandard part of weiss.util.Set is not needed.
20 */
21 private class KeySetClass extends ViewClass<KeyType> implements Set<KeyType>
22 {
23 public boolean remove( Object key )
24 { return MapImpl.this.remove( (KeyType) key ) != null; }
25
26 public Iterator<KeyType> iterator( )
27 { return new KeySetIterator( ); }
28
29 public KeyType getMatch( KeyType key )
30 { throw new UnsupportedOperationException( ); }
31 }
32
33 /**
34 * Class to model the value collection view.
35 * Default remove which is a sequential search is used.
36 * iterator gives a ValueCollectionIterator (see Figure 19.81).
37 */
38 private class ValueCollectionClass extends ViewClass<ValueType>
39 {
40 public Iterator<ValueType> iterator( )
41 { return new ValueCollectionIterator( ); }
42 }
figure 19.80
View classes for MapImpl
Search WWH ::




Custom Search