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.github.blacklocus.rdsecho.utl.Route53Find.java
public Optional<HostedZone> hostedZone(final Predicate<HostedZone> predicate) { return Optional.fromNullable(Iterables.getFirst(hostedZones(predicate), null)); }
From source file:net.minecraftforge.fml.common.asm.transformers.MarkerTransformer.java
private void readMapFile(String rulesFile) throws IOException { File file = new File(rulesFile); URL rulesResource;// w ww . ja v a2 s. c o m if (file.exists()) { rulesResource = file.toURI().toURL(); } else { rulesResource = Resources.getResource(rulesFile); } Resources.readLines(rulesResource, Charsets.UTF_8, new LineProcessor<Void>() { @Override public Void getResult() { return null; } @Override public boolean processLine(String input) throws IOException { String line = Iterables.getFirst(Splitter.on('#').limit(2).split(input), "").trim(); if (line.length() == 0) { return true; } List<String> parts = Lists.newArrayList(Splitter.on(" ").trimResults().split(line)); if (parts.size() != 2) { throw new RuntimeException("Invalid config file line " + input); } List<String> markerInterfaces = Lists .newArrayList(Splitter.on(",").trimResults().split(parts.get(1))); for (String marker : markerInterfaces) { markers.put(parts.get(0), marker); } return true; } }); }
From source file:com.google.idea.blaze.base.run.targetfinder.TargetFinder.java
@Nullable private TargetIdeInfo findTarget(Project project, Predicate<TargetIdeInfo> predicate) { List<TargetIdeInfo> results = findTargets(project, predicate); assert results.size() <= 1; return Iterables.getFirst(results, null); }
From source file:org.apache.metron.writer.WriterToBulkWriter.java
@Override public BulkWriterResponse write(String sensorType, WriterConfiguration configurations, Iterable<Tuple> tuples, List<MESSAGE_T> messages) throws Exception { BulkWriterResponse response = new BulkWriterResponse(); if (messages.size() > 1) { response.addAllErrors(new IllegalStateException("WriterToBulkWriter expects a batch of exactly 1"), tuples);/*from w w w . j a v a 2 s.c o m*/ return response; } try { messageWriter.write(sensorType, configurations, Iterables.getFirst(tuples, null), Iterables.getFirst(messages, null)); } catch (Exception e) { response.addAllErrors(e, tuples); return response; } response.addAllSuccesses(tuples); return response; }
From source file:com.eviware.loadui.integration.LoadUIUtils.java
public static String getOpenedProjectName(WorkspaceProvider workspaceProvider) { ProjectItem projectItem = Iterables.getFirst(workspaceProvider.getWorkspace().getProjects(), null); String openedProjectName = projectItem != null ? projectItem.getLabel() : ""; return openedProjectName; }
From source file:org.n52.javaps.coding.stream.AbstractSimilarityKeyRepository.java
protected C choose(Set<C> matches, K key) { if (matches == null || matches.isEmpty()) { LOG.debug("No implementation for {}", key); return null; } else if (matches.size() > 1) { return chooseFrom(matches, key); } else {//from www .j av a2s . co m return Iterables.getFirst(matches, null); } }
From source file:io.jenkins.blueocean.preload.FavoritesStatePreloader.java
@Override protected FetchData getFetchData(@Nonnull BlueUrlTokenizer blueUrl) { User jenkinsUser = User.current();// w w w. j a v a2 s. c om if (jenkinsUser != null) { BlueOrganization organization = Iterables.getFirst(OrganizationFactory.getInstance().list(), null); if (organization != null) { String pipelineFullName = blueUrl.getPart(BlueUrlTokenizer.UrlPart.PIPELINE); // don't need this list when at pipeline pages if (pipelineFullName != null) { return null; } UserImpl blueUser = new UserImpl(organization, jenkinsUser, organization.getUsers()); BlueFavoriteContainer favoritesContainer = blueUser.getFavorites(); if (favoritesContainer != null) { JSONArray favorites = new JSONArray(); // Limit the number of favorites to return to a sane amount Iterator<BlueFavorite> favoritesIterator = favoritesContainer.iterator(0, DEFAULT_LIMIT); while (favoritesIterator.hasNext()) { Reachable favorite = favoritesIterator.next(); try { favorites.add(JSONObject.fromObject(Export.toJson(favorite))); } catch (IOException e) { LOGGER.log(Level.FINE, String.format("Unable to preload favorites for User '%s'. Serialization error.", jenkinsUser.getFullName()), e); return null; } } return new FetchData(favoritesContainer.getLink().getHref() + "?start=0&limit=" + DEFAULT_LIMIT, favorites.toString()); } } } // Don't preload any data on the page. return null; }
From source file:com.facebook.presto.tpch.SampledTpchRecordSetProvider.java
@Override public RecordSet getRecordSet(Split split, List<? extends ColumnHandle> columns) { int sampleWeightField = -1; for (int i = 0; i < columns.size(); i++) { ColumnHandle column = columns.get(i); if (column instanceof TpchColumnHandle && ((TpchColumnHandle) column).getColumnName() .equals(SampledTpchMetadata.SAMPLE_WEIGHT_COLUMN_NAME)) { sampleWeightField = i;//from w ww.j a v a2 s .c o m break; } } List<? extends ColumnHandle> delegatedColumns = new ArrayList<>(columns); if (sampleWeightField > -1) { delegatedColumns.remove(sampleWeightField); RecordSet recordSet; if (delegatedColumns.isEmpty()) { // Pick a random column, so that we can figure out how many rows there are TpchSplit tpchSplit = (TpchSplit) split; ColumnHandle column = Iterables .getFirst(metadata.getColumnHandles(tpchSplit.getTableHandle()).values(), null); checkNotNull(column, "Could not find any columns"); recordSet = new EmptyRecordSet(super.getRecordSet(split, ImmutableList.of(column))); } else { recordSet = super.getRecordSet(split, delegatedColumns); } return new SampledTpchRecordSet(recordSet, sampleWeightField, sampleWeight); } else { return super.getRecordSet(split, columns); } }
From source file:org.eclipse.osee.orcs.db.internal.sql.SqlAliasManager.java
public String getFirstAlias(int level, AliasEntry table, ObjectType objectType) { Collection<String> aliases = getAliases(level, table, objectType); return Iterables.getFirst(aliases, null); }
From source file:org.apache.metron.enrichment.bolt.HBaseBolt.java
public static String zkConnectStringToPort(String connString) { String hostPortPair = Iterables.getFirst(Splitter.on(",").split(connString), ""); return Iterables.getLast(Splitter.on(":").split(hostPortPair), DEFAULT_ZK_PORT); }