List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:io.github.swagger2markup.internal.utils.RegexUtils.java
/** * Groups the operations by regex group. The key of the Multimap is the group name. * The value of the Multimap is a PathOperation * * @param allOperations all operations/*from w w w . ja v a2 s . c o m*/ * @param headerPattern regex pattern used for determining headers * @return Operations grouped by regex */ public static Multimap<String, PathOperation> groupOperationsByRegex(List<PathOperation> allOperations, Pattern headerPattern) { Multimap<String, PathOperation> operationsGroupedByRegex = LinkedHashMultimap.create(); for (PathOperation operation : allOperations) { String path = operation.getPath(); Matcher m = headerPattern.matcher(path); if (m.matches() && m.group(1) != null) { if (logger.isDebugEnabled()) { logger.debug("Added path operation '{}' to header '{}'", operation, m.group(1)); } operationsGroupedByRegex.put(m.group(1), operation); } else { if (logger.isWarnEnabled()) { logger.warn("Operation '{}' does not match regex '{}' and will not be included in output", operation, headerPattern.toString()); } } } return operationsGroupedByRegex; }
From source file:com.android.tools.idea.gradle.project.ProjectDiagnostics.java
public static void findAndReportStructureIssues(@NotNull Project project) { Multimap<String, Module> modulesByPath = ArrayListMultimap.create(); ModuleManager moduleManager = ModuleManager.getInstance(project); for (Module module : moduleManager.getModules()) { File moduleFilePath = new File(toSystemDependentName(module.getModuleFilePath())); File moduleDirPath = moduleFilePath.getParentFile(); if (moduleDirPath != null) { modulesByPath.put(moduleDirPath.getPath(), module); }/*from w w w . j av a 2 s .c o m*/ } Set<String> modulePaths = modulesByPath.keySet(); for (String modulePath : modulePaths) { Collection<Module> modules = modulesByPath.get(modulePath); int moduleCount = modules.size(); if (moduleCount > 1) { ProjectSyncMessages messages = ProjectSyncMessages.getInstance(project); StringBuilder msg = new StringBuilder(); msg.append("The modules "); int i = 0; Set<String> moduleNames = Sets.newHashSet(); for (Module module : modules) { if (i++ != 0) { msg.append(", "); } String name = module.getName(); moduleNames.add(name); msg.append("'").append(name).append("'"); } msg.append(" point to same directory in the file system."); String[] lines = { msg.toString(), "Each module has to have a unique path." }; Message message = new Message(PROJECT_STRUCTURE_ISSUES, Message.Type.ERROR, lines); List<DataNode<ModuleData>> modulesToDisplayInDialog = Lists.newArrayList(); if (ProjectSubset.isSettingEnabled()) { ProjectSubset subset = ProjectSubset.getInstance(project); Collection<DataNode<ModuleData>> cachedModules = subset.getCachedModuleData(); if (cachedModules != null) { for (DataNode<ModuleData> moduleNode : cachedModules) { if (moduleNames.contains(moduleNode.getData().getExternalName())) { modulesToDisplayInDialog.add(moduleNode); } } } } if (modulesToDisplayInDialog.isEmpty()) { messages.add(message); } else { messages.add(message, new AddOrRemoveModulesHyperlink()); } } } }
From source file:com.google.enterprise.connector.ldap.MockLdapHandlers.java
static Map<String, Multimap<String, String>> makeMultimapRepo(int repoSize) { Map<String, Multimap<String, String>> repo = Maps.newTreeMap(); String key;/*from w w w .j a v a 2 s . c om*/ Multimap<String, String> person = ArrayListMultimap.create(); for (int i = 0; i < repoSize; i++) { String name = "Employee" + i; key = "cn=" + name + ",ou=people,dc=example,dc=com"; person.put("dn", key); person.put("cn", name); person.put("employeenumber", Integer.toString(i)); String schemaKey = "key" + (i % 100); person.put(schemaKey, "cucu"); repo.put(key, person); } return repo; }
From source file:mx.bigdata.jcalais.rest.CalaisRestClient.java
private static Multimap<String, CalaisObject> createHierarchy(Map<String, Object> root) { Multimap<String, CalaisObject> result = ArrayListMultimap.create(); for (Map.Entry<String, Object> me : root.entrySet()) { Map<String, Object> map = (Map<String, Object>) me.getValue(); map.put("_uri", me.getKey()); String group = (String) map.get("_typeGroup"); result.put(group, new MapBasedCalaisObject(map)); }// w ww. ja v a2 s . c om return result; }
From source file:moa2014.MOAH12014.java
public static int principal(int[][] matrizatual) { long startTime = System.currentTimeMillis(); Multimap<Integer, String> open_list = TreeMultimap.create(); HashMap<String, Estado> processados = new HashMap(); int difmatrizatual = diferencaMatriz(matrizatual); String stringmatriz = transformaMatrizString(matrizatual); open_list.put(difmatrizatual, stringmatriz); Estado estadoatual = new Estado(matrizatual, 0); processados.put(stringmatriz, estadoatual); int arvoresgeradas = 0; int arvoresprocessadas = 0; while (!open_list.isEmpty()) { Iterator iterator = open_list.keySet().iterator(); Integer key = (Integer) iterator.next(); String matrizatualx1 = open_list.asMap().get(key).iterator().next(); Estado estadomenor = processados.get(matrizatualx1); int altura = estadomenor.getCusto(); //LOCALIZA O ZERO int[] zerot = localizazero(estadomenor.getMatriz()); int x = zerot[0]; int y = zerot[1]; int x0 = x - 1; int x1 = x + 1; int y0 = y - 1; int y1 = y + 1; int difmatrizatualx = diferencaMatriz(estadomenor.getMatriz()); if (difmatrizatualx == 0) { long endTime = System.currentTimeMillis(); System.out.println("---------------------------------------"); System.out.println("Arvores Geradas: " + arvoresgeradas); System.out.println("Arvores Processadas: " + arvoresprocessadas); System.out.println("Quantidade de Movimentos: " + estadomenor.getCusto()); System.out.println("Tempo de processamento " + (endTime - startTime) + " ms"); System.out.println("---------------------------------------\n\n"); return 0; }/* w ww. ja v a 2 s .c o m*/ arvoresprocessadas++; int[][] matrizatualx = estadomenor.getMatriz(); if (x0 >= 0) { int[][] matriz; matriz = copyarray(matrizatualx); matriz[x][y] = matrizatualx[x0][y]; matriz[x0][y] = matrizatualx[x][y]; String stringmatriz1 = transformaMatrizString(matriz); if (!(processados.containsKey(stringmatriz1))) { arvoresgeradas++; int diferencamatriz = diferencaMatriz(matriz); int custototal = diferencamatriz + altura + 1; Estado estadonovo = new Estado(matriz, altura + 1); open_list.put(custototal, stringmatriz1); processados.put(stringmatriz1, estadonovo); } } if (x1 <= 3) { int[][] matriz; matriz = copyarray(matrizatualx); matriz[x][y] = matrizatualx[x1][y]; matriz[x1][y] = matrizatualx[x][y]; String stringmatriz2 = transformaMatrizString(matriz); if (!(processados.containsKey(stringmatriz2))) { arvoresgeradas++; int diferencamatriz = diferencaMatriz(matriz); int custototal = diferencamatriz + altura + 1; Estado estadonovo = new Estado(matriz, altura + 1); open_list.put(custototal, stringmatriz2); processados.put(stringmatriz2, estadonovo); } } if (y0 >= 0) { int[][] matriz; matriz = copyarray(matrizatualx); matriz[x][y] = matrizatualx[x][y0]; matriz[x][y0] = matrizatualx[x][y]; String stringmatriz3 = transformaMatrizString(matriz); if (!(processados.containsKey(stringmatriz3))) { arvoresgeradas++; int diferencamatriz = diferencaMatriz(matriz); int custototal = diferencamatriz + altura + 1; Estado estadonovo = new Estado(matriz, altura + 1); open_list.put(custototal, stringmatriz3); processados.put(stringmatriz3, estadonovo); } } if (y1 <= 3) { int[][] matriz; matriz = copyarray(matrizatualx); matriz[x][y] = matrizatualx[x][y1]; matriz[x][y1] = matrizatualx[x][y]; int custoateaqui = diferencaMatriz(matriz) + altura + 1; String stringmatriz4 = transformaMatrizString(matriz); if (!(processados.containsKey(stringmatriz4))) { arvoresgeradas++; int diferencamatriz = diferencaMatriz(matriz); int custototal = diferencamatriz + altura + 1; Estado estadonovo = new Estado(matriz, altura + 1); open_list.put(custototal, stringmatriz4); processados.put(stringmatriz4, estadonovo); } } open_list.remove(key, matrizatualx1); } return 0; }
From source file:it.units.malelab.ege.benchmark.symbolicregression.MathUtils.java
public static Map<String, double[]> combinedValuesMap(Map<String, double[]> flatMap) { String[] names = new String[flatMap.keySet().size()]; int[] counters = new int[flatMap.keySet().size()]; Multimap<String, Double> multimap = ArrayListMultimap.create(); //init//from w w w . ja v a 2s .c om int y = 0; for (String name : flatMap.keySet()) { names[y] = name; counters[y] = 0; y = y + 1; } //fill map while (true) { for (int i = 0; i < names.length; i++) { multimap.put(names[i], flatMap.get(names[i])[counters[i]]); } for (int i = 0; i < counters.length; i++) { counters[i] = counters[i] + 1; if ((i < counters.length - 1) && (counters[i] == flatMap.get(names[i]).length)) { counters[i] = 0; } else { break; } } if (counters[counters.length - 1] == flatMap.get(names[counters.length - 1]).length) { break; } } //transform Map<String, double[]> map = new LinkedHashMap<>(); for (String key : multimap.keySet()) { double[] values = new double[multimap.get(key).size()]; int i = 0; for (Double value : multimap.get(key)) { values[i] = value; i = i + 1; } map.put(key, values); } return map; }
From source file:edu.uci.ics.sourcerer.tools.java.component.identifier.internal.ClusterIdentifier.java
public static ClusterCollection identifyFullyMatchingClusters(JarCollection jars) { TaskProgressLogger task = TaskProgressLogger.get(); task.start("Identifying fully matching clusters in " + jars.size() + " jar files"); Multimap<VersionedFqnNode, Cluster> clusterMap = ArrayListMultimap.create(); // Explore the tree in post-order for (VersionedFqnNode parent : jars.getRoot().getPostOrderIterable()) { // If it's a leaf, then it starts out as a trivial cluster if (!parent.hasChildren()) { clusterMap.put(parent, Cluster.create(parent)); }// w w w . java2 s.c om // If it has children, see what children always co-occur else { // Check if the node itself should be a cluster if (parent.getJars().size() > 0) { clusterMap.put(parent, Cluster.create(parent)); } for (VersionedFqnNode child : parent.getChildren()) { // Match the clusters from the children with the current clusters for this node for (Cluster childCluster : clusterMap.get(child)) { Cluster match = null; // Which clusters have already been found for this fragment? for (Cluster parentCluster : clusterMap.get(parent)) { if (areFullyCompatible(childCluster, parentCluster)) { // We found a match! match = parentCluster; // There can be only one, so break break; } } // If we found a match, merge if (match != null) { match.mergeCore(childCluster); } // Otherwise, promote the cluster else { clusterMap.put(parent, childCluster); } } clusterMap.removeAll(child); } } } ClusterCollection clusters = ClusterCollection.create(clusterMap.get(jars.getRoot())); task.report("Identified " + clusters.size() + " fully matching clusters"); task.finish(); return clusters; }
From source file:com.google.devtools.j2objc.translate.TypeSorter.java
private static Multimap<String, String> findSuperTypes(Map<String, ITypeBinding> bindingMap) { Multimap<String, String> superTypes = HashMultimap.create(); for (Map.Entry<String, ITypeBinding> entry : bindingMap.entrySet()) { String key = entry.getKey(); ITypeBinding type = entry.getValue(); ITypeBinding superclass = type.getSuperclass(); if (superclass != null) { String superclassKey = superclass.getTypeDeclaration().getKey(); if (bindingMap.containsKey(superclassKey)) { superTypes.put(key, superclassKey); }//from w ww . j a v a 2 s .c o m } for (ITypeBinding interfaze : type.getInterfaces()) { String interfaceKey = interfaze.getTypeDeclaration().getKey(); if (bindingMap.containsKey(interfaceKey)) { superTypes.put(key, interfaceKey); } } } return superTypes; }
From source file:com.bigdata.dastor.dht.BootStrapper.java
static Multimap<InetAddress, Range> getWorkMap(Multimap<Range, InetAddress> rangesWithSourceTarget, IFailureDetector failureDetector) { /*/*from ww w . j a v a 2 s .com*/ * Map whose key is the source node and the value is a map whose key is the * target and value is the list of ranges to be sent to it. */ Multimap<InetAddress, Range> sources = ArrayListMultimap.create(); // TODO look for contiguous ranges and map them to the same source for (Range range : rangesWithSourceTarget.keySet()) { for (InetAddress source : rangesWithSourceTarget.get(range)) { if (failureDetector.isAlive(source)) { sources.put(source, range); break; } } } return sources; }
From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.exporter.ecore.EntityClassStore.java
public static Multimap<Class<? extends IdEntity>, EObject> groupEObjects(Collection<EObject> eObjects) { Map<String, Class<? extends IdEntity>> nameToClassMappings = EntityClassStore.getNameToClassMappings(); Multimap<Class<? extends IdEntity>, EObject> orderedObjects = LinkedHashMultimap.create(); for (EObject eObject : eObjects) { Class<? extends IdEntity> clazz = nameToClassMappings.get(eObject.eClass().getName()); orderedObjects.put(clazz, eObject); }/*from w w w . j av a2 s . c o m*/ return orderedObjects; }