Mercurial > lasercutter
view 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 source
1 /**2 * Copyright (c) Rich Hickey. All rights reserved.3 * The use and distribution terms for this software are covered by the4 * 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 by7 * the terms of this license.8 * You must not remove this notice, or any other, from this software.9 **/11 /* rich Mar 1, 2008 */13 package clojure.lang;15 import java.io.StringWriter;17 public abstract class AMapEntry extends APersistentVector implements IMapEntry{19 public Object nth(int i){20 if(i == 0)21 return key();22 else if(i == 1)23 return val();24 else25 throw new IndexOutOfBoundsException();26 }28 private IPersistentVector asVector(){29 return LazilyPersistentVector.createOwning(key(), val());30 }32 public IPersistentVector assocN(int i, Object val){33 return asVector().assocN(i, val);34 }36 public int count(){37 return 2;38 }40 public ISeq seq(){41 return asVector().seq();42 }44 public IPersistentVector cons(Object o){45 return asVector().cons(o);46 }48 public IPersistentCollection empty(){49 return null;50 }52 public IPersistentStack pop(){53 return LazilyPersistentVector.createOwning(key());54 }56 public Object setValue(Object value){57 throw new UnsupportedOperationException();58 }60 /*62 public boolean equals(Object obj){63 return APersistentVector.doEquals(this, obj);64 }66 public int hashCode(){67 //must match logic in APersistentVector68 return 31 * (31 + Util.hash(key())) + Util.hash(val());69 // return Util.hashCombine(Util.hashCombine(0, Util.hash(key())), Util.hash(val()));70 }72 public String toString(){73 StringWriter sw = new StringWriter();74 try75 {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 }86 public int length(){87 return 2;88 }90 public Object nth(int i){91 if(i == 0)92 return key();93 else if(i == 1)94 return val();95 else96 throw new IndexOutOfBoundsException();97 }99 private IPersistentVector asVector(){100 return LazilyPersistentVector.createOwning(key(), val());101 }103 public IPersistentVector assocN(int i, Object val){104 return asVector().assocN(i, val);105 }107 public int count(){108 return 2;109 }111 public ISeq seq(){112 return asVector().seq();113 }115 public IPersistentVector cons(Object o){116 return asVector().cons(o);117 }119 public boolean containsKey(Object key){120 return asVector().containsKey(key);121 }123 public IMapEntry entryAt(Object key){124 return asVector().entryAt(key);125 }127 public Associative assoc(Object key, Object val){128 return asVector().assoc(key, val);129 }131 public Object valAt(Object key){132 return asVector().valAt(key);133 }135 public Object valAt(Object key, Object notFound){136 return asVector().valAt(key, notFound);137 }139 public Object peek(){140 return val();141 }144 public ISeq rseq() throws Exception{145 return asVector().rseq();146 }147 */149 }