List of usage examples for com.google.common.collect ArrayListMultimap create
public static <K, V> ArrayListMultimap<K, V> create()
From source file:eu.esdihumboldt.hale.common.align.model.transformation.tree.impl.CellNodeImpl.java
/** * Creates a cell node where the sources are populated from the given cell. * /*w w w .j av a 2 s . c om*/ * @param cell the cell * @param sourceNodes the factory for creating source nodes */ public CellNodeImpl(Cell cell, SourceNodeFactory sourceNodes) { super(); this.cell = cell; ListMultimap<SourceNode, String> sourceList = ArrayListMultimap.create(); if (cell.getSource() != null) { for (Entry<String, ? extends Entity> namedEntity : cell.getSource().entries()) { SourceNode node = sourceNodes.getSourceNode(namedEntity.getValue().getDefinition()); // XXX what about filter etc.?! node.addRelation(this); sourceList.put(node, namedEntity.getKey()); } } sources = Multimaps.unmodifiableListMultimap(sourceList); }
From source file:org.sonar.server.db.migrations.v51.CopyScmAccountsFromAuthorsToUsers.java
@Override public void execute(final Context context) throws SQLException { ProgressLogger progress = ProgressLogger.create(getClass(), counter); progress.start();//from ww w . j a v a2 s . c o m final Long now = system.now(); try { final Multimap<Long, String> authorsByPersonId = ArrayListMultimap.create(); context.prepareSelect("SELECT a.person_id, a.login FROM authors a," + " (SELECT person_id, COUNT(*) AS nb FROM authors GROUP BY person_id HAVING COUNT(*) > 1) group_by_person" + " WHERE a.person_id = group_by_person.person_id ").scroll(new Select.RowHandler() { @Override public void handle(Select.Row row) throws SQLException { authorsByPersonId.put(row.getNullableLong(1), row.getNullableString(2)); } }); Upsert update = context.prepareUpsert("UPDATE users SET scm_accounts = ?, updated_at = ? WHERE id = ?"); for (Long personId : authorsByPersonId.keySet()) { List<String> authors = newArrayList(authorsByPersonId.get(personId)); List<User> users = selectUsersFromLoginOrEmail(context, authors); if (users.size() == 1) { User user = users.get(0); if (authors.contains(user.login)) { authors.remove(user.login); } if (authors.contains(user.email)) { authors.remove(user.email); } if (!authors.isEmpty()) { update.setString(1, encodeScmAccounts(authors)).setLong(2, now).setLong(3, user.id) .addBatch(); counter.getAndIncrement(); } } } if (((UpsertImpl) update).getBatchCount() > 0L) { update.execute().commit(); } update.close(); progress.log(); } finally { progress.stop(); } }
From source file:core.TimeWindowAgentBase.java
public TimeWindowAgentBase(String info, String IDinputTerminal, String IDoutputTerminal) { super();/*from www . j av a 2 s. co m*/ this.setName(this.getName() + "@" + Relayer.getInstance().getAddress().toString()); //_sourceStream = new DefaultObservable<EventBean>(); this._info = info; this._type = "Window"; this._receivers[0] = new TopicReceiver(); inputTerminal = new IOTerminal(IDinputTerminal, "input channel " + _type, _receivers[0], this); outputTerminal = new IOTerminal(IDoutputTerminal, "output channel " + _type, this); _outputNotifier = new OQNotifier(this, QoSTuner.NOTIFICATION_PRIORITY); Queue<EventBean> selected1 = Queues.newArrayDeque(); _selectedEvents[0] = selected1; activeWindows = ArrayListMultimap.create(); //activeWindows = Multimaps.synchronizedListMultimap(activeWindows); //scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); timer = new Timer(); logger = new MyLogger("WindowsMeasures", WindowAgent.class.getName()); logger.log("Operator, isProduced, Processing Time, InputQ Size, OutputQ Size "); r = new TimerHandler(this); lock = new ReentrantLock(); }
From source file:com.isotrol.impe3.core.support.RouteParams.java
public static Multimap<String, String> toParams(UUID csrfToken, Route route) { if (route == null) { return ImmutableMultimap.of(); }/*from w w w . j a v a2 s. com*/ final PageKey key = route.getPage(); if (key == null) { return ImmutableMultimap.of(); } Multimap<String, String> p = ArrayListMultimap.create(); if (route.isSecure()) { p.put(SECURE, ""); } // The pk will only be an error page in case no page was resolved, so we turn to the main page if (key == PageKey.main() || key instanceof ErrorPage) { p.put(TYPE, TYPE_M); } else if (key instanceof Special) { p.put(TYPE, TYPE_S); p.put(NAME, ((Special) key).getName().toString()); } else if (key instanceof WithNavigation) { WithNavigation wn = (WithNavigation) key; final NavigationKey nk = wn.getNavigationKey(); if (nk != null) { if (nk.isCategory()) { p.put(CATEGORY, nk.getCategory().getId().toString()); } else if (nk.isTag()) { p.put(TAG, nk.getTag()); } if (nk.isContentType()) { p.put(TYPE, TYPE_L); p.put(CONTENT_TYPE, nk.getContentType().getId().toString()); } } if (wn instanceof NavigationPage) { p.put(TYPE, TYPE_N); } else if (wn instanceof ContentPage) { ContentPage cp = (ContentPage) key; final ContentKey ck = cp.getContentKey(); p.put(CONTENT_TYPE, ck.getContentType().getId().toString()); p.put(CONTENT_ID, ck.getContentId()); p.put(TYPE, TYPE_C); } } final Locale locale = route.getLocale(); if (locale != null) { p.put(LOCALE, locale.toString()); } final Device device = route.getDevice(); if (device != null) { p.put(DEVICE, device.getId().toString()); } if (csrfToken != null) { p.put(SESSIONCSRF, csrfToken.toString()); } return p; }
From source file:it.units.malelab.ege.distributed.worker.CommunicationRunnable.java
@Override public void run() { try (Socket socket = new Socket(worker.getMasterAddress(), worker.getMasterPort());) { //handshake ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream()); oos.flush();//from w ww . j a v a 2s. com ObjectInputStream ois = new ObjectInputStream(socket.getInputStream()); String challenge = DistributedUtils.decrypt((byte[]) ois.readObject(), worker.getKeyPhrase()); oos.writeObject(DistributedUtils.encrypt(DistributedUtils.reverse(challenge), worker.getKeyPhrase())); L.finer(String.format("Handshake response sent with \"%s\".", challenge)); //average stats Map<String, Number> avgStats = new HashMap<>(); for (String statName : worker.getStats().keySet()) { double s = 0; for (Number v : worker.getStats().get(statName)) { s = s + v.doubleValue(); } if (!worker.getStats().get(statName).isEmpty()) { avgStats.put(statName, s / worker.getStats().get(statName).size()); } } //prepare jobs data Multimap<String, Map<String, Object>> jobsData = ArrayListMultimap.create(); synchronized (worker.getCurrentJobsData()) { for (Job job : worker.getCurrentJobsData().keySet()) { jobsData.putAll(job.getId(), worker.getCurrentJobsData().get(job)); } worker.getCurrentJobsData().clear(); } //prepare jobs result Map<String, List<Node>> jobsResults = new HashMap<>(); synchronized (worker.getCompletedJobsResults()) { for (Map.Entry<Job, List<Node>> jobResultsEntry : worker.getCompletedJobsResults().entrySet()) { jobsResults.put(jobResultsEntry.getKey().getId(), jobResultsEntry.getValue()); } worker.getCompletedJobsResults().clear(); } //send worker message WorkerMessage workerMessage = new WorkerMessage(worker.getName(), worker.getInterval(), avgStats, worker.getFreeThreads(), worker.getMaxThreads(), jobsData, jobsResults); oos.writeObject(workerMessage); //read and consume master message MasterMessage masterMessage = (MasterMessage) ois.readObject(); for (Job job : masterMessage.getNewJobs()) { worker.submitJob(job); } //close socket.close(); } catch (IOException ex) { L.log(Level.SEVERE, String.format("Cannot connect to master: %s", ex.getMessage()), ex); } catch (ClassNotFoundException ex) { L.log(Level.SEVERE, String.format("Cannot decode response: %s", ex.getMessage()), ex); } catch (Throwable ex) { L.log(Level.SEVERE, String.format("Some error: %s", ex.getMessage()), ex); } }
From source file:eu.numberfour.n4js.tests.GrammarLinter.java
private static ListMultimap<String, Keyword> getAllKeywords(Grammar g) { ListMultimap<String, Keyword> keywords = ArrayListMultimap.create(); List<ParserRule> rules = GrammarUtil.allParserRules(g); for (ParserRule parserRule : rules) { List<Keyword> list = typeSelect(eAllContentsAsList(parserRule), Keyword.class); for (Keyword keyword : list) { keywords.put(keyword.getValue(), keyword); }//from w ww . j a va 2 s . c o m } List<EnumRule> enumRules = GrammarUtil.allEnumRules(g); for (EnumRule enumRule : enumRules) { List<Keyword> list = typeSelect(eAllContentsAsList(enumRule), Keyword.class); for (Keyword keyword : list) { keywords.put(keyword.getValue(), keyword); } } return keywords; }
From source file:br.eti.rslemos.podoscopista.FootprintRunner.java
private void collectDataPoints() { datapoints = ArrayListMultimap.create(); Field[] fields = clazz.getFields(); for (int i = 0; i < fields.length; i++) { if (fields[i].getAnnotation(Datapoint.class) != null && Modifier.isStatic(fields[i].getModifiers())) { datapoints.put(fields[i].getType(), fields[i]); }/*from w ww .java 2 s . c om*/ } datapoints.trimToSize(); }
From source file:com.ning.metrics.collector.processing.db.FeedEventProcessor.java
private ArrayListMultimap<String, FeedEvent> sortEventsByFeedKey(List<FeedEvent> feedEvents) { ArrayListMultimap<String, FeedEvent> multimap = ArrayListMultimap.create(); for (FeedEvent feedEvent : feedEvents) { final String feedKey = feedEvent.getMetadata().getFeed(); if (Strings.isNullOrEmpty(feedKey)) { continue; }/*from w ww . j ava2 s .co m*/ multimap.put(feedKey, feedEvent); } return multimap; }
From source file:org.opensingular.form.type.core.annotation.DocumentAnnotations.java
private SIAnnotation newAnnotation() { if (annotations == null) { annotations = newAnnotationList(document); annotationsMap = ArrayListMultimap.create(); }// ww w . jav a 2 s.c om return annotations.addNew(); }
From source file:fr.inria.oak.paxquery.common.xml.construction.ConstructionTreePattern.java
public ConstructionTreePattern(ConstructionTreePatternNode root) { this.root = root; this.root.setConstructionTreePattern(this); this.nodes = new HashSet<ConstructionTreePatternNode>(); this.nodes.add(root); this.parentEdges = new HashMap<ConstructionTreePatternNode, ConstructionTreePatternEdge>(); this.childrenEdges = ArrayListMultimap.create(); }