annotate src/clojure/lang/StringSeq.java @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
rev   line source
rlm@10 1 /**
rlm@10 2 * Copyright (c) Rich Hickey. All rights reserved.
rlm@10 3 * The use and distribution terms for this software are covered by the
rlm@10 4 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
rlm@10 5 * which can be found in the file epl-v10.html at the root of this distribution.
rlm@10 6 * By using this software in any fashion, you are agreeing to be bound by
rlm@10 7 * the terms of this license.
rlm@10 8 * You must not remove this notice, or any other, from this software.
rlm@10 9 **/
rlm@10 10
rlm@10 11 /* rich Dec 6, 2007 */
rlm@10 12
rlm@10 13 package clojure.lang;
rlm@10 14
rlm@10 15 public class StringSeq extends ASeq implements IndexedSeq{
rlm@10 16 public final CharSequence s;
rlm@10 17 public final int i;
rlm@10 18
rlm@10 19 static public StringSeq create(CharSequence s){
rlm@10 20 if(s.length() == 0)
rlm@10 21 return null;
rlm@10 22 return new StringSeq(null, s, 0);
rlm@10 23 }
rlm@10 24
rlm@10 25 StringSeq(IPersistentMap meta, CharSequence s, int i){
rlm@10 26 super(meta);
rlm@10 27 this.s = s;
rlm@10 28 this.i = i;
rlm@10 29 }
rlm@10 30
rlm@10 31 public Obj withMeta(IPersistentMap meta){
rlm@10 32 if(meta == meta())
rlm@10 33 return this;
rlm@10 34 return new StringSeq(meta, s, i);
rlm@10 35 }
rlm@10 36
rlm@10 37 public Object first(){
rlm@10 38 return Character.valueOf(s.charAt(i));
rlm@10 39 }
rlm@10 40
rlm@10 41 public ISeq next(){
rlm@10 42 if(i + 1 < s.length())
rlm@10 43 return new StringSeq(_meta, s, i + 1);
rlm@10 44 return null;
rlm@10 45 }
rlm@10 46
rlm@10 47 public int index(){
rlm@10 48 return i;
rlm@10 49 }
rlm@10 50
rlm@10 51 public int count(){
rlm@10 52 return s.length() - i;
rlm@10 53 }
rlm@10 54 }