/////// Cirbuf.java /////// class Cirbuf { public Cirbuf() { this(SIZE); } // no-arg constructor public Cirbuf(int s) { head = tail = length = 0; size = s; cb = new char[s]; // char array buffer } public boolean isEmpty() { return(length == 0); } public boolean isFull() { return(length == size);} public boolean put(char c) { if ( ! isFull() ) { cb[tail++] = c; length++; tail = mod(tail); return(true); } return(false); } public boolean get(char[] c) { if ( ! isEmpty() ) { c[0] = cb[head++]; length--; head = mod(head); return(true); } return(false); } private static final int SIZE = 16; private int head; // first char in buffer private int tail; // first empty slot in buffer private int length; // number of characters in buffer private int size; // capacity of buffer private char[] cb; // character buffer private int mod(int x) { return(x >= size ? x - size : x); } }