List of usage examples for com.google.common.collect Iterables find
@Nullable public static <T> T find(Iterable<? extends T> iterable, Predicate<? super T> predicate, @Nullable T defaultValue)
From source file:org.killbill.billing.util.tag.dao.DefaultTagDao.java
@Override protected boolean checkEntityAlreadyExists(final EntitySqlDao<TagModelDao, Tag> transactional, final TagModelDao entity, final InternalCallContext context) { return Iterables.find(transactional.getByAccountRecordId(context), new Predicate<TagModelDao>() { @Override//from w ww . ja v a2 s. co m public boolean apply(final TagModelDao existingTag) { return entity.equals(existingTag) || entity.isSame(existingTag); } }, null) != null; }
From source file:com.twitter.aurora.scheduler.configuration.Resources.java
private static Resource getResource(List<Resource> resource, String key) { return Iterables.find(resource, withName(key), null); }
From source file:org.grouplens.grapht.graph.DAGNode.java
/** * Search for an outgoing edge by a predicate. * * @param predicate A predicate over labels. * @return An outgoing edge matching the predicate, or {@code null} if no such edge exists. If * multiple edges have labels matching the predicate, it is undefined which one will be * added./*from ww w. j a v a 2 s . c om*/ */ public DAGEdge<V, E> getOutgoingEdgeWithLabel(Predicate<? super E> predicate) { Predicate<DAGEdge<?, E>> edgePred = DAGEdge.labelMatches(predicate); return Iterables.find(outgoingEdges, edgePred, null); }
From source file:org.sonar.server.debt.DebtModelBackup.java
@CheckForNull private static RuleDebt ruleDebt(String ruleRepo, String ruleKey, List<RuleDebt> ruleDebts) { if (ruleDebts.isEmpty()) { return null; }/*from w w w . ja v a2 s. c om*/ return Iterables.find(ruleDebts, new RuleDebtMatchRuleRepoAndRuleKey(ruleRepo, ruleKey), null); }
From source file:com.censoredsoftware.infractions.bukkit.legacy.util.MiscUtil.java
public static boolean removeInfraction(String target, final String givenID) { CompleteDossier dossier = Infractions.getCompleteDossier(target); Infraction infraction = Iterables.find(dossier.getInfractions(), new Predicate<Infraction>() { @Override/*from w w w. ja v a 2s . co m*/ public boolean apply(Infraction infraction) { return givenID.equals(getInfractionId(infraction)); } }, null); if (infraction != null) { dossier.acquit(infraction); return true; } return false; }
From source file:org.polarsys.reqcycle.traceability.cache.emfbased.CacheTraceabilityEngine.java
private TraceabilityLink getTraceabilityLink(Reachable container, TraceableElement sourceElements, Iterable<TraceableElement> targetElements, String label) { TraceabilityLink result = null;//from w w w .j ava2 s . co m AnalyzedResource analy = getResource(container); if (analy != null) { TraceabilityLink t = Iterables.find(analy.getLinks(), new TraceabilityLinkPredicate(sourceElements, targetElements, label), null); result = t; } return result; }
From source file:io.airlift.jaxrs.testing.MockRequest.java
private static <T> T firstNonNull(T... objects) { return Iterables.find(asList(objects), Predicates.<Object>notNull(), null); }
From source file:ru.ksu.niimm.cll.mocassin.crawl.parser.latex.StructureBuilderImpl.java
private boolean getNumberedProperty(OutlineNode node, LatexDocumentModel model) { int nodeType = node.getType(); if (nodeType == OutlineNode.TYPE_SECTION || nodeType == OutlineNode.TYPE_SUBSECTION || nodeType == OutlineNode.TYPE_SUBSUBSECTION) return true; // TODO: not accurate!! String nodeName = node.getName(); if (nodeName.endsWith("*")) return false; NewtheoremCommand foundCommand = Iterables.find(model.getNewtheorems(), new NewtheoremCommand.KeyPredicate(nodeName), null); if (foundCommand != null) { return foundCommand.isNumbered(); }/*from w ww .j a v a 2s. c om*/ return true; }
From source file:org.sonar.server.issue.ws.IssueShowWsHandler.java
/** * Can be null on removed component/*from w ww .jav a 2 s. co m*/ */ @CheckForNull private Component geProject(IssueQueryResult result, @Nullable final ComponentDto component) { if (component != null) { return Iterables.find(result.components(), new Predicate<Component>() { @Override public boolean apply(Component input) { return component.projectId().equals(((ComponentDto) input).getId()); } }, null); } return null; }
From source file:fr.putnami.pwt.core.model.client.ModelDriver.java
public Context<?> getContext(final Editor editor) { return Iterables.find(this.contexts, new Predicate<Context<?>>() { @Override//from w ww. ja v a 2s . co m public boolean apply(Context<?> context) { return context.getEditor() == editor; } }, null); }