View Javadoc

1   
2   package org.paneris.util;
3    
4   /**
5   
6   This extends a vector, it has an additional method that simply prevents duplicate
7   values being put into it.
8   
9   **/
10  
11  public class UniqueVector extends JoinVector {
12  
13    private static final long serialVersionUID = 1L;
14  
15  /**
16  constructor
17  **/
18      public UniqueVector() {
19          super();
20      }
21  
22  /**
23  constructor with an initial capacity
24  **/
25      public UniqueVector(int initialCapacity) {
26          super(initialCapacity);
27      }
28  
29  /**
30  constructor with an initial capacity and a capacity increment
31  **/
32      public UniqueVector(int initialCapacity, int capacityIncrement) {
33          super(initialCapacity, capacityIncrement);
34      }
35  
36  /**
37  add an element to the vector, but only if it is not already there
38  @return   true   if the element has been sucessfully added, false otherwise
39  **/
40      public boolean addUniqueElement(Object obj) {
41          if (!this.contains(obj)) {
42              this.addElement(obj);
43              return true;
44          } else {
45              return false;
46          }
47      }
48  }
49