Mercurial > lasercutter
diff 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 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clojure/lang/AMapEntry.java Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,149 @@ 1.4 +/** 1.5 + * Copyright (c) Rich Hickey. All rights reserved. 1.6 + * The use and distribution terms for this software are covered by the 1.7 + * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 1.8 + * which can be found in the file epl-v10.html at the root of this distribution. 1.9 + * By using this software in any fashion, you are agreeing to be bound by 1.10 + * the terms of this license. 1.11 + * You must not remove this notice, or any other, from this software. 1.12 + **/ 1.13 + 1.14 +/* rich Mar 1, 2008 */ 1.15 + 1.16 +package clojure.lang; 1.17 + 1.18 +import java.io.StringWriter; 1.19 + 1.20 +public abstract class AMapEntry extends APersistentVector implements IMapEntry{ 1.21 + 1.22 +public Object nth(int i){ 1.23 + if(i == 0) 1.24 + return key(); 1.25 + else if(i == 1) 1.26 + return val(); 1.27 + else 1.28 + throw new IndexOutOfBoundsException(); 1.29 +} 1.30 + 1.31 +private IPersistentVector asVector(){ 1.32 + return LazilyPersistentVector.createOwning(key(), val()); 1.33 +} 1.34 + 1.35 +public IPersistentVector assocN(int i, Object val){ 1.36 + return asVector().assocN(i, val); 1.37 +} 1.38 + 1.39 +public int count(){ 1.40 + return 2; 1.41 +} 1.42 + 1.43 +public ISeq seq(){ 1.44 + return asVector().seq(); 1.45 +} 1.46 + 1.47 +public IPersistentVector cons(Object o){ 1.48 + return asVector().cons(o); 1.49 +} 1.50 + 1.51 +public IPersistentCollection empty(){ 1.52 + return null; 1.53 +} 1.54 + 1.55 +public IPersistentStack pop(){ 1.56 + return LazilyPersistentVector.createOwning(key()); 1.57 +} 1.58 + 1.59 +public Object setValue(Object value){ 1.60 + throw new UnsupportedOperationException(); 1.61 +} 1.62 + 1.63 +/* 1.64 + 1.65 +public boolean equals(Object obj){ 1.66 + return APersistentVector.doEquals(this, obj); 1.67 +} 1.68 + 1.69 +public int hashCode(){ 1.70 + //must match logic in APersistentVector 1.71 + return 31 * (31 + Util.hash(key())) + Util.hash(val()); 1.72 +// return Util.hashCombine(Util.hashCombine(0, Util.hash(key())), Util.hash(val())); 1.73 +} 1.74 + 1.75 +public String toString(){ 1.76 + StringWriter sw = new StringWriter(); 1.77 + try 1.78 + { 1.79 + RT.print(this, sw); 1.80 + } 1.81 + catch(Exception e) 1.82 + { 1.83 + //checked exceptions stink! 1.84 + throw new RuntimeException(e); 1.85 + } 1.86 + return sw.toString(); 1.87 +} 1.88 + 1.89 +public int length(){ 1.90 + return 2; 1.91 +} 1.92 + 1.93 +public Object nth(int i){ 1.94 + if(i == 0) 1.95 + return key(); 1.96 + else if(i == 1) 1.97 + return val(); 1.98 + else 1.99 + throw new IndexOutOfBoundsException(); 1.100 +} 1.101 + 1.102 +private IPersistentVector asVector(){ 1.103 + return LazilyPersistentVector.createOwning(key(), val()); 1.104 +} 1.105 + 1.106 +public IPersistentVector assocN(int i, Object val){ 1.107 + return asVector().assocN(i, val); 1.108 +} 1.109 + 1.110 +public int count(){ 1.111 + return 2; 1.112 +} 1.113 + 1.114 +public ISeq seq(){ 1.115 + return asVector().seq(); 1.116 +} 1.117 + 1.118 +public IPersistentVector cons(Object o){ 1.119 + return asVector().cons(o); 1.120 +} 1.121 + 1.122 +public boolean containsKey(Object key){ 1.123 + return asVector().containsKey(key); 1.124 +} 1.125 + 1.126 +public IMapEntry entryAt(Object key){ 1.127 + return asVector().entryAt(key); 1.128 +} 1.129 + 1.130 +public Associative assoc(Object key, Object val){ 1.131 + return asVector().assoc(key, val); 1.132 +} 1.133 + 1.134 +public Object valAt(Object key){ 1.135 + return asVector().valAt(key); 1.136 +} 1.137 + 1.138 +public Object valAt(Object key, Object notFound){ 1.139 + return asVector().valAt(key, notFound); 1.140 +} 1.141 + 1.142 +public Object peek(){ 1.143 + return val(); 1.144 +} 1.145 + 1.146 + 1.147 +public ISeq rseq() throws Exception{ 1.148 + return asVector().rseq(); 1.149 +} 1.150 +*/ 1.151 + 1.152 +}