List of usage examples for com.google.common.collect SortedSetMultimap keySet
Set<K> keySet();
From source file:org.terasology.documentation.ApiScraper.java
/** * @param args (ignored)/*from w w w . j a v a 2 s. com*/ * @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.apache.beam.sdk.options.PipelineOptionsValidator.java
/** * Validates that the passed {@link PipelineOptions} conforms to all the validation criteria from * the passed in interface.//from w ww. j av a 2 s . c om * * <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.// w w w . ja v a 2 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 www . ja v a 2 s . c o 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 w ww . j a va2 s . c o 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;//w w w. j a va2 s .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); }// w w w . j a va2 s. co m }
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)); }//ww w. j a va 2s . co m grid.add(cells); maxX = Math.max(maxX, rank); } }
From source file:com.flaptor.indextank.index.rti.inverted.InvertedIndex.java
private void internalAdd(int idx, final Document document) { for (String field : document.getFieldNames()) { Iterator<AToken> tokens = parser.parseDocumentField(field, document.getField(field)); SortedSetMultimap<String, Integer> termPositions = TreeMultimap.create(); int tokenCount = 0; while (tokens.hasNext()) { tokenCount++;// ww w. jav a 2 s . c om AToken token = tokens.next(); termPositions.put(token.getText(), token.getPosition()); } for (String term : termPositions.keySet()) { Key key = new Key(field, term); SortedSet<Integer> positionsSet = termPositions.get(term); int[] positions = new int[positionsSet.size()]; int p = 0; for (Integer i : positionsSet) { positions[p++] = i; } DocTermMatchList original = invertedIndex.putIfAbsent(key, new DocTermMatchList(idx, positions, tokenCount)); if (original != null) { original.add(idx, positions, tokenCount); } } } }
From source file:com.facebook.buck.android.MergeAndroidResourcesStep.java
private void doExecute(ExecutionContext context) throws IOException { // A symbols file may look like: ///*from ww w . ja v a 2s.co m*/ // int id placeholder 0x7f020000 // int string debug_http_proxy_dialog_title 0x7f030004 // int string debug_http_proxy_hint 0x7f030005 // int string debug_http_proxy_summary 0x7f030003 // int string debug_http_proxy_title 0x7f030002 // int string debug_ssl_cert_check_summary 0x7f030001 // int string debug_ssl_cert_check_title 0x7f030000 // // Note that there are four columns of information: // - the type of the resource id (always seems to be int or int[], in practice) // - the type of the resource // - the name of the resource // - the value of the resource id // // In order to convert this to R.java, all resources of the same type are grouped into a static // class of that name. The static class contains static values that correspond to the resource // (type, name, value) tuples. // // The first step is to merge symbol files of the same package type and resource type/name. // That is, within a package type, each resource type/name pair must be unique. If there are // multiple pairs, only one will be written to the R.java file. // // Because the resulting files do not match their respective resources.arsc, the values are // meaningless and do not represent the usable final result. This is why the R.java file is // written without using final so that javac will not inline the values. Unfortunately, // though Robolectric doesn't read resources.arsc, it does assert that all the R.java resource // ids are unique. This forces us to re-enumerate new unique ids. SortedSetMultimap<String, Resource> rDotJavaPackageToResources = sortSymbols(symbolsFileToRDotJavaPackage, context.getProjectFilesystem(), true /* reenumerate */); // Create an R.java file for each package. for (String rDotJavaPackage : rDotJavaPackageToResources.keySet()) { // Create the content of R.java. SortedSet<Resource> resources = rDotJavaPackageToResources.get(rDotJavaPackage); // Write R.java in the pathToGeneratedJavaFiles directory. Admittedly, this will be written // to /tmp/com.example.stuff/R.java rather than /tmp/com/example/stuff/R.java. It turns out // that directory structure does not matter to javac. // Determine the path to R.java. Path pathToRDotJava = getOutputFilePath(pathToGeneratedJavaFiles, rDotJavaPackage); File rDotJava = context.getProjectFilesystem().getFileForRelativePath(pathToRDotJava); // Then write R.java to the output directory. Files.createParentDirs(rDotJava); try (BufferedWriter writer = Files.newWriter(rDotJava, Charsets.UTF_8)) { writeJavaCodeForPackageAndResources(new PrintWriter(writer), rDotJavaPackage, resources); } } }