List of usage examples for com.google.common.collect Multimap values
Collection<V> values();
From source file:org.debux.webmotion.server.tools.ReflectionUtils.java
/** * @return all ressource with pattern/*from ww w.ja v a2 s . c om*/ */ public static Collection<String> getResources(String regex) { Reflections reflections = new Reflections("", new ResourcesScanner(), new WrapClassLoader()); Store store = reflections.getStore(); Multimap<String, String> mmap = store.get(ResourcesScanner.class.getSimpleName()); final Pattern pattern = Pattern.compile(regex); Predicate predicate = new Predicate<String>() { @Override public boolean apply(String input) { return pattern.matcher(input).matches(); } }; Collection<String> resources = Collections2.filter(mmap.values(), predicate); return resources; }
From source file:org.jboss.errai.idea.plugin.ui.TemplateUtil.java
public static Map<String, ConsolidateDataFieldElementResult> getConsolidatedDataFields(PsiElement element, Project project) {/*w w w . j a v a 2s .c o m*/ final TemplateMetaData metaData = TemplateUtil.getTemplateMetaData(element); if (metaData == null) { return Collections.emptyMap(); } final PsiClass topLevelClass = PsiUtil.getTopLevelClass(element); if (topLevelClass == null) { return Collections.emptyMap(); } final String beanClass = topLevelClass.getQualifiedName(); final Map<String, ConsolidateDataFieldElementResult> results = new LinkedHashMap<String, ConsolidateDataFieldElementResult>(); final Collection<AnnotationSearchResult> allInjectionPoints = Util.findAllAnnotatedElements(element, Types.DATAFIELD); for (AnnotationSearchResult r : allInjectionPoints) { final String value = Util.getValueStringFromAnnotationWithDefault(r.getAnnotation()).getValue(); results.put(value, new ConsolidateDataFieldElementResult(value, beanClass, r.getOwningElement(), true)); } final Multimap<String, TemplateDataField> allDataFieldTags = TemplateUtil.findAllDataFieldTags(metaData, project, false); for (TemplateDataField ref : allDataFieldTags.values()) { final XmlAttribute attribute = ref.getTag().getAttribute("data-field"); if (attribute == null) { continue; } final XmlAttributeValue valueElement = attribute.getValueElement(); if (results.containsKey(ref.getDataFieldName())) { results.get(ref.getDataFieldName()).setLinkingElement(valueElement); continue; } results.put(ref.getDataFieldName(), new ConsolidateDataFieldElementResult(ref.getDataFieldName(), metaData.getTemplateExpression().getFileName(), valueElement, false)); } return results; }
From source file:org.debux.webmotion.server.tools.ReflectionUtils.java
/** * @return all classes with pattern// www .ja va2s. com */ public static Collection<String> getClasses(String regex) { Reflections reflections = new Reflections("", new ClassesScanner(), new WrapClassLoader()); Store store = reflections.getStore(); Multimap<String, String> mmap = store.get(ClassesScanner.class.getSimpleName()); final Pattern pattern = Pattern.compile(".*" + regex + "\\.class$"); Predicate predicate = new Predicate<String>() { @Override public boolean apply(String input) { return pattern.matcher(input).matches(); } }; Collection<String> resources = Collections2.filter(mmap.values(), predicate); return resources; }
From source file:org.debux.webmotion.server.tools.ReflectionUtils.java
/** * @return all classes with extend the super class *///from ww w . j a v a 2 s .c o m public static Collection<Class<?>> getClassesBySuperClass(final Class<?> superClass) { Reflections reflections = new Reflections("", new ClassesScanner(), new WrapClassLoader()); Store store = reflections.getStore(); Multimap<String, String> mmap = store.get(ClassesScanner.class.getSimpleName()); final Pattern pattern = Pattern.compile(".*\\.class$"); Predicate predicate = new Predicate<String>() { @Override public boolean apply(String input) { return pattern.matcher(input).matches(); } }; Collection<String> resources = Collections2.filter(mmap.values(), predicate); Collection<Class<?>> classes = new ArrayList<Class<?>>(); ClassLoader classLoader = ReflectionUtils.class.getClassLoader(); for (String resource : resources) { String fullName = resource.replaceAll("/", ".").replaceAll("\\.class$", ""); try { Class<?> klass = classLoader.loadClass(fullName); if (superClass.isAssignableFrom(klass) && !klass.equals(superClass)) { classes.add(klass); } } catch (ClassNotFoundException ex) { } } return classes; }
From source file:com.googlecode.blaisemath.graph.GraphUtils.java
/** * Generates ordered set of nodes from an adjacency map * @param <V> graph node type/*from w w w.j ava 2 s. c o m*/ * @param adj an adjacency map * @return list of nodes */ public static <V> Set<V> nodes(Multimap<V, V> adj) { Set<V> result = Sets.newLinkedHashSet(); result.addAll(adj.keySet()); result.addAll(adj.values()); return result; }
From source file:com.torodb.torod.db.backends.meta.routines.DeleteDocuments.java
public static int execute(Configuration configuration, CollectionSchema colSchema, Multimap<DocStructure, Integer> didsByStructure, @Nonnull DatabaseInterface databaseInterface) throws SQLException, RetryTransactionException { TableProvider tableProvider = new TableProvider(colSchema); DSLContext dsl = DSL.using(configuration); Set<SubDocTable> tables = Sets.newHashSet(); for (DocStructure structure : didsByStructure.keySet()) { tables.clear();// w w w .j a v a 2s . co m structure.accept(tableProvider, tables); executeDeleteSubDocuments(dsl, tables, didsByStructure.get(structure), databaseInterface); } Set<Integer> dids = Sets.newHashSet(didsByStructure.values()); return executeDeleteRoots(dsl, colSchema, dids, databaseInterface); }
From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraVerifier.java
static Set<String> sanityCheckDatacenters(Cassandra.Client client, int desiredRf, boolean safetyDisabled) throws InvalidRequestException, TException { ensureTestKeyspaceExists(client);//from www. j a v a2 s. c om Set<String> hosts = Sets.newHashSet(); Multimap<String, String> dataCenterToRack = HashMultimap.create(); List<TokenRange> ring = client.describe_ring(CassandraConstants.SIMPLE_RF_TEST_KEYSPACE); for (TokenRange tokenRange : ring) { for (EndpointDetails details : tokenRange.getEndpoint_details()) { dataCenterToRack.put(details.datacenter, details.rack); hosts.add(details.host); } } if (dataCenterToRack.size() == 1) { String dc = dataCenterToRack.keySet().iterator().next(); String rack = dataCenterToRack.values().iterator().next(); if (dc.equals(CassandraConstants.DEFAULT_DC) && rack.equals(CassandraConstants.DEFAULT_RACK) && desiredRf > 1) { // We don't allow greater than RF=1 because they didn't set up their network. logErrorOrThrow( "The cassandra cluster is not set up to be datacenter and rack aware. " + "Please set this up before running with a replication factor higher than 1.", safetyDisabled); } if (dataCenterToRack.values().size() < desiredRf && hosts.size() > desiredRf) { logErrorOrThrow("The cassandra cluster only has one DC, " + "and is set up with less racks than the desired number of replicas, " + "and there are more hosts than the replication factor. " + "It is very likely that your rack configuration is incorrect and replicas would not be placed correctly for the failure tolerance you want.", safetyDisabled); } } return dataCenterToRack.keySet(); }
From source file:com.google.errorprone.bugpatterns.WildcardImport.java
/** Creates a {@link Fix} that replaces wildcard imports. */ static Fix createFix(ImmutableList<ImportTree> wildcardImports, Multimap<ImportTree, TypeToImport> toFix, VisitorState state) {//from ww w .j a va 2 s .co m final SuggestedFix.Builder fix = SuggestedFix.builder(); for (ImportTree importToDelete : wildcardImports) { String importSpecification = importToDelete.getQualifiedIdentifier().toString(); if (importToDelete.isStatic()) { fix.removeStaticImport(importSpecification); } else { fix.removeImport(importSpecification); } } Multimap<Symbol, TypeToImport> importsByOwner = LinkedHashMultimap.create(); for (TypeToImport toImport : toFix.values()) { importsByOwner.put(toImport.owner(), toImport); } for (Map.Entry<Symbol, Collection<TypeToImport>> entries : importsByOwner.asMap().entrySet()) { final Symbol owner = entries.getKey(); if (entries.getValue().size() > MAX_MEMBER_IMPORTS) { qualifiedNameFix(fix, owner, state); } else { for (TypeToImport toImport : toFix.values()) { toImport.addFix(fix); } } } return fix.build(); }
From source file:org.napile.compiler.lang.resolve.processors.OverrideResolver.java
public static Multimap<CallableMemberDescriptor, CallableMemberDescriptor> collectSuperMethods( MutableClassDescriptor classDescriptor) { Set<CallableMemberDescriptor> inheritedFunctions = Sets.newLinkedHashSet(); for (NapileType supertype : classDescriptor.getSupertypes()) { for (DeclarationDescriptor descriptor : supertype.getMemberScope().getAllDescriptors()) { if (descriptor instanceof CallableMemberDescriptor) { CallableMemberDescriptor memberDescriptor = (CallableMemberDescriptor) descriptor; inheritedFunctions.add(memberDescriptor); }//from w ww. jav a 2 s. c o m } } // Only those actually inherited Set<CallableMemberDescriptor> filteredMembers = OverridingUtil.filterOverrides(inheritedFunctions); // Group members with "the same" signature Multimap<CallableMemberDescriptor, CallableMemberDescriptor> factoredMembers = CommonSuppliers .newLinkedHashSetHashSetMultimap(); for (CallableMemberDescriptor one : filteredMembers) { if (factoredMembers.values().contains(one)) continue; for (CallableMemberDescriptor another : filteredMembers) { // if (one == another) continue; factoredMembers.put(one, one); if (OverridingUtil.isOverridableBy(one, another) .getResult() == OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE || OverridingUtil.isOverridableBy(another, one) .getResult() == OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE) { factoredMembers.put(one, another); } } } return factoredMembers; }
From source file:grakn.core.graql.reasoner.plan.GraqlTraversalPlanner.java
/** * * @param atoms list of current atoms of interest * @param queryPattern corresponding pattern * @return an optimally ordered list of provided atoms *///www.java 2 s. c o m private static ImmutableList<Atom> planFromTraversal(List<Atom> atoms, Conjunction<?> queryPattern, TransactionOLTP tx) { Multimap<VarProperty, Atom> propertyMap = HashMultimap.create(); atoms.stream().filter(atom -> !(atom instanceof OntologicalAtom)) .forEach(atom -> atom.getVarProperties().forEach(property -> propertyMap.put(property, atom))); Set<VarProperty> properties = propertyMap.keySet(); GraqlTraversal graqlTraversal = TraversalPlanner.createTraversal(queryPattern, tx); ImmutableList<Fragment> fragments = Iterables.getOnlyElement(graqlTraversal.fragments()); List<Atom> atomList = new ArrayList<>(); atoms.stream().filter(atom -> atom instanceof OntologicalAtom).forEach(atomList::add); fragments.stream().map(Fragment::varProperty).filter(Objects::nonNull).filter(properties::contains) .distinct().flatMap(property -> propertyMap.get(property).stream()).distinct() .forEach(atomList::add); //add any unlinked items (disconnected and indexed for instance) propertyMap.values().stream().filter(at -> !atomList.contains(at)).forEach(atomList::add); return ImmutableList.copyOf(atomList); }