Example usage for java.util Comparator Comparator

List of usage examples for java.util Comparator Comparator

Introduction

In this page you can find the example usage for java.util Comparator Comparator.

Prototype

Comparator

Source Link

Usage

From source file:springfox.documentation.spi.service.contexts.Orderings.java

public static Comparator<ApiListingReference> listingReferencePathComparator() {
    return new Comparator<ApiListingReference>() {
        @Override//from   ww w  . j a  v  a2  s.  c om
        public int compare(ApiListingReference first, ApiListingReference second) {
            return first.getPath().compareTo(second.getPath());
        }
    };
}

From source file:com.github.jinahya.sql.database.metadata.bind.Table.java

public static Comparator<Table> natural() {

    return new Comparator<Table>() {

        @Override//from w  w  w  .j a  v  a 2 s .  c om
        public int compare(final Table o1, final Table o2) {

            // by TABLE_TYPE, TABLE_CAT, TABLE_SCHEM and TABLE_NAME
            return new CompareToBuilder().append(o1.getTableType(), o2.getTableType())
                    .append(o1.getTableCat(), o2.getTableCat()).append(o1.getTableSchem(), o2.getTableSchem())
                    .append(o1.getTableName(), o2.getTableName()).build();
        }

    };
}

From source file:com.github.sdbg.debug.core.internal.webkit.protocol.ChromiumTabInfo.java

static Comparator<ChromiumTabInfo> getComparator() {
    return new Comparator<ChromiumTabInfo>() {
        @Override//w w  w  .  j  a v  a  2s. c  om
        public int compare(ChromiumTabInfo o1, ChromiumTabInfo o2) {
            // Sort by the tab order.
            String url1 = o1.getWebSocketDebuggerUrl();
            String url2 = o2.getWebSocketDebuggerUrl();

            if (url1 == url2) {
                return 0;
            } else if (url1 == null) {
                return -1;
            } else if (url2 == null) {
                return 1;
            } else {
                return url1.compareTo(url2);
            }
        }
    };
}

From source file:com.alibaba.zonda.logger.server.util.DirectoryListener.java

public List<File> list(File startDirectory, String filterRegex) throws IOException {
    List<File> dirList = new ArrayList<File>();
    walk(startDirectory, dirList);//from   ww  w . ja va 2s .c o  m
    Collections.sort(dirList, new Comparator<File>() {
        public int compare(File f1, File f2) {
            return (Long.valueOf(f1.lastModified())).compareTo(Long.valueOf(f2.lastModified()));
        }
    });
    List<File> filteredDirList = new ArrayList<File>();
    for (File f : dirList) {
        if (f.getName().matches(filterRegex)) {
            filteredDirList.add(f);
        }
    }
    return filteredDirList;
}

From source file:au.org.biodiversity.nsl.tree.SimpleProfiler.java

public static void stopProfiling() {
    profiling = false;/*from w w w. ja v a 2 s  . c  om*/

    stoploggingts = System.currentTimeMillis();
    log.info("logging for " + (stoploggingts - startloggingts) + " ms");

    Map<String, Long> byTime = new HashMap<String, Long>();

    for (String k : itemTime.keySet()) {
        long t = itemTime.get(k);
        int ct = itemCt.get(k);

        //byTime.put(k, (t / ct));
        byTime.put(k, t); // I mainly care about the total time
    }

    ArrayList<Entry<String, Long>> byTimeSorted = new ArrayList<Entry<String, Long>>(byTime.entrySet());
    Collections.sort(byTimeSorted, new Comparator<Entry<String, Long>>() {
        public int compare(Entry<String, Long> o1, Entry<String, Long> o2) {
            return (int) (o1.getValue() - o2.getValue());
        }
    });

    for (Entry<String, Long> kk : byTimeSorted) {
        String k = kk.getKey();
        long t = itemTime.get(k);
        int ct = itemCt.get(k);

        log.info(k + " ct " + ct + " time " + t + " ms is " + (t * 100 / (stoploggingts - startloggingts))
                + "% avg " + (t / ct));

    }
}

From source file:net.panthema.BispanningGame.GraphString.java

public static String write_graph(MyGraph g, Transformer<Integer, Point2D> gl) {
    ByteArrayOutputStream ba = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(ba);

    // print the vertex list

    pw.print('V');
    pw.print(g.getVertexCount());//w  ww .jav  a2 s.  co  m
    pw.print(':');

    Collection<Integer> vcoll = g.getVertices();
    ArrayList<Integer> vlist = new ArrayList<Integer>(vcoll);
    Collections.sort(vlist, new Comparator<Integer>() {
        public int compare(Integer arg0, Integer arg1) {
            return arg0 - arg1;
        }
    });

    for (Integer v : vlist) {
        pw.print('i');
        pw.print(v);

        Point2D pos = gl.transform(v);
        pw.print('x');
        pw.print((int) pos.getX());
        pw.print('y');
        pw.print((int) pos.getY());

        pw.print('/');
    }
    pw.print(';');

    // print the edge list

    pw.print('E');
    pw.print(g.getEdgeCount());
    pw.print(':');

    Collection<MyEdge> ecoll = g.getEdges();
    ArrayList<MyEdge> elist = new ArrayList<MyEdge>(ecoll);
    Collections.sort(elist, new Comparator<MyEdge>() {
        public int compare(MyEdge arg0, MyEdge arg1) {
            return arg0.id - arg1.id;
        }
    });

    for (MyEdge e : elist) {
        Integer e_x = g.getEndpoints(e).getFirst();
        Integer e_y = g.getEndpoints(e).getSecond();

        pw.print('i');
        pw.print(e.id);

        pw.print('t');
        pw.print(e_x);
        pw.print('h');
        pw.print(e_y);

        pw.print('c');
        pw.print(e.color);

        pw.print('/');
    }
    pw.print(';');

    pw.flush();

    return ba.toString();
}

From source file:com.sec.ose.osi.util.tools.Tools.java

public static ArrayList<String> sortByValue(final HashMap<String, Integer> map) {
    ArrayList<String> key = new ArrayList<String>();
    key.addAll(map.keySet());/*from ww w .j  ava 2  s. com*/
    Collections.sort(key, new Comparator<Object>() {
        public int compare(Object o1, Object o2) {
            Integer v1 = map.get(o1);
            Integer v2 = map.get(o2);
            return v1.compareTo(v2);
        }
    });
    Collections.reverse(key);
    return key;
}

From source file:filterviewplugin.FilterViewSettings.java

private static ProgramFilter[] getAvailableFilters() {
    ProgramFilter[] allFilters = Plugin.getPluginManager().getFilterManager().getAvailableFilters().clone();
    Arrays.sort(allFilters, new Comparator<ProgramFilter>() {

        public int compare(ProgramFilter f1, ProgramFilter f2) {
            return f1.getName().compareToIgnoreCase(f2.getName());
        }/* ww w  . j av a 2 s.c  om*/
    });
    ArrayList<ProgramFilter> filters = new ArrayList<ProgramFilter>(Arrays.asList(allFilters));
    filters.remove(Plugin.getPluginManager().getFilterManager().getAllFilter());
    return filters.toArray(new ProgramFilter[filters.size()]);
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.IOHelper.java

/**
 * Sorts map by value (http://stackoverflow.com/a/2581754)
 *
 * @param map map//  w w  w  . ja  va2 s. co  m
 * @param <K> key
 * @param <V> value
 * @return sorted map by value
 */
public static <K, V extends Comparable<? super V>> LinkedHashMap<K, V> sortByValue(Map<K, V> map,
        final boolean asc) {
    List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
    Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
        @Override
        public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
            if (asc) {
                return (o1.getValue()).compareTo(o2.getValue());
            } else {
                return (o2.getValue()).compareTo(o1.getValue());
            }
        }
    });

    LinkedHashMap<K, V> result = new LinkedHashMap<>();
    for (Map.Entry<K, V> entry : list) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:com.pamarin.income.controller.NormalSettingsCtrl.java

private void sortBySymbolAscending() {
    Collections.sort(currencys, new Comparator<Currency>() {

        @Override//from ww  w  .ja  va 2 s  . com
        public int compare(Currency o1, Currency o2) {
            return o1.getSymbol().compareTo(o2.getSymbol());
        }
    });
}