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:com.palantir.atlasdb.shell.AtlasShellConnectionDialogModel.java
public void setSavedDbConnections(List<String> savedDbConnections) { this.savedDbConnections = savedDbConnections; this.setSelectedItem(Iterables.getFirst(this.savedDbConnections, null)); this.update(); }
From source file:org.loadui.testfx.service.finder.impl.NodeFinderImpl.java
public Node node(Predicate<Node> predicate) { Set<Node> resultNodes = nodes(predicate); return Iterables.getFirst(resultNodes, null); }
From source file:com.github.blacklocus.rdsecho.utl.Route53Find.java
public Optional<ResourceRecordSet> resourceRecordSet(final String hostedZoneId, final Predicate<ResourceRecordSet> predicate) { return Optional.fromNullable(Iterables.getFirst(resourceRecordSets(hostedZoneId, predicate), null)); }
From source file:org.janusgraph.graphdb.database.idassigner.placement.PropertyPlacementStrategy.java
private int getPartitionIDbyKey(JanusGraphVertex vertex) { Preconditions.checkState(idManager != null && key != null, "PropertyPlacementStrategy has not been initialized correctly"); assert idManager.getPartitionBound() <= Integer.MAX_VALUE; int partitionBound = (int) idManager.getPartitionBound(); JanusGraphVertexProperty p = (JanusGraphVertexProperty) Iterables .getFirst(vertex.query().keys(key).properties(), null); if (p == null) return -1; int hashPid = Math.abs(p.value().hashCode()) % partitionBound; assert hashPid >= 0 && hashPid < partitionBound; if (isExhaustedPartition(hashPid)) { //We keep trying consecutive partition ids until we find a non-exhausted one int newPid = hashPid; do {/* www . j a v a 2 s . c o m*/ newPid = (newPid + 1) % partitionBound; if (newPid == hashPid) //We have gone full circle - no more ids to try throw new IDPoolExhaustedException("Could not find non-exhausted partition"); } while (isExhaustedPartition(newPid)); return newPid; } else return hashPid; }
From source file:org.apache.metron.stellar.dsl.functions.OrdinalFunctions.java
private static Comparable orderList(Iterable<Comparable> list, BiFunction<Comparable, Comparable, Boolean> eval, String funcName) {/*from ww w .j a v a 2 s.c om*/ if (Iterables.isEmpty(list)) { return null; } Object o = Iterables.getFirst(list, null); Comparable ret = null; for (Object valueVal : list) { if (valueVal == null) { continue; } Comparable value = null; if (!(valueVal instanceof Comparable)) { throw new IllegalStateException( "Noncomparable object type " + valueVal.getClass().getName() + " submitted to " + funcName); } else { value = (Comparable) valueVal; } try { Comparable convertedRet = ConversionUtils.convert(ret, value.getClass()); if (convertedRet == null && ret != null) { throw new IllegalStateException("Incomparable objects were submitted to " + funcName + ": " + ret.getClass() + " is incomparable to " + value.getClass()); } if (ret == null || eval.apply(convertedRet, value)) { ret = value; } } catch (ClassCastException cce) { throw new IllegalStateException( "Incomparable objects were submitted to " + funcName + ": " + cce.getMessage(), cce); } } return ret; }
From source file:me.emmy.db.MySQLLayer.java
public Optional<PlayerLocationRecord> find(final Player player) { return Optional.fromNullable(Iterables.getFirst( jdbc.query(selectQuery, new Object[] { player.getName() }, LocationMapper.instance), null)); }
From source file:org.obm.sync.server.Request.java
public String getClientIP() { String xForwardedFor = req.getHeader("X-Forwarded-For"); if (StringUtils.isBlank(xForwardedFor)) { return req.getRemoteAddr(); }//from www. j a v a2s . com Iterable<String> ips = Splitter.on(',').trimResults().split(xForwardedFor); return Iterables.getFirst(ips, req.getRemoteAddr()); }
From source file:org.jboss.hal.ballroom.LabelBuilder.java
/** * Turns a list of names from the management model into a human readable enumeration wrapped in quotes and * separated with commas. The last name is separated with the specified conjunction. * * @return The list of names as human readable string or an empty string if the names are null or empty. *///from www . j a v a 2s . c o m public String enumeration(Iterable<String> names, String conjunction) { String enumeration = ""; if (names != null && !Iterables.isEmpty(names)) { int size = Iterables.size(names); if (size == 1) { return QUOTE + label(names.iterator().next()) + QUOTE; } else if (size == 2) { return QUOTE + label(Iterables.getFirst(names, "")) + QUOTE + SPACE + conjunction + SPACE + QUOTE + label(Iterables.getLast(names)) + QUOTE; } else { String last = Iterables.getLast(names); LinkedList<String> allButLast = new LinkedList<>(); Iterables.addAll(allButLast, names); allButLast.removeLast(); enumeration = allButLast.stream().map(name -> QUOTE + label(name) + QUOTE) .collect(Collectors.joining(", ")); enumeration = enumeration + SPACE + conjunction + SPACE + QUOTE + label(last) + QUOTE; } } return enumeration; }
From source file:com.android.tools.idea.navigator.nodes.AndroidManifestsGroupNode.java
@Nullable private VirtualFile findFileToOpen(@NotNull Set<VirtualFile> files) { VirtualFile bestFile = Iterables.getFirst(files, null); PsiManager psiManager = PsiManager.getInstance(myProject); for (VirtualFile f : files) { PsiFile psiFile = psiManager.findFile(f); if (psiFile == null) { continue; }// ww w . j a v a 2 s. c o m IdeaSourceProvider sourceProvider = AndroidManifestFileNode.getSourceProvider(getValue(), psiFile); if (sourceProvider != null && SdkConstants.FD_MAIN.equals(sourceProvider.getName())) { bestFile = f; } } return bestFile; }
From source file:org.jbpm.workbench.common.client.list.AbstractMultiGridView.java
protected void controlBulkOperations(final ListTable<T> extendedPagedTable) { enableWidgets(Iterables.getFirst(extendedPagedTable.getRightActionsToolbar(), null), extendedPagedTable.hasSelectedItems()); }