![JAR search and dependency download from the Maven repository](/logo.png)
com.viaoa.util.OAComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oa-core Show documentation
Show all versions of oa-core Show documentation
Object Automation library
The newest version!
/* Copyright 1999 Vince Via [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.viaoa.util;
import java.util.*;
import java.lang.reflect.*;
import com.viaoa.hub.Hub;
/**
OAComparator is used to sort objects. Hub.sort uses this when creating a HubSorter.
@see Hub#sort
see HubSortListener
*/
public class OAComparator implements Comparator {
Class clazz;
String propertyPaths;
boolean bAscending;
Method[][] methodss;
boolean[] bAscendings;
/**
* @param clazz
* @param propertyPaths, can include keywords "ASC" or "DESC" to determine ascending or descending.
* @param bAscending default value for sorting, true=Ascending, false=Descending
*/
public OAComparator(Class clazz, String propertyPaths, boolean bAscending) {
this.clazz = clazz;
this.propertyPaths = propertyPaths;
this.bAscending = bAscending;
}
public String getPropertyPaths() {
return propertyPaths;
}
public boolean getAsc() {
return bAscending;
}
public int compare(Object o1, Object o2) {
int x = preCheck(o1, o2);
if (x < 5) return x;
if (methodss == null) {
init();
}
if (methodss == null || methodss.length == 0) {
x = 0;
if (o1 instanceof Comparable && o2 instanceof Comparable) {
x = ((Comparable)o1).compareTo(((Comparable)o2));
}
if (!bAscending) {
if (x < 0) return 1;
if (x > 0) return -1;
}
return x;
}
for (int i=0; i hub = new Hub(Double.class);
hub.add(1.3);
hub.add(1.1);
hub.add(1.0);
hub.add(1.2);
hub.add(1.02);
hub.sort("", false);
for (double d : hub) {
System.out.println(""+d);
}
int x = 4;
x++;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy