KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > query > ImportSorter


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.query;
13
14 import com.versant.core.common.SortableBase;
15
16 import java.util.Vector JavaDoc;
17
18 /**
19  */

20 public class ImportSorter extends SortableBase{
21         private Vector JavaDoc imports;
22
23         public ImportSorter(final Vector JavaDoc imports) {
24             this.imports = imports;
25
26         }
27
28         public void sort() {
29             size = imports.size();
30             super.sort();
31         }
32
33         public Vector JavaDoc getImports() {
34             return imports;
35         }
36
37         public void setImports(final Vector JavaDoc 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 JavaDoc a = imports.get(index1);
47             Object JavaDoc 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 JavaDoc 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