KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > query > mem > BCodeSorter


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.mem;
13
14 import com.versant.core.common.OID;
15
16 import java.util.List JavaDoc;
17 import java.util.Comparator JavaDoc;
18 import java.util.Collections JavaDoc;
19
20 import com.versant.core.common.OID;
21 import com.versant.core.jdo.PMProxy;
22 import com.versant.core.jdo.VersantPersistenceManagerImp;
23
24 /**
25  * @keep-all
26  */

27 public class BCodeSorter implements Comparator JavaDoc {
28     private List JavaDoc toSort;
29     private PMProxy pmProxy;
30     private BCodeQuery bCodeCompare;
31
32     public void sort(List JavaDoc listOfOids, PMProxy pmProxy, BCodeQuery bCodeCompare) {
33         this.toSort = listOfOids;
34         this.pmProxy = pmProxy;
35         this.bCodeCompare = bCodeCompare;
36         Collections.sort(toSort, this);
37     }
38
39     public int compare(Object JavaDoc o1, Object JavaDoc o2) {
40         return compare((OID) o1, (OID) o2);
41     }
42
43     /**
44      * If there is a exception with the compare eg. null for one of the comp params then -1 is returned.
45      * @param o1
46      * @param o2
47      * @return
48      */

49     public int compare(OID o1, OID o2) {
50         int comp = 0;
51         try {
52             final VersantPersistenceManagerImp realPM = pmProxy.getRealPM();
53             comp = bCodeCompare.compare(realPM.getInternalSM(o1).queryStateWrapper,
54                     realPM.getInternalSM(o2).queryStateWrapper);
55         } catch (Exception JavaDoc e) {
56             comp = -1;
57         }
58         return comp;
59     }
60 }
61
62
63
Popular Tags