Example usage for com.google.common.collect Ordering from

List of usage examples for com.google.common.collect Ordering from

Introduction

In this page you can find the example usage for com.google.common.collect Ordering from.

Prototype

@GwtCompatible(serializable = true)
@Deprecated
public static <T> Ordering<T> from(Ordering<T> ordering) 

Source Link

Document

Simply returns its argument.

Usage

From source file:com.wrmsr.nativity.x86.App.java

public static void main(String[] args) throws Exception {
    logger.info("hi");

    Document doc;//w  ww  .j  a  va 2  s . c om
    try (InputStream is = App.class.getClassLoader().getResourceAsStream("x86reference.xml")) {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
        dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        doc = dBuilder.parse(is);
    }

    //optional, but recommended
    //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
    doc.getDocumentElement().normalize();

    List<Ref.Entry> entries = Lists.newArrayList();
    Ref.Parsing.parseRoot(doc, entries);
    ByteTrie<Ref.Entry> trie = DisImpl.buildTrie(entries);

    System.out.println(trie.toDetailedString());
    System.out.println();
    System.out.println();

    // Dis.run(trie);

    Ordering<Pair<Ref.Operand.Type, Ref.Operand.Address>> ord = Ordering.from((o1, o2) -> {
        int c = ObjectUtils.compare(o1.getLeft(), o2.getLeft());
        if (c == 0) {
            c = ObjectUtils.compare(o1.getRight(), o2.getRight());
        }
        return c;
    });

    Set<Pair<Ref.Operand.Type, Ref.Operand.Address>> set = Sets.newHashSet();
    for (Ref.Entry entry : entries) {
        for (Ref.Syntax syntax : entry.getSyntaxes()) {
            for (Ref.Operand operand : syntax.getOperands()) {
                set.add(new ImmutablePair<>(operand.type, operand.address));
            }
        }
    }
    for (Pair<Ref.Operand.Type, Ref.Operand.Address> pair : ord.sortedCopy(set)) {
        System.out.println(pair);
    }
    System.out.println("\n");

    DisImpl.run(trie);
}

From source file:com.stackframe.bentographer.BentoGrapher.java

/**
 * @param args the command line arguments
 *//*from  w  ww  . jav  a  2 s . com*/
public static void main(String[] args) throws Exception {
    Class.forName("org.sqlite.JDBC");
    File db = findDatabase();
    Connection connection = openConnection(db);
    try {
        Map<String, Library> libraries = getLibraries(connection);
        String selected = (String) select(libraries.keySet(), "Choose Library", "Library");
        Library library = libraries.get(selected);
        Collection<Field> fields = getFields(connection, library);

        fields = Collections2.filter(fields, new Predicate<Field>() {

            @Override
            public boolean apply(Field t) {
                return !ignorableFields.contains(t.type);
            }
        });

        Comparator<Field> dateComparator = makeTypeComparator("com.filemaker.bento.field.core.date");
        Comparator<Field> dateCreatedComparator = makeTypeComparator(
                "com.filemaker.bento.field.private.timestamp.dateCreated");
        Comparator<Field> dateModifiedComparator = makeTypeComparator(
                "com.filemaker.bento.field.private.timestamp.dateModified");
        Ordering<Field> xOrdering = Ordering.from(dateComparator).compound(dateCreatedComparator)
                .compound(dateModifiedComparator);
        Collection<Field> sortedXFields = xOrdering.immutableSortedCopy(fields);

        // FIXME: This depends on the implemenation of Field.toString() returning the type name. It should use a Renderer or something.
        final Field x = (Field) select(sortedXFields, "Choose X", "X");

        fields = Collections2.filter(fields, new Predicate<Field>() {

            @Override
            public boolean apply(Field t) {
                return t != x;
            }
        });

        Ordering<Field> yOrdering = Ordering.from(Collections.reverseOrder(dateModifiedComparator))
                .compound(Collections.reverseOrder(dateCreatedComparator))
                .compound(Collections.reverseOrder(dateComparator));
        Collection<Field> sortedYFields = yOrdering.immutableSortedCopy(fields);
        Field y = (Field) select(sortedYFields, "Choose Y", "Y");

        // FIXME: Make the rendering of dates smart. It looks like date is seconds since 1/1/2001 and is defined by Core Data.
        // FIXME: Make the graphs printable.
        // FIXME: Make it easy to dynamically add more Y values to same graph.
        // FIXME: Package up a binary that is easy to run. (JNLP/Web Startable?)
        // FIXME: Publish some screenshots to make it easier to understand what this is for.
        // FIXME: Make it possible to save graph paramters and automatically bring them back up.
        // FIXME: Make setting of min as 0 configurable.
        // FIXME: Fix graph to show actual data points on lines.

        makeGraph(connection, library, x, y);
    } finally {
        connection.close();
    }
}

From source file:nz.co.testamation.common.util.CollectionUtil.java

public static <T extends Comparable> T getMax(Collection<T> collection) {
    if (collection == null || collection.isEmpty()) {
        return null;
    }/*from  w  w  w.ja  v  a  2 s . co m*/

    return Ordering.from(new Comparator<T>() {
        @Override
        public int compare(T o1, T o2) {
            return o1.compareTo(o2);
        }
    }).max(collection);
}

From source file:com.google.errorprone.bugpatterns.testdata.OrderingFromPositiveCases.java

public static void positiveCase1() {
    // BUG: Diagnostic contains: new Ordering<String>(
    Ordering<String> ord = Ordering.from(new Comparator<String>() {
        @Override//from   w w  w .  ja v  a2 s . c  o  m
        public int compare(String first, String second) {
            int compare = first.length() - second.length();
            return (compare != 0) ? compare : first.compareTo(second);
        }
    });
}

From source file:com.google.errorprone.bugpatterns.OrderingFromNegativeCases.java

public static void negativeCase1() {
    Comparator<String> comparator = new Comparator<String>() {
        @Override//  ww w .j  ava2  s  .  c  om
        public int compare(String first, String second) {
            int compare = first.length() - second.length();
            return (compare != 0) ? compare : first.compareTo(second);
        }
    };
    Ordering<String> ord = Ordering.from(comparator);
}

From source file:de.flapdoodle.guava.Sort.java

public static <T> List<T> sortBy(Iterable<T> source, Comparator<? super T> comparator) {
    return Ordering.from(comparator).sortedCopy(source);
}

From source file:moavns.SolucaoAleatoria.java

public static Solucao VizinhoRedundancia(Solucao inicio) {
    Comparator comparador = new Comparador();
    Ordering<Float> ordenacao = Ordering.natural();
    Comparator ordenacao1 = ordenacao;
    Ordering<Solucao> ordenacao2 = Ordering.from(comparador);
    Multimap<Float, Solucao> novassolucoes = TreeMultimap.create(ordenacao1, ordenacao2);
    for (Integer entrada : inicio.getLinhasX().keySet()) {
        Solucao novasolucao = new Solucao(inicio);
        Coluna testar = inicio.getLinhasX().get(entrada);
        novasolucao.getColunas().add(testar);
        novasolucao.setCustototal(novasolucao.getCustototal() + testar.getCusto());
        Solucao solucaox = eliminarRedundancia(novasolucao);
        String stringsolucao = MOAVNS.transformaSolucao(solucaox);
        if (!MOAVNS.solucoes.contains(stringsolucao)) {
            return solucaox;
        }/*from   w  w  w . j  a  v  a2 s . co m*/
    }
    return inicio;
}

From source file:org.eclipse.sirius.table.business.internal.metamodel.operations.DColumnOperations.java

/**
 * Sort the column cells considering their index and return them.
 *
 * @param column//from  w  w w  .  ja  va  2 s .c  om
 *            column.
 * @return a sorted set of cells.
 */
public static Collection<DCell> getOrderedCells(final DColumn column) {
    final Map<DLine, Integer> lineIndices = Maps.newHashMap();
    fillIndices(column.getTable(), lineIndices, 0);
    Ordering<DCell> ordering = Ordering.from(new Comparator<DCell>() {
        @Override
        public int compare(DCell a, DCell b) {
            int result = 0;
            DLine lineA = a.getLine();
            DLine lineB = b.getLine();
            if (lineA == null) {
                result = -1;
            } else if (lineB == null) {
                result = 1;
            } else {
                Integer aIndex = lineIndices.get(lineA);
                Integer bIndex = lineIndices.get(lineB);
                if (aIndex == null || bIndex == null) {
                    throw new RuntimeException(Messages.Table_UnexpectedExceptionMessage);
                }
                return aIndex - bIndex;
            }
            return result;
        }
    });
    List<DCell> result = ordering.sortedCopy(column.getCells());
    return result;
}

From source file:com.eviware.loadui.util.collections.SafeExplicitOrdering.java

public static <T> Ordering<T> of(List<T> valuesInOrder) {
    return Ordering.from(new SafeExplicitOrdering<>(valuesInOrder));
}

From source file:de.flapdoodle.guava.Sort.java

public static <T, S> Ordering<T> orderBy(Function<T, S> sortTransformation, Comparator<? super S> comparator) {
    return Ordering.from(comparator).onResultOf(sortTransformation);
}