1 2 12 package com.versant.core.jdo.query; 13 14 import com.versant.core.common.SortableBase; 15 16 import java.util.Vector ; 17 18 20 public class VariableSorter extends SortableBase{ 21 private Vector variables; 22 23 public VariableSorter(final Vector variables) { 24 this.variables = variables; 25 } 26 27 28 public Vector getvariables() { 29 return variables; 30 } 31 32 public void sort() { 33 size = variables.size(); 34 super.sort(); 35 } 36 37 public void setvariables(final Vector variables) { 38 this.variables = variables; 39 } 40 41 protected int compare(final int a,final int b) { 42 return ((VarNode)variables.get(a)).getIdentifier().compareTo(((VarNode)variables.get(b)).getIdentifier()); 43 } 44 45 protected void swap(final int index1, final int index2) { 46 Object a = variables.get(index1); 47 Object b = variables.get(index2); 48 49 variables.remove(index1); 50 variables.insertElementAt(b,index1); 51 52 variables.remove(index2); 53 variables.insertElementAt(a,index2); 54 } 55 56 public VarNode search(String name){ 57 int low = 0; 58 int high = variables.size() - 1; 59 int mid, cmp; 60 VarNode node; 61 while(low <= high){ 62 mid = (low + high) / 2; 63 node = (VarNode)variables.get(mid); 64 cmp = node.getIdentifier().compareTo(name); 65 if( cmp < 0) low = mid + 1; 66 else if(cmp > 0) high = mid - 1; 67 else return node; 68 } 69 return null; 70 } 71 } 72 | Popular Tags |