List of usage examples for com.google.common.collect Iterables get
@Nullable public static <T> T get(Iterable<? extends T> iterable, int position, @Nullable T defaultValue)
From source file:edu.udo.scaffoldhunter.gui.data.MessageModel.java
@Override public Object getChild(Object parent, int index) { if (parent == root) { Object child = Iterables.get(jobs.values(), index, null); logger.trace("getChild at index {} : {}", index, child); return child; }//from w ww. ja v a2 s . c o m if (!(parent instanceof MessageTreeNode)) { logger.trace("getChild at index {} : null", index); return null; } Object child = ((MessageTreeNode<?>) parent).getChild(index); logger.trace("getChild at index {} : {}", index, child); return child; }
From source file:diskCacheV111.srm.dcache.DcacheUserManager.java
public DcacheUserManager(LoginStrategy loginStrategy, DataSource dataSource, String type) { this.loginStrategy = loginStrategy; this.jdbcTemplate = new JdbcTemplate(dataSource); this.persistence = new CanonicalizingByteArrayStore((id, encoded) -> jdbcTemplate .update("INSERT INTO srmuser (id, type, encoded) VALUES(?,?,?)", ps -> { ps.setLong(1, id);//from w w w . java 2 s .co m ps.setString(2, type); ps.setBytes(3, encoded); }), id -> Iterables.get(jdbcTemplate.query("SELECT encoded FROM srmuser WHERE id = ?", (rs, rowNum) -> rs.getBytes(1), id), 0, null), id -> jdbcTemplate.update("DELETE FROM srmuser WHERE id=?", id)); }
From source file:edu.mit.streamjit.impl.common.IOInfo.java
/** * Creates IOInfo objects for all edges of the given set of workers. The workers * must have their predecessor/successor relationships initialized, but they * need not be connected with channels. The given set need not be * connected (in the reachability sense). * @param workers a set of workers/*from w w w. jav a2 s . c o m*/ * @return a set of IOInfo objects for all edges of the given set */ public static ImmutableSet<IOInfo> allEdges(Set<? extends Worker<?, ?>> workers) { //TODO: we'll get most edges twice, once while traversing preds and once //for succs. Using a sorted set is a total hack. ImmutableSortedSet.Builder<IOInfo> retval = ImmutableSortedSet.orderedBy(IOInfo.TOKEN_SORT); boolean overallInput = false; boolean overallOutput = false; for (Worker<?, ?> w : workers) { List<? extends Worker<?, ?>> preds = Workers.getPredecessors(w); List<? extends Channel<?>> ichans = Workers.getInputChannels(w); checkArgument((preds.size() == ichans.size()) || (preds.isEmpty() && ichans.size() == 1)); if (preds.isEmpty()) { checkArgument(!overallInput, "two overall inputs?!"); Channel<?> chan = Iterables.get(ichans, 0, null); retval.add(new IOInfo(null, w, chan, Blob.Token.createOverallInputToken(w), ConnectionKind.INPUT)); overallInput = true; } for (int i = 0; i < preds.size(); ++i) { Worker<?, ?> pred = preds.get(i); Channel<?> chan = Iterables.get(ichans, i, null); Blob.Token token = new Blob.Token(pred, w); retval.add(new IOInfo(pred, w, chan, token, workers.contains(pred) ? ConnectionKind.INTERNAL : ConnectionKind.INPUT)); } } for (Worker<?, ?> w : workers) { List<? extends Worker<?, ?>> succs = Workers.getSuccessors(w); List<? extends Channel<?>> ochans = Workers.getOutputChannels(w); checkArgument((succs.size() == ochans.size()) || (succs.isEmpty() && ochans.size() == 1)); if (succs.isEmpty()) { checkArgument(!overallOutput, "two overall outputs?!"); Channel<?> chan = Iterables.get(ochans, 0, null); retval.add( new IOInfo(w, null, chan, Blob.Token.createOverallOutputToken(w), ConnectionKind.OUTPUT)); overallOutput = true; } for (int i = 0; i < succs.size(); ++i) { Worker<?, ?> succ = succs.get(i); Channel<?> chan = Iterables.get(ochans, i, null); Blob.Token token = new Blob.Token(w, succ); retval.add(new IOInfo(w, succ, chan, token, workers.contains(succ) ? ConnectionKind.INTERNAL : ConnectionKind.OUTPUT)); } } return retval.build(); }
From source file:brooklyn.entity.cloudfoundry.CloudFoundryEntityImpl.java
protected CloudFoundryPaasLocation getLocationOrNull() { return Iterables.get(Iterables.filter(getLocations(), CloudFoundryPaasLocation.class), 0, null); }
From source file:foo.domaintest.email.AutoreplyAction.java
@Override public void run() { if (!presentedApiKey.equals(requiredApiKey)) { throw new BadRequestException("Invalid API key"); }/* ww w . j av a 2s . c om*/ Iterable<String> subjectWords = Splitter.on(CharMatcher.WHITESPACE).omitEmptyStrings().trimResults() .split(nullToEmpty(subject)); // For spam-ignoring purposes, we only respond if the subject starts with the word "TEST". if (!"TEST".equalsIgnoreCase(getFirst(subjectWords, null))) { logger.info("Subject did not begin with the word 'TEST'"); return; } String newBody = null; // Try to consider the second word (if any) as a stash token. If it is one, stash the headers. String token = Iterables.get(subjectWords, 1, null); if (token != null && memcache.load(new Key(TOKEN, token)) != null) { Map<String, Object> params = new HashMap<>(); params.put("payload", rawHeaders); memcache.save(new Key(STASH, token), params, STASH_EXPIRATION); newBody = tempUrlFactory.getTempUrl(token); } String newSender = "tester@" + Splitter.on('@').splitToList(to).get(1); String newRecipient = Optional.fromNullable(replyTo).or(from); // We construct the references and in-reply-to headers according to RFC 5322 3.6.4. The new // references is the old message id. The new in-reply-to is the old references plus the old // message id. If there's no old references but there is an old in-reply-to with exactly one id, // we use that in place of the references. String newInReplyTo = messageId; if (isNullOrEmpty(references) && !isNullOrEmpty(inReplyTo) && !WHITESPACE.matchesAnyOf(inReplyTo.trim())) { references = inReplyTo; } String newReferences = emptyToNull(Joiner.on(' ').skipNulls().join(references, messageId)); logger.info(String.format("Sending from %s to %s", newSender, newRecipient)); logger.info(String.format("in-reply-to: %s, references: %s", newInReplyTo, newReferences)); emailer.send(newSender, newRecipient, newBody, newInReplyTo, newReferences); }
From source file:org.apache.brooklyn.entity.openshift.OpenShiftEntityImpl.java
protected OpenShiftPaasLocation getLocationOrNull() { return Iterables.get(Iterables.filter(getLocations(), OpenShiftPaasLocation.class), 0, null); }
From source file:com.flaptor.indextank.storage.RawLog.java
public Segment getFirstSegment() { Segment segment = Iterables.get(Segment.iterateSegments(root, root.getHistoryLogPath()), 0, null); if (segment == null) { segment = Iterables.get(Segment.iterateSegments(root, root.getLiveLogPath()), 0, null); }/*from w w w . j a va 2 s.c om*/ return segment; }
From source file:org.wisdom.ebean.runtime.EbeanCrudService.java
/** * Retrieves the entity matching the given filter. If several entities matches, the first is returned. * * @param filter the filter/* w w w . j a va 2 s . co m*/ * @return the first matching instance, {@literal null} if none */ @Override public T findOne(final EntityFilter<T> filter) { return Iterables.get(findAll(filter), 0, null); }
From source file:com.jive.myco.seyren.core.service.notification.FlowdockNotificationService.java
private String formatContent(List<String> emojis, Check check, Subscription subscription, List<Alert> alerts) { String url = String.format("%s/#/checks/%s", seyrenConfig.getBaseUrl(), check.getId()); String alertsString = Joiner.on(", ").join(transform(alerts, new Function<Alert, String>() { @Override// w w w . j a va 2 s . c o m public String apply(Alert input) { return String.format("%s: %s", input.getTarget(), input.getValue().toString()); } })); return String.format("%s %s has entered its %s state - [%s] - %s - %s", Iterables.get(emojis, check.getState().ordinal(), ""), check.getName(), check.getState().toString(), alertsString, Iterables.getFirst(alerts, null).getTimestamp(), url); }
From source file:com.jive.myco.seyren.core.service.notification.SlackNotificationService.java
private String formatContent(List<String> emojis, Check check, Subscription subscription, List<Alert> alerts) { String url = String.format("%s/#/checks/%s", seyrenConfig.getBaseUrl(), check.getId()); String alertsString = Joiner.on(", ").join(transform(alerts, new Function<Alert, String>() { @Override// ww w. j av a 2 s .com public String apply(Alert input) { return String.format("%s: %s", input.getTarget(), input.getValue().toString()); } })); return String.format("[%s] %s %s has entered its %s state - [%s] - %s", Iterables.getFirst(alerts, null).getTimestamp(), Iterables.get(emojis, check.getState().ordinal(), ""), check.getName(), check.getState().toString(), alertsString, url); }