List of usage examples for com.google.common.collect Iterables getLast
public static <T> T getLast(Iterable<T> iterable)
From source file:pl.nalazek.githubsearch.data.ResponsePackage.java
/** * @return <code>null</code> when response not found, otherwise {@link ResponsePartitioned}. *//*from ww w.j a v a2 s . c o m*/ @Nullable public ResponsePartitioned getLastResponseWithExchangeType(ExchangeType exchangeType) { List<ResponsePartitioned> responses = exchangeTypeMap.get(exchangeType); return responses != null ? Iterables.getLast(responses) : null; }
From source file:org.sosy_lab.cpachecker.util.refinement.PrefixSelector.java
public InfeasiblePrefix selectSlicedPrefix(PrefixPreference pPrefixPreference, List<InfeasiblePrefix> pInfeasiblePrefixes) { switch (pPrefixPreference) { case LENGTH_SHORT: return pInfeasiblePrefixes.get(0); case LENGTH_LONG: return Iterables.getLast(pInfeasiblePrefixes); case RANDOM:/* w ww .j a va2 s. c om*/ return pInfeasiblePrefixes.get(new Random().nextInt(pInfeasiblePrefixes.size())); // scoring based on domain-types case DOMAIN_GOOD_SHORT: case DOMAIN_GOOD_LONG: case DOMAIN_BAD_SHORT: case DOMAIN_BAD_LONG: // // scoring based on domain-types and width of precision case DOMAIN_GOOD_WIDTH_NARROW_SHORT: // // scoring based on width of precision case WIDTH_NARROW_SHORT: case WIDTH_NARROW_LONG: case WIDTH_WIDE_SHORT: case WIDTH_WIDE_LONG: // // scoring based on width of precision and presence of loop counters case WIDTH_NARROW_NO_LOOP_SHORT: // // scoring based on depth of pivot state case PIVOT_SHALLOW_SHORT: case PIVOT_SHALLOW_LONG: case PIVOT_DEEP_SHORT: case PIVOT_DEEP_LONG: // // case ASSIGNMENTS_FEWEST_SHORT: case ASSIGNMENTS_FEWEST_LONG: case ASSIGNMENTS_MOST_SHORT: case ASSIGNMENTS_MOST_LONG: case ASSUMPTIONS_FEWEST_SHORT: case ASSUMPTIONS_FEWEST_LONG: case ASSUMPTIONS_MOST_SHORT: case ASSUMPTIONS_MOST_LONG: return obtainScoreBasedPrefix(pPrefixPreference, pInfeasiblePrefixes); default: assert (false) : "invalid prefix-preference " + pPrefixPreference + " given"; return null; } }
From source file:com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.ApiLevel.java
public String getCpuCorrectedApiLevel(String targetCpu) { // Check that this API level supports the given cpu architecture (eg 64 bit is supported on only // 21+).//w ww. j av a 2s.co m if (!apiLevelToArchitectures.containsEntry(correctedApiLevel, targetCpu)) { // If the given API level does not support the given architecture, find an API level that // does support this architecture. A warning isn't printed because the crosstools for // architectures that aren't supported by this API level are generated anyway, even if the // user doesn't intend to use them (eg, if they're building for only 32 bit archs, the // crosstools for the 64 bit toolchains are generated regardless). // API_LEVEL_TO_ARCHITECTURES.inverse() returns a map of architectures to the APIs that // support that architecture. return Iterables.getLast(apiLevelToArchitectures.inverse().get(targetCpu)); } return correctedApiLevel; }
From source file:com.google.errorprone.refaster.RefasterRule.java
@VisibleForTesting static String fromSecondLevel(String qualifiedTemplateClass) { List<String> path = Splitter.on('.').splitToList(qualifiedTemplateClass); for (int topLevel = 0; topLevel < path.size() - 1; topLevel++) { if (Ascii.isUpperCase(path.get(topLevel).charAt(0))) { return Joiner.on('_').join(path.subList(topLevel + 1, path.size())); }//from w ww . ja v a2 s. c om } return Iterables.getLast(path); }
From source file:org.sonar.javascript.checks.FunctionComplexityCheck.java
private boolean endsWithReturnStatement(BlockTree body) { List<StatementTree> statements = body.statements(); return !statements.isEmpty() && Iterables.getLast(statements).is(Kind.RETURN_STATEMENT); }
From source file:com.opengamma.integration.viewer.status.impl.ViewStatusResultAggregatorImpl.java
private ViewStatusModel aggregate(final List<ViewColumnType> columnTypes) { ArgumentChecker.notNull(columnTypes, "aggregations"); if (columnTypes.isEmpty()) { return defaultModel(); }//from www . j a v a 2 s . c o m Iterable<ViewColumnType> fixedColumnTypes = Iterables.limit(columnTypes, columnTypes.size() - 1); final Map<List<String>, Set<String>> fixedRow2Columns = Maps.newHashMap(); for (ViewStatusKey viewStatusKey : _viewStatusResult.keySet()) { ViewStatusKeyBean viewStatusKeyBean = new ViewStatusKeyBean(viewStatusKey.getSecurityType(), viewStatusKey.getValueRequirementName(), viewStatusKey.getCurrency(), viewStatusKey.getTargetType()); List<String> key = viewStatusKey(viewStatusKeyBean, fixedColumnTypes); Set<String> columnValues = fixedRow2Columns.get(key); if (columnValues == null) { columnValues = Sets.newHashSet(); fixedRow2Columns.put(key, columnValues); } columnValues.addAll( viewStatusKey(viewStatusKeyBean, Collections.singletonList(Iterables.getLast(columnTypes)))); } Set<String> extraColumns = getExtraColumns(fixedRow2Columns); List<List<String>> columnHeaders = makeHeaders(columnTypes, extraColumns); List<List<Object>> rowData = createRowData(fixedRow2Columns, extraColumns, columnTypes); return new SimpleViewStatusModel(columnHeaders, rowData, _viewStatusResult); }
From source file:brooklyn.location.cloud.CloudLocation.java
@Override public MachineLocation obtain(Map<?, ?> flags) throws NoMachinesAvailableException { synchronized (mutex) { // Check context for entity being deployed Object context = flags.get(LocationConfigKeys.CALLER_CONTEXT.getName()); if (context != null && !(context instanceof Entity)) { throw new IllegalStateException("Invalid location context: " + context); }//ww w. j a va2 s .c o m Entity entity = (Entity) context; // Look for idle CloudMachine first Set<Entity> idle = Sets.newTreeSet(new Ordering<Entity>() { @Override public int compare(@Nullable Entity left, @Nullable Entity right) { return ComparisonChain.start().compare(left.getAttribute(MachineEntity.CPU_USAGE), right.getAttribute(MachineEntity.CPU_USAGE)).result(); } }); for (Entity e : getOwner().getCloudMachineList()) { if (Boolean.TRUE.equals(e.getAttribute(CloudMachine.SERVICE_UP)) && e.getAttribute(CloudMachine.ENTITY) == null) { idle.add(e); } } if (idle.size() > 0) { CloudMachineLocation machine = (CloudMachineLocation) Iterables.getLast(idle); machine.setEntity(entity); return machine; } // Obtain a new machine location MachineLocation machine = provisioner.obtain(flags); obtained.add(machine); return machine; } }
From source file:com.google.devtools.build.lib.skyframe.SkylarkModuleCycleReporter.java
@Override public boolean maybeReportCycle(SkyKey topLevelKey, CycleInfo cycleInfo, boolean alreadyReported, EventHandler eventHandler) { ImmutableList<SkyKey> pathToCycle = cycleInfo.getPathToCycle(); ImmutableList<SkyKey> cycle = cycleInfo.getCycle(); if (pathToCycle.isEmpty()) { return false; }/*w w w . java2s. com*/ SkyKey lastPathElement = pathToCycle.get(pathToCycle.size() - 1); if (alreadyReported) { return true; } else if (Iterables.all(cycle, IS_SKYLARK_MODULE_SKY_KEY) // The last element before the cycle has to be a PackageFunction or SkylarkModule. && (IS_PACKAGE_SKY_KEY.apply(lastPathElement) || IS_SKYLARK_MODULE_SKY_KEY.apply(lastPathElement))) { Function printer = new Function<SkyKey, String>() { @Override public String apply(SkyKey input) { if (input.argument() instanceof SkylarkImportLookupValue.SkylarkImportLookupKey) { return ((SkylarkImportLookupValue.SkylarkImportLookupKey) input.argument()).importLabel .toString(); } else if (input.argument() instanceof PackageIdentifier) { return ((PackageIdentifier) input.argument()) + "/BUILD"; } else { throw new UnsupportedOperationException(); } } }; StringBuilder cycleMessage = new StringBuilder().append("cycle detected in extension files: ") .append("\n ").append(printer.apply(lastPathElement)); AbstractLabelCycleReporter.printCycle(cycleInfo.getCycle(), cycleMessage, printer); // TODO(bazel-team): it would be nice to pass the Location of the load Statement in the // BUILD file. eventHandler.handle(Event.error(null, cycleMessage.toString())); return true; } else if (Iterables.any(cycle, IS_PACKAGE_LOOKUP) && Iterables.any(cycle, IS_WORKSPACE_FILE) && (IS_REPOSITORY_DIRECTORY.apply(lastPathElement) || IS_PACKAGE_SKY_KEY.apply(lastPathElement) || IS_EXTERNAL_PACKAGE.apply(lastPathElement))) { // We have a cycle in the workspace file, report as such. Label fileLabel = (Label) Iterables.getLast(Iterables.filter(cycle, IS_AST_FILE_LOOKUP)).argument(); String repositoryName = fileLabel.getPackageIdentifier().getRepository().strippedName(); eventHandler.handle(Event.error(null, "Failed to load Skylark extension '" + fileLabel.toString() + "'.\n" + "It usually happens when the repository is not defined prior to being used.\n" + "Maybe repository '" + repositoryName + "' was defined later in your WORKSPACE file?")); return true; } return false; }
From source file:org.lttng.scope.lttng.ust.core.analysis.debuginfo.internal.FileOffsetMapper.java
/** * Get the function/symbol name corresponding to binary file and offset. * * @param file//from ww w. jav a2s .c o m * The binary file to look at * @param buildId * The expected buildId of the binary file (is not verified at * the moment) * @param offset * The memory offset in the file * @return The corresponding function/symbol name */ public static @Nullable String getFunctionNameFromOffset(File file, @Nullable String buildId, long offset) { /* * TODO We are currently also using 'addr2line' to resolve function * names, which requires the binary's DWARF information to be available. * A better approach would be to use the binary's symbol table (if it is * not stripped), since this is usually more readily available than * DWARF. */ Iterable<Addr2lineInfo> output = getAddr2lineInfo(file, buildId, offset); if (output == null || Iterables.isEmpty(output)) { return null; } Addr2lineInfo info = Iterables.getLast(output); return info.fFunctionName; }
From source file:com.facebook.presto.sql.planner.iterative.rule.MultipleDistinctAggregationToMarkDistinct.java
@Override public Result apply(AggregationNode parent, Captures captures, Context context) { if (!SystemSessionProperties.useMarkDistinct(context.getSession())) { return Result.empty(); }/*from ww w. j a va 2s .c om*/ // the distinct marker for the given set of input columns Map<Set<Symbol>, Symbol> markers = new HashMap<>(); Map<Symbol, Aggregation> newAggregations = new HashMap<>(); PlanNode subPlan = parent.getSource(); for (Map.Entry<Symbol, Aggregation> entry : parent.getAggregations().entrySet()) { Aggregation aggregation = entry.getValue(); FunctionCall call = aggregation.getCall(); if (call.isDistinct() && !call.getFilter().isPresent() && !aggregation.getMask().isPresent()) { Set<Symbol> inputs = call.getArguments().stream().map(Symbol::from).collect(toSet()); Symbol marker = markers.get(inputs); if (marker == null) { marker = context.getSymbolAllocator().newSymbol(Iterables.getLast(inputs).getName(), BOOLEAN, "distinct"); markers.put(inputs, marker); ImmutableSet.Builder<Symbol> distinctSymbols = ImmutableSet.<Symbol>builder() .addAll(parent.getGroupingKeys()).addAll(inputs); parent.getGroupIdSymbol().ifPresent(distinctSymbols::add); subPlan = new MarkDistinctNode(context.getIdAllocator().getNextId(), subPlan, marker, ImmutableList.copyOf(distinctSymbols.build()), Optional.empty()); } // remove the distinct flag and set the distinct marker newAggregations.put(entry.getKey(), new Aggregation( new FunctionCall(call.getName(), call.getWindow(), call.getFilter(), call.getOrderBy(), false, call.getArguments()), aggregation.getSignature(), Optional.of(marker))); } else { newAggregations.put(entry.getKey(), aggregation); } } return Result .ofPlanNode(new AggregationNode(parent.getId(), subPlan, newAggregations, parent.getGroupingSets(), ImmutableList.of(), parent.getStep(), parent.getHashSymbol(), parent.getGroupIdSymbol())); }