KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > lib > TKSortableInteger


1 package com.teamkonzept.lib;
2
3 public class TKSortableInteger implements TKSortable {
4
5     private Integer JavaDoc value;
6
7     public TKSortableInteger (int value) { this.value = new Integer JavaDoc(value); }
8     public TKSortableInteger (String JavaDoc s) { this.value = new Integer JavaDoc(s); }
9     public String JavaDoc toString () { return value.toString(); }
10     public int intValue () { return value.intValue(); }
11
12     public int cmp (TKSortable other) {
13
14         if (other instanceof TKSortableInteger) {
15         
16             int thisValue = value.intValue();
17             int otherValue = ((TKSortableInteger) other).intValue();
18             
19             if (thisValue < otherValue) return -1;
20             else if (thisValue > otherValue) return 1;
21             else return 0;
22             
23         } else return value.toString().compareTo (other.toString());
24     };
25 }
26
Popular Tags