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