List of usage examples for com.google.common.collect ImmutableSet contains
boolean contains(Object o);
From source file:uk.ac.york.mondo.integration.api.EffectiveMetamodelRuleset.java
/** * Returns all the slots explicitly included (after filtering), or a singleton * set with {@link #WILDCARD} if all slots are included. */// www . j av a2s . c om public ImmutableSet<String> getIncludedSlots(String mmURI, String typeName) { if (isEverythingIncluded()) { return ImmutableSet.of(WILDCARD); } else if (exclusions.contains(mmURI, WILDCARD)) { return ImmutableSet.of(); } final ImmutableSet<String> included = inclusions.get(mmURI, typeName); if (included == null) { return ImmutableSet.of(); } final ImmutableSet<String> excluded = exclusions.get(mmURI, typeName); if (excluded == null) { return included; } ImmutableSet.Builder<String> result = new ImmutableSet.Builder<>(); for (String slot : included) { if (!excluded.contains(slot)) { result.add(slot); } } return result.build(); }
From source file:com.arpnetworking.tsdcore.sinks.WavefrontSink.java
/** * {@inheritDoc}//from w w w. j ava2s . co m */ @Override public void recordAggregateData(final PeriodicData periodicData) { for (final AggregatedData aggregatedData : periodicData.getData()) { if (!aggregatedData.isSpecified()) { continue; } final ReportPoint.Builder reportPointBuilder = ReportPoint.newBuilder(); final FQDSN fqdsn = aggregatedData.getFQDSN(); reportPointBuilder.setMetric(buildMetricName(fqdsn, periodicData.getPeriod())); reportPointBuilder.setHost(periodicData.getDimensions().get("host")); reportPointBuilder.setValue(aggregatedData.getValue().getValue()); reportPointBuilder.setTimestamp(periodicData.getStart().getMillis()); reportPointBuilder.setTable("dummy"); // Build the list of annotations based on cluster and white listed dimensions final Map<String, String> annotations = Maps.newHashMap(); annotations.put("cluster", fqdsn.getCluster()); if (_whiteListedDimensions.isPresent()) { // Respect the whitelist. final ImmutableSet<String> whiteList = _whiteListedDimensions.get(); for (final Map.Entry<String, String> dimension : periodicData.getDimensions().entrySet()) { if (whiteList.contains(dimension.getKey())) { annotations.put(dimension.getKey(), dimension.getValue()); } } } else { // Don't use the whitelist, send everything. for (final Map.Entry<String, String> dimension : periodicData.getDimensions().entrySet()) { final String k = dimension.getKey(); if (!k.equals(CombinedMetricData.CLUSTER_KEY) && !k.equals(CombinedMetricData.HOST_KEY) && !k.equals(CombinedMetricData.SERVICE_KEY)) { annotations.put(dimension.getKey(), dimension.getValue()); } } } reportPointBuilder.setAnnotations(annotations); // Report the actual data point _pointHandler.reportPoint(reportPointBuilder.build(), ""); } }
From source file:com.google.caliper.runner.ExperimentingRunnerModule.java
@Provides ImmutableSet<Instrumentation> provideInstrumentations(CaliperOptions options, BenchmarkClass benchmarkClass, ImmutableSet<Instrument> instruments) throws InvalidBenchmarkException { ImmutableSet.Builder<Instrumentation> builder = ImmutableSet.builder(); ImmutableSet<String> benchmarkMethodNames = options.benchmarkMethodNames(); Set<String> unusedBenchmarkNames = new HashSet<String>(benchmarkMethodNames); for (Instrument instrument : instruments) { for (Method method : findAllBenchmarkMethods(benchmarkClass.benchmarkClass(), instrument)) { if (benchmarkMethodNames.isEmpty() || benchmarkMethodNames.contains(method.getName())) { builder.add(instrument.createInstrumentation(method)); unusedBenchmarkNames.remove(method.getName()); }//ww w. j av a2s. c om } } if (!unusedBenchmarkNames.isEmpty()) { throw new InvalidBenchmarkException( "Invalid benchmark method(s) specified in options: " + unusedBenchmarkNames); } return builder.build(); }
From source file:com.google.jimfs.JimfsFileSystemProvider.java
@Override public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException { JimfsPath checkedPath = checkPath(path); ImmutableSet<OpenOption> opts = Options.getOptionsForOutputStream(options); RegularFile file = getDefaultView(checkedPath).getOrCreateRegularFile(checkedPath, opts, NO_ATTRS); return new JimfsOutputStream(file, opts.contains(APPEND)); }
From source file:com.facebook.buck.android.ExopackageInstaller.java
@VisibleForTesting static ImmutableMap<String, Path> filterLibrariesForAbi(Path nativeLibsDir, ImmutableMultimap<String, Path> allLibraries, String abi, ImmutableSet<String> ignoreLibraries) { ImmutableMap.Builder<String, Path> filteredLibraries = ImmutableMap.builder(); for (Map.Entry<String, Path> entry : allLibraries.entries()) { Path relativePath = nativeLibsDir.relativize(entry.getValue()); // relativePath is of the form libs/x86/foo.so, or assetLibs/x86/foo.so etc. Preconditions.checkState(relativePath.getNameCount() == 3); Preconditions.checkState(relativePath.getName(0).toString().equals("libs") || relativePath.getName(0).toString().equals("assetLibs")); String libAbi = relativePath.getParent().getFileName().toString(); String libName = relativePath.getFileName().toString(); if (libAbi.equals(abi) && !ignoreLibraries.contains(libName)) { filteredLibraries.put(entry); }//from w ww . j ava 2 s. c o m } return filteredLibraries.build(); }
From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.CassandraCluster.java
@NotNull static List<String> hasResources(@NotNull final Protos.Offer offer, @NotNull final TaskResources taskResources, @NotNull final Map<String, Long> portMapping, @NotNull final String mesosRole) { final List<String> errors = newArrayList(); final ListMultimap<String, Protos.Resource> availableResources = resourcesForRoleAndOffer(mesosRole, offer); final double availableCpus = maxResourceValueDouble(availableResources.get("cpus")).or(0d); final long availableMem = maxResourceValueLong(availableResources.get("mem")).or(0l); final long availableDisk = maxResourceValueLong(availableResources.get("disk")).or(0l); if (availableCpus < taskResources.getCpuCores()) { errors.add(String.format("Not enough cpu resources for role %s. Required %s only %s available", mesosRole, String.valueOf(taskResources.getCpuCores()), String.valueOf(availableCpus))); }//ww w .j av a 2 s.com if (availableMem < taskResources.getMemMb()) { errors.add(String.format("Not enough mem resources for role %s. Required %d only %d available", mesosRole, taskResources.getMemMb(), availableMem)); } if (availableDisk < taskResources.getDiskMb()) { errors.add(String.format("Not enough disk resources for role %s. Required %d only %d available", mesosRole, taskResources.getDiskMb(), availableDisk)); } ImmutableSet<Long> ports = from(availableResources.get("ports")).transformAndConcat(resourceToPortSet()) .toSet(); for (final Map.Entry<String, Long> entry : portMapping.entrySet()) { final String key = entry.getKey(); final Long value = entry.getValue(); if (!ports.contains(value)) { errors.add(String.format("Unavailable port %d(%s) for role %s. %d other ports available", value, key, mesosRole, ports.size())); } } return errors; }
From source file:org.ambraproject.rhino.service.impl.IngestionService.java
private String getManuscriptEntry(ImmutableSet<String> entryNames, ManifestXml manifestXml) { ManifestXml.Representation manuscriptRepr = manifestXml.getArticleAsset().getRepresentation("manuscript") .orElseThrow(() -> new RestClientException("Manuscript entry not found in manifest", HttpStatus.BAD_REQUEST)); String manuscriptEntry = manuscriptRepr.getFile().getEntry(); if (!entryNames.contains(manuscriptEntry)) { throw new RestClientException("Manuscript file not found in archive: " + manuscriptEntry, HttpStatus.BAD_REQUEST); }/*from w w w . jav a 2 s . c o m*/ return manuscriptEntry; }
From source file:com.facebook.buck.testutil.endtoend.EndToEndWorkspace.java
private ImmutableMap<String, String> overrideSystemEnvironment(boolean buckdEnabled, ImmutableMap<String, String> environmentOverrides) { ImmutableMap.Builder<String, String> environmentBuilder = ImmutableMap.builder(); // Ensure that we make it look like we're not running from within buck. This is fine since // we're running in a completely different directory. Also make sure that NO_BUCKD is only // set if buckdEnabled is false ImmutableSet<String> keysToRemove = ImmutableSet.of("BUCK_ROOT_BUILD_ID", "NO_BUCKD"); for (Map.Entry<String, String> entry : EnvVariablesProvider.getSystemEnv().entrySet()) { if (keysToRemove.contains(entry.getKey())) { continue; }//from w w w . ja v a 2s. com environmentBuilder.put(entry.getKey(), entry.getValue()); } if (!buckdEnabled) { environmentBuilder.put("NO_BUCKD", "1"); } Map<String, String> finalEnvironment = new HashMap<>(environmentBuilder.build()); finalEnvironment.putAll(environmentOverrides); return ImmutableMap.copyOf(finalEnvironment); }
From source file:com.outerspacecat.icalendar.RecurrenceFunctions.java
/** * Returns a function for transforming instances of {@link FixedSchedule} into * zero or more instances. Used to apply BYDAY values to a YEARLY recurrence. * <p>/* www. jav a2s .co m*/ * May not work for all chronologies. * * @param byDay the values to alter supplied fixed schedules with. Must be non * {@code null} and must contain one or more elements. * @return a function for transforming instances of {@link FixedSchedule} into * zero or more instances. Never {@code null}. */ static Function<ChronoFixedSchedule, List<ChronoFixedSchedule>> yearlyByDayExpander( final ImmutableSet<DayOfWeekOccurrence> byDay) { Preconditions.checkNotNull(byDay, "byDay required"); Preconditions.checkArgument(!byDay.isEmpty(), "byDay must be non empty"); return new Function<ChronoFixedSchedule, List<ChronoFixedSchedule>>() { @Override public List<ChronoFixedSchedule> apply(final ChronoFixedSchedule obj) { Preconditions.checkNotNull(obj, "obj required"); List<ChronoFixedSchedule> ret = new ArrayList<ChronoFixedSchedule>(); int daysInYear = (int) (obj.getDateOfStart().range(ChronoField.DAY_OF_YEAR).getMaximum()); for (int dayOfYear = 1; dayOfYear <= daysInYear; ++dayOfYear) { ChronoLocalDate adjustedStart = obj.getDateOfStart().with(ChronoField.DAY_OF_YEAR, dayOfYear); DayOfWeek dayOfWeek = DayOfWeek.of(adjustedStart.get(ChronoField.DAY_OF_WEEK)); int numericPrefix = dayOfYear / 7 + (dayOfYear % 7 == 0 ? 0 : 1); int dayOfWeekOccurrencesInYear = (int) (numericPrefix + ((daysInYear - dayOfYear) / 7)); if (byDay.contains(new DayOfWeekOccurrence(Optional.absent(), dayOfWeek)) || byDay.contains( new DayOfWeekOccurrence(Optional.fromNullable(numericPrefix), dayOfWeek)) || byDay.contains(new DayOfWeekOccurrence( Optional.fromNullable(numericPrefix - dayOfWeekOccurrencesInYear - 1), dayOfWeek))) ret.add(obj.adjustDateOfStart(adjustedStart)); } return ret; } }; }
From source file:com.outerspacecat.icalendar.RecurrenceFunctions.java
/** * Returns a function for transforming instances of {@link FixedSchedule} into * zero or more instances. Used to apply BYDAY values to a MONTHLY recurrence. * <p>/* w ww. jav a 2s . com*/ * May not work for all chronologies. * * @param byDay the values to alter supplied fixed schedules with. Must be non * {@code null} and must contain one or more elements. * @return a function for transforming instances of {@link FixedSchedule} into * zero or more instances. Never {@code null}. */ static Function<ChronoFixedSchedule, List<ChronoFixedSchedule>> monthlyByDayExpander( final ImmutableSet<DayOfWeekOccurrence> byDay) { Preconditions.checkNotNull(byDay, "byDay required"); Preconditions.checkArgument(!byDay.isEmpty(), "byDay must be non empty"); return new Function<ChronoFixedSchedule, List<ChronoFixedSchedule>>() { @Override public List<ChronoFixedSchedule> apply(final ChronoFixedSchedule obj) { Preconditions.checkNotNull(obj, "obj required"); List<ChronoFixedSchedule> ret = new ArrayList<ChronoFixedSchedule>(); long daysInMonth = obj.getDateOfStart().range(ChronoField.DAY_OF_MONTH).getMaximum(); for (int dayOfMonth = 1; dayOfMonth <= daysInMonth; ++dayOfMonth) { ChronoLocalDate adjustedStart = obj.getDateOfStart().with(ChronoField.DAY_OF_MONTH, dayOfMonth); DayOfWeek dayOfWeek = DayOfWeek.of(adjustedStart.get(ChronoField.DAY_OF_WEEK)); int numericPrefix = dayOfMonth / 7 + (dayOfMonth % 7 == 0 ? 0 : 1); int dayOfWeekOccurrencesInMonth = (int) (numericPrefix + ((daysInMonth - dayOfMonth) / 7)); if (byDay.contains(new DayOfWeekOccurrence(Optional.absent(), dayOfWeek)) || byDay.contains( new DayOfWeekOccurrence(Optional.fromNullable(numericPrefix), dayOfWeek)) || byDay.contains(new DayOfWeekOccurrence( Optional.fromNullable(numericPrefix - dayOfWeekOccurrencesInMonth - 1), dayOfWeek))) ret.add(obj.adjustDateOfStart(adjustedStart)); } return ret; } }; }