List of usage examples for com.google.common.collect Iterables getLast
@Nullable public static <T> T getLast(Iterable<? extends T> iterable, @Nullable T defaultValue)
From source file:org.eclipse.xtext.xbase.typesystem.LocalVariableCapturer.java
protected static <R extends LocalVariableCapturer> R findLocalClassSupertype(JvmDeclaredType type) { JvmTypeReference superType = Iterables.getLast(type.getSuperTypes(), null); if (superType == null) { return null; }/*from w w w .jav a 2 s .c o m*/ return findLocalClassSupertype(superType); }
From source file:org.apache.aurora.scheduler.storage.durability.TransactionRecorder.java
void add(Op op) { Op prior = Iterables.getLast(ops, null); if (prior == null || !coalesce(prior, op)) { ops.add(op); } }
From source file:io.crate.execution.dsl.phases.AbstractProjectionsPhase.java
protected static List<DataType> extractOutputTypes(List<Symbol> outputs, List<Projection> projections) { Projection lastProjection = Iterables.getLast(projections, null); if (lastProjection == null) { return Symbols.typeView(outputs); } else {// w w w. j a v a 2s . c o m return Symbols.typeView(lastProjection.outputs()); } }
From source file:uk.gov.gchq.koryphe.impl.function.LastItem.java
@Override @SuppressFBWarnings(value = "DE_MIGHT_IGNORE", justification = "Any exceptions are to be ignored") public T apply(final Iterable<T> input) { if (null == input) { throw new IllegalArgumentException("Input cannot be null"); }/*from w ww . java2s . co m*/ try { return Iterables.getLast(input, null); } finally { CloseableUtil.close(input); } }
From source file:io.druid.server.router.PriorityTieredBrokerSelectorStrategy.java
@Override public Optional<String> getBrokerServiceName(TieredBrokerConfig tierConfig, Query query) { final int priority = query.getContextPriority(0); if (priority < minPriority) { return Optional.of(Iterables.getLast(tierConfig.getTierToBrokerMap().values(), tierConfig.getDefaultBrokerServiceName())); } else if (priority >= maxPriority) { return Optional.of(Iterables.getFirst(tierConfig.getTierToBrokerMap().values(), tierConfig.getDefaultBrokerServiceName())); }/*from w w w .j a va 2 s .com*/ return Optional.absent(); }
From source file:foo.domaintest.http.TempAction.java
/** Serve stashed requests. */ @Override//from ww w .j av a 2 s.co m @SuppressWarnings("unchecked") public void run() { String token = Iterables.getLast(Splitter.on('/').split(requestPath), ""); Map<String, Object> params = memcache.load(new Key(STASH, token)); if (params == null) { throw new NotFoundException("No stashed request for this token"); } else { response.setStatus((Integer) params.get("status")).setSleepSeconds((Integer) params.get("sleepSeconds")) .setMimeType((String) params.get("mimeType")) .setCookiesToDelete((List<String>) params.get("cookiesToDelete")) .setCookiesToAdd((Map<String, String>) params.get("cookiesToAdd")) .setHeaders((Map<String, String>) params.get("headers")) .setPayload((String) params.get("payload")).send(); memcache.delete(new Key(STASH, token)); } }
From source file:io.crate.planner.node.dql.AbstractProjectionsPhase.java
protected static List<DataType> extractOutputTypes(List<Symbol> outputs, List<Projection> projections) { Projection lastProjection = Iterables.getLast(projections, null); if (lastProjection == null) { return Symbols.extractTypes(outputs); } else {/*from w w w . j a v a 2 s . co m*/ return Symbols.extractTypes(lastProjection.outputs()); } }
From source file:org.apache.metron.performance.sampler.BiasedSampler.java
public static List<Map.Entry<Integer, Integer>> readDistribution(BufferedReader distrFile, boolean quiet) throws IOException { List<Map.Entry<Integer, Integer>> ret = new ArrayList<>(); if (!quiet) { System.out.println("Using biased sampler with the following biases:"); }// w ww . ja v a 2s . co m int sumLeft = 0; int sumRight = 0; for (String line = null; (line = distrFile.readLine()) != null;) { if (line.startsWith("#")) { continue; } Iterable<String> it = Splitter.on(",").split(line.trim()); if (Iterables.size(it) != 2) { throw new IllegalArgumentException( line + " should be a comma separated pair of integers, but was not."); } int left = Integer.parseInt(Iterables.getFirst(it, null)); int right = Integer.parseInt(Iterables.getLast(it, null)); if (left <= 0 || left > 100) { throw new IllegalArgumentException( line + ": " + (left < 0 ? left : right) + " must a positive integer in (0, 100]"); } if (right <= 0 || right > 100) { throw new IllegalArgumentException(line + ": " + right + " must a positive integer in (0, 100]"); } if (!quiet) { System.out.println( "\t" + left + "% of templates will comprise roughly " + right + "% of sample output"); } ret.add(new AbstractMap.SimpleEntry<>(left, right)); sumLeft += left; sumRight += right; } if (sumLeft > 100 || sumRight > 100) { throw new IllegalStateException( "Neither columns must sum to beyond 100. " + "The first column is the % of templates. " + "The second column is the % of the sample that % of template occupies."); } else if (sumLeft < 100 && sumRight < 100) { int left = 100 - sumLeft; int right = 100 - sumRight; if (!quiet) { System.out.println( "\t" + left + "% of templates will comprise roughly " + right + "% of sample output"); } ret.add(new AbstractMap.SimpleEntry<>(left, right)); } return ret; }
From source file:net.holmes.core.common.MimeType.java
/** * Instantiates a new mime type./*from w w w.j a va 2s .c o m*/ * * @param mimeType mime type */ private MimeType(final String mimeType) { this.mimeType = mimeType; Iterable<String> iterable = Splitter.on('/').split(mimeType); this.type = MediaType.getByValue(Iterables.getFirst(iterable, "")); this.subType = Iterables.getLast(iterable, ""); }
From source file:net.sourceforge.fenixedu.domain.cms.UnitClassTemplateController.java
@Override public Site selectSiteForPath(String[] possibleUnits) { Unit selectedUnit = Iterables.getLast(findUnitsInPath(possibleUnits), null); return selectedUnit != null ? selectedUnit.getSite() : null; }