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:com.github.jinahya.sql.database.metadata.bind.PrimaryKey.java

public static Comparator<PrimaryKey> natural() {

    return new Comparator<PrimaryKey>() {

        @Override//  w ww. j av  a  2 s.co m
        public int compare(final PrimaryKey o1, final PrimaryKey o2) {

            // by COLUMN_NAME.
            return new CompareToBuilder().append(o1.getColumnName(), o2.getColumnName()).build();
        }

    };
}

From source file:fr.ribesg.bukkit.ncore.updater.FileDescription.java

public static SortedMap<String, FileDescription> parse(final String jsonString) {
    final SortedMap<String, FileDescription> result = new TreeMap<>(new Comparator<String>() {

        @Override/*  w  w  w . j ava  2s  .  c om*/
        public int compare(final String a, final String b) {
            return -a.compareTo(b);
        }
    });
    final JSONArray array = (JSONArray) JSONValue.parse(jsonString);
    for (final Object o : array.toArray()) {
        final JSONObject object = (JSONObject) o;
        final String fileName = (String) object.get(FILENAME_KEY);
        final String version = VersionUtil.getVersion((String) object.get(VERSION_KEY));
        final String bukkitVersion = (String) object.get(BUKKIT_VERSION_KEY);
        final String type = (String) object.get(TYPE_KEY);
        final String link = (String) object.get(DOWNLOAD_URL_KEY);
        final FileDescription fileDescription = new FileDescription(fileName, version, link, type,
                bukkitVersion);
        if (VersionUtil.isRelease(version)) {
            result.put(version, fileDescription);
        }
    }
    return result;
}

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

public static Comparator<TablePrivilege> natural() {

    return new Comparator<TablePrivilege>() {

        @Override//w ww  .j  a v  a2 s  .  com
        public int compare(final TablePrivilege o1, final TablePrivilege o2) {

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

    };
}

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

public static Comparator<Operation> nickNameComparator() {
    return new Comparator<Operation>() {
        @Override/*w ww.j  av a  2s  .c  o  m*/
        public int compare(Operation first, Operation second) {
            return nullToEmpty(first.getUniqueId()).compareTo(nullToEmpty(second.getUniqueId()));
        }
    };
}

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

public static Comparator<ColumnPrivilege> natural() {

    return new Comparator<ColumnPrivilege>() {

        @Override/*from  w  ww.  j  av a  2  s .c  om*/
        public int compare(final ColumnPrivilege o1, final ColumnPrivilege o2) {

            // by COLUMN_NAME and PRIVILEGE.
            return new CompareToBuilder().append(o1.getColumnName(), o2.getColumnName())
                    .append(o1.getPrivilege(), o2.getPrivilege()).build();
        }

    };
}

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

public static Comparator<BestRowIdentifier> natural() {

    return new Comparator<BestRowIdentifier>() {

        @Override//  w  ww .  j  ava  2 s  .  c om
        public int compare(final BestRowIdentifier o1, final BestRowIdentifier o2) {

            // They are ordered by SCOPE.
            return o1.getScope() - o2.getScope();
        }

    };
}

From source file:com.cronutils.model.field.CronField.java

public static Comparator<CronField> createFieldComparator() {
    return new Comparator<CronField>() {
        @Override/*from   w  ww.j av  a2s.c om*/
        public int compare(CronField o1, CronField o2) {
            return o1.getField().getOrder() - o2.getField().getOrder();
        }
    };
}

From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.RecBase.java

public static <T extends RecBase> void sortByIdx(List<T> list, final int idx, boolean desc) {
    if (desc == true) {
        Collections.sort(list, new Comparator<T>() {

            @Override//from w  ww .  j a  va  2  s .  c  o m
            public int compare(T o1, T o2) {
                return o2.get(idx).compareTo(o1.get(idx));
            }
        });
    } else {
        Collections.sort(list, new Comparator<T>() {

            @Override
            public int compare(T o1, T o2) {
                return o1.get(idx).compareTo(o2.get(idx));
            }
        });
    }
}

From source file:Main.java

/** Returns an alphabetically sorted list of the keys. */
public static Vector getSortedKeyList(Hashtable hashtable) {
    Vector result = new Vector();
    Enumeration keys = hashtable.keys();
    while (keys.hasMoreElements()) {
        result.add(keys.nextElement());//from w  ww.ja v a 2  s .  c o m
    }
    Collections.sort(result, new Comparator() {
        public int compare(Object a, Object b) {
            String textA = a.toString();
            String textB = b.toString();

            return textA.compareToIgnoreCase(textB);
        }
    });

    return result;
}

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

public static Comparator<Catalog> natural() {

    return new Comparator<Catalog>() {

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

            //  by catalog name
            return new CompareToBuilder().append(o1.getTableCat(), o2.getTableCat()).build();
        }

    };
}