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

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

Introduction

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

Prototype

@GwtCompatible(serializable = true)
public static Ordering<Object> usingToString() 

Source Link

Document

Returns an ordering that compares objects by the natural ordering of their string representations as returned by toString() .

Usage

From source file:com.github.jsdossier.DocWriter.java

private Iterable<Comment> getImplementedTypes(NominalType nominalType) {
    Set<JSType> interfaces = typeRegistry.getImplementedTypes(nominalType);
    return transform(Ordering.usingToString().sortedCopy(interfaces), new Function<JSType, Comment>() {
        @Override/*from  w  w w  . ja  v a  2  s .com*/
        public Comment apply(JSType input) {
            return linker.formatTypeExpression(input);
        }
    });
}

From source file:org.eclipse.sirius.business.internal.movida.registry.ViewpointRegistry.java

public void dumpStatus(StringBuilder out) {
    out.append("Entries:\n"); //$NON-NLS-1$
    for (URI uri : Ordering.usingToString().sortedCopy(entries.keySet())) {
        Entry entry = entries.get(uri);/*from   ww  w.j  ava 2  s. co  m*/
        out.append(" - ").append(uri).append(" => ").append(entry.getResource().getURI()).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    }

    out.append("\n"); //$NON-NLS-1$
    out.append("ResourceSet:\n"); //$NON-NLS-1$
    for (Resource res : resourceSet.getResources()) {
        out.append(" - ").append(res.getURI()).append(" [loaded=").append(String.valueOf(res.isLoaded())) //$NON-NLS-1$//$NON-NLS-2$
                .append("]").append("\n"); //$NON-NLS-1$ //$NON-NLS-2$
        out.append("\tResolved dependencies:\n\t\t") //$NON-NLS-1$
                .append(Joiner.on("\n\t\t").join(new ResourceQuery(res).getResolvedDependencies())) //$NON-NLS-1$
                .append("\n"); //$NON-NLS-1$
        out.append("\tUnresolved dependencies:\n\t\t") //$NON-NLS-1$
                .append(Joiner.on("\n\t\t").join(new ResourceQuery(res).getUnresolvedDependencies())) //$NON-NLS-1$
                .append("\n"); //$NON-NLS-1$
    }

    out.append("\n"); //$NON-NLS-1$
    out.append("Transitive dependencies:\n"); //$NON-NLS-1$
    ViewpointDependenciesTracker tracker = new ViewpointDependenciesTracker(this);
    for (URI uri : Sets.newHashSet(entries.keySet())) {
        if (uri.toString().startsWith("viewpoint:/t/")) { //$NON-NLS-1$
            tracker.add(uri);
        }
    }
    for (URI uri : tracker.getTrackedElements()) {
        out.append(uri).append("\n"); //$NON-NLS-1$
        out.append(" - direct:  ").append(Joiner.on(", ").join(tracker.getDependencies(uri))).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        out.append(" - reverse: ").append(Joiner.on(", ").join(tracker.getReverseDependencies(uri))) //$NON-NLS-1$//$NON-NLS-2$
                .append("\n"); //$NON-NLS-1$
        out.append("\n"); //$NON-NLS-1$
    }
    tracker.dispose();
}

From source file:com.mycelium.wallet.Utils.java

public static List<Address> sortAddresses(List<Address> addresses) {
    return Ordering.usingToString().sortedCopy(addresses);
}

From source file:com.facebook.presto.metadata.StaticFunctionNamespace.java

private List<ApplicableFunction> selectMostSpecificFunctions(List<ApplicableFunction> applicableFunctions,
        List<TypeSignatureProvider> parameters) {
    checkArgument(!applicableFunctions.isEmpty());

    List<ApplicableFunction> mostSpecificFunctions = selectMostSpecificFunctions(applicableFunctions);
    if (mostSpecificFunctions.size() <= 1) {
        return mostSpecificFunctions;
    }//from w ww .  j a v a 2 s  . c om

    Optional<List<Type>> optionalParameterTypes = toTypes(parameters, typeManager);
    if (!optionalParameterTypes.isPresent()) {
        // give up and return all remaining matches
        return mostSpecificFunctions;
    }

    List<Type> parameterTypes = optionalParameterTypes.get();
    if (!someParameterIsUnknown(parameterTypes)) {
        // give up and return all remaining matches
        return mostSpecificFunctions;
    }

    // look for functions that only cast the unknown arguments
    List<ApplicableFunction> unknownOnlyCastFunctions = getUnknownOnlyCastFunctions(applicableFunctions,
            parameterTypes);
    if (!unknownOnlyCastFunctions.isEmpty()) {
        mostSpecificFunctions = unknownOnlyCastFunctions;
        if (mostSpecificFunctions.size() == 1) {
            return mostSpecificFunctions;
        }
    }

    // If the return type for all the selected function is the same, and the parameters are declared as RETURN_NULL_ON_NULL
    // all the functions are semantically the same. We can return just any of those.
    if (returnTypeIsTheSame(mostSpecificFunctions)
            && allReturnNullOnGivenInputTypes(mostSpecificFunctions, parameterTypes)) {
        // make it deterministic
        ApplicableFunction selectedFunction = Ordering.usingToString().reverse()
                .sortedCopy(mostSpecificFunctions).get(0);
        return ImmutableList.of(selectedFunction);
    }

    return mostSpecificFunctions;
}