view src/clojure/lang/ChunkBuffer.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 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 **/
11 /* rich May 26, 2009 */
13 package clojure.lang;
15 final public class ChunkBuffer implements Counted{
16 Object[] buffer;
17 int end;
19 public ChunkBuffer(int capacity){
20 buffer = new Object[capacity];
21 end = 0;
22 }
24 public void add(Object o){
25 buffer[end++] = o;
26 }
28 public IChunk chunk(){
29 ArrayChunk ret = new ArrayChunk(buffer, 0, end);
30 buffer = null;
31 return ret;
32 }
34 public int count(){
35 return end;
36 }
37 }