Пример #1
0
 public static void sort(Vector subnodes) {
   for (int i = 1; i < subnodes.size(); ++i) {
     Sortable currNode = (Sortable) subnodes.elementAt(i);
     int j = i - 1;
     for (; j >= 0; --j) {
       Sortable itemJ = (Sortable) subnodes.elementAt(j);
       if (compareNodes(itemJ, currNode) <= 0) {
         break;
       }
       subnodes.setElementAt(itemJ, j + 1);
     }
     if (j + 1 != i) {
       subnodes.setElementAt(currNode, j + 1);
     }
   }
 }
Пример #2
0
 public static void removeAll(Vector to, Vector all) {
   synchronized (to) {
     int current = 0;
     for (int index = 0; index < to.size(); ++index) {
       if (0 <= Util.getIndex(all, to.elementAt(index))) continue;
       if (current < index) {
         to.setElementAt(to.elementAt(index), current);
         current++;
       }
     }
     if (current < to.size()) to.setSize(current);
   }
 }
 /**
  * Safe version of setElementAt Sets the component at the specified index of this vector to be the
  * specified object. The previous component at that position is discarded. If index is greater or
  * equal to the current size of the vector, size will be automatically enlarged
  *
  * @param obj
  * @param index
  */
 public void setElementAt(Object obj, int index) {
   height = width = 0; // discarding cached values
   if (index >= elementCount) this.setSize(index + 1);
   super.setElementAt(obj, index);
 }