Java Reference
In-Depth Information
51
// Pair class
52
protected static abstract class Pair<KeyType,ValueType>
53
implements Map.Entry<KeyType,ValueType>
54
{
55
public Pair( KeyType k, ValueType v )
56
{ key = k; value = v; }
57
58
final public KeyType getKey( )
59
{ return key; }
60
61
final public ValueType getValue( )
62
{ return value; }
63
64
final public ValueType setValue( ValueType newValue )
{ ValueType oldValue = value; value = newValue; return oldValue; }
65
66
67
final public String toString( )
68
{ return key + "=" + value; }
69
70
private KeyType key;
71
private ValueType value;
72
}
73
74
// Views
75
public Set<KeyType> keySet( )
76
{ return new KeySetClass( ); }
77
public Collection<ValueType> values( )
78
{ return new ValueCollectionClass( ); }
79
public Set<Map.Entry<KeyType,ValueType>> entrySet( )
80
{ return getSet( ); }
81
82
private abstract class ViewClass<AnyType> extends AbstractCollection<AnyType>
83
{ /* Figure 19.80 */ }
84
private class KeySetClass extends ViewClass<KeyType> implements Set<KeyType>
85
{ /* Figure 19.80 */ }
86
private class ValueCollectionClass extends ViewClass<ValueType>
87
{ /* Figure 19.80 */ }
88
89
private class ValueCollectionIterator implements Iterator<ValueType>
90
{ /* Figure 19.81 */ }
91
private class KeySetIterator implements Iterator<KeyType>
92
{ /* Figure 19.81 */ }
93
}
figure 19.78
Abstract
MapImpl
helper class skeleton (part 2)
Search WWH ::
Custom Search