KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jofti > model > ComparableBoolean


1 /*
2  * Created on Aug 7, 2005
3  *
4  */

5 package com.jofti.model;
6
7 /**
8  *
9  *
10  * Comparable wrapper object for Boolean class. This is superceeded in 1.5 but for 1.4 code we have to use it.
11   
12  * @author xenephon (xenephon@jofti.com)
13  *
14  */

15 public class ComparableBoolean implements Comparable JavaDoc
16 {
17     private Boolean JavaDoc value =Boolean.FALSE;
18     
19     public ComparableBoolean(String JavaDoc value){
20         this.value = Boolean.valueOf(value);
21     }
22     public ComparableBoolean(Boolean JavaDoc value){
23         this.value = value;
24     }
25     
26     public ComparableBoolean(boolean value){
27         this.value = Boolean.valueOf(value);
28     }
29
30     /* (non-Javadoc)
31      * @see java.lang.Comparable#compareTo(java.lang.Object)
32      */

33     public int compareTo(Object JavaDoc arg0)
34     {
35         if (arg0 instanceof ComparableBoolean){
36             ComparableBoolean temp = (ComparableBoolean)arg0;
37             if (value.equals(Boolean.FALSE)){
38                if (temp.value.equals(Boolean.FALSE)){
39                    return 0;
40                }else{
41                    return -1;
42                }
43             }else{
44                 if (temp.value.equals(Boolean.TRUE)){
45                     return 0;
46                 }else{
47                     return 1;
48                 }
49             }
50         }else{
51             return -1;
52         }
53         
54     }
55     
56     public int hashCode(){
57         return value.hashCode();
58     }
59     
60     public boolean equals(Object JavaDoc obj){
61         return value.equals(obj);
62     }
63     
64     public String JavaDoc toString(){
65         return value.toString();
66     }
67 }
68
Popular Tags