List of usage examples for com.google.common.collect Multimap get
Collection<V> get(@Nullable K key);
From source file:org.ms2ms.io.PsmWriters.java
public static void writeNovor(String filename, Multimap<SpectrumIdentifier, PeptideMatch> id_match, String score, String input) throws IOException { if (!Tools.isSet(id_match) || !Strs.isSet(filename)) return;/*from ww w . j a v a 2 s . c o m*/ System.out.print("Writing the PSMs to " + filename); FileWriter w = new FileWriter(filename); // write the header as required w.write(newNovorHeader(input).toString()); int counts = 1; String delim = ", "; w.write("# id, scanNum, RT, mz(data), z, pepMass(denovo), err(data-denovo), ppm(1e6*err/(mz*z)), score, peptide, aaScore, \n"); for (SpectrumIdentifier id : id_match.keySet()) { // only care about the run as indicated if (id.getSpectrum().indexOf(input) != 0) continue; for (PeptideMatch m : id_match.get(id)) { // let's fake an aaScore String aascore = null; for (int i = 0; i < m.size(); i++) aascore = Strs.extend(aascore, "1", "-"); w.write((counts++) + delim + id.getScanNumbers().getFirst().getValue() + delim + (Tools.isSet(id.getRetentionTimes()) ? id.getRetentionTimes().getFirst().getTime() : 0) + delim + id.getPrecursorMz().get() + delim + id.getAssumedCharge().get() + delim + m.getNeutralPeptideMass() + delim + m.getMassDiff() + delim + 1E6 * m.getMassDiff() / m.getNeutralPeptideMass() + delim + m.getScore(score) + delim + m.toSymbolString() + delim + aascore + "\n"); } } System.out.println(" --> " + counts); w.close(); }
From source file:org.sonar.server.permission.ws.TemplateGroupsAction.java
private static WsPermissions.WsGroupsResponse buildResponse(List<GroupDto> groups, List<PermissionTemplateGroupDto> groupPermissions, Paging paging) { Multimap<Long, String> permissionsByGroupId = TreeMultimap.create(); groupPermissions.forEach(groupPermission -> permissionsByGroupId.put(groupPermission.getGroupId(), groupPermission.getPermission())); WsPermissions.WsGroupsResponse.Builder response = WsPermissions.WsGroupsResponse.newBuilder(); groups.forEach(group -> {/*from ww w. jav a 2 s .c o m*/ WsPermissions.Group.Builder wsGroup = response.addGroupsBuilder().setName(group.getName()); if (group.getId() != 0L) { wsGroup.setId(String.valueOf(group.getId())); } if (group.getDescription() != null) { wsGroup.setDescription(group.getDescription()); } wsGroup.addAllPermissions(permissionsByGroupId.get(group.getId())); }); response.getPagingBuilder().setPageIndex(paging.pageIndex()).setPageSize(paging.pageSize()) .setTotal(paging.total()); return response.build(); }
From source file:com.google.idea.blaze.base.sync.projectstructure.ContentEntryEditor.java
public static void createContentEntries(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, ModifiableRootModel modifiableRootModel) { ImportRoots importRoots = ImportRoots.builder(workspaceRoot, Blaze.getBuildSystem(project)) .add(projectViewSet).build(); Collection<WorkspacePath> rootDirectories = importRoots.rootDirectories(); Collection<WorkspacePath> excludeDirectories = importRoots.excludeDirectories(); Multimap<WorkspacePath, WorkspacePath> excludesByRootDirectory = sortExcludesByRootDirectory( rootDirectories, excludeDirectories); SourceTestConfig testConfig = new SourceTestConfig(projectViewSet); SourceFolderProvider provider = SourceFolderProvider.getSourceFolderProvider(blazeProjectData); List<ContentEntry> contentEntries = Lists.newArrayList(); for (WorkspacePath rootDirectory : rootDirectories) { File root = workspaceRoot.fileForPath(rootDirectory); ContentEntry contentEntry = modifiableRootModel.addContentEntry(pathToUrl(root.getPath())); contentEntries.add(contentEntry); for (WorkspacePath exclude : excludesByRootDirectory.get(rootDirectory)) { File excludeFolder = workspaceRoot.fileForPath(exclude); contentEntry.addExcludeFolder(pathToIdeaUrl(excludeFolder)); }/*from ww w . ja v a 2 s . c o m*/ ImmutableMap<VirtualFile, SourceFolder> sourceFolders = provider.initializeSourceFolders(contentEntry); VirtualFile rootFile = getVirtualFile(root); if (rootFile == null) { IssueOutput .warn(String.format("Could not find directory %s. Your 'test_sources' project view " + "attribute will not have any effect. Please resync.", workspaceRoot)) .submit(context); continue; } SourceFolder rootSource = sourceFolders.get(rootFile); walkFileSystem(workspaceRoot, testConfig, excludesByRootDirectory.get(rootDirectory), contentEntry, provider, sourceFolders, rootSource, rootFile); } }
From source file:com.torodb.torod.db.postgresql.query.processors.InProcessor.java
@Nullable private static ProcessedQueryCriteria getNumericQuery(InQueryCriteria criteria, Multimap<BasicType, Value<?>> byTypeValues) { ImmutableList.Builder<Value<?>> newInBuilder = ImmutableList.builder(); for (Value<?> value : byTypeValues.values()) { newInBuilder.add(value);//from www . j a v a 2 s.co m } ImmutableList<Value<?>> newIn = newInBuilder.build(); if (newIn.isEmpty()) { return null; } DisjunctionBuilder structureBuilder = new DisjunctionBuilder(); structureBuilder.add(new TypeIsQueryCriteria(criteria.getAttributeReference(), BasicType.DOUBLE)); structureBuilder.add(new TypeIsQueryCriteria(criteria.getAttributeReference(), BasicType.INTEGER)); structureBuilder.add(new TypeIsQueryCriteria(criteria.getAttributeReference(), BasicType.LONG)); newInBuilder.addAll(byTypeValues.get(BasicType.DOUBLE)); newInBuilder.addAll(byTypeValues.get(BasicType.INTEGER)); newInBuilder.addAll(byTypeValues.get(BasicType.LONG)); return new ProcessedQueryCriteria(structureBuilder.build(), new InQueryCriteria(criteria.getAttributeReference(), newIn)); }
From source file:com.google.devtools.build.lib.packages.EnvironmentGroup.java
/** * Given an environment and set of environments that directly fulfill it, computes a nested * set of environments that <i>transitively</i> fulfill it, places it into transitiveFulfillers, * and returns that set.// ww w .j a va 2 s . c o m */ private static NestedSet<Label> setTransitiveFulfillers(Label env, Multimap<Label, Label> directFulfillers, Map<Label, NestedSet<Label>> transitiveFulfillers) { if (transitiveFulfillers.containsKey(env)) { return transitiveFulfillers.get(env); } else if (!directFulfillers.containsKey(env)) { // Nobody fulfills this environment. NestedSet<Label> emptySet = NestedSetBuilder.emptySet(Order.STABLE_ORDER); transitiveFulfillers.put(env, emptySet); return emptySet; } else { NestedSetBuilder<Label> set = NestedSetBuilder.stableOrder(); for (Label fulfillingEnv : directFulfillers.get(env)) { set.add(fulfillingEnv); set.addTransitive(setTransitiveFulfillers(fulfillingEnv, directFulfillers, transitiveFulfillers)); } NestedSet<Label> builtSet = set.build(); transitiveFulfillers.put(env, builtSet); return builtSet; } }
From source file:org.crypto.sse.RR2Lev.java
public static RR2Lev constructEMMPar(final byte[] key, final Multimap<String, String> lookup, final int bigBlock, final int smallBlock, final int dataSize) throws InterruptedException, ExecutionException, IOException { final Multimap<String, byte[]> dictionary = ArrayListMultimap.create(); random.setSeed(CryptoPrimitives.randomSeed(16)); for (int i = 0; i < dataSize; i++) { // initialize all buckets with random values free.add(i);//w w w .ja v a 2 s. com } List<String> listOfKeyword = new ArrayList<String>(lookup.keySet()); int threads = 0; if (Runtime.getRuntime().availableProcessors() > listOfKeyword.size()) { threads = listOfKeyword.size(); } else { threads = Runtime.getRuntime().availableProcessors(); } ExecutorService service = Executors.newFixedThreadPool(threads); ArrayList<String[]> inputs = new ArrayList<String[]>(threads); final Map<Integer, String> concurrentMap = new ConcurrentHashMap<Integer, String>(); for (int i = 0; i < listOfKeyword.size(); i++) { concurrentMap.put(i, listOfKeyword.get(i)); } for (int j = 0; j < threads; j++) { service.execute(new Runnable() { @SuppressWarnings("unused") @Override public void run() { while (concurrentMap.keySet().size() > 0) { // write code Set<Integer> possibleValues = concurrentMap.keySet(); Random rand = new Random(); int temp = rand.nextInt(possibleValues.size()); List<Integer> listOfPossibleKeywords = new ArrayList<Integer>(possibleValues); // set the input as randomly selected from the remaining // possible keys String[] input = { concurrentMap.get(listOfPossibleKeywords.get(temp)) }; // remove the key concurrentMap.remove(listOfPossibleKeywords.get(temp)); try { Multimap<String, byte[]> output = setup(key, input, lookup, bigBlock, smallBlock, dataSize); Set<String> keys = output.keySet(); for (String k : keys) { dictionary.putAll(k, output.get(k)); } } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | IOException | InvalidAlgorithmParameterException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); } // Make sure executor stops service.shutdown(); // Blocks until all tasks have completed execution after a shutdown // request service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); return new RR2Lev(dictionary, array); }
From source file:com.twitter.common.metrics.JvmStats.java
/** * Add a series of system and jvm-level stats to the given registry. *///from w ww.j ava 2 s . co m public static void register(MetricRegistry registry) { final MetricRegistry stats = registry.scope("jvm"); final MemoryMXBean mem = ManagementFactory.getMemoryMXBean(); // memory stats final MetricRegistry heapRegistry = stats.scope("heap"); registerMemoryStats(heapRegistry, new MemoryReporter() { @Override public MemoryUsage getUsage() { return mem.getHeapMemoryUsage(); } }); final MetricRegistry nonHeapRegistry = stats.scope("nonheap"); registerMemoryStats(nonHeapRegistry, new MemoryReporter() { @Override public MemoryUsage getUsage() { return mem.getNonHeapMemoryUsage(); } }); // threads final ThreadMXBean threads = ManagementFactory.getThreadMXBean(); final MetricRegistry threadRegistry = stats.scope("thread"); threadRegistry.register(new AbstractGauge<Integer>("daemon_count") { @Override public Integer read() { return threads.getDaemonThreadCount(); } }); threadRegistry.register(new AbstractGauge<Integer>("count") { @Override public Integer read() { return threads.getThreadCount(); } }); threadRegistry.register(new AbstractGauge<Integer>("peak_count") { @Override public Integer read() { return threads.getPeakThreadCount(); } }); // class loading bean final ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean(); stats.register(new AbstractGauge<Integer>("classes_loaded") { @Override public Integer read() { return classLoadingBean.getLoadedClassCount(); } }); stats.register(new AbstractGauge<Long>("total_classes_loaded") { @Override public Long read() { return classLoadingBean.getTotalLoadedClassCount(); } }); stats.register(new AbstractGauge<Long>("classes_unloaded") { @Override public Long read() { return classLoadingBean.getUnloadedClassCount(); } }); // runtime final RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); stats.register(new AbstractGauge<Long>("start_time") { @Override public Long read() { return runtime.getStartTime(); } }); stats.register(new AbstractGauge<Long>("uptime") { @Override public Long read() { return runtime.getUptime(); } }); //stats.register(new AbstractGauge<String>) // os final OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); stats.register(new AbstractGauge<Integer>("num_cpus") { @Override public Integer read() { return os.getAvailableProcessors(); } }); if (os instanceof com.sun.management.OperatingSystemMXBean) { final com.sun.management.OperatingSystemMXBean sunOsMbean = (com.sun.management.OperatingSystemMXBean) os; // if this is indeed an operating system stats.register(new AbstractGauge<Long>("free_physical_memory") { @Override public Long read() { return sunOsMbean.getFreePhysicalMemorySize(); } }); stats.register(new AbstractGauge<Long>("free_swap") { @Override public Long read() { return sunOsMbean.getFreeSwapSpaceSize(); } }); stats.register(new AbstractGauge<Long>("process_cpu_time") { @Override public Long read() { return sunOsMbean.getProcessCpuTime(); } }); } if (os instanceof com.sun.management.UnixOperatingSystemMXBean) { // it's a unix system... I know this! final UnixOperatingSystemMXBean unix = (UnixOperatingSystemMXBean) os; stats.register(new AbstractGauge<Long>("fd_count") { @Override public Long read() { return unix.getOpenFileDescriptorCount(); } }); stats.register(new AbstractGauge<Long>("fd_limit") { @Override public Long read() { return unix.getMaxFileDescriptorCount(); } }); } // mem final List<MemoryPoolMXBean> memPool = ManagementFactory.getMemoryPoolMXBeans(); final MetricRegistry memRegistry = stats.scope("mem"); final MetricRegistry currentMem = memRegistry.scope("current"); final MetricRegistry postGCRegistry = memRegistry.scope("postGC"); for (final MemoryPoolMXBean pool : memPool) { String name = normalizeName(pool.getName()); registerMemoryStats(currentMem.scope(name), new MemoryReporter() { @Override public MemoryUsage getUsage() { return pool.getUsage(); } }); registerMemoryStats(postGCRegistry.scope(name), new MemoryReporter() { @Override public MemoryUsage getUsage() { return pool.getCollectionUsage(); } }); } currentMem.register(new AbstractGauge<Long>("used") { @Override public Long read() { long sum = 0; for (MemoryPoolMXBean pool : memPool) { MemoryUsage usage = pool.getUsage(); if (usage != null) { sum += usage.getUsed(); } } return sum; } }); AbstractGauge<Long> totalPostGCGauge = new AbstractGauge<Long>("used") { @Override public Long read() { long sum = 0; for (MemoryPoolMXBean pool : memPool) { MemoryUsage usage = pool.getCollectionUsage(); if (usage != null) { sum += usage.getUsed(); } } return sum; } }; postGCRegistry.register(totalPostGCGauge); // java 1.7 specific buffer pool gauges Multimap<String, AbstractGauge<Long>> java17gauges = buildJava17Gauges(); if (!java17gauges.isEmpty()) { MetricRegistry bufferRegistry = stats.scope("buffer"); for (String scope : java17gauges.keySet()) { MetricRegistry pool = bufferRegistry.scope(scope); for (AbstractGauge<Long> gauge : java17gauges.get(scope)) { pool.register(gauge); } } } // gc final List<GarbageCollectorMXBean> gcPool = ManagementFactory.getGarbageCollectorMXBeans(); MetricRegistry gcRegistry = stats.scope("gc"); for (final GarbageCollectorMXBean gc : gcPool) { String name = normalizeName(gc.getName()); MetricRegistry scoped = memRegistry.scope(name); scoped.register(new AbstractGauge<Long>("cycles") { @Override public Long read() { return gc.getCollectionCount(); } }); scoped.register(new AbstractGauge<Long>("msec") { @Override public Long read() { return gc.getCollectionTime(); } }); } gcRegistry.register(new AbstractGauge<Long>("cycles") { @Override public Long read() { long sum = 0; for (GarbageCollectorMXBean pool : gcPool) { long count = pool.getCollectionCount(); if (count > 0) { sum += count; } } return sum; } }); gcRegistry.register(new AbstractGauge<Long>("msec") { @Override public Long read() { long sum = 0; for (GarbageCollectorMXBean pool : gcPool) { long msec = pool.getCollectionTime(); if (msec > 0) { sum += msec; } } return sum; } }); }
From source file:org.crypto.sse.RH2Lev.java
public static RH2Lev constructEMMPar(final byte[] key, final Multimap<String, String> lookup, final int bigBlock, final int smallBlock, final int dataSize) throws InterruptedException, ExecutionException, IOException { final Multimap<String, byte[]> dictionary = ArrayListMultimap.create(); for (int i = 0; i < dataSize; i++) { free.add(i);//from ww w .ja v a 2 s. c o m } random.setSeed(CryptoPrimitives.randomSeed(16)); List<String> listOfKeyword = new ArrayList<String>(lookup.keySet()); int threads = 0; if (Runtime.getRuntime().availableProcessors() > listOfKeyword.size()) { threads = listOfKeyword.size(); } else { threads = Runtime.getRuntime().availableProcessors(); } ExecutorService service = Executors.newFixedThreadPool(threads); ArrayList<String[]> inputs = new ArrayList<String[]>(threads); final Map<Integer, String> concurrentMap = new ConcurrentHashMap<Integer, String>(); for (int i = 0; i < listOfKeyword.size(); i++) { concurrentMap.put(i, listOfKeyword.get(i)); } for (int j = 0; j < threads; j++) { service.execute(new Runnable() { @SuppressWarnings("unused") @Override public void run() { while (concurrentMap.keySet().size() > 0) { Random rand = new Random(); String[] input = { "" }; synchronized (concurrentMap) { Set<Integer> possibleValues = concurrentMap.keySet(); int temp = rand.nextInt(possibleValues.size()); List<Integer> listOfPossibleKeywords = new ArrayList<Integer>(possibleValues); // set the input as randomly selected from the remaining // possible keys input[0] = concurrentMap.get(listOfPossibleKeywords.get(temp)); // remove the key concurrentMap.remove(listOfPossibleKeywords.get(temp)); } try { Multimap<String, byte[]> output = setup(key, input, lookup, bigBlock, smallBlock, dataSize); Set<String> keys = output.keySet(); for (String k : keys) { dictionary.putAll(k, output.get(k)); } } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | IOException | InvalidAlgorithmParameterException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); } service.shutdown(); // Blocks until all tasks have completed execution after a shutdown // request service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); return new RH2Lev(dictionary, array); }
From source file:org.crypto.sse.DynRH2Lev.java
public static TreeMultimap<String, byte[]> tokenUpdate(byte[] key, Multimap<String, String> lookup) throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, IOException { TreeMultimap<String, byte[]> tokenUp = TreeMultimap.create(Ordering.natural(), Ordering.usingToString()); SecureRandom random = new SecureRandom(); random.setSeed(CryptoPrimitives.randomSeed(16)); byte[] iv = new byte[16]; for (String word : lookup.keySet()) { byte[] key3 = CryptoPrimitives.generateCmac(key, 3 + new String()); byte[] key4 = CryptoPrimitives.generateCmac(key, 4 + word); for (String id : lookup.get(word)) { random.nextBytes(iv);//from ww w . jav a2 s .co m int counter = 0; if (state.get(word) != null) { counter = state.get(word); } state.put(word, counter + 1); byte[] l = CryptoPrimitives.generateCmac(key4, "" + counter); byte[] value = CryptoPrimitives.encryptAES_CTR_String(key3, iv, id, sizeOfFileIdentifer); tokenUp.put(new String(l), value); } } return tokenUp; }
From source file:org.crypto.sse.EMM2Lev.java
public static RH2Lev constructEMMPar(final byte[] key, final Multimap<String, String> lookup, final int bigBlock, final int smallBlock, final int dataSize) throws InterruptedException, ExecutionException, IOException { final Multimap<String, byte[]> dictionary = ArrayListMultimap.create(); for (int i = 0; i < dataSize; i++) { free.add(i);//from w ww.jav a2 s .c o m } random.setSeed(CryptoPrimitives.randomSeed(16)); List<String> listOfKeyword = new ArrayList<String>(lookup.keySet()); int threads = 0; if (Runtime.getRuntime().availableProcessors() > listOfKeyword.size()) { threads = listOfKeyword.size(); } else { threads = Runtime.getRuntime().availableProcessors(); } ExecutorService service = Executors.newFixedThreadPool(threads); ArrayList<String[]> inputs = new ArrayList<String[]>(threads); final Map<Integer, String> concurrentMap = new ConcurrentHashMap<Integer, String>(); for (int i = 0; i < listOfKeyword.size(); i++) { concurrentMap.put(i, listOfKeyword.get(i)); } for (int j = 0; j < threads; j++) { service.execute(new Runnable() { @SuppressWarnings("unused") @Override public void run() { while (concurrentMap.keySet().size() > 0) { Set<Integer> possibleValues = concurrentMap.keySet(); Random rand = new Random(); int temp = rand.nextInt(possibleValues.size()); List<Integer> listOfPossibleKeywords = new ArrayList<Integer>(possibleValues); // set the input as randomly selected from the remaining // possible keys String[] input = { concurrentMap.get(listOfPossibleKeywords.get(temp)) }; // remove the key concurrentMap.remove(listOfPossibleKeywords.get(temp)); try { Multimap<String, byte[]> output = setup(key, input, lookup, bigBlock, smallBlock, dataSize); Set<String> keys = output.keySet(); for (String k : keys) { dictionary.putAll(k, output.get(k)); } } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | IOException | InvalidAlgorithmParameterException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); } service.shutdown(); // Blocks until all tasks have completed execution after a shutdown // request service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); return new RH2Lev(dictionary, array); }