List of usage examples for com.google.common.collect Multimap get
Collection<V> get(@Nullable K key);
From source file:org.terasology.entitySystem.pojo.PojoEventSystem.java
@Override public void send(EntityRef entity, Event event, Component component) { if (Thread.currentThread() != mainThread) { pendingEvents.offer(new PendingEvent(entity, event, component)); } else {/*from w w w . ja v a 2s .c o m*/ Multimap<Class<? extends Component>, EventHandlerInfo> handlers = componentSpecificHandlers .get(event.getClass()); if (handlers != null) { for (EventHandlerInfo eventHandler : handlers.get(component.getClass())) { if (eventHandler.isValidFor(entity)) { eventHandler.invoke(entity, event); } } } } }
From source file:org.napile.compiler.lang.resolve.processors.DeclarationResolver.java
private void checkRedeclarationsInNamespaces() { for (PackageDescriptor descriptor : context.getPackages().values()) { Multimap<Name, DeclarationDescriptor> simpleNameDescriptors = ((WritableScope) descriptor .getMemberScope()).getDeclaredDescriptorsAccessibleBySimpleName(); for (Name name : simpleNameDescriptors.keySet()) { Collection<DeclarationDescriptor> descriptors = simpleNameDescriptors.get(name); if (descriptors.size() > 1) { for (DeclarationDescriptor declarationDescriptor : descriptors) { for (PsiElement declaration : getDeclarationsByDescriptor(declarationDescriptor)) { assert declaration != null; trace.report(REDECLARATION.on(declaration, declarationDescriptor.getName().getName())); }//w w w. ja v a 2 s.c o m } } } } }
From source file:edu.umn.msi.tropix.webgui.server.SearchImpl.java
private List<ServiceBean> convertResults(final Multimap<String, SearchHit> shBeans) { final List<ServiceBean> serviceBeans = new LinkedList<ServiceBean>(); for (final String catalogId : shBeans.keySet()) { final Collection<SearchHit> hits = shBeans.get(catalogId); BasicEntry[] bsBeans = null;//from w ww.j a va 2 s. c om try { bsBeans = this.catalogClient.getEntryAPI(catalogId) .getBasicDetails(CatalogUtils.getServiceIDsFromSHBeanList(hits), 500); } catch (final RemoteException e) { ExceptionUtils.logQuietly(SearchImpl.LOG, e, "Failed to obtain basic details"); continue; } if (bsBeans == null) { bsBeans = new BasicEntry[0]; } try { serviceBeans.addAll(convertBasicServiceBeanToServiceBean( this.catalogClient.getOntologAPI(catalogId), Arrays.asList(bsBeans), true)); } catch (final Exception e) { ExceptionUtils.logQuietly(SearchImpl.LOG, e, "Failed to convert catalog results"); continue; } for (final SearchHit searchBean : hits) { for (final ServiceBean serviceBean : serviceBeans) { if (searchBean.getEntryID().equals(serviceBean.getId())) { serviceBean.setCatalogId(catalogId); if (searchBean.getInstances() != null && searchBean.getInstances().length > 0) { serviceBean.setSearchHits(getUIHitInsts(searchBean.getInstances())); } serviceBean.setLuceneScore(searchBean.getWeightedScore()); } } } } return serviceBeans; }
From source file:org.gradle.plugins.ide.internal.resolver.DefaultIdeDependencyResolver.java
private void recordParents(Multimap<ResolvedComponentResult, ResolvedComponentResult> parents, ResolvedComponentResult parent, ResolvedComponentResult child) { parents.put(child, parent);//from w w w .jav a2 s .c o m for (ResolvedComponentResult grandParent : parents.get(parent)) { recordParents(parents, grandParent, child); } }
From source file:org.apache.cassandra.db.compaction.LeveledCompactionStrategy.java
public ScannerList getScanners(Collection<SSTableReader> sstables, Range<Token> range) { Multimap<Integer, SSTableReader> byLevel = ArrayListMultimap.create(); for (SSTableReader sstable : sstables) { byLevel.get(sstable.getSSTableLevel()).add(sstable); }// ww w.ja v a 2 s . com List<ISSTableScanner> scanners = new ArrayList<ISSTableScanner>(sstables.size()); try { for (Integer level : byLevel.keySet()) { // level can be -1 when sstables are added to Tracker but not to LeveledManifest // since we don't know which level those sstable belong yet, we simply do the same as L0 sstables. if (level <= 0) { // L0 makes no guarantees about overlapping-ness. Just create a direct scanner for each for (SSTableReader sstable : byLevel.get(level)) scanners.add(sstable.getScanner(range, CompactionManager.instance.getRateLimiter())); } else { // Create a LeveledScanner that only opens one sstable at a time, in sorted order List<SSTableReader> intersecting = LeveledScanner.intersecting(byLevel.get(level), range); if (!intersecting.isEmpty()) scanners.add(new LeveledScanner(intersecting, range)); } } } catch (Throwable t) { try { new ScannerList(scanners).close(); } catch (Throwable t2) { t.addSuppressed(t2); } throw t; } return new ScannerList(scanners); }
From source file:org.sonar.core.issue.tracking.AbstractTracker.java
protected void match(Tracking<RAW, BASE> tracking, Function<Trackable, SearchKey> searchKeyFactory) { if (tracking.isComplete()) { return;/* ww w .ja va 2s. co m*/ } Multimap<SearchKey, BASE> baseSearch = ArrayListMultimap.create(); for (BASE base : tracking.getUnmatchedBases()) { baseSearch.put(searchKeyFactory.apply(base), base); } for (RAW raw : tracking.getUnmatchedRaws()) { SearchKey rawKey = searchKeyFactory.apply(raw); Collection<BASE> bases = baseSearch.get(rawKey); bases.stream().sorted( comparing(this::statusRank).reversed().thenComparing(comparing(Trackable::getCreationDate))) .findFirst().ifPresent(match -> { tracking.match(raw, match); baseSearch.remove(rawKey, match); }); } }
From source file:com.streamsets.pipeline.lib.jdbc.JdbcMultiRowRecordWriter.java
@SuppressWarnings("unchecked") private void processPartition(Connection connection, Multimap<Long, Record> partitions, Long partitionKey, List<OnRecordErrorException> errorRecords) throws SQLException, OnRecordErrorException { Collection<Record> partition = partitions.get(partitionKey); // Fetch the base insert query for this partition. SortedMap<String, String> columnsToParameters = getFilteredColumnsToParameters(getColumnsToParameters(), partition.iterator().next()); // put all the records in a queue for consumption LinkedList<Record> queue = new LinkedList<>(partition); // compute number of rows per batch if (columnsToParameters.isEmpty()) { throw new OnRecordErrorException(Errors.JDBCDEST_22); }/*from w w w .j a va2 s . c o m*/ int maxRowsPerBatch = maxPrepStmtParameters / columnsToParameters.size(); PreparedStatement statement = null; // parameters are indexed starting with 1 int paramIdx = 1; int rowCount = 0; while (!queue.isEmpty()) { // we're at the start of a batch. if (statement == null) { // instantiate the new statement statement = generatePreparedStatement(columnsToParameters, // the next batch will have either the max number of records, or however many are left. Math.min(maxRowsPerBatch, queue.size()), getTableName(), connection); } // process the next record into the current statement Record record = queue.removeFirst(); for (String column : columnsToParameters.keySet()) { Field field = record.get(getColumnsToFields().get(column)); Field.Type fieldType = field.getType(); Object value = field.getValue(); try { switch (fieldType) { case LIST: List<Object> unpackedList = unpackList((List<Field>) value); Array array = connection.createArrayOf(getSQLTypeName(fieldType), unpackedList.toArray()); statement.setArray(paramIdx, array); break; case DATE: case DATETIME: // Java Date types are not accepted by JDBC drivers, so we need to convert to java.sql.Date java.util.Date date = field.getValueAsDatetime(); statement.setObject(paramIdx, new java.sql.Date(date.getTime())); break; default: statement.setObject(paramIdx, value, getColumnType(column)); break; } } catch (SQLException e) { LOG.error(Errors.JDBCDEST_23.getMessage(), column, fieldType.toString(), e); throw new OnRecordErrorException(record, Errors.JDBCDEST_23, column, fieldType.toString()); } ++paramIdx; } rowCount++; // check if we've filled up the current batch if (rowCount == maxRowsPerBatch) { // time to execute the current batch statement.addBatch(); statement.executeBatch(); statement.close(); statement = null; // reset our counters rowCount = 0; paramIdx = 1; } } // check if there are any records left. this should occur whenever there isn't *exactly* maxRowsPerBatch records in // this partition. if (statement != null) { statement.addBatch(); statement.executeBatch(); statement.close(); } }
From source file:org.jclouds.ec2.compute.strategy.EC2ListNodesStrategy.java
protected Function<String, Set<? extends Reservation<? extends RunningInstance>>> instancesByIdInRegion( final Multimap<String, String> idsByRegions) { return new Function<String, Set<? extends Reservation<? extends RunningInstance>>>() { @Override/*from w w w .j av a 2 s .c o m*/ public Set<? extends Reservation<? extends RunningInstance>> apply(String from) { return client.getInstanceApi().get().describeInstancesInRegion(from, toArray(idsByRegions.get(from), String.class)); } }; }
From source file:org.crypto.sse.ZMF.java
public static Map<String, boolean[]> setupSetMV2(byte[] key, String keyword, Multimap<String, String> documentsComposition, Multimap<String, String> keywordComposition, int falsePosRate) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, IOException { // Extract all documents' identifiers that are associated to the keyword // Initialize a set that will contain all elements Multimap<String, String> totalElements = ArrayListMultimap.create(); int maxSize = 0; Map<String, Map<Integer, Boolean>> state = new HashMap<String, Map<Integer, Boolean>>(); // Create a Set that contains all elements of documents that contain // "keyword"// ww w .j ava2 s . co m for (String identifier : keywordComposition.get(keyword)) { // Filtering the keywords that are associated to a large number of // keywords for (String word : documentsComposition.get(identifier)) { if (!totalElements.get(word).contains(identifier) && ((double) TextExtractPar.lp1.get(word).size() / TextExtractPar.maxTupleSize > IEXZMF.filterParameter)) { totalElements.put(word, identifier); } } if (documentsComposition.get(identifier).size() > maxSize) { maxSize = documentsComposition.get(identifier).size(); } state.put(identifier, new HashMap<Integer, Boolean>()); } // This can be used to reduce the size of the Bloom filters to store // only significant keywords // Limiting to a number of 1000 keywords per file // maxSize =1000; // determine the size of the largest array double maxArraySize = falsePosRate * maxSize / Math.log(2); // Creation of an array that has as a size a power of 2 int counter = 0; for (int j = 0; j < 1000; j++) { if (maxArraySize > Math.pow(2, counter)) { counter++; } else { break; } } // The final size of the array equals maxArraySize = Math.pow(2, counter); // Key of PRF applied to elements byte[] keyPRF = new byte[key.length / 3]; System.arraycopy(key, 0, keyPRF, 0, key.length / 3); // Printer.debugln("Key PRF "+ // CryptoPrimitives.booleanToString(CryptoPrimitives.bytesToBoolean(keyPRF))); // Key for the online cipher byte[] keyOCHash = new byte[key.length / 3]; System.arraycopy(key, key.length / 3, keyOCHash, 0, key.length / 3); byte[] keyOCEnc = new byte[key.length / 3]; System.arraycopy(key, 2 * key.length / 3, keyOCEnc, 0, key.length / 3); // Creation of online Cipher values in memory List<byte[][]> onlineCipherList = new ArrayList<byte[][]>(); for (int i = 0; i < maxArraySize; i++) { boolean[] messageBol = CryptoPrimitives.intToBoolean(i, counter); onlineCipherList.add(CryptoPrimitives.onlineCipherOWF(keyOCHash, keyOCEnc, messageBol)); } // Block Size of the OC in bytes int blockSize = 32; // Initialization of all Matryoshka filters boolean mask; Map<String, boolean[]> listOfBloomFilter = new HashMap<String, boolean[]>(); for (String identifier : keywordComposition.get(keyword)) { // determine the size of the Matryoshka filter int count = 0; double filterSize = 0; // MF each has a size at most maxSize if (documentsComposition.get(identifier).size() < maxSize) { filterSize = falsePosRate * documentsComposition.get(identifier).size() / Math.log(2); } else { filterSize = falsePosRate * maxSize / Math.log(2); } // Assuming of course that there is no filter with more than 2^1000 // cells for (int j = 0; j < 1000; j++) { if (filterSize > Math.pow(2, count)) { count++; } else { break; } } // creation of an empty filter boolean[] bloomFilter = new boolean[(int) Math.pow(2, count)]; // initialization of the state for (int v = 0; v < Math.pow(2, count); v++) { state.get(identifier).put(v, false); } // Adding the mask to all positions of the filter for (int j = 0; j < (int) Math.pow(2, count); j++) { // Truncating only the required position from the OC byte[] positionFinal = new byte[count * blockSize]; for (int s = 0; s < count; s++) { System.arraycopy(onlineCipherList.get(j)[s], 0, positionFinal, s * blockSize, blockSize); } // Computing the Random Oracle byte[] hmac2 = CryptoPrimitives.generateHmac(keyHMAC, CryptoPrimitives.concat(identifier.getBytes(), positionFinal)); // We truncate the needed bits from the output of the HMAC to // get the bit 1 to counter mask = (CryptoPrimitives.getBit(hmac2, 0) != 0); bloomFilter[j] = mask; } listOfBloomFilter.put(identifier, bloomFilter); } // Insertion of the elements in the filters for (String word : totalElements.keySet()) { for (String id : totalElements.get(word)) { // determine the size of the Matryoshka filter int count = 0; // double filterSize= falsePosRate * // documentsComposition.get(id).size()/Math.log(2); double filterSize = 0; if (documentsComposition.get(id).size() < maxSize) { filterSize = falsePosRate * documentsComposition.get(id).size() / Math.log(2); } else { filterSize = falsePosRate * maxSize / Math.log(2); } for (int j = 0; j < 1000; j++) { if (filterSize > Math.pow(2, count)) { count++; } else { break; } } for (int j = 0; j < falsePosRate; j++) { // Computation of the position where the element will be // inserted byte[] hmac = CryptoPrimitives.generateHmac(keyHMAC, CryptoPrimitives.concat(String.valueOf(j).getBytes(), CryptoPrimitives.generateHmac( keyPRF, CryptoPrimitives.concat(keyword.getBytes(), word.getBytes())))); int pos = CryptoPrimitives.getIntFromByte(hmac, count); if (state.get(id).get(pos).equals(false)) { boolean[] temp = listOfBloomFilter.get(id); temp[pos] = true ^ temp[pos]; listOfBloomFilter.put(id, temp); state.get(id).put(pos, true); } } } } return listOfBloomFilter; }
From source file:com.informatica.um.binge.api.impl.PluginsFactory.java
/** * Load the plugin class and return the native and java dependencies for the plugin * @param pluginClass/*from w w w. j a v a2 s . c o m*/ * @param deps * @return * @throws MalformedURLException * @throws ClassNotFoundException */ private Class loadPluginClass(String pluginClass, Multimap<String, File> deps, File pluginFolder) throws MalformedURLException, ClassNotFoundException { URL[] jars = new URL[deps.get(LIB).size()]; int i = 0; for (File file : deps.get(LIB)) { LOG.info("Loading jar file {}", file.getAbsolutePath()); jars[i++] = file.toURI().toURL(); } // Create URL class loader and load the class file return new URLClassLoader(jars).loadClass(pluginClass); }