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:org.gradle.model.internal.manage.schema.extract.ModelPropertyExtractionContext.java

public Set<ModelType<?>> getDeclaredBy() {
    ImmutableSortedSet.Builder<ModelType<?>> declaredBy = new ImmutableSortedSet.Builder<ModelType<?>>(
            Ordering.usingToString());
    for (PropertyAccessorExtractionContext accessor : accessors.values()) {
        for (Method method : accessor.getDeclaringMethods()) {
            declaredBy.add(ModelType.declaringType(method));
        }/*from  www  . java2  s.  c o  m*/
    }
    return declaredBy.build();
}

From source file:com.facebook.buck.jvm.java.JarBackedJavac.java

@Override
protected JavaCompiler createCompiler(JavacExecutionContext context) {
    ClassLoaderCache classLoaderCache = context.getClassLoaderCache();
    ClassLoader compilerClassLoader = classLoaderCache.getClassLoaderForClassPath(
            ClassLoader.getSystemClassLoader(),
            FluentIterable.from(context.getAbsolutePathsForInputs()).transform(PATH_TO_URL)
                    // Use "toString" since URL.equals does DNS lookups.
                    .toSortedSet(Ordering.usingToString()).asList());
    try {//from   w w w.  j a va  2s  . co m
        return (JavaCompiler) compilerClassLoader.loadClass(compilerClassName).newInstance();
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.crypto.sse.DynRH2Lev.java

public static TreeMultimap<String, byte[]> tokenUpdate(byte[] key, Multimap<String, String> lookup)
        throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException,
        NoSuchProviderException, NoSuchPaddingException, IOException {

    TreeMultimap<String, byte[]> tokenUp = TreeMultimap.create(Ordering.natural(), Ordering.usingToString());

    SecureRandom random = new SecureRandom();
    random.setSeed(CryptoPrimitives.randomSeed(16));
    byte[] iv = new byte[16];

    for (String word : lookup.keySet()) {

        byte[] key3 = CryptoPrimitives.generateCmac(key, 3 + new String());

        byte[] key4 = CryptoPrimitives.generateCmac(key, 4 + word);

        for (String id : lookup.get(word)) {
            random.nextBytes(iv);/* ww  w .  jav  a  2 s.  c o m*/

            int counter = 0;

            if (state.get(word) != null) {
                counter = state.get(word);
            }

            state.put(word, counter + 1);

            byte[] l = CryptoPrimitives.generateCmac(key4, "" + counter);

            byte[] value = CryptoPrimitives.encryptAES_CTR_String(key3, iv, id, sizeOfFileIdentifer);

            tokenUp.put(new String(l), value);
        }

    }

    return tokenUp;

}

From source file:org.clusion.DynRHAndroid.java

public static TreeMultimap<String, byte[]> tokenUpdate(byte[] key, Multimap<String, String> lookup)
        throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException,
        NoSuchProviderException, NoSuchPaddingException, IOException {

    // We use a lexicographic sorted list such that the server
    // will not know any information of the inserted elements creation order
    TreeMultimap<String, byte[]> tokenUp = TreeMultimap.create(Ordering.natural(), Ordering.usingToString());

    // Key generation
    for (String word : lookup.keySet()) {

        byte[] key2 = CryptoPrimitivesAndroid.generateCmac(key, 2 + word);
        // generate keys for response-hiding construction for SIV (Synthetic
        // IV)/*from  ww  w .  j  a  v  a2 s .  c  om*/
        byte[] key3 = CryptoPrimitivesAndroid.generateCmac(key, 3 + new String());

        byte[] key4 = CryptoPrimitivesAndroid.generateCmac(key, 4 + word);

        byte[] key5 = CryptoPrimitivesAndroid.generateCmac(key, 5 + word);

        for (String id : lookup.get(word)) {
            int counter = 0;

            if (state.get(word) != null) {
                counter = state.get(word);
            }

            state.put(word, counter + 1);

            byte[] l = CryptoPrimitivesAndroid.generateCmac(key5, "" + counter);

            String value = new String(CryptoPrimitivesAndroid.DTE_encryptAES_CTR_String(key3, key4, id, 20),
                    "ISO-8859-1");

            tokenUp.put(new String(l), CryptoPrimitivesAndroid.encryptAES_CTR_String(key2,
                    CryptoPrimitivesAndroid.randomBytes(16), value, sizeOfFileIdentifer));

        }

    }
    return tokenUp;
}

From source file:org.eclipse.recommenders.utils.Recommendations.java

public static Comparator<Recommendation<?>> compareByRelevance() {
    return new Comparator<Recommendation<?>>() {

        @Override//from ww w.  j  a v a  2s.com
        public int compare(Recommendation<?> o1, Recommendation<?> o2) {
            int res = -1 * Double.compare(o1.getRelevance(), o2.getRelevance());
            return res != 0 ? res : Ordering.usingToString().compare(o1, o2);
        }
    };
}

From source file:com.eviware.loadui.ui.fx.control.ToolBox.java

public void initialize() {
    getStyleClass().setAll(DEFAULT_STYLE_CLASS);

    label.getStyleClass().add("title");

    itemComparators.put(null, Ordering.usingToString());

    items.addListener(new ListChangeListener<E>() {
        @Override//  ww  w.  j  av a2s  . c  om
        public void onChanged(ListChangeListener.Change<? extends E> change) {
            while (change.next()) {
                for (E node : change.getRemoved()) {
                    node.getProperties().remove(TOOL_BOX_PROPERTY);
                }

                for (E node : change.getAddedSubList()) {
                    node.getProperties().put(TOOL_BOX_PROPERTY, this);
                }
            }
        }
    });
}

From source file:com.navercorp.pinpoint.web.service.AdminServiceImpl.java

@Override
public Map<String, List<Application>> getAgentIdMap() {
    Map<String, List<Application>> agentIdMap = new TreeMap<>(Ordering.usingToString());
    List<Application> applications = this.applicationIndexDao.selectAllApplicationNames();
    for (Application application : applications) {
        List<String> agentIds = this.applicationIndexDao.selectAgentIds(application.getName());
        for (String agentId : agentIds) {
            if (!agentIdMap.containsKey(agentId)) {
                agentIdMap.put(agentId, new ArrayList<Application>());
            }//from   w w w .j a va  2 s . c  o m
            agentIdMap.get(agentId).add(application);
        }
    }
    return agentIdMap;
}

From source file:dk.frankbille.scoreboard.components.LeagueSelector.java

public LeagueSelector(String id, IModel<League> model) {
    super(id, model);

    setRenderBodyOnly(true);//from   ww w.j av a2s. co m

    final IModel<SortedMap<Boolean, Set<League>>> allLeaguesModel = new LoadableDetachableModel<SortedMap<Boolean, Set<League>>>() {
        @Override
        protected SortedMap<Boolean, Set<League>> load() {
            SortedMap<Boolean, Set<League>> groupedLeagues = new TreeMap<Boolean, Set<League>>(
                    Ordering.natural().reverse());

            List<League> allLeagues = scoreBoardService.getAllLeagues();
            for (League league : allLeagues) {
                Set<League> leaguesByState = groupedLeagues.get(league.isActive());
                if (leaguesByState == null) {
                    leaguesByState = new HashSet<League>();
                    groupedLeagues.put(league.isActive(), leaguesByState);
                }
                leaguesByState.add(league);
            }

            return groupedLeagues;
        }
    };

    IModel<List<Boolean>> leagueStatesModel = new LoadableDetachableModel<List<Boolean>>() {
        @Override
        protected List<Boolean> load() {
            return new ArrayList<Boolean>(allLeaguesModel.getObject().keySet());
        }
    };

    Select<League> select = new Select<League>("select", model) {

    };
    select.add(new Select2Enabler());
    select.add(AttributeAppender.replace("class", new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            return LeagueSelector.this.getMarkupAttributes().getString("class", "");
        }
    }));
    add(select);

    select.add(new ListView<Boolean>("leagueGroups", leagueStatesModel) {

        @Override
        protected void populateItem(ListItem<Boolean> item) {
            item.add(AttributeAppender.replace("label",
                    new StringResourceModel("active.${modelObject}", new Model<Serializable>(item))));

            List<League> leagueList = Ordering.usingToString()
                    .sortedCopy(allLeaguesModel.getObject().get(item.getModelObject()));

            item.add(new SelectOptions<League>("leagues", leagueList, new IOptionRenderer<League>() {
                @Override
                public String getDisplayValue(League league) {
                    return league.getName();
                }

                @Override
                public IModel<League> getModel(League league) {
                    return new Model<League>(league);
                }
            }));
        }
    });
}

From source file:com.facebook.buck.java.JarBackedJavac.java

@Override
protected JavaCompiler createCompiler(ExecutionContext context, final SourcePathResolver resolver) {
    ClassLoaderCache classLoaderCache = context.getClassLoaderCache();
    ClassLoader compilerClassLoader = classLoaderCache.getClassLoaderForClassPath(
            ClassLoader.getSystemClassLoader(),
            FluentIterable.from(classpath).transformAndConcat(new Function<SourcePath, Collection<Path>>() {
                @Override/*from   w ww . j  a v  a2  s . c om*/
                public Collection<Path> apply(SourcePath input) {
                    Set<Path> paths = new HashSet<>();
                    Optional<BuildRule> rule = resolver.getRule(input);
                    if (rule instanceof JavaLibrary) {
                        paths.addAll(((JavaLibrary) rule).getTransitiveClasspathEntries().values());
                    } else {
                        paths.add(resolver.getPath(input));
                    }
                    return paths;
                }
            }).transform(PATH_TO_URL)
                    // Use "toString" since URL.equals does DNS lookups.
                    .toSortedSet(Ordering.usingToString()).asList());
    try {
        return (JavaCompiler) compilerClassLoader.loadClass(compilerClassName).newInstance();
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.gradle.internal.component.AmbiguousConfigurationSelectionException.java

static void formatConfiguration(StringBuilder sb, AttributeContainer fromConfigurationAttributes,
        AttributesSchema consumerSchema, List<ConfigurationMetadata> matches, Set<String> requestedAttributes,
        int maxConfLength, final String conf) {
    Optional<ConfigurationMetadata> match = Iterables.tryFind(matches, new Predicate<ConfigurationMetadata>() {
        @Override/*from w  w w.j  a va  2s .c  om*/
        public boolean apply(ConfigurationMetadata input) {
            return conf.equals(input.getName());
        }
    });
    if (match.isPresent()) {
        AttributeContainer producerAttributes = match.get().getAttributes();
        Set<Attribute<?>> targetAttributes = producerAttributes.keySet();
        Set<String> targetAttributeNames = Sets
                .newTreeSet(Iterables.transform(targetAttributes, ATTRIBUTE_NAME));
        Set<Attribute<?>> allAttributes = Sets.union(fromConfigurationAttributes.keySet(),
                producerAttributes.keySet());
        Set<String> commonAttributes = Sets.intersection(requestedAttributes, targetAttributeNames);
        Set<String> consumerOnlyAttributes = Sets.difference(requestedAttributes, targetAttributeNames);
        sb.append("   ").append("- Configuration '").append(StringUtils.rightPad(conf + "'", maxConfLength + 1))
                .append(" :");
        List<Attribute<?>> sortedAttributes = Ordering.usingToString().sortedCopy(allAttributes);
        List<String> values = new ArrayList<String>(sortedAttributes.size());
        formatAttributes(sb, fromConfigurationAttributes, consumerSchema, producerAttributes, commonAttributes,
                consumerOnlyAttributes, sortedAttributes, values);
    }
}