List of usage examples for com.google.common.collect ImmutableSet.Builder addAll
boolean addAll(Collection<? extends E> c);
From source file:com.google.devtools.build.lib.rules.cpp.CppCompilationContext.java
/** * Returns the context for a LIPO compile action. This uses the include dirs * and defines of the library, but the declared inclusion dirs/srcs from both * the library and the owner binary./*from www. j a va 2 s.co m*/ * * <p>TODO(bazel-team): this might make every LIPO target have an unnecessary large set of * inclusion dirs/srcs. The correct behavior would be to merge only the contexts * of actual referred targets (as listed in .imports file). * * <p>Undeclared inclusion checking ({@link #getDeclaredIncludeDirs()}, * {@link #getDeclaredIncludeWarnDirs()}, and * {@link #getDeclaredIncludeSrcs()}) needs to use the union of the contexts * of the involved source files. * * <p>For include and define command line flags ({@link #getIncludeDirs()} * {@link #getQuoteIncludeDirs()}, {@link #getSystemIncludeDirs()}, and * {@link #getDefines()}) LIPO compilations use the same values as non-LIPO * compilation. * * <p>Include scanning is not handled by this method. See * {@code IncludeScannable#getAuxiliaryScannables()} instead. * * @param ownerContext the compilation context of the owner binary * @param libContext the compilation context of the library */ public static CppCompilationContext mergeForLipo(CppCompilationContext ownerContext, CppCompilationContext libContext) { ImmutableSet.Builder<Artifact> prerequisites = ImmutableSet.builder(); prerequisites.addAll(ownerContext.compilationPrerequisites); prerequisites.addAll(libContext.compilationPrerequisites); ModuleInfo.Builder moduleInfo = new ModuleInfo.Builder(); moduleInfo.merge(ownerContext.moduleInfo); moduleInfo.merge(libContext.moduleInfo); ModuleInfo.Builder picModuleInfo = new ModuleInfo.Builder(); picModuleInfo.merge(ownerContext.picModuleInfo); picModuleInfo.merge(libContext.picModuleInfo); return new CppCompilationContext(libContext.commandLineContext, prerequisites.build(), mergeSets(ownerContext.declaredIncludeDirs, libContext.declaredIncludeDirs), mergeSets(ownerContext.declaredIncludeWarnDirs, libContext.declaredIncludeWarnDirs), mergeSets(ownerContext.declaredIncludeSrcs, libContext.declaredIncludeSrcs), mergeSets(ownerContext.pregreppedHdrs, libContext.pregreppedHdrs), moduleInfo.build(), picModuleInfo.build(), mergeSets(ownerContext.directModuleMaps, libContext.directModuleMaps), libContext.cppModuleMap); }
From source file:com.github.rinde.rinsim.central.arrays.ArraysSolverValidator.java
/** * Validates the {@link SolutionObject}s that are produced by a * {@link MultiVehicleArraysSolver}. If any of the {@link SolutionObject}s is * infeasible, an {@link IllegalArgumentException} is thrown. * @param sols The {@link SolutionObject}s that are validated. * @param travelTime Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * ./*from w w w . j ava 2 s. c om*/ * @param releaseDates Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param dueDates Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param servicePairs Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param serviceTimes Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param vehicleTravelTimes Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param inventories Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param remainingServiceTimes Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @param currentDestinations Parameter as specified by * {@link MultiVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], int[][], int[][], int[], int[], SolutionObject[])} * . * @return The solution as is supplied, used for method chaining. */ public static SolutionObject[] validateOutputs(SolutionObject[] sols, int[][] travelTime, int[] releaseDates, int[] dueDates, int[][] servicePairs, int[] serviceTimes, int[][] vehicleTravelTimes, int[][] inventories, int[] remainingServiceTimes, int[] currentDestinations) { final int n = travelTime.length; final ImmutableSet.Builder<Integer> routeSetBuilder = ImmutableSet.builder(); int visitedLocations = 0; for (final SolutionObject sol : sols) { routeSetBuilder.addAll(toSet(sol.route)); visitedLocations += sol.route.length - 2; } final Set<Integer> routeSet = routeSetBuilder.build(); final Set<Integer> locationSet = ContiguousSet.create(Range.closedOpen(0, travelTime.length), DiscreteDomain.integers()); checkArgument(visitedLocations == n - 2, "The number of visits in routes should equal the number of locations, " + "expected: %s, observed: %s.", n - 2, visitedLocations); // checks duplicates and missing locations checkArgument(routeSet.size() == n, "Every location should appear exactly once in one route. Missing " + "location: %s.", Sets.difference(locationSet, routeSet)); // checks for completeness of tour checkArgument(routeSet.equals(locationSet), "Not all locations are serviced, there is probably a non-existing " + "location in the route. Set difference: %s.", Sets.difference(routeSet, locationSet)); final ImmutableMultimap.Builder<Integer, Integer> inventoryBuilder = ImmutableMultimap.builder(); for (int i = 0; i < inventories.length; i++) { inventoryBuilder.put(inventories[i][0], inventories[i][1]); } final Multimap<Integer, Integer> inventoryMap = inventoryBuilder.build(); for (int v = 0; v < sols.length; v++) { final SolutionObject sol = sols[v]; /* * CHECK SERVICE SEQUENCE */ checkArgument(sol.route[0] == 0, "The route should always start with the vehicle start location: 0, " + "actual:%s.", sol.route[0]); checkArgument(sol.route[sol.route.length - 1] == n - 1, "The route should always finish with the depot."); if (currentDestinations[v] != 0) { checkArgument(sol.route[1] == currentDestinations[v], "Vehicle %s has a current destination %s, as such this must be the " + "first point to visit (at index 1). The route: %s.", v, currentDestinations[v], Arrays.toString(sol.route)); } final Set<Integer> locs = ImmutableSet.copyOf(Ints.asList(sol.route)); final Collection<Integer> inventory = inventoryMap.get(v); for (final Integer i : inventory) { checkArgument(locs.contains(i), "Every location in the inventory of a vehicle should occur in its " + "route, route for vehicle %s does not contain location %s.", v, i); } // check service pairs ordering, pickups should be visited before // their corresponding delivery location final Map<Integer, Integer> pairs = newHashMap(); for (int i = 0; i < servicePairs.length; i++) { pairs.put(servicePairs[i][0], servicePairs[i][1]); } final Set<Integer> seen = newHashSet(); final Set<Integer> set = newHashSet(Ints.asList(sol.route)); for (int i = 1; i < sol.route.length - 1; i++) { if (pairs.containsKey(sol.route[i])) { checkArgument(!seen.contains(pairs.get(sol.route[i])), "Pickups should be visited before their corresponding deliveries." + " Location %s should be visited after location %s.", pairs.get(sol.route[i]), sol.route[i]); checkArgument(set.contains(pairs.get(sol.route[i])), "Vehicle %s: this route should contain both the pickup and " + "delivery location, found %s, didn't find %s.", v, sol.route[i], pairs.get(sol.route[i])); } seen.add(sol.route[i]); } /* * CHECK ARRIVAL TIMES */ checkArgument(sol.arrivalTimes.length == sol.route.length, "Number of arrival times should equal number of locations."); checkArgument(sol.arrivalTimes[0] == 0, "The first arrival time should be 0, was %s.", sol.arrivalTimes[0]); // check feasibility final int[] minArrivalTimes = ArraysSolvers.computeArrivalTimes(sol.route, travelTime, remainingServiceTimes[v], vehicleTravelTimes[v], serviceTimes, releaseDates); for (int i = 1; i < sol.route.length; i++) { checkArgument(sol.arrivalTimes[i] >= minArrivalTimes[i], "Vehicle %s, route index %s, arrivalTime (%s) needs to be greater " + "or equal to minArrivalTime (%s).", v, i, sol.arrivalTimes[i], minArrivalTimes[i]); } /* * CHECK OBJECTIVE VALUE */ // sum travel time final int totalTravelTime = ArraysSolvers.computeTotalTravelTime(sol.route, travelTime, vehicleTravelTimes[v]); // sum tardiness final int tardiness = ArraysSolvers.computeRouteTardiness(sol.route, sol.arrivalTimes, serviceTimes, dueDates, remainingServiceTimes[v]); checkArgument(sol.objectiveValue == totalTravelTime + tardiness, "Vehicle %s: incorrect objective value (%s), it should be travel " + "time + tardiness = %s + %s = %s.", v, sol.objectiveValue, totalTravelTime, tardiness, totalTravelTime + tardiness); } return sols; }
From source file:com.opengamma.strata.calc.marketdata.MarketDataRequirements.java
/** * Merges multiple sets of requirements into a single set. * * @param requirements market data requirements * @return a single set of requirements containing all the requirements from the input sets *//* ww w. j ava 2s.c o m*/ public static MarketDataRequirements combine(List<MarketDataRequirements> requirements) { ImmutableSet.Builder<ObservableId> observablesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<MarketDataId<?>> nonObservablesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<ObservableId> timeSeriesBuilder = ImmutableSet.builder(); ImmutableSet.Builder<Currency> outputCurrenciesBuilder = ImmutableSet.builder(); for (MarketDataRequirements req : requirements) { observablesBuilder.addAll(req.observables); nonObservablesBuilder.addAll(req.nonObservables); timeSeriesBuilder.addAll(req.timeSeries); outputCurrenciesBuilder.addAll(req.outputCurrencies); } return new MarketDataRequirements(observablesBuilder.build(), nonObservablesBuilder.build(), timeSeriesBuilder.build(), outputCurrenciesBuilder.build()); }
From source file:com.google.devtools.build.lib.rules.cpp.CcCompilationContext.java
/** * Returns the context for a LIPO compile action. This uses the include dirs and defines of the * library, but the declared inclusion dirs/srcs from both the library and the owner binary. * * <p>TODO(bazel-team): this might make every LIPO target have an unnecessary large set of * inclusion dirs/srcs. The correct behavior would be to merge only the contexts of actual * referred targets (as listed in .imports file). * * <p>Undeclared inclusion checking ({@link #getDeclaredIncludeDirs()}, {@link * #getDeclaredIncludeWarnDirs()}, and {@link #getDeclaredIncludeSrcs()}) needs to use the union * of the contexts of the involved source files. * * <p>For include and define command line flags ({@link #getIncludeDirs()} {@link * #getQuoteIncludeDirs()}, {@link #getSystemIncludeDirs()}, and {@link #getDefines()}) LIPO * compilations use the same values as non-LIPO compilation. * * <p>Include scanning is not handled by this method. See {@code * IncludeScannable#getAuxiliaryScannables()} instead. * * @param ownerCcCompilationContext the {@code CcCompilationContext} of the owner binary * @param libCcCompilationContext the {@code CcCompilationContext} of the library *//*w ww.j av a2s . c o m*/ public static CcCompilationContext mergeForLipo(CcCompilationContext ownerCcCompilationContext, CcCompilationContext libCcCompilationContext) { ImmutableSet.Builder<Artifact> prerequisites = ImmutableSet.builder(); prerequisites.addAll(ownerCcCompilationContext.compilationPrerequisites); prerequisites.addAll(libCcCompilationContext.compilationPrerequisites); ModuleInfo.Builder moduleInfo = new ModuleInfo.Builder(); moduleInfo.merge(ownerCcCompilationContext.moduleInfo); moduleInfo.merge(libCcCompilationContext.moduleInfo); ModuleInfo.Builder picModuleInfo = new ModuleInfo.Builder(); picModuleInfo.merge(ownerCcCompilationContext.picModuleInfo); picModuleInfo.merge(libCcCompilationContext.picModuleInfo); return new CcCompilationContext(libCcCompilationContext.commandLineCcCompilationContext, prerequisites.build(), mergeSets(ownerCcCompilationContext.declaredIncludeDirs, libCcCompilationContext.declaredIncludeDirs), mergeSets(ownerCcCompilationContext.declaredIncludeWarnDirs, libCcCompilationContext.declaredIncludeWarnDirs), mergeSets(ownerCcCompilationContext.declaredIncludeSrcs, libCcCompilationContext.declaredIncludeSrcs), mergeSets(ownerCcCompilationContext.pregreppedHdrs, libCcCompilationContext.pregreppedHdrs), mergeSets(ownerCcCompilationContext.nonCodeInputs, libCcCompilationContext.nonCodeInputs), moduleInfo.build(), picModuleInfo.build(), mergeSets(ownerCcCompilationContext.directModuleMaps, libCcCompilationContext.directModuleMaps), libCcCompilationContext.cppModuleMap, libCcCompilationContext.verificationModuleMap, libCcCompilationContext.propagateModuleMapAsActionInput); }
From source file:com.github.rinde.rinsim.central.arrays.ArraysSolvers.java
/** * Converts the {@link GlobalStateObject} into an {@link ArraysObject} using * the specified output time unit.//from ww w .j a va 2 s . c o m * @param state The state to convert. * @param outputTimeUnit The {@link Unit} to use as time in the resulting * object. * @return An {@link ArraysObject} using the specified output time unit. */ public static ArraysObject toSingleVehicleArrays(GlobalStateObject state, Unit<Duration> outputTimeUnit) { final UnitConverter timeConverter = state.getTimeUnit().getConverterTo(outputTimeUnit); final VehicleStateObject v = state.getVehicles().iterator().next(); // we check all vehicles in case this method is used in other contexts final ImmutableSet.Builder<Parcel> cargoBuilder = ImmutableSet.builder(); for (final VehicleStateObject vs : state.getVehicles()) { cargoBuilder.addAll(vs.getContents()); } final Set<Parcel> inCargo = cargoBuilder.build(); // there are always two locations: the current vehicle location and // the depot final int numLocations = 2 + state.getAvailableParcels().size() * 2 + inCargo.size(); final int[] releaseDates = new int[numLocations]; final int[] dueDates = new int[numLocations]; final int[][] servicePairs = new int[state.getAvailableParcels().size()][2]; final int[] serviceTimes = new int[numLocations]; // we need to create two mappings: // Parcel -> pickup index / deliver index // index -> Parcel final ImmutableMap.Builder<Parcel, ParcelIndexObj> parcel2indexBuilder = ImmutableMap.builder(); final ImmutableMap.Builder<Integer, ParcelIndexObj> index2parcelBuilder = ImmutableMap.builder(); // we wrap the points in PointWrapper to avoid problems with (possibly) // duplicates in the points final ImmutableList.Builder<Point> points = ImmutableList.builder(); points.add(v.getLocation()); int index = 1; int spIndex = 0; for (final Parcel p : state.getAvailableParcels()) { serviceTimes[index] = DoubleMath.roundToInt(timeConverter.convert(p.getPickupDuration()), RoundingMode.CEILING); // add pickup location and time window points.add(p.getPickupLocation()); final int deliveryIndex = index + state.getAvailableParcels().size(); final ParcelIndexObj pio = new ParcelIndexObj(p, index, deliveryIndex); parcel2indexBuilder.put(p, pio); index2parcelBuilder.put(index, pio); index2parcelBuilder.put(deliveryIndex, pio); final int[] tw = convertTW(p.getPickupTimeWindow(), state.getTime(), timeConverter); releaseDates[index] = tw[0]; dueDates[index] = tw[1]; checkState(releaseDates[index] <= dueDates[index]); // link the pair with its delivery location (see next loop) servicePairs[spIndex++] = new int[] { index, deliveryIndex }; index++; } checkState(spIndex == state.getAvailableParcels().size(), "%s %s", state.getAvailableParcels().size(), spIndex); final List<Parcel> deliveries = new ImmutableList.Builder<Parcel>().addAll(state.getAvailableParcels()) .addAll(inCargo).build(); for (final Parcel p : deliveries) { serviceTimes[index] = DoubleMath.roundToInt(timeConverter.convert(p.getDeliveryDuration()), RoundingMode.CEILING); points.add(p.getDeliveryLocation()); if (inCargo.contains(p)) { final ParcelIndexObj pio = new ParcelIndexObj(p, -1, index); parcel2indexBuilder.put(p, pio); index2parcelBuilder.put(index, pio); } final int[] tw = convertTW(p.getDeliveryTimeWindow(), state.getTime(), timeConverter); releaseDates[index] = tw[0]; dueDates[index] = tw[1]; checkState(releaseDates[index] <= dueDates[index]); index++; } checkState(index == numLocations - 1); // the start position of the truck points to the depot location points.add(v.getDto().getStartPosition()); // end of the day dueDates[index] = fixTWend(v.getDto().getAvailabilityTimeWindow().end(), state.getTime(), timeConverter); releaseDates[index] = Math.min(0, dueDates[index]); final Measure<Double, Velocity> speed = Measure.valueOf(v.getDto().getSpeed(), state.getSpeedUnit()); final ImmutableList<Point> pointList = points.build(); final ImmutableMap<Parcel, ParcelIndexObj> parcel2indexMap = parcel2indexBuilder.build(); final ImmutableMap<Integer, ParcelIndexObj> index2parcelMap = index2parcelBuilder.build(); final int[][] travelTime = ArraysSolvers.toTravelTimeMatrix(pointList, state.getDistUnit(), speed, outputTimeUnit, RoundingMode.CEILING); @Nullable SolutionObject[] sol = null; if (v.getRoute().isPresent() && state.getVehicles().size() == 1) { // the assumption is that if the current route of one vehicle is known, // the routes of all vehicles should be known. sol = toCurrentSolutions(state, parcel2indexMap, travelTime, releaseDates, dueDates, serviceTimes, new int[][] { travelTime[0] }, new int[] { 0 }); } return new ArraysObject(travelTime, releaseDates, dueDates, servicePairs, serviceTimes, sol, pointList, parcel2indexMap, index2parcelMap); }
From source file:com.facebook.presto.server.protocol.Query.java
private static Set<String> globalUniqueNodes(StageInfo stageInfo) { if (stageInfo == null) { return ImmutableSet.of(); }// w w w .jav a 2s . c o m ImmutableSet.Builder<String> nodes = ImmutableSet.builder(); for (TaskInfo task : stageInfo.getTasks()) { // todo add nodeId to TaskInfo URI uri = task.getTaskStatus().getSelf(); nodes.add(uri.getHost() + ":" + uri.getPort()); } for (StageInfo subStage : stageInfo.getSubStages()) { nodes.addAll(globalUniqueNodes(subStage)); } return nodes.build(); }
From source file:com.facebook.buck.apple.project_generator.XCodeProjectCommandHelper.java
@VisibleForTesting static ImmutableSet<ProjectGenerator.Option> buildWorkspaceGeneratorOptions(boolean isReadonly, boolean isWithTests, boolean isWithDependenciesTests, boolean isProjectsCombined, boolean shouldUseHeaderMaps, boolean shouldMergeHeaderMaps, boolean shouldGenerateHeaderSymlinkTreesOnly) { ImmutableSet.Builder<ProjectGenerator.Option> optionsBuilder = ImmutableSet.builder(); if (isReadonly) { optionsBuilder.add(ProjectGenerator.Option.GENERATE_READ_ONLY_FILES); }// ww w .ja v a2 s . c om if (isWithTests) { optionsBuilder.add(ProjectGenerator.Option.INCLUDE_TESTS); } if (isWithDependenciesTests) { optionsBuilder.add(ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS); } if (isProjectsCombined) { optionsBuilder.addAll(ProjectGenerator.COMBINED_PROJECT_OPTIONS); } else { optionsBuilder.addAll(ProjectGenerator.SEPARATED_PROJECT_OPTIONS); } if (!shouldUseHeaderMaps) { optionsBuilder.add(ProjectGenerator.Option.DISABLE_HEADER_MAPS); } if (shouldMergeHeaderMaps) { optionsBuilder.add(ProjectGenerator.Option.MERGE_HEADER_MAPS); } if (shouldGenerateHeaderSymlinkTreesOnly) { optionsBuilder.add(ProjectGenerator.Option.GENERATE_HEADERS_SYMLINK_TREES_ONLY); } return optionsBuilder.build(); }
From source file:com.facebook.presto.hive.metastore.CachingHiveMetastore.java
private static Set<HivePrivilege> toGrants(List<PrivilegeGrantInfo> userGrants) { if (userGrants == null) { return ImmutableSet.of(); }//from ww w . j a va 2 s .c o m ImmutableSet.Builder<HivePrivilege> privileges = ImmutableSet.builder(); for (PrivilegeGrantInfo userGrant : userGrants) { privileges.addAll(parsePrivilege(userGrant)); if (userGrant.isGrantOption()) { privileges.add(HivePrivilege.GRANT); } } return privileges.build(); }
From source file:es.udc.pfc.gamelib.chess.pieces.ChessRook.java
@Override public final ImmutableSet<Position> getStandardMoves(final ChessBoard board) { final ImmutableSet.Builder<Position> moves = ImmutableSet.builder(); moves.addAll(getMovesTo(board, Direction.N)); moves.addAll(getMovesTo(board, Direction.S)); moves.addAll(getMovesTo(board, Direction.E)); moves.addAll(getMovesTo(board, Direction.W)); return moves.build(); }
From source file:com.spotify.heroic.aggregation.Collapse.java
@Override public CollapseInstance apply(final AggregationContext context) { final AggregationInstance instance = each.orElse(Empty.INSTANCE).apply(context); final Optional<List<String>> of = this.of.map(o -> { final ImmutableSet.Builder<String> b = ImmutableSet.builder(); b.addAll(o).addAll(context.requiredTags()); return ImmutableList.copyOf(b.build()); });/* w w w . j a v a 2 s . c o m*/ return new CollapseInstance(of, instance); }