KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > DxLib > DxAbstractBag


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: DxAbstractBag.java,v 1.6 2000/10/28 16:55:14 daniela Exp $
8

9 package org.ozoneDB.DxLib;
10
11
12 /**
13  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
14  * @version $Revision: 1.6 $Date: 2000/10/28 16:55:14 $
15  */

16 public abstract class DxAbstractBag extends DxAbstractCollection implements DxBag {
17     
18     final static long serialVersionUID = 1L;
19     
20     
21     public DxAbstractBag() {
22     }
23     
24     
25     /**
26      * Compares two bags for equality. Returns true, if obj is also a DxBag,
27      * both bags have the same size and it contains all elements in the same
28      * order as the receiver.
29      */

30     public boolean equals( Object JavaDoc obj ) {
31         if (obj instanceof DxBag && obj != null) {
32             DxBag rhs = (DxBag)obj;
33             
34             if (this == obj) {
35                 return true;
36             }
37             if (count() != rhs.count()) {
38                 return false;
39             }
40             
41             DxIterator it = iterator();
42             DxIterator it2 = rhs.iterator();
43             Object JavaDoc cursor;
44             Object JavaDoc cursor2;
45             while ((cursor = it.next()) != null && (cursor2 = it2.next()) != null) {
46                 if (!cursor.equals( cursor2 )) {
47                     return false;
48                 }
49             }
50             return true;
51         } else {
52             return false;
53         }
54     }
55     
56     
57     public synchronized boolean add( Object JavaDoc obj ) {
58         return addBack( obj );
59     }
60     
61     
62     public synchronized boolean addBack( Object JavaDoc obj ) {
63         throw new RuntimeException JavaDoc( "" );
64     }
65     
66 }
67
Popular Tags