Mercurial > lasercutter
diff src/clojure/lang/EnumerationSeq.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/EnumerationSeq.java Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,78 @@ 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 3, 2008 */ 1.15 + 1.16 +package clojure.lang; 1.17 + 1.18 +import java.io.IOException; 1.19 +import java.io.NotSerializableException; 1.20 +import java.util.Enumeration; 1.21 + 1.22 +public class EnumerationSeq extends ASeq{ 1.23 +final Enumeration iter; 1.24 +final State state; 1.25 + 1.26 + static class State{ 1.27 + volatile Object val; 1.28 + volatile Object _rest; 1.29 +} 1.30 + 1.31 +public static EnumerationSeq create(Enumeration iter){ 1.32 + if(iter.hasMoreElements()) 1.33 + return new EnumerationSeq(iter); 1.34 + return null; 1.35 +} 1.36 + 1.37 +EnumerationSeq(Enumeration iter){ 1.38 + this.iter = iter; 1.39 + state = new State(); 1.40 + this.state.val = state; 1.41 + this.state._rest = state; 1.42 +} 1.43 + 1.44 +EnumerationSeq(IPersistentMap meta, Enumeration iter, State state){ 1.45 + super(meta); 1.46 + this.iter = iter; 1.47 + this.state = state; 1.48 +} 1.49 + 1.50 +public Object first(){ 1.51 + if(state.val == state) 1.52 + synchronized(state) 1.53 + { 1.54 + if(state.val == state) 1.55 + state.val = iter.nextElement(); 1.56 + } 1.57 + return state.val; 1.58 +} 1.59 + 1.60 +public ISeq next(){ 1.61 + if(state._rest == state) 1.62 + synchronized(state) 1.63 + { 1.64 + if(state._rest == state) 1.65 + { 1.66 + first(); 1.67 + state._rest = create(iter); 1.68 + } 1.69 + } 1.70 + return (ISeq) state._rest; 1.71 +} 1.72 + 1.73 +public EnumerationSeq withMeta(IPersistentMap meta){ 1.74 + return new EnumerationSeq(meta, iter, state); 1.75 +} 1.76 + 1.77 +private void writeObject (java.io.ObjectOutputStream out) throws IOException { 1.78 + throw new NotSerializableException(getClass().getName()); 1.79 +} 1.80 + 1.81 +}