List of usage examples for com.google.common.collect Iterables getLast
public static <T> T getLast(Iterable<T> iterable)
From source file:com.google.devtools.build.lib.rules.android.AndroidBuildViewTestCase.java
protected static Artifact getResourceArtifact(ConfiguredTarget target) { // the last provider is the provider from the target. if (target.getConfiguration().getFragment(AndroidConfiguration.class).useParallelResourceProcessing()) { return Iterables.getLast(target.getProvider(AndroidResourcesProvider.class).getDirectAndroidResources()) .getJavaClassJar();/*from w ww. ja va 2s . c om*/ } else { return Iterables.getLast(target.getProvider(AndroidResourcesProvider.class).getDirectAndroidResources()) .getJavaSourceJar(); } }
From source file:com.google.dart.engine.services.internal.correction.StatementAnalyzer.java
/** * Checks final selected {@link ASTNode}s after processing {@link CompilationUnit}. *//* w w w. ja v a 2s .c om*/ private void checkSelectedNodes(CompilationUnit unit) { List<ASTNode> nodes = getSelectedNodes(); // some tokens before first selected node { ASTNode firstNode = nodes.get(0); SourceRange rangeBeforeFirstNode = rangeStartStart(selection, firstNode); if (hasTokens(rangeBeforeFirstNode)) { invalidSelection( "The beginning of the selection contains characters that do not belong to a statement.", RefactoringStatusContext.create(unit, rangeBeforeFirstNode)); } } // some tokens after last selected node { ASTNode lastNode = Iterables.getLast(nodes); SourceRange rangeAfterLastNode = rangeEndEnd(lastNode, selection); if (hasTokens(rangeAfterLastNode)) { invalidSelection("The end of the selection contains characters that do not belong to a statement.", RefactoringStatusContext.create(unit, rangeAfterLastNode)); } } }
From source file:org.ambraproject.rhino.service.taxonomy.impl.TaxonomyClassificationServiceImpl.java
private static String getTermFromPath(String path) { return Iterables.getLast(TAXONOMY_PATH_SPLITTER.split(path)); }
From source file:org.jclouds.vcloud.config.CommonVCloudRestClientModule.java
@Provides @Singleton/*from w w w . j a va2 s .c o m*/ @OrgList URI provideOrgListURI(Supplier<VCloudSession> sessionSupplier) { VCloudSession session = sessionSupplier.get(); return URI.create(Iterables.getLast(session.getOrgs().values()).getHref().toASCIIString() .replaceAll("org/.*", "org")); }
From source file:org.glowroot.ui.TransactionJsonService.java
@GET(path = "/backend/transaction/percentiles", permission = "agent:transaction:overview") String getPercentiles(@BindAgentRollupId String agentRollupId, @BindRequest TransactionPercentileRequest request, @BindAutoRefresh boolean autoRefresh) throws Exception { AggregateQuery query = toChartQuery(request, DataKind.GENERAL); long liveCaptureTime = clock.currentTimeMillis(); List<PercentileAggregate> percentileAggregates = transactionCommonService .getPercentileAggregates(agentRollupId, query, autoRefresh); if (percentileAggregates.isEmpty() && fallBackToLargestAggregates(query)) { // fall back to largest aggregates in case expiration settings have recently changed query = withLargestRollupLevel(query); percentileAggregates = transactionCommonService.getPercentileAggregates(agentRollupId, query, autoRefresh);/*from w w w . j ava 2 s. c o m*/ if (!percentileAggregates.isEmpty() && ignoreFallBackData(query, Iterables.getLast(percentileAggregates).captureTime())) { // this is probably data from before the requested time period percentileAggregates = ImmutableList.of(); } } long dataPointIntervalMillis = configRepository.getRollupConfigs().get(query.rollupLevel()) .intervalMillis(); PercentileData percentileData = getDataSeriesForPercentileChart(request, percentileAggregates, request.percentile(), dataPointIntervalMillis, liveCaptureTime); Map<Long, Long> transactionCounts = getTransactionCounts2(percentileAggregates); StringBuilder sb = new StringBuilder(); JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb)); try { jg.writeStartObject(); jg.writeObjectField("dataSeries", percentileData.dataSeriesList()); jg.writeNumberField("dataPointIntervalMillis", dataPointIntervalMillis); jg.writeObjectField("transactionCounts", transactionCounts); jg.writeObjectField("mergedAggregate", percentileData.mergedAggregate()); jg.writeEndObject(); } finally { jg.close(); } return sb.toString(); }
From source file:com.google.errorprone.bugpatterns.ClassNewInstance.java
private void fixThrows(VisitorState state, SuggestedFix.Builder fix) { MethodTree methodTree = state.findEnclosing(MethodTree.class); if (methodTree == null || methodTree.getThrows().isEmpty()) { return;//from w ww . j av a2 s . com } ImmutableMap.Builder<Type, ExpressionTree> thrown = ImmutableMap.builder(); for (ExpressionTree e : methodTree.getThrows()) { thrown.put(ASTHelpers.getType(e), e); } UnhandledResult<ExpressionTree> result = unhandled(thrown.build(), state); if (result.unhandled.isEmpty()) { return; } List<String> newThrows = new ArrayList<>(); for (Type handle : result.unhandled) { newThrows.add(handle.tsym.getSimpleName().toString()); } Collections.sort(newThrows); fix.postfixWith(Iterables.getLast(methodTree.getThrows()), ", " + Joiner.on(", ").join(newThrows)); // the other exceptions are in java.lang fix.addImport("java.lang.reflect.InvocationTargetException"); }
From source file:org.eigenbase.sql.fun.SqlCaseOperator.java
private RelDataType inferTypeFromOperands(RelDataTypeFactory typeFactory, List<RelDataType> argTypes) { assert (argTypes.size() % 2) == 1 : "odd number of arguments expected: " + argTypes.size(); assert argTypes.size() > 1 : argTypes.size(); List<RelDataType> thenTypes = new ArrayList<RelDataType>(); for (int j = 1; j < (argTypes.size() - 1); j += 2) { thenTypes.add(argTypes.get(j));/*from w w w .j a v a2 s .com*/ } thenTypes.add(Iterables.getLast(argTypes)); return typeFactory.leastRestrictive(thenTypes); }
From source file:fr.xebia.demo.amazon.aws.AmazonAwsInfrastructureMaker.java
/** * Returns a base-64 version of the mime-multi-part user-data file. * //from w w w .jav a2 s. c om * @param distribution * @param dbInstance * @param jdbcUsername * @param jdbcPassword * @param warUrl * @return */ protected String buildUserData(Distribution distribution, DBInstance dbInstance, String jdbcUsername, String jdbcPassword, String warUrl) { // USER DATA SHELL SCRIPT Map<String, Object> rootMap = Maps.newHashMap(); rootMap.put("catalinaBase", distribution.getCatalinaBase()); rootMap.put("warUrl", warUrl); String warName = Iterables.getLast(Splitter.on("/").split(warUrl)); rootMap.put("warName", warName); Map<String, String> systemProperties = Maps.newHashMap(); rootMap.put("systemProperties", systemProperties); String jdbcUrl = "jdbc:mysql://" + dbInstance.getEndpoint().getAddress() + ":" + dbInstance.getEndpoint().getPort() + "/" + dbInstance.getDBName(); systemProperties.put("jdbc.url", jdbcUrl); systemProperties.put("jdbc.username", jdbcUsername); systemProperties.put("jdbc.password", jdbcPassword); String shellScript = FreemarkerUtils.generate(rootMap, "/provision_tomcat.py.fmt"); // USER DATA CLOUD CONFIG InputStream cloudConfigAsStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(distribution.getCloudConfigFilePath()); Preconditions.checkNotNull(cloudConfigAsStream, "'" + distribution.getCloudConfigFilePath() + "' not found in path"); Readable cloudConfig = new InputStreamReader(cloudConfigAsStream); return CloudInitUserDataBuilder.start() // .addShellScript(shellScript) // .addCloudConfig(cloudConfig) // .buildBase64UserData(); }
From source file:edu.harvard.med.screensaver.ui.libraries.LibrarySearchResults.java
@SuppressWarnings("unchecked") protected List<? extends TableColumn<Library, ?>> buildColumns() { ArrayList<TableColumn<Library, ?>> columns = Lists.newArrayList(); columns.add(new TextEntityColumn<Library>(RelationshipPath.from(Library.class).toProperty("shortName"), "Short Name", "The abbreviated name for the library", TableColumn.UNGROUPED) { @Override/*from www . j a v a2 s . c om*/ public String getCellValue(Library library) { return library.getShortName(); } @Override public boolean isCommandLink() { return true; } @Override public Object cellAction(Library library) { return viewSelectedEntity(); } }); columns.add(new TextEntityColumn<Library>(RelationshipPath.from(Library.class).toProperty("libraryName"), "Library Name", "The full name of the library", TableColumn.UNGROUPED) { @Override public String getCellValue(Library library) { return library.getLibraryName(); } }); IntegerEntityColumn column = new IntegerEntityColumn<Library>(Library.startPlate, "Experimental Well Count", "The number of experimental wells in the library (click link to browse experimental wells)", TableColumn.UNGROUPED) { @Override public Integer getCellValue(Library library) { return library.getExperimentalWellCount(); } @Override public boolean isCommandLink() { return true; } public Object cellAction(Library library) { _wellsBrowser.searchWellsForLibrary(library); return BROWSE_WELLS; } }; columns.add(column); if (!!!getApplicationProperties().isFacility(LincsScreensaverConstants.FACILITY_KEY) || !!!getScreensaverUser().isUserInRole(ScreensaverUserRole.GUEST)) { columns.add(new TextEntityColumn<Library>(RelationshipPath.from(Library.class).toProperty("provider"), "Provider", "The vendor or source that provided the library", TableColumn.UNGROUPED) { @Override public String getCellValue(Library library) { return library.getProvider(); } }); } columns.add(new EnumEntityColumn<Library, ScreenType>( RelationshipPath.from(Library.class).toProperty("screenType"), "Screen Type", "'RNAi' or 'Small Molecule'", TableColumn.UNGROUPED, ScreenType.values()) { @Override public ScreenType getCellValue(Library library) { return library.getScreenType(); } }); columns.add( new EnumEntityColumn<Library, Solvent>(RelationshipPath.from(Library.class).toProperty("solvent"), "Solvent", "Solvent used in the library wells", TableColumn.UNGROUPED, Solvent.values()) { @Override public Solvent getCellValue(Library library) { return library.getSolvent(); } }); Iterables.getLast(columns).setVisible(false); if (!!!getApplicationProperties().isFacility(LincsScreensaverConstants.FACILITY_KEY)) { columns.add(new EnumEntityColumn<Library, LibraryType>( RelationshipPath.from(Library.class).toProperty("libraryType"), "Library Type", "The type of library, e.g., 'Commercial', 'Known Bioactives', 'siRNA', etc.", TableColumn.UNGROUPED, LibraryType.values()) { @Override public LibraryType getCellValue(Library library) { return library.getLibraryType(); } }); columns.add(new BooleanEntityColumn<Library>(RelationshipPath.from(Library.class).toProperty("pool"), "Is Pool", "Whether wells contains pools of reagents or single reagents", TableColumn.UNGROUPED) { @Override public Boolean getCellValue(Library library) { return library.isPool(); } }); } columns.add(new IntegerEntityColumn<Library>(Library.startPlate, "Start Plate", "The plate number for the first plate in the library", TableColumn.UNGROUPED) { @Override public Integer getCellValue(Library library) { return library.getStartPlate(); } }); columns.add(new IntegerEntityColumn<Library>(Library.endPlate, "End Plate", "The plate number for the last plate in the library", TableColumn.UNGROUPED) { @Override public Integer getCellValue(Library library) { return library.getEndPlate(); } }); if (!!!getApplicationProperties().isFacility(LincsScreensaverConstants.FACILITY_KEY)) { columns.add(new TextSetEntityColumn<Library>(Library.copies.toProperty("name"), "Copies", "The copies that have been made of this library", TableColumn.UNGROUPED) { @Override public Set<String> getCellValue(Library library) { if (library == null) { return null; } return Sets.newTreeSet(Iterables.transform(library.getCopies(), Copy.ToName)); } }); columns.get(columns.size() - 1).setAdministrative(true); } columns.add(new EnumEntityColumn<Library, LibraryScreeningStatus>( RelationshipPath.from(Library.class).toProperty("screeningStatus"), "Screening Status", "Screening status for the library, e.g., 'Allowed', 'Not Allowed', 'Not Yet Plated', etc.", TableColumn.UNGROUPED, LibraryScreeningStatus.values()) { @Override public LibraryScreeningStatus getCellValue(Library library) { return library == null ? null : library.getScreeningStatus(); } }); columns.get(columns.size() - 1).setAdministrative(true); columns.add(new DateColumn<Library>("Date First Plated", "The earliest date on which a copy of this library was plated", TableColumn.UNGROUPED) { @Override public LocalDate getDate(Library library) { return library.getDateScreenable(); } }); if (getApplicationProperties().isFacility(LincsScreensaverConstants.FACILITY_KEY)) { columns.add( new DateEntityColumn<Library>(RelationshipPath.from(Library.class).toProperty("dateCreated"), "Date Data Received", "The date the data was received", TableColumn.UNGROUPED) { @Override protected LocalDate getDate(Library library) { return library.getDateCreated().toLocalDate(); } }); } if (getApplicationProperties().isFacility(LincsScreensaverConstants.FACILITY_KEY)) { columns.add(new DateEntityColumn<Library>(RelationshipPath.from(Library.class).toProperty("dateLoaded"), "Date Loaded", "The date the library data was loaded", TableColumn.UNGROUPED) { @Override protected LocalDate getDate(Library library) { return library.getDateLoaded() == null ? null : library.getDateLoaded().toLocalDate(); } }); } if (getApplicationProperties().isFacility(LincsScreensaverConstants.FACILITY_KEY)) { columns.add(new DateEntityColumn<Library>( RelationshipPath.from(Library.class).toProperty("datePubliclyAvailable"), "Date Publicly Available", "The date the library data was made publicly available", TableColumn.UNGROUPED) { @Override protected LocalDate getDate(Library library) { return library.getDatePubliclyAvailable() == null ? null : library.getDatePubliclyAvailable().toLocalDate(); } }); } // TableColumnManager<Library> columnManager = getColumnManager(); // columnManager.addCompoundSortColumns(columnManager.getColumn("Screen Type"), // columnManager.getColumn("Library Type"), // columnManager.getColumn("Short Name")); // columnManager.addCompoundSortColumns(columnManager.getColumn("Library Type"), // columnManager.getColumn("Short HName")); return columns; }
From source file:com.google.errorprone.bugpatterns.collectionincompatibletype.CollectionIncompatibleType.java
@Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { MatchResult directResult = firstNonNullMatchResult(DIRECT_MATCHERS, tree, state); MatchResult typeArgResult = null; if (directResult == null) { typeArgResult = firstNonNullMatchResult(TYPE_ARG_MATCHERS, tree, state); }/*w ww . j av a 2s. co m*/ if (directResult == null && typeArgResult == null) { return Description.NO_MATCH; } Verify.verify(directResult == null ^ typeArgResult == null); MatchResult result = MoreObjects.firstNonNull(directResult, typeArgResult); Types types = state.getTypes(); if (types.isCastable(result.sourceType(), types.erasure(ASTHelpers.getUpperBound(result.targetType(), types)))) { return Description.NO_MATCH; } // For error message, use simple names instead of fully qualified names unless they are // identical. String sourceTreeType = Signatures.prettyType(ASTHelpers.getType(result.sourceTree())); String sourceType = Signatures.prettyType(result.sourceType()); String targetType = Signatures.prettyType(result.targetType()); if (sourceType.equals(targetType)) { sourceType = result.sourceType().toString(); targetType = result.targetType().toString(); } Description.Builder description = buildDescription(tree); if (typeArgResult != null) { description.setMessage(String.format( "Argument '%s' should not be passed to this method; its type %s has a type argument " + "%s that is not compatible with its collection's type argument %s", result.sourceTree(), sourceTreeType, sourceType, targetType)); } else { description.setMessage(String.format( "Argument '%s' should not be passed to this method; its type %s is not compatible " + "with its collection's type argument %s", result.sourceTree(), sourceType, targetType)); } switch (fixType) { case PRINT_TYPES_AS_COMMENT: description.addFix(SuggestedFix.prefixWith(tree, String.format("/* expected: %s, actual: %s */", ASTHelpers.getUpperBound(result.targetType(), types), result.sourceType()))); break; case CAST: Fix fix; if (typeArgResult != null) { TypeArgOfMethodArgMatcher matcher = (TypeArgOfMethodArgMatcher) typeArgResult.matcher(); String fullyQualifiedType = matcher.getMethodArgTypeName(); String simpleType = Iterables.getLast(Splitter.on('.').split(fullyQualifiedType)); fix = SuggestedFix.builder().prefixWith(result.sourceTree(), String.format("(%s<?>) ", simpleType)) .addImport(fullyQualifiedType).build(); } else { fix = SuggestedFix.prefixWith(result.sourceTree(), "(Object) "); } description.addFix(fix); break; case SUPPRESS_WARNINGS: SuggestedFix.Builder builder = SuggestedFix.builder(); builder.prefixWith(result.sourceTree(), String.format("/* expected: %s, actual: %s */ ", targetType, sourceType)); addSuppressWarnings(builder, state, "CollectionIncompatibleType"); description.addFix(builder.build()); break; case NONE: break; } return description.build(); }