List of usage examples for com.google.common.collect Multimap asMap
Map<K, Collection<V>> asMap();
From source file:google.registry.tools.DomainCheckFeeCommand.java
@Override void initEppToolCommand() { Multimap<String, String> domainNameMap = validateAndGroupDomainNamesByTld(mainParameters); for (Collection<String> values : domainNameMap.asMap().values()) { setSoyTemplate(DomainCheckFeeSoyInfo.getInstance(), DomainCheckFeeSoyInfo.DOMAINCHECKFEE); addSoyRecord(clientId, new SoyMapData("domainNames", values)); }// ww w . ja va2 s .co m }
From source file:org.apache.hadoop.hbase.index.coprocessor.regionserver.IndexRegionObserver.java
private static Collection<Delete> getIndexDeletes(List<IndexSpecification> indexSpecs, HRegion userRegion, HRegion indexRegion, KeyValue deleteKV) throws IOException { Collection<Delete> indexDeletes = new LinkedHashSet<Delete>(); List<IndexSpecification> indicesToUpdate = new LinkedList<IndexSpecification>(); Multimap<Long, KeyValue> groupedKV = doGetAndGroupByTS(indexSpecs, userRegion, deleteKV, indicesToUpdate); // There can be multiple index kvs for each user kv // So, prepare all resultant index delete kvs for this user delete kv for (Entry<Long, Collection<KeyValue>> entry : groupedKV.asMap().entrySet()) { for (IndexSpecification index : indicesToUpdate) { ByteArrayBuilder indexRow = IndexUtils.getIndexRowKeyHeader(index, indexRegion.getStartKey(), deleteKV.getRow());// w w w. ja v a2 s.c o m boolean update = false; for (ColumnQualifier cq : index.getIndexColumns()) { KeyValue kvFound = null; for (KeyValue kv : entry.getValue()) { if (Bytes.equals(cq.getColumnFamily(), kv.getFamily()) && Bytes.equals(cq.getQualifier(), kv.getQualifier())) { kvFound = kv; update = true; break; } } if (kvFound == null) { indexRow.position(indexRow.position() + cq.getMaxValueLength()); } else { IndexUtils.updateRowKeyForKV(cq, kvFound, indexRow); } } if (update) { // Append the actual row key at the end of the index row key. indexRow.put(deleteKV.getRow()); Delete idxDelete = new Delete(indexRow.array()); if (deleteKV.isDeleteType()) { idxDelete.deleteColumn(Constants.IDX_COL_FAMILY, Constants.IDX_COL_QUAL, entry.getKey()); } else { idxDelete.deleteFamily(Constants.IDX_COL_FAMILY, entry.getKey()); } idxDelete.setWriteToWAL(false); indexDeletes.add(idxDelete); } } } return indexDeletes; }
From source file:com.github.cbismuth.fdupes.stream.DuplicateFinderByKey.java
public <K> Collection<PathElement> getDuplicates(final Collection<PathElement> input, final Function<PathElement, K> keyMapper, final Collection<PathElement> uniqueElements) { Preconditions.checkNotNull(input, "null pass stream"); Preconditions.checkNotNull(keyMapper, "null pass key mapper"); final Multimap<K, PathElement> multimap = input.parallelStream().collect(toMultimap(keyMapper)); uniqueElements.addAll(multimap.asMap().entrySet().parallelStream().map(Map.Entry::getValue) .filter(value -> value.size() == 1).flatMap(Collection::parallelStream).collect(toList())); return multimap.asMap().entrySet().parallelStream().map(Map.Entry::getValue) .filter(value -> value.size() > 1).flatMap(Collection::parallelStream).collect(toList()); }
From source file:com.github.cbismuth.fdupes.io.BufferedAnalyzer.java
private void reportDuplicationSize(final Multimap<PathElement, PathElement> duplicates) { final double sizeInMb = duplicates.asMap().values().parallelStream().flatMap(Collection::parallelStream) .mapToLong(PathElement::size).sum() / 1024.0 / 1024.0; LOGGER.info("Total size of duplicated files is {} mb", NumberFormat.getNumberInstance().format(sizeInMb)); }
From source file:moa2014.MOAH52014.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 h1x = MOAH12014.diferencaMatriz(matrizatual); int h2x = MOAH22014.diferencaMatriz(matrizatual); int h3x = MOAH32014.diferencaMatriz(matrizatual); int difmatrizatual = maior(h1x, h2x, h3x); 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 = MOAH32014.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 2s .c o m*/ int[][] matrizatualx = estadomenor.getMatriz(); arvoresprocessadas++; 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++; h1x = MOAH12014.diferencaMatriz(matriz); h2x = MOAH22014.diferencaMatriz(matriz); h3x = MOAH32014.diferencaMatriz(matriz); int diferencamatriz = maior(h1x, h2x, h3x); 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++; h1x = MOAH12014.diferencaMatriz(matriz); h2x = MOAH22014.diferencaMatriz(matriz); h3x = MOAH32014.diferencaMatriz(matriz); int diferencamatriz = maior(h1x, h2x, h3x); 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++; h1x = MOAH12014.diferencaMatriz(matriz); h2x = MOAH22014.diferencaMatriz(matriz); h3x = MOAH32014.diferencaMatriz(matriz); int diferencamatriz = maior(h1x, h2x, h3x); 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]; String stringmatriz4 = transformaMatrizString(matriz); if (!(processados.containsKey(stringmatriz4))) { arvoresgeradas++; h1x = MOAH12014.diferencaMatriz(matriz); h2x = MOAH22014.diferencaMatriz(matriz); h3x = MOAH32014.diferencaMatriz(matriz); int diferencamatriz = maior(h1x, h2x, h3x); 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:org.obm.provisioning.json.MultimapJsonSerializer.java
@Override public void serialize(Multimap value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeObject(value.asMap()); }
From source file:org.eclipse.xtext.xbase.typesystem.util.MultimapJoiner.java
/** * Returns a string containing the string representation of each entry of {@code map}, using the previously * configured separator and key-value separator. *//*from w w w . j a v a 2s . c om*/ public String join(Multimap<?, ?> map) { return join(map.asMap().entrySet()); }
From source file:controllers.api.BundlesApiController.java
public Result index() { Multimap<String, ConfigurationBundle> bundles = bundleService.all(); return ok(Json.toJsonString(bundles.asMap())).as(MediaType.JSON_UTF_8.toString()); }
From source file:org.apache.abdera2.activities.io.gson.MultimapAdapter.java
public JsonElement serialize(Multimap src, Type typeOfSrc, JsonSerializationContext context) { return context.serialize(src.asMap(), Map.class); }
From source file:com.github.jasonruckman.sidney.ext.guava.MultimapSerializer.java
@Override public void writeValue(Multimap<K, V> value, Contexts.WriteContext context) { Map<K, Collection<V>> map = value.asMap(); context.getMeta().writeConcreteType(value.getClass()); context.getMeta().writeRepetitionCount(map.size()); for (Map.Entry<K, Collection<V>> entry : map.entrySet()) { keySerializer.writeValue(entry.getKey(), context); context.getMeta().writeRepetitionCount(entry.getValue().size()); for (V v : entry.getValue()) { valueSerializer.writeValue(v, context); }//w ww . j av a 2 s .c om } }