-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathAMapEntry.java
More file actions
151 lines (117 loc) · 2.87 KB
/
AMapEntry.java
File metadata and controls
151 lines (117 loc) · 2.87 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Copyright (c) Rich Hickey. All rights reserved.
* The use and distribution terms for this software are covered by the
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
* which can be found in the file epl-v10.html at the root of this distribution.
* By using this software in any fashion, you are agreeing to be bound by
* the terms of this license.
* You must not remove this notice, or any other, from this software.
**/
/* rich Mar 1, 2008 */
package clojure.lang;
import java.io.StringWriter;
public abstract class AMapEntry extends APersistentVector implements IMapEntry{
private static final long serialVersionUID = -5007980429903443802L;
public Object nth(int i){
if(i == 0)
return key();
else if(i == 1)
return val();
else
throw new IndexOutOfBoundsException();
}
private IPersistentVector asVector(){
return LazilyPersistentVector.createOwning(key(), val());
}
public IPersistentVector assocN(int i, Object val){
return asVector().assocN(i, val);
}
public int count(){
return 2;
}
public ISeq seq(){
return asVector().seq();
}
public IPersistentVector cons(Object o){
return asVector().cons(o);
}
public IPersistentCollection empty(){
return null;
}
public IPersistentStack pop(){
return LazilyPersistentVector.createOwning(key());
}
public Object setValue(Object value){
throw new UnsupportedOperationException();
}
/*
public boolean equals(Object obj){
return APersistentVector.doEquals(this, obj);
}
public int hashCode(){
//must match logic in APersistentVector
return 31 * (31 + Util.hash(key())) + Util.hash(val());
// return Util.hashCombine(Util.hashCombine(0, Util.hash(key())), Util.hash(val()));
}
public String toString(){
StringWriter sw = new StringWriter();
try
{
RT.print(this, sw);
}
catch(Exception e)
{
//checked exceptions stink!
throw Util.sneakyThrow(e);
}
return sw.toString();
}
public int length(){
return 2;
}
public Object nth(int i){
if(i == 0)
return key();
else if(i == 1)
return val();
else
throw new IndexOutOfBoundsException();
}
private IPersistentVector asVector(){
return LazilyPersistentVector.createOwning(key(), val());
}
public IPersistentVector assocN(int i, Object val){
return asVector().assocN(i, val);
}
public int count(){
return 2;
}
public ISeq seq(){
return asVector().seq();
}
public IPersistentVector cons(Object o){
return asVector().cons(o);
}
public boolean containsKey(Object key){
return asVector().containsKey(key);
}
public IMapEntry entryAt(Object key){
return asVector().entryAt(key);
}
public Associative assoc(Object key, Object val){
return asVector().assoc(key, val);
}
public Object valAt(Object key){
return asVector().valAt(key);
}
public Object valAt(Object key, Object notFound){
return asVector().valAt(key, notFound);
}
public Object peek(){
return val();
}
public ISeq rseq() {
return asVector().rseq();
}
*/
}