rlm@10
|
1 /**
|
rlm@10
|
2 * Copyright (c) Rich Hickey. All rights reserved.
|
rlm@10
|
3 * The use and distribution terms for this software are covered by the
|
rlm@10
|
4 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
rlm@10
|
5 * which can be found in the file epl-v10.html at the root of this distribution.
|
rlm@10
|
6 * By using this software in any fashion, you are agreeing to be bound by
|
rlm@10
|
7 * the terms of this license.
|
rlm@10
|
8 * You must not remove this notice, or any other, from this software.
|
rlm@10
|
9 **/
|
rlm@10
|
10
|
rlm@10
|
11 /* rich Mar 1, 2008 */
|
rlm@10
|
12
|
rlm@10
|
13 package clojure.lang;
|
rlm@10
|
14
|
rlm@10
|
15 import java.io.StringWriter;
|
rlm@10
|
16
|
rlm@10
|
17 public abstract class AMapEntry extends APersistentVector implements IMapEntry{
|
rlm@10
|
18
|
rlm@10
|
19 public Object nth(int i){
|
rlm@10
|
20 if(i == 0)
|
rlm@10
|
21 return key();
|
rlm@10
|
22 else if(i == 1)
|
rlm@10
|
23 return val();
|
rlm@10
|
24 else
|
rlm@10
|
25 throw new IndexOutOfBoundsException();
|
rlm@10
|
26 }
|
rlm@10
|
27
|
rlm@10
|
28 private IPersistentVector asVector(){
|
rlm@10
|
29 return LazilyPersistentVector.createOwning(key(), val());
|
rlm@10
|
30 }
|
rlm@10
|
31
|
rlm@10
|
32 public IPersistentVector assocN(int i, Object val){
|
rlm@10
|
33 return asVector().assocN(i, val);
|
rlm@10
|
34 }
|
rlm@10
|
35
|
rlm@10
|
36 public int count(){
|
rlm@10
|
37 return 2;
|
rlm@10
|
38 }
|
rlm@10
|
39
|
rlm@10
|
40 public ISeq seq(){
|
rlm@10
|
41 return asVector().seq();
|
rlm@10
|
42 }
|
rlm@10
|
43
|
rlm@10
|
44 public IPersistentVector cons(Object o){
|
rlm@10
|
45 return asVector().cons(o);
|
rlm@10
|
46 }
|
rlm@10
|
47
|
rlm@10
|
48 public IPersistentCollection empty(){
|
rlm@10
|
49 return null;
|
rlm@10
|
50 }
|
rlm@10
|
51
|
rlm@10
|
52 public IPersistentStack pop(){
|
rlm@10
|
53 return LazilyPersistentVector.createOwning(key());
|
rlm@10
|
54 }
|
rlm@10
|
55
|
rlm@10
|
56 public Object setValue(Object value){
|
rlm@10
|
57 throw new UnsupportedOperationException();
|
rlm@10
|
58 }
|
rlm@10
|
59
|
rlm@10
|
60 /*
|
rlm@10
|
61
|
rlm@10
|
62 public boolean equals(Object obj){
|
rlm@10
|
63 return APersistentVector.doEquals(this, obj);
|
rlm@10
|
64 }
|
rlm@10
|
65
|
rlm@10
|
66 public int hashCode(){
|
rlm@10
|
67 //must match logic in APersistentVector
|
rlm@10
|
68 return 31 * (31 + Util.hash(key())) + Util.hash(val());
|
rlm@10
|
69 // return Util.hashCombine(Util.hashCombine(0, Util.hash(key())), Util.hash(val()));
|
rlm@10
|
70 }
|
rlm@10
|
71
|
rlm@10
|
72 public String toString(){
|
rlm@10
|
73 StringWriter sw = new StringWriter();
|
rlm@10
|
74 try
|
rlm@10
|
75 {
|
rlm@10
|
76 RT.print(this, sw);
|
rlm@10
|
77 }
|
rlm@10
|
78 catch(Exception e)
|
rlm@10
|
79 {
|
rlm@10
|
80 //checked exceptions stink!
|
rlm@10
|
81 throw new RuntimeException(e);
|
rlm@10
|
82 }
|
rlm@10
|
83 return sw.toString();
|
rlm@10
|
84 }
|
rlm@10
|
85
|
rlm@10
|
86 public int length(){
|
rlm@10
|
87 return 2;
|
rlm@10
|
88 }
|
rlm@10
|
89
|
rlm@10
|
90 public Object nth(int i){
|
rlm@10
|
91 if(i == 0)
|
rlm@10
|
92 return key();
|
rlm@10
|
93 else if(i == 1)
|
rlm@10
|
94 return val();
|
rlm@10
|
95 else
|
rlm@10
|
96 throw new IndexOutOfBoundsException();
|
rlm@10
|
97 }
|
rlm@10
|
98
|
rlm@10
|
99 private IPersistentVector asVector(){
|
rlm@10
|
100 return LazilyPersistentVector.createOwning(key(), val());
|
rlm@10
|
101 }
|
rlm@10
|
102
|
rlm@10
|
103 public IPersistentVector assocN(int i, Object val){
|
rlm@10
|
104 return asVector().assocN(i, val);
|
rlm@10
|
105 }
|
rlm@10
|
106
|
rlm@10
|
107 public int count(){
|
rlm@10
|
108 return 2;
|
rlm@10
|
109 }
|
rlm@10
|
110
|
rlm@10
|
111 public ISeq seq(){
|
rlm@10
|
112 return asVector().seq();
|
rlm@10
|
113 }
|
rlm@10
|
114
|
rlm@10
|
115 public IPersistentVector cons(Object o){
|
rlm@10
|
116 return asVector().cons(o);
|
rlm@10
|
117 }
|
rlm@10
|
118
|
rlm@10
|
119 public boolean containsKey(Object key){
|
rlm@10
|
120 return asVector().containsKey(key);
|
rlm@10
|
121 }
|
rlm@10
|
122
|
rlm@10
|
123 public IMapEntry entryAt(Object key){
|
rlm@10
|
124 return asVector().entryAt(key);
|
rlm@10
|
125 }
|
rlm@10
|
126
|
rlm@10
|
127 public Associative assoc(Object key, Object val){
|
rlm@10
|
128 return asVector().assoc(key, val);
|
rlm@10
|
129 }
|
rlm@10
|
130
|
rlm@10
|
131 public Object valAt(Object key){
|
rlm@10
|
132 return asVector().valAt(key);
|
rlm@10
|
133 }
|
rlm@10
|
134
|
rlm@10
|
135 public Object valAt(Object key, Object notFound){
|
rlm@10
|
136 return asVector().valAt(key, notFound);
|
rlm@10
|
137 }
|
rlm@10
|
138
|
rlm@10
|
139 public Object peek(){
|
rlm@10
|
140 return val();
|
rlm@10
|
141 }
|
rlm@10
|
142
|
rlm@10
|
143
|
rlm@10
|
144 public ISeq rseq() throws Exception{
|
rlm@10
|
145 return asVector().rseq();
|
rlm@10
|
146 }
|
rlm@10
|
147 */
|
rlm@10
|
148
|
rlm@10
|
149 }
|