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 ImportSorter extends SortableBase{ 21 private Vector imports; 22 23 public ImportSorter(final Vector imports) { 24 this.imports = imports; 25 26 } 27 28 public void sort() { 29 size = imports.size(); 30 super.sort(); 31 } 32 33 public Vector getImports() { 34 return imports; 35 } 36 37 public void setImports(final Vector imports) { 38 this.imports = imports; 39 } 40 41 protected int compare(final int a, final int b) { 42 return ((ImportNode)imports.get(a)).name.compareTo(((ImportNode)imports.get(b)).name); 43 } 44 45 protected void swap(final int index1,final int index2) { 46 Object a = imports.get(index1); 47 Object b = imports.get(index2); 48 49 imports.remove(index1); 50 imports.insertElementAt(b,index1); 51 52 imports.remove(index2); 53 imports.insertElementAt(a,index2); 54 } 55 56 public ImportNode search(String name){ 57 int low = 0; 58 int high = imports.size() - 1; 59 int mid, cmp; 60 ImportNode node; 61 while(low <= high){ 62 mid = (low + high) / 2; 63 node = (ImportNode)imports.get(mid); 64 cmp = node.name.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 73 74 75 | Popular Tags |