-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractMap.java
More file actions
114 lines (100 loc) · 2.27 KB
/
AbstractMap.java
File metadata and controls
114 lines (100 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.sun.source.util;
import java.util.Collection;
public abstract class AbstractMap<K,V> implements Map<K, V>
{
protected AbstractMap(){
}
public int size() {
return entrySet().size();
}
public boolean isEmpty() {
return size()==0;
}
public boolean containsValue(Object value) {
Iterator<Entry<K, V>> i=entrySet().iterator();
if(value==null) {
while(i.hasNext()) {
Entry<K, V> var1=i.next();
if(var1.getValue()==null) {
return true;
}
}
}else {
while(i.hasNext()) {
Entry<K, V> entry=i.next();
if(entry.getValue().equals(value))
return true;
}
}
return false;
}
public boolean containsKey(Object key) {
Iterator<Entry<K, V>> i=entrySet().iterator();
if(key==null) {
while(i.hasNext()) {
Entry<K, V> e=i.next();
if(e.getKey()==null)
return true;
}
}else {
while(i.hasNext()) {
Entry<K, V> e=i.next();
if(key.equals(e.getKey()))
return true;
}
}
return false;
}
public V get(Object key) {
Iterator<Entry<K, V>> i=entrySet().iterator();
if(key==null) {
while(i.hasNext()) {
Entry<K, V> e=i.next();
if(e.getKey()==null)
return e.getValue();
}
}else {
while(i.hasNext()) {
Entry<K, V> e=i.next();
if(e.getKey().equals(key))
return e.getValue();
}
}
return null;
}
public V put(K k,V v) {
throw new UnsupportedOperationException();
}
public V remove(Object key) {
Iterator<Entry<K, V>> i=entrySet().iterator();
Entry<K, V> currentEntry=null;
if(key==null) {
while(i.hasNext()) {
Entry<K, V> e=i.next();
if(e.getKey()==null)
currentEntry=e;
}
}else {
while(i.hasNext()) {
Entry<K, V> e=i.next();
if(e.getKey().equals(key))
currentEntry=e;
}
}
V oldValue=null;
if(currentEntry!=null) {
oldValue=currentEntry.getValue();
i.remove();
}
return oldValue;
}
public void putAll(Map<? extends K, ? extends V> m) {
for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
put(e.getKey(), e.getValue());
}
public void clear() {
entrySet().clear();
}
transient Set<K> keySet;
transient Collection<V> values;
}