Example usage for com.google.common.collect SortedSetMultimap get

List of usage examples for com.google.common.collect SortedSetMultimap get

Introduction

In this page you can find the example usage for com.google.common.collect SortedSetMultimap get.

Prototype

@Override
SortedSet<V> get(@Nullable K key);

Source Link

Document

Returns a collection view of all values associated with a key.

Usage

From source file:org.terasology.documentation.ApiScraper.java

/**
 * @param args (ignored)/*from  w  w w . ja  va  2 s .c  om*/
 * @throws Exception if the module environment cannot be loaded
 */
public static void main(String[] args) throws Exception {
    ModuleManager moduleManager = ModuleManagerFactory.create();
    ModuleEnvironment environment = moduleManager.getEnvironment();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

    SortedSetMultimap<String, String> sortedApi = Multimaps.newSortedSetMultimap(new HashMap<>(), TreeSet::new);

    for (Class<?> apiClass : environment.getTypesAnnotatedWith(API.class)) {
        //System.out.println("Processing: " + apiClass);
        boolean isPackage = apiClass.isSynthetic();
        URL location;
        String category;
        String apiPackage = "";
        if (isPackage) {
            apiPackage = apiClass.getPackage().getName();
            location = classLoader.getResource(apiPackage.replace('.', '/'));
        } else {

            location = apiClass.getResource('/' + apiClass.getName().replace('.', '/') + ".class");
        }

        if (location == null) {
            System.out.println("Failed to get a class/package location, skipping " + apiClass);
            continue;
        }

        switch (location.getProtocol()) {
        case "jar":

            // Find out what jar it came from and consider that the category
            String categoryFragment = location.getPath();
            //System.out.println("category fragment as path: " + categoryFragment);
            int bang = categoryFragment.lastIndexOf("!");
            int hyphen = categoryFragment.lastIndexOf("-", bang);
            int slash = categoryFragment.lastIndexOf("/", hyphen);
            category = categoryFragment.substring(slash + 1, hyphen);
            //System.out.println("category fragment pared down: " + category);

            if (isPackage) {
                //System.out.println("Jar-based Package: " + apiPackage + ", came from " + location);
                sortedApi.put(category, apiPackage + " (PACKAGE)");
            } else {
                //System.out.println("Jar-based Class: " + apiClass + ", came from " + location);
                sortedApi.put(category,
                        apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)"));
            }

            break;

        case "file":

            // If file based we know it is local so organize it like that
            category = "terasology engine";

            if (isPackage) {
                //System.out.println("Local Package: " + apiPackage + ", came from " + location);
                sortedApi.put(category, apiPackage + " (PACKAGE)");
            } else {
                //System.out.println("Local Class: " + apiClass + ", came from " + location);
                sortedApi.put(category,
                        apiClass.getName() + (apiClass.isInterface() ? " (INTERFACE)" : " (CLASS)"));
            }

            break;

        default:
            System.out.println("Unknown protocol for: " + apiClass + ", came from " + location);
        }
    }
    sortedApi.putAll("external", ExternalApiWhitelist.CLASSES.stream()
            .map(clazz -> clazz.getName() + " (CLASS)").collect(Collectors.toSet()));
    sortedApi.putAll("external", ExternalApiWhitelist.PACKAGES.stream().map(packagee -> packagee + " (PACKAGE)")
            .collect(Collectors.toSet()));

    System.out.println("# Modding API:\n");
    for (String key : sortedApi.keySet()) {
        System.out.println("## " + key + "\n");
        for (String value : sortedApi.get(key)) {
            System.out.println("* " + value);
        }
        System.out.println("");
    }
}

From source file:org.ambraproject.wombat.model.TaxonomyGraph.java

/**
 * @param categoryPaths a list of all slash-delimited category paths in the taxonomy
 * @return a parsed graph representation of the taxonomy
 *//*from  www . j a v a2s  .c om*/
public static TaxonomyGraph create(Collection<String> categoryPaths) {
    Set<String> names = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
    SortedSetMultimap<String, String> parentsToChildren = caseInsensitiveSetMultimap();
    SortedSetMultimap<String, String> childrenToParents = caseInsensitiveSetMultimap();
    for (String categoryPath : categoryPaths) {
        List<String> categories = parseTerms(categoryPath);
        for (int i = 0; i < categories.size(); i++) {
            String node = categories.get(i);
            names.add(node);
            if (i > 0) {
                String parent = categories.get(i - 1);
                parentsToChildren.put(parent, node);
                childrenToParents.put(node, parent);
            }
        }
    }

    ImmutableSortedMap.Builder<String, CategoryInfo> categoryMap = ImmutableSortedMap
            .orderedBy(String.CASE_INSENSITIVE_ORDER);
    for (String name : names) {
        categoryMap.put(name, new CategoryInfo(name, childrenToParents.get(name), parentsToChildren.get(name)));
    }

    return new TaxonomyGraph(categoryMap.build());
}

From source file:org.apache.beam.sdk.options.PipelineOptionsValidator.java

/**
 * Validates that the passed {@link PipelineOptions} conforms to all the validation criteria from
 * the passed in interface.//from   ww w.  j  a v  a 2s  .  com
 *
 * <p>Note that the interface requested must conform to the validation criteria specified on
 * {@link PipelineOptions#as(Class)}.
 *
 * @param klass The interface to fetch validation criteria from.
 * @param options The {@link PipelineOptions} to validate.
 * @return The type
 */
public static <T extends PipelineOptions> T validate(Class<T> klass, PipelineOptions options) {
    checkNotNull(klass);
    checkNotNull(options);
    checkArgument(Proxy.isProxyClass(options.getClass()));
    checkArgument(Proxy.getInvocationHandler(options) instanceof ProxyInvocationHandler);

    // Ensure the methods for T are registered on the ProxyInvocationHandler
    T asClassOptions = options.as(klass);

    ProxyInvocationHandler handler = (ProxyInvocationHandler) Proxy.getInvocationHandler(asClassOptions);

    SortedSetMultimap<String, Method> requiredGroups = TreeMultimap.create(Ordering.natural(),
            PipelineOptionsFactory.MethodNameComparator.INSTANCE);
    for (Method method : ReflectHelpers.getClosureOfMethodsOnInterface(klass)) {
        Required requiredAnnotation = method.getAnnotation(Validation.Required.class);
        if (requiredAnnotation != null) {
            if (requiredAnnotation.groups().length > 0) {
                for (String requiredGroup : requiredAnnotation.groups()) {
                    requiredGroups.put(requiredGroup, method);
                }
            } else {
                checkArgument(handler.invoke(asClassOptions, method, null) != null,
                        "Missing required value for [%s, \"%s\"]. ", method, getDescription(method));
            }
        }
    }

    for (String requiredGroup : requiredGroups.keySet()) {
        if (!verifyGroup(handler, asClassOptions, requiredGroups.get(requiredGroup))) {
            throw new IllegalArgumentException("Missing required value for group [" + requiredGroup
                    + "]. At least one of the following properties "
                    + Collections2.transform(requiredGroups.get(requiredGroup), ReflectHelpers.METHOD_FORMATTER)
                    + " required. Run with --help=" + klass.getSimpleName() + " for more information.");
        }
    }

    return asClassOptions;
}

From source file:com.google.cloud.dataflow.sdk.options.PipelineOptionsValidator.java

/**
 * Validates that the passed {@link PipelineOptions} conforms to all the validation criteria from
 * the passed in interface./* ww w  . j av a2 s  .  c  o m*/
 *
 * <p>Note that the interface requested must conform to the validation criteria specified on
 * {@link PipelineOptions#as(Class)}.
 *
 * @param klass The interface to fetch validation criteria from.
 * @param options The {@link PipelineOptions} to validate.
 * @return The type
 */
public static <T extends PipelineOptions> T validate(Class<T> klass, PipelineOptions options) {
    checkNotNull(klass);
    checkNotNull(options);
    checkArgument(Proxy.isProxyClass(options.getClass()));
    checkArgument(Proxy.getInvocationHandler(options) instanceof ProxyInvocationHandler);

    // Ensure the methods for T are registered on the ProxyInvocationHandler
    T asClassOptions = options.as(klass);

    ProxyInvocationHandler handler = (ProxyInvocationHandler) Proxy.getInvocationHandler(asClassOptions);

    SortedSetMultimap<String, Method> requiredGroups = TreeMultimap.create(Ordering.natural(),
            PipelineOptionsFactory.MethodNameComparator.INSTANCE);
    for (Method method : ReflectHelpers.getClosureOfMethodsOnInterface(klass)) {
        Required requiredAnnotation = method.getAnnotation(Validation.Required.class);
        if (requiredAnnotation != null) {
            if (requiredAnnotation.groups().length > 0) {
                for (String requiredGroup : requiredAnnotation.groups()) {
                    requiredGroups.put(requiredGroup, method);
                }
            } else {
                checkArgument(handler.invoke(asClassOptions, method, null) != null,
                        "Missing required value for [" + method + ", \"" + getDescription(method) + "\"]. ");
            }
        }
    }

    for (String requiredGroup : requiredGroups.keySet()) {
        if (!verifyGroup(handler, asClassOptions, requiredGroups.get(requiredGroup))) {
            throw new IllegalArgumentException("Missing required value for group [" + requiredGroup
                    + "]. At least one of the following properties "
                    + Collections2.transform(requiredGroups.get(requiredGroup), ReflectHelpers.METHOD_FORMATTER)
                    + " required. Run with --help=" + klass.getSimpleName() + " for more information.");
        }
    }

    return asClassOptions;
}

From source file:org.gradle.cache.internal.VersionSpecificCacheCleanupAction.java

private void performCleanup(CleanupProgressMonitor progressMonitor) {
    MinimumTimestampProvider minimumTimestampProvider = new MinimumTimestampProvider();
    SortedSetMultimap<GradleVersion, VersionSpecificCacheDirectory> cacheDirsByBaseVersion = scanForVersionSpecificCacheDirs();
    for (GradleVersion baseVersion : cacheDirsByBaseVersion.keySet()) {
        performCleanup(cacheDirsByBaseVersion.get(baseVersion), minimumTimestampProvider, progressMonitor);
    }//from   w  w  w  . j a va 2 s.  co  m
    markCleanedUp();
}

From source file:org.lobid.lodmill.ElasticsearchIndexer.java

private void updateAliases(final String name, final String suffix) {
    final SortedSetMultimap<String, String> indices = groupByIndexCollection(name);
    for (String prefix : indices.keySet()) {
        final SortedSet<String> indicesForPrefix = indices.get(prefix);
        final String newIndex = indicesForPrefix.last();
        final String newAlias = prefix + suffix;
        LOG.info("Prefix " + prefix + ", newest index: " + newIndex);
        removeOldAliases(indicesForPrefix, newAlias);
        if (!name.equals(newAlias) && !newIndex.equals(newAlias))
            createNewAlias(newIndex, newAlias);
        deleteOldIndices(name, indicesForPrefix);
    }//from  ww w  .j a v a  2s  .  co  m
}

From source file:org.lobid.lodmill.ElasticsearchIndexer.java

private void getNewestIndex() {
    String indexNameWithoutTimestamp = indexName.replaceAll("20.*", "");
    final SortedSetMultimap<String, String> indices = groupByIndexCollection(indexName);
    for (String prefix : indices.keySet()) {
        final SortedSet<String> indicesForPrefix = indices.get(prefix);
        final String newestIndex = indicesForPrefix.last();
        if (newestIndex.startsWith(indexNameWithoutTimestamp))
            indexName = newestIndex;/*from  w w  w  .  j a  v  a2s  .c  o  m*/
    }
    LOG.info("Going to UPDATE existing index " + indexName);
}

From source file:org.lobid.lodmill.hadoop.NTriplesToJsonLd.java

private void updateAliases(final String name, final String suffix) {
    final SortedSetMultimap<String, String> indices = groupByIndexCollection();
    for (String prefix : indices.keySet()) {
        final SortedSet<String> indicesForPrefix = indices.get(prefix);
        final String newIndex = indicesForPrefix.last();
        final String newAlias = prefix + suffix;
        LOG.info(format("Prefix '%s', newest index: %s", prefix, newIndex));
        removeOldAliases(indicesForPrefix, newAlias);
        createNewAlias(newIndex, newAlias);
        deleteOldIndices(name, indicesForPrefix);
    }// www . j av  a2 s  . c  o  m
}

From source file:uk.ac.ebi.atlas.bioentity.BioEntityPageController.java

protected void initBioentityPropertyService(String identifier) {
    String species = speciesLookupService.fetchSpeciesForBioentityId(identifier);

    SortedSetMultimap<String, String> propertyValuesByType = bioEntityPropertyDao
            .fetchGenePageProperties(identifier, getPagePropertyTypes());
    SortedSet<String> entityNames = propertyValuesByType.get(getBioentityPropertyName());
    if (entityNames.isEmpty()) {
        entityNames.add(identifier);//w ww  .ja  va  2 s.c o m
    }

    ImmutableSetMultimap<Integer, GoPoTerm> goTerms = mapGoTermsByDepth(propertyValuesByType.get("go"));
    ImmutableSetMultimap<Integer, GoPoTerm> poTerms = mapPoTermsByDepth(propertyValuesByType.get("po"));

    bioEntityPropertyService.init(species, propertyValuesByType, goTerms, poTerms, entityNames, identifier);
}

From source file:eu.interedition.collatex.lab.VariantGraphLayout.java

private void fillLevels() {
    final SortedSetMultimap<Integer, VariantGraph.Vertex> ranks = VariantGraphRanking.of(graph).getByRank();
    for (Integer rank : ranks.keySet()) {
        final List<Cell> cells = Lists.<Cell>newLinkedList();
        for (VariantGraph.Vertex vertex : ranks.get(rank)) {
            cells.add(new Cell(rank, cells.size(), vertex));
        }//from   www .  ja  va 2s. c om
        grid.add(cells);
        maxX = Math.max(maxX, rank);
    }
}