01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: DxListDeque.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
08:
09: package org.ozoneDB.DxLib;
10:
11: /**
12: *
13: *
14: * @author <a href="http://www.softwarebuero.de/">SMB</a>
15: * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $
16: */
17: public class DxListDeque extends DxListBag implements DxDeque {
18:
19: final static long serialVersionUID = 1L;
20:
21: /**
22: */
23: public DxListDeque() {
24: }
25:
26: /**
27: */
28: public Object peek() {
29: return peekBottom();
30: }
31:
32: /**
33: */
34: public Object peekTop() {
35: //if the deque is empty, this return null
36: return top.prev().data();
37: }
38:
39: /**
40: */
41: public Object peekBottom() {
42: //if the deque is empty, this return null
43: return start.next().data();
44: }
45:
46: /**
47: */
48: public synchronized void push(Object obj) {
49: pushBottom(obj);
50: }
51:
52: /**
53: */
54: public synchronized void pushTop(Object obj) {
55: top.storeInfront(new DxListNode(obj));
56: itemCount++;
57: }
58:
59: /**
60: */
61: public synchronized void pushBottom(Object obj) {
62: start.storeBehind(new DxListNode(obj));
63: itemCount++;
64: }
65:
66: /**
67: */
68: public Object pop() {
69: return popBottom();
70: }
71:
72: /**
73: */
74: public Object popTop() {
75: Object answer = top.prev().data();
76: if (answer != null) {
77: top.prev().remove();
78: itemCount--;
79: }
80: return answer;
81: }
82:
83: /**
84: */
85: public Object popBottom() {
86: Object answer = start.next().data();
87: if (answer != null) {
88: start.next().remove();
89: itemCount--;
90: }
91: return answer;
92: }
93: }
|