Java Reference
In-Depth Information
53
54 @Override /** Return true if the specified key is in the map */
55
public boolean containsKey(K key) {
containsKey
56
if (get(key) != null )
57
return true ;
58
else
59
return false ;
60 }
61
62 @Override /** Return true if this map contains the value */
63 public boolean containsValue(V value) {
64 for ( int i = 0 ; i < capacity; i++) {
65 if (table[i] != null ) {
66 LinkedList<Entry<K, V>> bucket = table[i];
67
containsValue
for (Entry<K, V> entry: bucket)
68
if (entry.getValue().equals(value))
69
return true ;
70 }
71 }
72
73
return false ;
74 }
75
76 @Override /** Return a set of entries in the map */
77 public java.util.Set<MyMap.Entry<K,V>> entrySet() {
78 java.util.Set<MyMap.Entry<K, V>> set =
79
entrySet
new java.util.HashSet<>();
80
81 for ( int i = 0 ; i < capacity; i++) {
82 if (table[i] != null ) {
83 LinkedList<Entry<K, V>> bucket = table[i];
84 for (Entry<K, V> entry: bucket)
85 set.add(entry);
86 }
87 }
88
89
return set;
90 }
91
92 @Override /** Return the value that matches the specified key */
93 public V get(K key) {
94 int bucketIndex = hash(key.hashCode());
95 if (table[bucketIndex] != null ) {
96 LinkedList<Entry<K, V>> bucket = table[bucketIndex];
97
get
for (Entry<K, V> entry: bucket)
98
if (entry.getKey().equals(key))
99
return entry.getValue();
100 }
101
102
return null ;
103 }
104
105 @Override /** Return true if this map contains no entries */
106
public boolean isEmpty() {
isEmpty
107
return size == 0 ;
108 }
109
110 @Override /** Return a set consisting of the keys in this map */
111 public java.util.Set<K> keySet() {
112 java.util.Set<K> set = new java.util.HashSet<K>();
keySet
 
Search WWH ::




Custom Search