View Javadoc

1   /*
2    *    This program is free software; you can redistribute it and/or modify
3    *    it under the terms of the GNU General Public License as published by
4    *    the Free Software Foundation; either version 2 of the License, or
5    *    (at your option) any later version.
6    *
7    *    This program is distributed in the hope that it will be useful,
8    *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10   *    GNU General Public License for more details.
11   *
12   *    You should have received a copy of the GNU General Public License
13   *    along with this program; if not, write to the Free Software
14   *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15   */
16  
17  
18  package jr239.co620;
19  import java.util.HashSet;
20  import java.util.Set;
21  
22  
23  /**
24   *
25   * @author jar
26   */
27  public class Couple<E> 
28  extends  HashSet<E>
29  implements Set<E>, Cloneable, java.io.Serializable{
30      
31       private static final long serialVersionUID = -0xe1224eeL;
32       
33       private Couple(){
34           
35       }
36       
37      public Couple( E e1, E e2) {
38          super(2);
39         if (e1.equals(e2) ){
40             System.err.println("Couples need unique elementes. Provided couple is: (" + e1+","+ e2+")"   );
41         }else{
42          if ( ! (super.add( e1) && super.add(e2)) ){
43             System.err.println("Sytem was unable to create couple:(" + e1+","+ e2+")");
44              }
45          }    
46      }
47      
48      public boolean add(E e){
49         System.err.println("Couple.add( E e..): Only one element ot the couple was provided");
50          return false;
51      }
52      
53      
54     public void remove(E e){
55          System.err.println("Couple.remove( E e..): Only one element ot the couple was provided");
56      }
57      
58     public boolean remove(E e1, E e2){
59          return ( super.remove(e2) && super.remove(e1));
60      }
61     
62     
63      public boolean add(E e1, E e2){
64        
65          return false;
66      }
67      
68  }