List of usage examples for com.google.common.collect Multimaps newMultimap
public static <K, V> Multimap<K, V> newMultimap(Map<K, Collection<V>> map, final Supplier<? extends Collection<V>> factory)
From source file:org.terasology.documentation.apiScraper.CompleteApiScraper.java
/** * * @return Project's Packages, Interfaces, Classes and Methods * @throws Exception if the module environment cannot be loaded *///from w w w .j a va2 s. com static StringBuffer getApi() throws Exception { ModuleManager moduleManager = ModuleManagerFactory.create(); ModuleEnvironment environment = moduleManager.getEnvironment(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Multimap<String, String> api = Multimaps.newMultimap(new HashMap<String, Collection<String>>(), ArrayList::new); for (Class<?> apiClass : environment.getTypesAnnotatedWith(API.class)) { 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) { logger.error("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(); int bang = categoryFragment.lastIndexOf("!"); int hyphen = categoryFragment.lastIndexOf("-", bang); int slash = categoryFragment.lastIndexOf("/", hyphen); category = categoryFragment.substring(slash + 1, hyphen); if (isPackage) { api.put(category, apiPackage + " (PACKAGE)"); } else { addToApi(category, apiClass, api); } break; case "file": // If file based we know it is local so organize it like that category = TERASOLOGY_API_CLASS_CATEGORY; if (isPackage) { api.put(category, apiPackage + " (PACKAGE)"); } else { addToApi(category, apiClass, api); } break; default: logger.error("Unknown protocol for: " + apiClass + ", came from " + location); } } api.putAll(EXTERNAL, ExternalApiWhitelist.CLASSES.stream().map(clazz -> clazz.getName() + " (CLASS)") .collect(Collectors.toSet())); api.putAll(EXTERNAL, ExternalApiWhitelist.PACKAGES.stream().map(packagee -> packagee + " (PACKAGE)") .collect(Collectors.toSet())); //Puts the information in the StringBuffer StringBuffer stringApi = new StringBuffer(); stringApi.append("# Modding API:\n"); for (String key : api.keySet()) { stringApi.append("## "); stringApi.append(key); stringApi.append("\n"); for (String value : api.get(key)) { stringApi.append("* "); stringApi.append(value); stringApi.append("\n"); } stringApi.append("\n"); } return stringApi; }
From source file:fm.last.commons.hive.serde.TableDefinition.java
/** * Creates a new {@link TableDefinition}. * /*from w w w .jav a 2 s. com*/ * @param table {@link Properties} declared on the Hive table. * @param fieldFactory A factory instance that can provide {@link Field} definitions to map to the Hive table columns. */ TableDefinition(Properties table, FieldFactory fieldFactory) { this.fieldFactory = fieldFactory; String columnNameProperty = table.getProperty("columns"); String columnTypeProperty = table.getProperty("columns.types"); if (columnNameProperty.length() == 0) { columnNames = Collections.emptyList(); } else { columnNames = Collections.unmodifiableList(Arrays.asList(columnNameProperty.split(","))); } if (columnTypeProperty.length() == 0) { columnTypes = Collections.emptyList(); } else { columnTypes = Collections .unmodifiableList(TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProperty)); } if (columnNames.size() != columnTypes.size()) { throw new IllegalStateException("columnNames.size() != columnTypes.size()"); } String columnSortOrder = table.getProperty(Constants.SERIALIZATION_SORT_ORDER); columnSortOrderIsDesc = new boolean[columnNames.size()]; for (int i = 0; i < columnSortOrderIsDesc.length; i++) { columnSortOrderIsDesc[i] = (columnSortOrder != null && columnSortOrder.charAt(i) == '-'); } fieldNameToColumnId = Multimaps.newMultimap(new HashMap<Field, Collection<Integer>>(), new Supplier<Set<Integer>>() { @Override public Set<Integer> get() { return new HashSet<Integer>(); } }); mapColumnsToFields(table); }
From source file:com.mewmew.fairy.v1.cli.AnnotatedCLI.java
public AnnotatedCLI(Class... clazz) { final List<AnnotatedOption> list = new ArrayList<AnnotatedOption>(); for (Class aClass : clazz) { for (Field field : aClass.getDeclaredFields()) { Param param = field.getAnnotation(Param.class); if (param != null) { list.add(new AnnotatedOption(aClass, field, param)); }// w w w. java 2 s . c o m Args arg = field.getAnnotation(Args.class); if (arg != null) { args.put(aClass, field); } } for (Constructor ctor : aClass.getConstructors()) { AnnotatedConstructor actor = new AnnotatedConstructor(aClass, ctor); Class[] types = ctor.getParameterTypes(); Annotation[][] annotations = ctor.getParameterAnnotations(); for (int i = 0; i < types.length; i++) { Class type = types[i]; Annotation[] ann = annotations[i]; for (Annotation annotation : ann) { if (annotation instanceof Param) { actor.addParam((Param) annotation, type); } } } if (actor.isValid()) { ctors.put(aClass, actor); } } } options = new Options(); mappings = Multimaps.newMultimap(Maps.<Class, Collection<AnnotatedOption>>newHashMap(), new Supplier<Collection<AnnotatedOption>>() { public Collection<AnnotatedOption> get() { return new ArrayList<AnnotatedOption>(); } }); for (AnnotatedConstructor constructor : ctors.values()) { for (AnnotatedConstructor.AnnotatedParam param : constructor.getParams()) { boolean hasArgs = !(param.getType().equals(boolean.class) || param.getType().equals(Boolean.class)); String option = param.getParam().option(); while (options.hasOption(option)) { option = option + option; } options.addOption(option, param.getParam().name(), hasArgs, param.getParam().desc()); } } for (AnnotatedOption opt : list) { boolean hasArgs = !(opt.field.getType().equals(boolean.class) || opt.field.getType().equals(Boolean.class)); while (options.hasOption(opt.getOpt())) { opt.setOpt(opt.getOpt() + opt.getOpt()); } options.addOption(opt.getOpt(), opt.getName(), hasArgs, opt.getParam().desc()); mappings.put(opt.clazz, opt); } }
From source file:com.google.jstestdriver.output.XmlPrinterImpl.java
private Multimap<String, TestResult> newMultiMap() { return Multimaps.newMultimap(Maps.<String, Collection<TestResult>>newHashMap(), new Supplier<Collection<TestResult>>() { public Collection<TestResult> get() { return Lists.newLinkedList(); }// w w w .ja v a 2 s . c o m }); }
From source file:financial.market.GeographicalMarket.java
public GeographicalMarket(GoodType goodType) { super(goodType); //the buyers quote are kept in a priority queue from the highest to the lowest //but because these are oilCustomers only, I can "cheat" and order the keys too by TreeMap<GeographicalCustomer, Collection<Quote>> backingBuyerTreeMapPOJO = new TreeMap<>( new Comparator<GeographicalCustomer>() { @Override//from www .j a va 2 s .co m public int compare(GeographicalCustomer o1, GeographicalCustomer o2) { int priceComparison = -Long.compare(o1.getMaxPrice(), o2.getMaxPrice()); if (priceComparison != 0) return priceComparison; else return Integer.compare(o1.hashCode(), o2.hashCode()); //otherwise just order them by hash } }); //now we are going to encase the treemap in an observable property so that I don't have to write a million listeners there buyerBackerMap = FXCollections.observableMap(backingBuyerTreeMapPOJO); buyersWhoPlacedAQuote = Multimaps.newMultimap(buyerBackerMap, new Supplier<PriorityQueue<Quote>>() { @Override public PriorityQueue<Quote> get() { return new PriorityQueue<>(1, new Comparator<Quote>() { @Override public int compare(Quote o1, Quote o2) { return -Long.compare(o1.getPriceQuoted(), o2.getPriceQuoted()); } }); } }); //sellers quote are sorted from lowest to highest sellersWhoPlacedAQuote = Multimaps.newMultimap(new LinkedHashMap<>(), () -> new PriorityQueue<>(1, (o1, o2) -> Long.compare(o1.getPriceQuoted(), o2.getPriceQuoted()))); //make sure the buyers and sellers were initialized assert getBuyers() != null; assert getBuyers() != null; //you'll schedule yourself in the start }
From source file:cpw.mods.fml.client.modloader.ModLoaderClientHelper.java
public ModLoaderClientHelper(Minecraft client) { this.client = client; ModLoaderHelper.sidedHelper = this; keyBindingContainers = Multimaps.newMultimap( Maps.<ModLoaderModContainer, Collection<ModLoaderKeyBindingHandler>>newHashMap(), new Supplier<Collection<ModLoaderKeyBindingHandler>>() { @Override/* w w w.j a v a 2s . c o m*/ public Collection<ModLoaderKeyBindingHandler> get() { return Collections.singleton(new ModLoaderKeyBindingHandler()); } }); }
From source file:org.eclipse.xtext.mwe.Validator.java
protected Multimap<URI, MWEDiagnostic> groupByURI(MWEDiagnostic[] diagnostic) { Multimap<URI, MWEDiagnostic> result = Multimaps.newMultimap( Maps.<URI, Collection<MWEDiagnostic>>newLinkedHashMap(), new Supplier<Collection<MWEDiagnostic>>() { @Override/*w w w .jav a 2s . c om*/ public Collection<MWEDiagnostic> get() { return Sets.newTreeSet(getDiagnosticComparator()); } }); result.putAll(Multimaps.index(Arrays.asList(diagnostic), new Function<MWEDiagnostic, URI>() { @Override public URI apply(MWEDiagnostic from) { Issue issue = (Issue) from.getElement(); URI uriToProblem = issue.getUriToProblem(); return uriToProblem != null ? uriToProblem.trimFragment() : NullURI; } })); return result; }
From source file:eu.stratosphere.sopremo.operator.IterativeSopremoModule.java
private Multimap<Operator<?>, Operator<?>> getSuccessorRelations(final Set<Operator<?>> stepOutputs) { final Multimap<Operator<?>, Operator<?>> successors = Multimaps.newMultimap( new IdentityHashMap<Operator<?>, Collection<Operator<?>>>(), IdentitySetSupplier.<Operator<?>>getInstance()); OneTimeTraverser.INSTANCE.traverse(stepOutputs, OperatorNavigator.INSTANCE, new GraphTraverseListener<Operator<?>>() { @Override/* w w w.ja v a 2 s .com*/ public void nodeTraversed(final Operator<?> node) { for (final JsonStream input : node.getInputs()) { successors.put(input.getSource().getOperator(), node); successors.putAll(input.getSource().getOperator(), successors.get(node)); } } }); return successors; }
From source file:org.apache.shindig.gadgets.http.HttpResponse.java
public static Multimap<String, String> newHeaderMultimap() { TreeMap<String, Collection<String>> map = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER); return Multimaps.newMultimap(map, HEADER_COLLECTION_SUPPLIER); }
From source file:io.sarl.lang.validation.SARLValidator.java
/** Check for unused capacities. * * @param uses - the capacity use declaration. */// w ww. ja va2 s . co m @SuppressWarnings("unchecked") @Check(CheckType.NORMAL) public void checkUnusedCapacities(SarlCapacityUses uses) { if (!isIgnored(UNUSED_AGENT_CAPACITY)) { EObject container = uses.getDeclaringType(); EObject jvmContainer = this.associations.getPrimaryJvmElement(container); final String annotationId = ImportedCapacityFeature.class.getName(); Multimap<String, JvmOperation> importedFeatures = Multimaps.newMultimap( CollectionLiterals.<String, Collection<JvmOperation>>newHashMap(), new Supplier<Collection<JvmOperation>>() { @Override public Collection<JvmOperation> get() { return CollectionLiterals.<JvmOperation>newArrayList(); } }); Iterable<EObject> fitleredObjects = IterableExtensions.filter(jvmContainer.eContents(), new Functions.Function1<EObject, Boolean>() { @SuppressWarnings("synthetic-access") @Override public Boolean apply(EObject it) { if (it instanceof JvmOperation) { JvmOperation operation = (JvmOperation) it; if (doGetFirstAnnotation(operation, annotationId) != null) { return Boolean.TRUE; } } return Boolean.FALSE; } }); for (EObject method : fitleredObjects) { JvmOperation operation = (JvmOperation) method; EList<JvmAnnotationValue> annotationValues = doGetFirstAnnotation(operation, annotationId) .getValues(); JvmTypeAnnotationValue annotationType = (JvmTypeAnnotationValue) annotationValues.get(0); JvmTypeReference capacityType = annotationType.getValues().get(0); importedFeatures.put(capacityType.getIdentifier(), operation); } int index = 0; for (JvmTypeReference capacity : uses.getCapacities()) { Collection<JvmOperation> operations = importedFeatures.get(capacity.getIdentifier()); if (!operations.isEmpty()) { if (!doGetLocalUsage(operations, container)) { addIssue(MessageFormat.format(Messages.SARLValidator_42, capacity.getSimpleName()), uses, SARL_CAPACITY_USES__CAPACITIES, index, UNUSED_AGENT_CAPACITY, capacity.getSimpleName()); } } ++index; } } }