001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.kernel;
032:
033: import java.util.*;
034:
035: public final class KeLinkedList {
036: public class KeListIterator implements ListIterator {
037: protected KeListEntry pdm_act = null;
038: protected KeLinkedList pdm_list = null;
039: protected int pdm_idx = 0;
040:
041: public KeListIterator(KeLinkedList xList) {
042: this .pdm_act = xList.pem_first;
043: this .pdm_list = xList;
044: }
045:
046: /**
047: * <p>
048: * Does...
049: * </p>
050: * <p>
051: *
052: * @return a Type with
053: * </p>
054: * <p>
055: * @param
056: * </p>
057: */
058: public void add(Object o) {
059: KeListEntry l_new = new KeListEntry(null, null, o);
060: if (this .pdm_act == null) {
061: KeLinkedList.this .pem_last.pcmf_insertBehind(l_new);
062: KeLinkedList.this .pem_last = l_new;
063: } else {
064: this .pdm_act.pcmf_insertBefore(l_new);
065: if (KeLinkedList.this .pem_first == this .pdm_act)
066: KeLinkedList.this .pem_first = l_new;
067: }
068: ;
069: }
070:
071: public void addVar(Object o) {
072: KeListEntry l_new = new KeVarListEntry(null, null, o);
073: if (this .pdm_act == null) {
074: KeLinkedList.this .pem_last.pcmf_insertBehind(l_new);
075: KeLinkedList.this .pem_last = l_new;
076: } else {
077: this .pdm_act.pcmf_insertBefore(l_new);
078: if (KeLinkedList.this .pem_first == this .pdm_act)
079: KeLinkedList.this .pem_first = l_new;
080: }
081: ;
082: }
083:
084: /**
085: * <p>
086: * Does...
087: * </p>
088: * <p>
089: *
090: * @return a Type with
091: * </p>
092: * <p>
093: * @param
094: * </p>
095: */
096:
097: public KeListEntry pcmf_addEntry(Object o) {
098: KeListEntry l_new = new KeListEntry(null, null, o);
099: if (this .pdm_act == null) {
100: KeLinkedList.this .pem_last.pcmf_insertBehind(l_new);
101: KeLinkedList.this .pem_last = l_new;
102: } else {
103: this .pdm_act.pcmf_insertBefore(l_new);
104: if (KeLinkedList.this .pem_first == this .pdm_act)
105: KeLinkedList.this .pem_first = l_new;
106: }
107: ;
108: return (l_new);
109: }
110:
111: public KeListEntry pcmf_addVarEntry(Object o) {
112: KeListEntry l_new = new KeVarListEntry(null, null, o);
113: if (this .pdm_act == null) {
114: KeLinkedList.this .pem_last.pcmf_insertBehind(l_new);
115: KeLinkedList.this .pem_last = l_new;
116: } else {
117: this .pdm_act.pcmf_insertBefore(l_new);
118: if (KeLinkedList.this .pem_first == this .pdm_act)
119: KeLinkedList.this .pem_first = l_new;
120: }
121: ;
122: return (l_new);
123: }
124:
125: /**
126: * <p>
127: * Does...
128: * </p>
129: * <p>
130: *
131: * @return a Type with
132: * </p>
133: * <p>
134: * @param
135: * </p>
136: */
137: public boolean hasNext() {
138: if (this .pdm_act != null)
139: return (true);
140: else
141: return (false);
142: }
143:
144: /**
145: * <p>
146: * Does...
147: * </p>
148: * <p>
149: *
150: * @return a Type with
151: * </p>
152: * <p>
153: * @param
154: * </p>
155: */
156: public boolean hasPrevious() {
157: if (this .pdm_act == null)
158: return (true);
159:
160: if (this .pdm_act.pdm_prev != null)
161: return (true);
162: else
163: return (false);
164: }
165:
166: /**
167: * <p>
168: * Does...
169: * </p>
170: * <p>
171: *
172: * @return a Type with
173: * </p>
174: * <p>
175: * @param
176: * </p>
177: */
178: public Object next() {
179: Object l_res = this .pdm_act.getPem_entry();
180: this .pdm_act = this .pdm_act.getPem_next();
181: this .pdm_idx++;
182:
183: return (l_res);
184: }
185:
186: /**
187: * <p>
188: * Does...
189: * </p>
190: * <p>
191: *
192: * @return a Type with
193: * </p>
194: * <p>
195: * @param
196: * </p>
197: */
198: public boolean isNextVar() {
199: return (this .pdm_act.pcmf_isVar());
200: }
201:
202: /**
203: * <p>
204: * Does...
205: * </p>
206: * <p>
207: *
208: * @return a Type with
209: * </p>
210: * <p>
211: * @param
212: * </p>
213: */
214: public int nextIndex() {
215: return (this .pdm_idx);
216: }
217:
218: /**
219: * <p>
220: * Does...
221: * </p>
222: * <p>
223: *
224: * @return a Type with
225: * </p>
226: * <p>
227: * @param
228: * </p>
229: */
230: public Object previous() {
231: if (this .pdm_act == null) {
232: this .pdm_act = KeLinkedList.this .pem_last;
233: this .pdm_idx--;
234: return (this .pdm_act.getPem_entry());
235: }
236: ;
237: this .pdm_act = this .pdm_act.getPem_prev();
238: Object l_res = this .pdm_act.getPem_entry();
239: this .pdm_idx--;
240:
241: return (l_res);
242: }
243:
244: /**
245: * <p>
246: * Does...
247: * </p>
248: * <p>
249: *
250: * @return a Type with
251: * </p>
252: * <p>
253: * @param
254: * </p>
255: */
256: public int previousIndex() {
257: return (this .pdm_idx - 1);
258: }
259:
260: /**
261: * <p>
262: * Does...
263: * </p>
264: * <p>
265: *
266: * @return a Type with
267: * </p>
268: * <p>
269: * @param
270: * </p>
271: */
272: public void remove() {
273: if (this .pdm_act == null) {
274: KeListEntry l_etr = KeLinkedList.this .pem_last
275: .getPem_prev();
276: KeLinkedList.this .pem_last.pcmf_remove();
277: KeLinkedList.this .pem_last = l_etr;
278:
279: return;
280: }
281: if (this .pdm_act == KeLinkedList.this .pem_first)
282: KeLinkedList.this .pem_first = this .pdm_act
283: .getPem_next();
284:
285: this .pdm_act.getPem_prev().pcmf_remove();
286:
287: return;
288: }
289:
290: /**
291: * <p>
292: * Does...
293: * </p>
294: * <p>
295: *
296: * @return a Type with
297: * </p>
298: * <p>
299: * @param
300: * </p>
301: */
302: public Object removeObj() {
303: if (this .pdm_act == null) {
304: KeListEntry l_etr = KeLinkedList.this .pem_last
305: .getPem_prev();
306: KeLinkedList.this .pem_last.pcmf_remove();
307: KeLinkedList.this .pem_last = l_etr;
308:
309: return (KeLinkedList.this .pem_last.pdm_entry);
310: }
311: if (this .pdm_act == KeLinkedList.this .pem_first)
312: KeLinkedList.this .pem_first = this .pdm_act
313: .getPem_next();
314:
315: KeListEntry l_le = this .pdm_act.getPem_prev();
316: l_le.pcmf_remove();
317:
318: return (l_le.pdm_entry);
319: }
320:
321: /**
322: * <p>
323: * Does...
324: * </p>
325: * <p>
326: *
327: * @return a Type with
328: * </p>
329: * <p>
330: * @param
331: * </p>
332: */
333: public void set(Object o) {
334: if (this .pdm_act == null)
335: KeLinkedList.this .pem_last.setPem_entry(o);
336: else
337: this .pdm_act.getPem_prev().setPem_entry(o);
338: }
339:
340: /**
341: * <p>
342: * Does...
343: * </p>
344: * <p>
345: *
346: * @return a Type with
347: * </p>
348: * <p>
349: * @param
350: * </p>
351: */
352: public KeListEntry pcmf_getActEntry() {
353: return (this .pdm_act);
354: }
355: }
356:
357: public class KeVarListEntry extends KeListEntry {
358: public KeVarListEntry(KeListEntry xNext, KeListEntry xPrev,
359: Object xEntry) {
360: super (xNext, xPrev, xEntry);
361: }
362:
363: public KeVarListEntry() {
364: super ();
365: }
366:
367: public boolean pcmf_isVar() {
368: return (true);
369: }
370: }
371:
372: public class KeListEntry {
373: protected KeListEntry pdm_next;
374: protected KeListEntry pdm_prev;
375: protected Object pdm_entry;
376:
377: public KeListEntry() {
378: this .pdm_next = null;
379: this .pdm_prev = null;
380: this .pdm_entry = null;
381: }
382:
383: public KeListEntry(KeListEntry xNext, KeListEntry xPrev,
384: Object xEntry) {
385: this .pdm_next = xNext;
386: this .pdm_prev = xPrev;
387: this .pdm_entry = xEntry;
388: }
389:
390: public boolean pcmf_isVar() {
391: return (false);
392: }
393:
394: public void pcmf_remove() {
395: if (this .pdm_prev != null)
396: this .pdm_prev.setPem_next(this .pdm_next);
397: if (this .pdm_next != null)
398: this .pdm_next.setPem_prev(this .pdm_prev);
399:
400: this .pdm_next = null;
401: this .pdm_prev = null;
402:
403: KeLinkedList.this .pem_size--;
404: }
405:
406: public void pcmf_insertBefore(KeListEntry xEntry) {
407: xEntry.setPem_prev(this .pdm_prev);
408: xEntry.setPem_next(this );
409: if (this .pdm_prev != null)
410: this .pdm_prev.setPem_next(xEntry);
411:
412: this .pdm_prev = xEntry;
413:
414: KeLinkedList.this .pem_size++;
415: }
416:
417: public void pcmf_insertBehind(KeListEntry xEntry) {
418: xEntry.setPem_prev(this );
419: xEntry.setPem_next(this .pdm_next);
420: if (this .pdm_next != null)
421: this .pdm_next.setPem_prev(xEntry);
422:
423: this .pdm_next = xEntry;
424:
425: KeLinkedList.this .pem_size++;
426: }
427:
428: public Object getPem_entry() {
429: return pdm_entry;
430: }
431:
432: public KeListEntry getPem_next() {
433: return pdm_next;
434: }
435:
436: public KeListEntry getPem_prev() {
437: return pdm_prev;
438: }
439:
440: public void setPem_entry(Object object) {
441: pdm_entry = object;
442: }
443:
444: protected void setPem_next(KeListEntry entry) {
445: pdm_next = entry;
446: }
447:
448: protected void setPem_prev(KeListEntry entry) {
449: pdm_prev = entry;
450: }
451: }
452:
453: protected KeListEntry pem_first = null;
454: protected KeListEntry pem_last = null;
455: protected int pem_size = 0;
456:
457: /**
458: *
459: */
460: public KeLinkedList() {
461: }
462:
463: public void pcmf_clearList() {
464: this .pem_first = null;
465: this .pem_last = null;
466: this .pem_size = 0;
467: }
468:
469: public KeListEntry pcmf_add(Object xObj) {
470: if (pem_size == 0) {
471: KeListEntry l_entry = new KeListEntry(null, null, xObj);
472: this .pem_first = l_entry;
473: this .pem_last = l_entry;
474: this .pem_size++;
475: return (l_entry);
476: } else {
477: KeListEntry l_entry = new KeListEntry(null, this .pem_last,
478: xObj);
479: this .pem_last.setPem_next(l_entry);
480: this .pem_last = l_entry;
481: this .pem_size++;
482: return (l_entry);
483: }
484: }
485:
486: public KeListEntry pcmf_addVar(Object xObj) {
487: if (pem_size == 0) {
488: KeListEntry l_entry = new KeVarListEntry(null, null, xObj);
489: this .pem_first = l_entry;
490: this .pem_last = l_entry;
491: this .pem_size++;
492: return (l_entry);
493: } else {
494: KeListEntry l_entry = new KeVarListEntry(null,
495: this .pem_last, xObj);
496: this .pem_last.setPem_next(l_entry);
497: this .pem_last = l_entry;
498: this .pem_size++;
499: return (l_entry);
500: }
501: }
502:
503: public int pcmf_getSize() {
504: return (this .pem_size);
505: }
506:
507: public KeListEntry pcmf_newEntry() {
508: return (new KeListEntry());
509: };
510:
511: public KeListEntry pcmf_newVarEntry() {
512: return (new KeVarListEntry());
513: };
514:
515: public KeListIterator listIterator() {
516: return (new KeListIterator(this));
517: };
518: }
|