01: // @@
02: // @@
03: /*
04: * Wi.Ser Framework
05: *
06: * Version: 1.8.1, 20-September-2007
07: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
08: *
09: * This library is free software; you can redistribute it and/or
10: * modify it under the terms of the GNU Lesser General Public
11: * License as published by the Free Software Foundation; either
12: * version 2 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * Lesser General Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser General Public
20: * License along with this library located in LGPL.txt in the
21: * license directory; if not, write to the
22: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23: * Boston, MA 02111-1307, USA.
24: *
25: * If this agreement does not cover your requirements, please contact us
26: * via email to get detailed information about the commercial license
27: * or our service offerings!
28: *
29: */
30: // @@
31: package de.ug2t.kernel;
32:
33: import java.util.*;
34:
35: public final class KeRingBuffer {
36: private Object pem_buffer[] = null;
37: private int pem_size = 16;
38: private int pem_insertPtr = 16;
39:
40: public KeRingBuffer() {
41: this .pem_buffer = new Object[this .pem_size];
42: return;
43: }
44:
45: public KeRingBuffer(int xSize) {
46: this .pem_size = xSize;
47: this .pem_buffer = new Object[this .pem_size];
48: this .pem_insertPtr = this .pem_size;
49:
50: return;
51: }
52:
53: public void pcmf_addElement(Object xObj) {
54: if (this .pem_insertPtr == 0)
55: System.arraycopy(this .pem_buffer, 0, this .pem_buffer, 1,
56: this .pem_size - 1);
57: else
58: this .pem_insertPtr--;
59:
60: this .pem_buffer[this .pem_insertPtr] = xObj;
61:
62: return;
63: };
64:
65: public Iterator pcmf_getValues() {
66: Object l_target[] = new Object[this .pem_size
67: - this .pem_insertPtr];
68: System.arraycopy(this .pem_buffer, this .pem_insertPtr, l_target,
69: 0, this .pem_size - this .pem_insertPtr);
70: ArrayList l_vect = new ArrayList();
71: for (int i = 0; i < l_target.length; i++)
72: l_vect.add(l_target[i]);
73:
74: return (l_vect.iterator());
75: };
76:
77: public String toString() {
78: String l_res = "";
79: Iterator l_it = this .pcmf_getValues();
80: while (l_it.hasNext())
81: l_res = l_res + l_it.next().toString() + "\n";
82:
83: return (l_res);
84: }
85: }
|