List of usage examples for com.google.common.collect ArrayListMultimap create
public static <K, V> ArrayListMultimap<K, V> create()
From source file:com.twitter.common.collections.Multimaps.java
/** * Prunes a multimap based on a predicate, returning the pruned values. The input map will be * modified.//from w w w.j a v a2s .com * * @param map The multimap to prune. * @param filterRule The pruning rule. When the predicate returns {@code false} for an entry, it * will be pruned, otherwise it will be retained. * @param <K> The key type in the multimap. * @param <V> The value type in the multimap. * @return A new multimap, containing the pruned keys/values. */ public static <K, V> Multimap<K, V> prune(Multimap<K, V> map, Predicate<? super Collection<V>> filterRule) { Preconditions.checkNotNull(map); Preconditions.checkNotNull(filterRule); Multimap<K, V> pruned = ArrayListMultimap.create(); Iterator<Map.Entry<K, Collection<V>>> asMapItr = map.asMap().entrySet().iterator(); while (asMapItr.hasNext()) { Map.Entry<K, Collection<V>> asMapEntry = asMapItr.next(); if (!filterRule.apply(asMapEntry.getValue())) { pruned.putAll(asMapEntry.getKey(), asMapEntry.getValue()); asMapItr.remove(); } } return pruned; }
From source file:com.talis.storage.SubmittedItem.java
public SubmittedItem(MediaType mediaType, InputStream entity, Multimap<String, String> metadata) { this.mediaType = mediaType; this.entity = entity; this.metadata = ArrayListMultimap.create(); this.metadata.putAll(metadata); }
From source file:com.oarfish.keywords.rake.RakeMatrix.java
/** * method to initialize the frequency and degree matrix * * @param candidateKeyword//from w w w . j a v a 2s . c o m */ private void initMatrix(CandidateKeyword[] candidateKeyword) { ListMultimap<String, String> coocurrenceMatrix = ArrayListMultimap.create(); for (CandidateKeyword candidate : candidateKeyword) { //do not include adjoin keywords in the matrix if (candidate.isIsAdjoin() == true) { continue; } String[] tokens = candidate.getLabel().split(" "); HashSet<String> tokenSet = Sets.newHashSet(tokens); for (String token : tokens) { int currentFreq = getOrDefault(freqMap, token, 0); //update frequency map freqMap.put(token, currentFreq + 1); //update co-occurence matrix for (String neighbor : tokenSet) { if (!neighbor.equals(token)) { coocurrenceMatrix.put(token, neighbor); } } } } for (String token : freqMap.keySet()) { //degree is define as: freq(t) + size of co-occurrence_vector(t) int degree = freqMap.get(token) + coocurrenceMatrix.get(token).size(); degreeMap.put(token, degree); } }
From source file:tech.mcprison.prison.util.ItemManager.java
public ItemManager() throws Exception { File file = new File(Prison.get().getDataFolder(), "/items.csv"); items = ArrayListMultimap.create(); if (!file.exists()) { InputStream inputStream = getClass().getResourceAsStream("/items.csv"); Files.copy(inputStream, Paths.get(file.getPath())); }// w w w . jav a 2 s . c o m BufferedReader in = new BufferedReader(new FileReader(file)); String inputLine; while ((inputLine = in.readLine()) != null) { try { if (!inputLine.startsWith("#")) { String[] array = inputLine.split(","); String itemName = array[0]; int id = Integer.parseInt(array[1]); short data = Short.parseShort(array[2]); items.put(BlockType.getBlockWithData(id, data), itemName.toLowerCase()); } } catch (Exception e) { throw new IOException("Error while reading items.csv -- it's probably invalid", e); } } }
From source file:com.greensopinion.finance.services.transaction.TransactionNormalizer.java
/** * Removes transaction pairs that are self-canceling. *///from www . jav a 2s .c o m public List<Transaction> normalize(List<Transaction> transactions) { List<Transaction> normalizedTransactions = new ArrayList<>(transactions); ListMultimap<Long, Transaction> transactionByAbsoluteValue = ArrayListMultimap.create(); for (Transaction transaction : transactions) { transactionByAbsoluteValue.put(Math.abs(transaction.getAmount()), transaction); } for (Long amount : transactionByAbsoluteValue.keySet()) { List<Transaction> list = transactionByAbsoluteValue.get(amount); Set<Transaction> canceledOut = Sets.newIdentityHashSet(); for (Transaction transaction : list) { if (canceledOut.contains(transaction)) { continue; } for (Transaction transaction2 : list) { if (transaction.getAmount() == -transaction2.getAmount() && !canceledOut.contains(transaction2)) { canceledOut.add(transaction); canceledOut.add(transaction2); break; } } } normalizedTransactions.removeAll(canceledOut); } return normalizedTransactions; }
From source file:com.tomtom.camera.api.v2.ImageCapabilitiesV2.java
ImageCapabilitiesV2(ArrayList<ImageModeV2> imageCapabilityItems) { mImageCapabilitiesV2 = ArrayListMultimap.create(); mImageModeSettingsMap = new HashMap<>(); initImageModeSettings(imageCapabilityItems); }
From source file:org.marinemc.net.PacketQue.java
public PacketQue(final Client c) { que = ArrayListMultimap.create(); this.c = new WeakReference<>(c); }
From source file:org.apache.bigtop.itest.hbase.system.Scanner.java
public static int doScan(HTable table, int val) throws IOException, InterruptedException { Scan s = new Scan(); byte[] start = {}; byte[] stop = {}; byte[] value = Bytes.toBytes(String.format("%010d", val)); s.setStartRow(start);// ww w . j a v a 2 s .com s.setStopRow(stop); SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("f1"), Bytes.toBytes("qual"), CompareOp.EQUAL, value); s.setFilter(filter); // Keep track of gathered elements. Multimap<String, String> mm = ArrayListMultimap.create(); // Counts int cnt = 0; long i = 0; ResultScanner rs = table.getScanner(s); for (Result r : rs) { if (r.getRow() == null) { continue; } NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> columnFamilyMap = r.getMap(); // Output time to show if flush related. String k = Bytes.toStringBinary(r.getRow()); if (mm.get(k).size() >= 1) { System.out.println("Duplicate rowkey " + k); LOG.error("Duplicate rowkey " + k); } mm.put(Bytes.toStringBinary(r.getRow()), i + ": " + r); cnt++; i++; } System.out.println("scan items counted: " + cnt + " for scan " + s.toString() + " with filter f1:qual == " + Bytes.toString(value)); // Print out dupes. int dupes = 0; for (Entry<String, Collection<String>> e : mm.asMap().entrySet()) { if (e.getValue().size() > 1) { dupes++; System.out.print("Row " + e.getKey() + " had time stamps: "); String[] tss = e.getValue().toArray(new String[0]); System.out.println(Arrays.toString(tss)); } } return dupes; }
From source file:org.eclipse.milo.opcua.sdk.server.api.AbstractNodeManager.java
public AbstractNodeManager() { nodeMap = makeNodeMap(new MapMaker()); referenceMultimap = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); }
From source file:net.orzo.IntermediateResults.java
/** * */ public IntermediateResults() { this.data = ArrayListMultimap.create(); }