Mercurial > lasercutter
comparison 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 |
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 3, 2008 */ | |
12 | |
13 package clojure.lang; | |
14 | |
15 import java.io.IOException; | |
16 import java.io.NotSerializableException; | |
17 import java.util.Enumeration; | |
18 | |
19 public class EnumerationSeq extends ASeq{ | |
20 final Enumeration iter; | |
21 final State state; | |
22 | |
23 static class State{ | |
24 volatile Object val; | |
25 volatile Object _rest; | |
26 } | |
27 | |
28 public static EnumerationSeq create(Enumeration iter){ | |
29 if(iter.hasMoreElements()) | |
30 return new EnumerationSeq(iter); | |
31 return null; | |
32 } | |
33 | |
34 EnumerationSeq(Enumeration iter){ | |
35 this.iter = iter; | |
36 state = new State(); | |
37 this.state.val = state; | |
38 this.state._rest = state; | |
39 } | |
40 | |
41 EnumerationSeq(IPersistentMap meta, Enumeration iter, State state){ | |
42 super(meta); | |
43 this.iter = iter; | |
44 this.state = state; | |
45 } | |
46 | |
47 public Object first(){ | |
48 if(state.val == state) | |
49 synchronized(state) | |
50 { | |
51 if(state.val == state) | |
52 state.val = iter.nextElement(); | |
53 } | |
54 return state.val; | |
55 } | |
56 | |
57 public ISeq next(){ | |
58 if(state._rest == state) | |
59 synchronized(state) | |
60 { | |
61 if(state._rest == state) | |
62 { | |
63 first(); | |
64 state._rest = create(iter); | |
65 } | |
66 } | |
67 return (ISeq) state._rest; | |
68 } | |
69 | |
70 public EnumerationSeq withMeta(IPersistentMap meta){ | |
71 return new EnumerationSeq(meta, iter, state); | |
72 } | |
73 | |
74 private void writeObject (java.io.ObjectOutputStream out) throws IOException { | |
75 throw new NotSerializableException(getClass().getName()); | |
76 } | |
77 | |
78 } |