Public Member Functions | |
OrderedVector () | |
boolean | add (Object obj) |
Override the Vector add(Object) method. |
|
00018 { 00019 super(); 00020 } |
|
Override the Vector add(Object) method. The method implements and ordered insert. All elements in the ordered vector are unique (so if the Integer is found in the Vector it will not be added). This algorithm has an N2 worst case time complexity so it is not designed for efficiency.
00035 { 00036 Integer newInt = (Integer)obj; 00037 int len = size(); 00038 boolean found = false; 00039 int i; 00040 for (i = 0; i < len; i++) { 00041 Integer intObj = (Integer)elementAt( i ); 00042 if (newInt.compareTo( intObj ) > 0) { 00043 continue; 00044 } 00045 else { 00046 if (newInt.compareTo( intObj ) == 0) { 00047 found = true; 00048 } 00049 break; 00050 } 00051 } // for 00052 if (i == len) { 00053 addElement( newInt ); 00054 } 00055 else if (!found) { 00056 insertElementAt( newInt, i ); 00057 } 00058 return true; 00059 } // add |