List of usage examples for com.google.common.collect ImmutableSet isEmpty
boolean isEmpty();
From source file:com.facebook.buck.features.project.intellij.IjProjectCommandHelper.java
public static ImmutableSet<BuildTarget> filterTests(ImmutableSet<BuildTarget> testTargets, CellPathResolver cellPathResolver, ImmutableSet<String> includes, ImmutableSet<String> excludes) { BuildTargetPatternParser<BuildTargetPattern> parser = BuildTargetPatternParser.forVisibilityArgument(); ImmutableSet<BuildTargetPattern> includePatterns = getPatterns(parser, cellPathResolver, includes); ImmutableSet<BuildTargetPattern> excludePatterns = getPatterns(parser, cellPathResolver, excludes); return RichStream.from(testTargets) .filter(test -> (includePatterns.isEmpty() || includePatterns.stream().anyMatch(pattern -> pattern.matches(test))) && (excludePatterns.isEmpty() || excludePatterns.stream().noneMatch(pattern -> pattern.matches(test)))) .toImmutableSet();//from w ww .j av a2s . c om }
From source file:com.outerspacecat.icalendar.RecurrenceFunctions.java
/** * Returns a function for transforming instances of * {@link ChronoFixedSchedule} into zero or more instances. If {@code field} * is not applicable to a fixed schedule then the generated list will be * empty. If a value is out of range then it will be ignored. * // w w w. ja v a 2s . c om * @param field the field to modify using each value in {@code values}. Must * be non {@code null}. * @param values the values to alter supplied fixed schedules with. Must be * non {@code null}, must contain one or more elements, and each * element must be >= 0. * @return a function for transforming instances of * {@link ChronoFixedSchedule} into zero or more instances. Never * {@code null}. */ static Function<ChronoFixedSchedule, List<ChronoFixedSchedule>> expander(final TemporalField field, final ImmutableSet<Integer> values) { Preconditions.checkNotNull(field, "field required"); Preconditions.checkNotNull(values, "values required"); Preconditions.checkArgument(!values.isEmpty(), "values must be non empty"); for (Integer value : values) Preconditions.checkArgument(value >= 0, "each values element must be >=0"); final ImmutableSortedSet<Integer> sortedValues = ImmutableSortedSet.copyOf(values); 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>(); if (obj.getStartDate() != null) { if (obj.getStartDate().isSupported(field)) { ValueRange range = obj.getStartDate().range(field); for (int value : sortedValues) { if (!range.isValidValue(value)) continue; ret.add(obj.adjustStartDate(obj.getStartDate().with(field, value))); } } } else if (obj.getZonedStartDateTime() != null) { if (obj.getZonedStartDateTime().isSupported(field)) { ValueRange range = obj.getZonedStartDateTime().range(field); for (int value : sortedValues) { if (!range.isValidValue(value)) continue; ret.add(obj.adjustZonedStartDateTime(obj.getZonedStartDateTime().with(field, value))); } } } else { throw new IllegalStateException("no start date or zoned start date-time"); } return ret; } }; }
From source file:com.outerspacecat.icalendar.RecurrenceFunctions.java
/** * Returns a function for transforming instances of * {@link ChronoFixedSchedule} into zero or more instances. Used to apply * BYDAY values to a WEEKLY recurrence or a YEARLY recurrence with BYWEEKNO * values./*from w ww . j ava 2 s .c om*/ * <p> * May not work for all chronologies. * * @param weekStart the week start. Must be non {@code null}. * @param daysOfWeek the values to alter supplied fixed schedules with. Must * be non {@code null}.. * @return a function for transforming instances of {@link FixedSchedule} into * zero or more instances. Never {@code null}. */ static Function<ChronoFixedSchedule, List<ChronoFixedSchedule>> weeklyByDayExpander(final DayOfWeek weekStart, final ImmutableSet<DayOfWeek> daysOfWeek) { Preconditions.checkNotNull(weekStart, "weekStart required"); Preconditions.checkNotNull(daysOfWeek, "daysOfWeek required"); Preconditions.checkArgument(!daysOfWeek.isEmpty(), "jodaByDay 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>(); ChronoLocalDate startOfWeek = obj.getDateOfStart().minus( (7 + obj.getDateOfStart().get(ChronoField.DAY_OF_WEEK) - weekStart.getValue()) % 7, ChronoUnit.DAYS); for (int i = 0; i < 7; ++i) { ChronoLocalDate adjustedStart = startOfWeek.plus(i, ChronoUnit.DAYS); if (daysOfWeek.contains(DayOfWeek.of(adjustedStart.get(ChronoField.DAY_OF_WEEK)))) ret.add(obj.adjustDateOfStart(adjustedStart)); } return ret; } }; }
From source file:com.outerspacecat.icalendar.RecurrenceFunctions.java
/** * Returns a function for transforming instances of * {@link ChronoFixedSchedule} into zero or more instances. If {@code field} * is not applicable to a fixed schedule then the generated list will be * empty. If a value is out of range then it will be ignored. * /* w w w . j av a 2 s. c o m*/ * @param field the field to modify using each value in {@code values}. Must * be non {@code null}. * @param values the values to alter supplied fixed schedules with. Must be * non {@code null} and must contain one or more elements. Elements may * be negative, but must be non zero. * @return a function for transforming instances of * {@link ChronoFixedSchedule} into zero or more instances. Never * {@code null}. */ static Function<ChronoFixedSchedule, List<ChronoFixedSchedule>> signedExpander(final TemporalField field, final ImmutableSet<Integer> values) { Preconditions.checkNotNull(field, "field required"); Preconditions.checkNotNull(values, "values required"); Preconditions.checkArgument(!values.isEmpty(), "values must be non empty"); for (Integer value : values) Preconditions.checkArgument(value != 0, "each values element must be non zero"); 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>(); if (obj.getStartDate() != null) { if (obj.getStartDate().isSupported(field)) { ValueRange range = obj.getStartDate().range(field); long maximum = range.getMaximum(); ImmutableSortedSet<Long> sortedValues = ImmutableSortedSet.copyOf( Iterables.transform(values, (input) -> input < 0 ? maximum + input + 1 : input)); for (Long value : sortedValues) { if (!range.isValidValue(value)) continue; ret.add(obj.adjustStartDate(obj.getStartDate().with(field, value))); } } } else if (obj.getZonedStartDateTime() != null) { if (obj.getZonedStartDateTime().isSupported(field)) { ValueRange range = obj.getStartDate().range(field); long maximum = range.getMaximum(); ImmutableSortedSet<Long> sortedValues = ImmutableSortedSet.copyOf( Iterables.transform(values, (input) -> input < 0 ? maximum + input + 1 : input)); for (Long value : sortedValues) { if (!range.isValidValue(value)) continue; ret.add(obj.adjustZonedStartDateTime(obj.getZonedStartDateTime().with(field, value))); } } } else { throw new IllegalStateException("no start date or zoned start date-time"); } 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 BYWEEKNO values to a YEARLY * recurrence.//from w ww. j a va2s. c o m * <p> * May not work for all chronologies. * * @param byWeekNo the values to alter supplied fixed schedules with. Must be * non {@code null}, must contain one or more elements, and each * element must be >= -53 and <= 53, but not 0. * @return a function for transforming instances of {@link FixedSchedule} into * zero or more instances. Never {@code null}. */ static Function<ChronoFixedSchedule, List<ChronoFixedSchedule>> yearlyByWeekNoExpander( final DayOfWeek weekStart, final ImmutableSet<Integer> byWeekNo) { Preconditions.checkNotNull(weekStart, "weekStart required"); Preconditions.checkNotNull(byWeekNo, "byWeekNo required"); Preconditions.checkArgument(!byWeekNo.isEmpty(), "byWeekNo must be non empty"); for (Integer value : byWeekNo) Preconditions.checkArgument(value >= -53 && value <= 53 && value != 0, "each byWeekNo element must be >= 53 and <= 53, but not 0"); 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>(); ChronoLocalDate firstDayOfYear = obj.getDateOfStart().with(ChronoField.DAY_OF_YEAR, 1); // offset to the closest day on WEEKSTART before or on the // 1st int daysToStartOfFirstWeek = -1 * ((7 + firstDayOfYear.get(ChronoField.DAY_OF_WEEK) - weekStart.getValue()) % 7); // the first week must have 4 or more days in the original // year if (daysToStartOfFirstWeek < -3) daysToStartOfFirstWeek += 7; ChronoLocalDate startOfFirstWeekOfYear = firstDayOfYear.plus(daysToStartOfFirstWeek, ChronoUnit.DAYS); long daysInYear = obj.getDateOfStart().range(ChronoField.DAY_OF_YEAR).getMaximum(); long weeksInYear = (daysInYear - daysToStartOfFirstWeek) / 7; // 4 or more days left over counts as one last week if ((daysInYear - daysToStartOfFirstWeek) % 7 >= 4) ++weeksInYear; final long maximum = weeksInYear; ImmutableSortedSet<Long> sortedValues = ImmutableSortedSet .copyOf(Iterables.transform(byWeekNo, (input) -> input < 0 ? maximum + input + 1 : input)); for (Long value : sortedValues) { if (value < 1 || value > maximum) continue; ChronoLocalDate startOfWeek = startOfFirstWeekOfYear.plus((value - 1) * 7, ChronoUnit.DAYS); ret.add(obj.adjustDateOfStart(startOfWeek)); } return ret; } }; }
From source file:google.registry.model.registry.label.DomainLabelMetrics.java
/** Update all three reserved list metrics. */ static void recordReservedListCheckOutcome(String tld, ImmutableSet<MetricsReservedListMatch> matches, double elapsedMillis) { MetricsReservedListMatch mostSevereMatch = null; for (MetricsReservedListMatch match : matches) { reservedListHits.increment(tld, match.reservedListName(), match.reservationType().toString()); if ((mostSevereMatch == null) || (match.reservationType().compareTo(mostSevereMatch.reservationType()) > 0)) { mostSevereMatch = match;//from w w w. j av a 2s. c o m } } String matchCount = String.valueOf(matches.size()); String mostSevereReservedList = matches.isEmpty() ? "(none)" : mostSevereMatch.reservedListName(); String mostSevereReservationType = (matches.isEmpty() ? "(none)" : mostSevereMatch.reservationType()) .toString(); reservedListChecks.increment(tld, matchCount, mostSevereReservedList, mostSevereReservationType); reservedListProcessingTime.record(elapsedMillis, tld, matchCount, mostSevereReservedList, mostSevereReservationType); }
From source file:com.google.devtools.build.lib.rules.objc.ReleaseBundling.java
/** * Returns a {@link ReleaseBundling} object constructed using the information available in given * context.//from w ww. j ava2s. c om */ public static ReleaseBundling releaseBundling(RuleContext ruleContext) throws InterruptedException { Preconditions.checkState(!Strings.isNullOrEmpty(ruleContext.attributes().get(BUNDLE_ID_ATTR, Type.STRING)), "requires a bundle_id value"); String primaryBundleId = null; String fallbackBundleId = null; Artifact provisioningProfile; if (ruleContext.attributes().isAttributeValueExplicitlySpecified(BUNDLE_ID_ATTR)) { primaryBundleId = ruleContext.attributes().get(BUNDLE_ID_ATTR, Type.STRING); } else { fallbackBundleId = ruleContext.attributes().get(BUNDLE_ID_ATTR, Type.STRING); } Artifact explicitProvisioningProfile = ruleContext.getPrerequisiteArtifact(PROVISIONING_PROFILE_ATTR, Mode.TARGET); if (explicitProvisioningProfile != null) { provisioningProfile = explicitProvisioningProfile; } else { provisioningProfile = ruleContext.getPrerequisiteArtifact(DEFAULT_PROVISIONING_PROFILE_ATTR, Mode.TARGET); } ImmutableSet<TargetDeviceFamily> families = null; List<String> rawFamilies = ruleContext.attributes().get(FAMILIES_ATTR, Type.STRING_LIST); try { families = ImmutableSet.copyOf(TargetDeviceFamily.fromNamesInRule(rawFamilies)); } catch (InvalidFamilyNameException | RepeatedFamilyNameException e) { families = ImmutableSet.of(); } if (families.isEmpty()) { ruleContext.attributeError(FAMILIES_ATTR, INVALID_FAMILIES_ERROR); } return new ReleaseBundling.Builder() .setIpaArtifact(ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA)) .setBundleId(ruleContext.attributes().get(BUNDLE_ID_ATTR, Type.STRING)) .setPrimaryBundleId(primaryBundleId).setFallbackBundleId(fallbackBundleId) .setAppIcon(Strings.emptyToNull(ruleContext.attributes().get(APP_ICON_ATTR, Type.STRING))) .setLaunchImage(Strings.emptyToNull(ruleContext.attributes().get(LAUNCH_IMAGE_ATTR, Type.STRING))) .setLaunchStoryboard(ruleContext.getPrerequisiteArtifact(LAUNCH_STORYBOARD_ATTR, Mode.TARGET)) .setProvisioningProfile(provisioningProfile) .setProvisioningProfileAttributeName(PROVISIONING_PROFILE_ATTR).setTargetDeviceFamilies(families) .setIntermediateArtifacts(ObjcRuleClasses.intermediateArtifacts(ruleContext)) .setEntitlements(ruleContext.getPrerequisiteArtifact("entitlements", Mode.TARGET)).build(); }
From source file:org.sosy_lab.cpachecker.util.expressions.And.java
public static <LeafType> ExpressionTree<LeafType> of(Iterable<ExpressionTree<LeafType>> pOperands) { // If one of the operands is false, return false if (Iterables.contains(pOperands, ExpressionTrees.getFalse())) { return ExpressionTrees.getFalse(); }/* w ww .ja v a 2 s .co m*/ // Filter out trivial operands and flatten the hierarchy ImmutableSet<ExpressionTree<LeafType>> operands = FluentIterable.from(pOperands) .filter(Predicates.not(Predicates.equalTo(ExpressionTrees.<LeafType>getTrue()))) .transformAndConcat(new Function<ExpressionTree<LeafType>, Iterable<ExpressionTree<LeafType>>>() { @Override public Iterable<ExpressionTree<LeafType>> apply(ExpressionTree<LeafType> pOperand) { if (pOperand instanceof And) { return (And<LeafType>) pOperand; } return Collections.singleton(pOperand); } }).toSet(); // If there are no operands, return the neutral element if (operands.isEmpty()) { return ExpressionTrees.getTrue(); } // If there is only one operand, return it if (operands.size() == 1) { return operands.iterator().next(); } return new And<>(operands); }
From source file:com.google.devtools.common.options.InvocationPolicyEnforcer.java
private static boolean policyApplies(FlagPolicy policy, ImmutableSet<String> applicableCommands) { // Skip the flag policy if it doesn't apply to this command. If the commands list is empty, // then the policy applies to all commands. if (policy.getCommandsList().isEmpty() || applicableCommands.isEmpty()) { return true; }//from w w w. j a v a 2 s . c o m return !Collections.disjoint(policy.getCommandsList(), applicableCommands); }
From source file:com.facebook.buck.apple.project_generator.XCodeProjectCommandHelper.java
@VisibleForTesting static ImmutableSet<BuildTarget> generateWorkspacesForTargets(BuckEventBus buckEventBus, Cell cell, BuckConfig buckConfig, ListeningExecutorService executorService, final TargetGraphAndTargets targetGraphAndTargets, ImmutableSet<BuildTarget> passedInTargetsSet, ImmutableSet<ProjectGenerator.Option> options, FocusedModuleTargetMatcher focusModules, Map<Path, ProjectGenerator> projectGenerators, boolean combinedProject) throws IOException, InterruptedException { ImmutableSet<BuildTarget> targets; if (passedInTargetsSet.isEmpty()) { targets = targetGraphAndTargets.getProjectRoots().stream().map(TargetNode::getBuildTarget) .collect(MoreCollectors.toImmutableSet()); } else {//from w w w .j ava 2 s . co m targets = passedInTargetsSet; } LazyActionGraph lazyActionGraph = new LazyActionGraph(targetGraphAndTargets.getTargetGraph(), buckEventBus); LOG.debug("Generating workspace for config targets %s", targets); ImmutableSet.Builder<BuildTarget> requiredBuildTargetsBuilder = ImmutableSet.builder(); for (final BuildTarget inputTarget : targets) { TargetNode<?, ?> inputNode = targetGraphAndTargets.getTargetGraph().get(inputTarget); XcodeWorkspaceConfigDescriptionArg workspaceArgs; if (inputNode.getDescription() instanceof XcodeWorkspaceConfigDescription) { TargetNode<XcodeWorkspaceConfigDescriptionArg, ?> castedWorkspaceNode = castToXcodeWorkspaceTargetNode( inputNode); workspaceArgs = castedWorkspaceNode.getConstructorArg(); } else if (canGenerateImplicitWorkspaceForDescription(inputNode.getDescription())) { workspaceArgs = createImplicitWorkspaceArgs(inputNode); } else { throw new HumanReadableException( "%s must be a xcode_workspace_config, apple_binary, apple_bundle, or apple_library", inputNode); } AppleConfig appleConfig = buckConfig.getView(AppleConfig.class); HalideBuckConfig halideBuckConfig = new HalideBuckConfig(buckConfig); CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(buckConfig); SwiftBuckConfig swiftBuckConfig = new SwiftBuckConfig(buckConfig); CxxPlatform defaultCxxPlatform = cell.getKnownBuildRuleTypes().getDefaultCxxPlatforms(); WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(cell, targetGraphAndTargets.getTargetGraph(), workspaceArgs, inputTarget, options, combinedProject, focusModules, !appleConfig.getXcodeDisableParallelizeBuild(), defaultCxxPlatform, buckConfig.getView(ParserConfig.class).getBuildFileName(), lazyActionGraph::getBuildRuleResolverWhileRequiringSubgraph, buckEventBus, halideBuckConfig, cxxBuckConfig, swiftBuckConfig); Preconditions.checkNotNull(executorService, "CommandRunnerParams does not have executor for PROJECT pool"); generator.generateWorkspaceAndDependentProjects(projectGenerators, executorService); ImmutableSet<BuildTarget> requiredBuildTargetsForWorkspace = generator.getRequiredBuildTargets(); LOG.debug("Required build targets for workspace %s: %s", inputTarget, requiredBuildTargetsForWorkspace); requiredBuildTargetsBuilder.addAll(requiredBuildTargetsForWorkspace); } return requiredBuildTargetsBuilder.build(); }