List of usage examples for com.google.common.collect ArrayListMultimap create
public static <K, V> ArrayListMultimap<K, V> create()
From source file:aritzh.waywia.universe.World.java
public static World newWorld(String name, File universeFolder) throws IOException { String folderName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, name); File root = new File(universeFolder, folderName); if (!root.exists() && !root.mkdirs()) throw new IOException("Could not create folder for new world at: " + root.getAbsolutePath()); BDSCompound customData = new BDSCompound("CustomData"); Multimap<String, Entity> entities = ArrayListMultimap.create(); HashMap<String, Player> player = Maps.newHashMap(); Matrix<Block> blocks = new Matrix<>(50, 38, new BackgroundBlock()); return new World(name, root, customData, entities, player, blocks); }
From source file:org.sonar.batch.rule.RulesProvider.java
private Rules load(RuleDao ruleDao, DefaultDebtModel debtModel, Durations durations) { RulesBuilder rulesBuilder = new RulesBuilder(); List<RuleParamDto> ruleParamDtos = ruleDao.selectParameters(); ListMultimap<Integer, RuleParamDto> paramDtosByRuleId = ArrayListMultimap.create(); for (RuleParamDto dto : ruleParamDtos) { paramDtosByRuleId.put(dto.getRuleId(), dto); }/* w w w . j a va 2 s .c o m*/ for (RuleDto ruleDto : ruleDao.selectEnablesAndNonManual()) { RuleKey ruleKey = RuleKey.of(ruleDto.getRepositoryKey(), ruleDto.getRuleKey()); NewRule newRule = rulesBuilder.add(ruleKey).setId(ruleDto.getId()).setName(ruleDto.getName()) .setSeverity(ruleDto.getSeverityString()).setDescription(ruleDto.getDescription()) .setStatus(ruleDto.getStatus()).setInternalKey(ruleDto.getConfigKey()); if (hasCharacteristic(ruleDto)) { newRule.setDebtSubCharacteristic(effectiveCharacteristic(ruleDto, ruleKey, debtModel).key()); newRule.setDebtRemediationFunction(effectiveFunction(ruleDto, ruleKey, durations)); } for (RuleParamDto ruleParamDto : paramDtosByRuleId.get(ruleDto.getId())) { newRule.addParam(ruleParamDto.getName()).setDescription(ruleParamDto.getDescription()); } } return rulesBuilder.build(); }
From source file:org.sonar.plsqlopen.checks.UnnecessaryAliasInQueryCheck.java
@Override public void visitNode(AstNode node) { if (node.hasAncestor(dmlStatements)) { // if the current node is inside another DML statement (i.e. subquery), the node should be // ignored because it is considered in the analysis of the outer statement return;//from w ww . j a va 2s . c o m } ListMultimap<String, TableReference> tableReferences = ArrayListMultimap.create(); for (AstNode fromClause : node.getDescendants(DmlGrammar.DML_TABLE_EXPRESSION_CLAUSE)) { AstNode table = fromClause.getFirstChild(DmlGrammar.TABLE_REFERENCE); AstNode alias = fromClause.getFirstChild(DmlGrammar.ALIAS); if (table != null) { tableReferences.put(table.getTokenOriginalValue().toLowerCase(), new TableReference(table, alias)); } } for (String tableName : tableReferences.keySet()) { List<TableReference> references = tableReferences.get(tableName); checkReference(references); } }
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 w w. j ava 2s.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); }
From source file:com.ning.http.multipart.MultipartRequestEntity.java
/** * Creates a new multipart entity containing the given parts. * @param parts The parts to include./*ww w .j a va2s . c o m*/ * @param methodParams The params of the HttpMethod using this entity. */ public MultipartRequestEntity(Part[] parts, Multimap<String, String> methodParams) { if (parts == null) { throw new IllegalArgumentException("parts cannot be null"); } if (methodParams == null) { methodParams = ArrayListMultimap.create(); } this.parts = parts; this.methodParams = methodParams; }
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);// www. j a va2 s . co 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:fr.inria.oak.paxquery.common.xml.construction.ConstructionTreePattern.java
private ConstructionTreePattern() { this.nodes = new HashSet<ConstructionTreePatternNode>(); this.parentEdges = new HashMap<ConstructionTreePatternNode, ConstructionTreePatternEdge>(); this.childrenEdges = ArrayListMultimap.create(); }
From source file:com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsViaIteratorsDoFn.java
@Override public void processElement(ProcessContext c) throws Exception { K key = c.element().getKey();//from www . j av a2 s . c om Iterable<WindowedValue<V>> value = c.element().getValue(); PeekingReiterator<WindowedValue<V>> iterator; if (value instanceof Collection) { iterator = new PeekingReiterator<>(new ListReiterator<WindowedValue<V>>( new ArrayList<WindowedValue<V>>((Collection<WindowedValue<V>>) value), 0)); } else if (value instanceof Reiterable) { iterator = new PeekingReiterator<>(((Reiterable<WindowedValue<V>>) value).iterator()); } else { throw new IllegalArgumentException( "Input to GroupAlsoByWindowsDoFn must be a Collection or Reiterable"); } // This ListMultimap is a map of window maxTimestamps to the list of active // windows with that maxTimestamp. ListMultimap<Instant, BoundedWindow> windows = ArrayListMultimap.create(); while (iterator.hasNext()) { WindowedValue<V> e = iterator.peek(); for (BoundedWindow window : e.getWindows()) { // If this window is not already in the active set, emit a new WindowReiterable // corresponding to this window, starting at this element in the input Reiterable. if (!windows.containsEntry(window.maxTimestamp(), window)) { // Iterating through the WindowReiterable may advance iterator as an optimization // for as long as it detects that there are no new windows. windows.put(window.maxTimestamp(), window); c.windowingInternals().outputWindowedValue( KV.of(key, (Iterable<V>) new WindowReiterable<V>(iterator, window)), e.getTimestamp(), Arrays.asList(window)); } } // Copy the iterator in case the next DoFn cached its version of the iterator instead // of immediately iterating through it. // And, only advance the iterator if the consuming operation hasn't done so. iterator = iterator.copy(); if (iterator.hasNext() && iterator.peek() == e) { iterator.next(); } // Remove all windows with maxTimestamp behind the current timestamp. Iterator<Instant> windowIterator = windows.keys().iterator(); while (windowIterator.hasNext() && windowIterator.next().isBefore(e.getTimestamp())) { windowIterator.remove(); } } }
From source file:cpw.mods.fml.common.LoadController.java
public LoadController(Loader loader) { this.loader = loader; this.masterChannel = new EventBus("FMLMainChannel"); this.masterChannel.register(this); state = LoaderState.NOINIT;/*from w w w.j a v a 2s. c o m*/ packageOwners = ArrayListMultimap.create(); }
From source file:org.sonar.server.computation.issue.FillComponentIssuesVisitorRule.java
@Override public Statement apply(final Statement statement, Description description) { return new Statement() { @Override/*from w w w . ja va 2s . c om*/ public void evaluate() throws Throwable { try { statement.evaluate(); } finally { issues = ArrayListMultimap.create(); } } }; }