List of usage examples for org.apache.commons.collections ComparatorUtils NATURAL_COMPARATOR
Comparator NATURAL_COMPARATOR
To view the source code for org.apache.commons.collections ComparatorUtils NATURAL_COMPARATOR.
Click Source Link
From source file:com.linkedin.pinot.common.restlet.PinotRestletApplication.java
protected void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) { TreeSet<String> pathsOrderedByLength = new TreeSet<String>( ComparatorUtils.chainedComparator(new Comparator<String>() { @Override/*from ww w .ja v a 2 s . co m*/ public int compare(String left, String right) { int leftLength = left.length(); int rightLength = right.length(); return leftLength < rightLength ? -1 : (leftLength == rightLength ? 0 : 1); } }, ComparatorUtils.NATURAL_COMPARATOR)); for (Method method : clazz.getDeclaredMethods()) { Annotation annotationInstance = method.getAnnotation(Paths.class); if (annotationInstance != null) { pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value())); } } for (String routePath : pathsOrderedByLength) { LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName()); attachRoute(router, routePath, clazz); } }
From source file:br.com.autonomiccs.apacheCloudStack.client.ApacheCloudStackApiCommandParameter.java
@Override @SuppressWarnings("unchecked") public int compareTo(ApacheCloudStackApiCommandParameter o) { return ComparatorUtils.NATURAL_COMPARATOR.compare(this.name, o.name); }
From source file:net.micwin.openspace.view.construction.ConstructionPage.java
private Component composeBluePrintTable(List<BluePrint> bluePrints) { String id = "bluePrintsTable"; List<BluePrint> buildPlans = DaoManager.I.getBluePrintDao().findByController(getAvatar()); Collections.sort(buildPlans, new Comparator<BluePrint>() { @Override/*from w ww. j a va2 s . c o m*/ public int compare(BluePrint o1, BluePrint o2) { return ComparatorUtils.NATURAL_COMPARATOR.compare(o2.getUsageCounts(), o1.getUsageCounts()); } }); StringBuilder builder = new StringBuilder(); for (BluePrint bluePrint : bluePrints) { if (builder.length() > 0) { builder.append(", "); } builder.append(bluePrint.getName()); } // TODO dummy entry return new Label(id, builder.toString()); }
From source file:com.ineunet.knife.core.query.QueryParamParser.java
/** * Create a Comparator by <code>orderBy</code> and <code>sort</code>. *//*from w w w . j a va 2s . c o m*/ @SuppressWarnings("unchecked") public <X> Comparator<X> getComparator() { parse(); if (StringUtils.isBlank(orderByField)) return ComparatorUtils.NATURAL_COMPARATOR; Comparator<X> mycmp = ComparableComparator.getInstance(); if ("DESC".equalsIgnoreCase(sort)) { mycmp = ComparatorUtils.reversedComparator(mycmp); } return new BeanComparator(orderByField, mycmp); }
From source file:com.linkedin.pinot.controller.api.ControllerRestApplication.java
private void attachRoutesForClass(Router router, Class<? extends ServerResource> clazz) { TreeSet<String> pathsOrderedByLength = new TreeSet<String>( ComparatorUtils.chainedComparator(new Comparator<String>() { private IntComparator _intComparator = IntComparators.NATURAL_COMPARATOR; @Override//from w w w .ja v a 2 s. com public int compare(String o1, String o2) { return _intComparator.compare(o1.length(), o2.length()); } }, ComparatorUtils.NATURAL_COMPARATOR)); for (Method method : clazz.getDeclaredMethods()) { Annotation annotationInstance = method.getAnnotation(Paths.class); if (annotationInstance != null) { pathsOrderedByLength.addAll(Arrays.asList(((Paths) annotationInstance).value())); } } for (String routePath : pathsOrderedByLength) { LOGGER.info("Attaching route {} -> {}", routePath, clazz.getSimpleName()); router.attach(routePath, clazz); } }
From source file:acromusashi.stream.ml.clustering.kmeans.KmeansCalculator.java
/** * Kmeans??<br>// w w w. j a va2s.c o m * ???<br> * <ol> * <li>????????(?n????n?????)</li> * <li>n?????????????????????????????</li> * <li>???????</li> * </ol> * * @param baseKmeans Kmeans * @param targetKmeans Kmeans * @return ? */ public static final KmeansDataSet mergeKmeans(KmeansDataSet baseKmeans, KmeansDataSet targetKmeans) { KmeansDataSet merged = new KmeansDataSet(); int centroidNum = (int) ComparatorUtils.min(baseKmeans.getCentroids().length, targetKmeans.getCentroids().length, ComparatorUtils.NATURAL_COMPARATOR); // ??????? List<CentroidMapping> allDistance = calculateDistances(baseKmeans.getCentroids(), targetKmeans.getCentroids(), centroidNum); // n????????????????? Collections.sort(allDistance, new CentroidsComparator()); Map<Integer, Integer> resultMapping = createCentroidMappings(centroidNum, allDistance); // ?? double[][] mergedCentroids = mergeCentroids(baseKmeans.getCentroids(), targetKmeans.getCentroids(), resultMapping); merged.setCentroids(mergedCentroids); return merged; }
From source file:acromusashi.stream.ml.anomaly.lof.LofCalculator.java
/** * basePoint?targetPoint?????(Reachability distance)? * /* w w w .ja va2s .co m*/ * @param basePoint * @param targetPoint * @return ??? */ protected static double calculateReachDistance(LofPoint basePoint, LofPoint targetPoint) { double distance = MathUtils.distance(basePoint.getDataPoint(), targetPoint.getDataPoint()); double reachDistance = (double) ComparatorUtils.max(distance, targetPoint.getkDistance(), ComparatorUtils.NATURAL_COMPARATOR); return reachDistance; }
From source file:org.omnaest.utils.beans.adapter.ListToTypeAdapterTest.java
@SuppressWarnings("unchecked") @Test//from ww w. j av a2s .c om public void testNewInstanceOrderedByComparable() { // TestInterface testInterface = new TestClass(); testInterface.getFieldStringList().add("first list value"); testInterface.getFieldStringList().add("second list value"); // List<Object> list = new ArrayList<Object>(); // TestInterface testInterfaceAdapter = ListToTypeAdapter.newInstance(list, TestInterface.class, ComparatorUtils.NATURAL_COMPARATOR, false); // BeanUtils.copyPropertyValues(testInterface, testInterfaceAdapter); // assertEquals(3, list.size()); assertEquals(testInterface.getFieldDouble(), list.get(0)); assertEquals(testInterface.getFieldString(), list.get(1)); assertEquals(testInterface.getFieldStringList(), list.get(2)); }
From source file:org.omnaest.utils.beans.replicator.BeanReplicatorWithCollectionsTest.java
@SuppressWarnings("unchecked") @Test// ww w . j a v a 2s. c om public void testMappingOfVariousCollectionTypes() { TestSimpleBean testSimpleBean = new TestSimpleBean(); { Map<String, Object> map = MapUtils.builder().<String, Object>put("key1", "value1").put("key2", "value2") .buildAs().linkedHashMap(); testSimpleBean.setMap(map); testSimpleBean.setSortedMap(MapUtils.builder().putAll(map).buildAs() .treeMap(ComparatorUtils.reversedComparator(ComparatorUtils.NATURAL_COMPARATOR))); testSimpleBean.setSet(SetUtils.valueOf("a", "b", "c", "d")); testSimpleBean.setSortedSet(new TreeSet<String>(SetUtils.valueOf("b", "c", "d", "a"))); testSimpleBean.setList(ListUtils.valueOf(new SubBean("a", "b"), new SubBean("c", "d"))); testSimpleBean.setCollection(ListUtils.valueOf("a", "b", "c", "d")); testSimpleBean.setIterable(ListUtils.valueOf("a", "b", "c", "d")); testSimpleBean.setArray(new String[] { "a", "b", "c", "d" }); } BeanCopier<TestSimpleBean> beanCopier = new BeanCopier<TestSimpleBean>(TestSimpleBean.class); TestSimpleBean clone = beanCopier.clone(testSimpleBean); assertNotNull(clone); assertEquals(testSimpleBean.getMap(), clone.getMap()); assertNotSame(testSimpleBean.getMap(), clone.getMap()); assertEquals(testSimpleBean.getSortedMap(), clone.getSortedMap()); assertNotSame(testSimpleBean.getSortedMap(), clone.getSortedMap()); assertEquals(testSimpleBean.getSet(), clone.getSet()); assertNotSame(testSimpleBean.getSet(), clone.getSet()); assertEquals(testSimpleBean.getSortedSet(), clone.getSortedSet()); assertNotSame(testSimpleBean.getSortedSet(), clone.getSortedSet()); assertEquals(testSimpleBean.getList(), clone.getList()); assertNotSame(testSimpleBean.getList(), clone.getList()); assertEquals(testSimpleBean.getCollection(), clone.getCollection()); assertNotSame(testSimpleBean.getCollection(), clone.getCollection()); assertEquals(testSimpleBean.getIterable(), clone.getIterable()); assertNotSame(testSimpleBean.getIterable(), clone.getIterable()); assertArrayEquals(testSimpleBean.getArray(), clone.getArray()); assertNotSame(testSimpleBean.getArray(), clone.getArray()); }
From source file:org.omnaest.utils.structure.collection.list.sorted.TreeList.java
/** * @see TreeList//from w ww . ja va 2s . c om */ public TreeList() { this(new Factory<SortedMap<AccessorReadable<E>, ElementList>>() { @Override public SortedMap<AccessorReadable<E>, ElementList> newInstance() { @SuppressWarnings("unchecked") final Comparator<E> comparator = ComparatorUtils.NATURAL_COMPARATOR; return new TreeMap<AccessorReadable<E>, ElementList>(newComparatorForAccessor(comparator)); } }); }