List of usage examples for com.google.common.collect Iterables getFirst
@Nullable public static <T> T getFirst(Iterable<? extends T> iterable, @Nullable T defaultValue)
From source file:org.eclipse.incquery.runtime.matchers.psystem.annotations.PAnnotation.java
/** * Returns the value of the first occurrence of an attribute * @param attributeName/* ww w .j av a 2s . c o m*/ * @return the attribute value, or null, if attribute is not available */ public Object getFirstValue(String attributeName) { return Iterables.getFirst(getAllValues(attributeName), null); }
From source file:com.SilenceIt.utils.GetCalEntries.java
public TimePeriod getEntries() { Date nowtime = new Date(); Map<String, List<TimePeriod>> busytimes; try {// ww w . j a v a 2 s . co m busytimes = getFreeBusyTimes.getBusyTimes(OAuthManager.getInstance().getAccount().name, nowtime, 1); for (List<TimePeriod> busy : busytimes.values()) { Log.d(Constants.TAG, "busy: " + busy.toString()); } Log.d(Constants.TAG, "size of busytimes: " + busytimes.values().size()); Log.d(Constants.TAG, "is empty busytimes: " + busytimes.values().isEmpty()); List<TimePeriod> defaultFirst = new ArrayList<TimePeriod>(); Log.d(Constants.TAG, "defaultFirst: " + defaultFirst.toString()); Log.d(Constants.TAG, "First: " + Iterables.getFirst(busytimes.values(), defaultFirst)); try { if (Iterables.getFirst(busytimes.values(), defaultFirst).isEmpty()) { Log.d(Constants.TAG, "No events"); } else { FirstEvent = Iterables.get(busytimes.values(), 0).get(0); } } catch (IndexOutOfBoundsException e1) { Log.d(Constants.TAG, "Index Out of Bound Exception"); } } catch (final Exception e) { Log.e(Constants.TAG, "Some Serious ERROR"); e.printStackTrace(); //Log.e(Constants.TAG, e.getStackTrace().toString()); } Log.d(Constants.TAG, "Returning FirstEvent: " + FirstEvent.toString()); return FirstEvent; }
From source file:nextmethod.web.razor.parser.internal.WhiteSpaceRewriter.java
@Override protected SyntaxTreeNode rewriteBlock(@Nonnull final BlockBuilder parent, @Nonnull final Block block) { final BlockBuilder newBlock = new BlockBuilder(checkNotNull(block)); newBlock.getChildren().clear();//from www . ja v a2 s. c om final Span ws = typeAs(Iterables.getFirst(block.getChildren(), null), Span.class); Collection<SyntaxTreeNode> newNodes = block.getChildren(); if (ws != null && ParserHelpers.isAllOfString(ws.getContent(), ParserHelpers::isWhitespace)) { // Add this node to the parent final SpanBuilder builder = new SpanBuilder(ws); builder.clearSymbols(); fillSpan(builder, ws.getStart(), ws.getContent()); parent.getChildren().add(builder.build()); // Remove the old whitespace node newNodes = Lists.newArrayList(Iterables.skip(block.getChildren(), 1)); } for (SyntaxTreeNode node : newNodes) { newBlock.getChildren().add(node); } return newBlock.build(); }
From source file:com.google.idea.blaze.base.run.rulefinder.RuleFinder.java
@Nullable public RuleIdeInfo firstRuleOfKinds(Project project, List<Kind> kinds) { return Iterables.getFirst(rulesOfKinds(project, kinds), null); }
From source file:com.github.blacklocus.rdsecho.utl.Route53Find.java
public Optional<HostedZone> hostedZone() { return Optional.fromNullable(Iterables.getFirst(hostedZones(), null)); }
From source file:com.google.idea.blaze.base.run.targetfinder.TargetFinder.java
@Nullable public TargetIdeInfo firstTargetOfKinds(Project project, List<Kind> kinds) { return Iterables.getFirst(targetsOfKinds(project, kinds), null); }
From source file:org.gradle.plugins.ide.internal.generator.XmlPersistableConfigurationObject.java
@Nullable protected static Node findFirstWithAttributeValue(@Nullable List<Node> nodes, final String attribute, final String value) { return nodes == null ? null : Iterables.getFirst(Iterables.filter(nodes, new Predicate<Node>() { @Override//from w w w .j a va 2 s .c o m public boolean apply(Node node) { return value.equals(node.attribute(attribute)); } }), null); }
From source file:com.google.idea.blaze.base.buildmap.OpenCorrespondingBuildFile.java
@Nullable private File getBuildFile(Project project, @Nullable VirtualFile virtualFile) { if (virtualFile == null) { return null; }/* ww w .ja v a 2 s . c o m*/ File file = new File(virtualFile.getPath()); Collection<File> fileInfoList = FileToBuildMap.getInstance(project).getBuildFilesForFile(file); return Iterables.getFirst(fileInfoList, null); }
From source file:com.rockhoppertech.music.examples.Guava.java
public static void ranges() { RangeSet<Double> set = TreeRangeSet.create(); // for (double i = 1d; i < 4d; i++) { // set.add(Range.closed(i, i + 1d)); // }//w w w . ja v a2s.c o m set.add(Range.closed(1d, 4d)); logger.debug("the set {}", set); set.remove(Range.closed(2.5, 3d)); logger.debug("after remove: set {}", set); RangeSet<Double> comp = set.complement(); logger.debug("after remove: set comp {}", comp); Range<Double> first = Iterables.getFirst(set.asRanges(), null); logger.debug("first {}", first); //Iterables. for (Range<Double> r : set.asRanges()) { logger.debug("iterated range {}", r); } //lowerEndpoint(); set.clear(); set.add(Range.open(1d, 4d)); comp = set.complement(); logger.debug("open comp {}", comp); }
From source file:org.solovyev.common.collections.multimap.ObjectsChangedMapUpdater.java
private boolean containsChangedObjects(@Nonnull Map<K, List<V>> map) { if (changedObjects.size() > 1) { return true; } else if (changedObjects.size() == 1) { final V changedObject = Iterables.getFirst(changedObjects, null); for (List<V> objects : map.values()) { if (objects.contains(changedObject)) { return true; }/*from www . java 2s . c o m*/ } return false; } else { return false; } }