List of usage examples for com.google.common.collect Sets filter
@GwtIncompatible("NavigableSet") @SuppressWarnings("unchecked") @CheckReturnValue public static <E> NavigableSet<E> filter(NavigableSet<E> unfiltered, Predicate<? super E> predicate)
From source file:com.axemblr.provisionr.cloudstack.core.Zones.java
public static boolean hasSecurityGroupEnabled(final CloudStackClient cloudStackClient, final String zoneName) { Set<Zone> ourZone = Sets.filter(cloudStackClient.getZoneClient().listZones(), new Predicate<Zone>() { @Override//from w w w . jav a 2 s.c o m public boolean apply(Zone input) { return input.getName().equals(zoneName); } }); return Iterables.getOnlyElement(ourZone).isSecurityGroupsEnabled(); }
From source file:org.apache.provisionr.cloudstack.core.Zones.java
public static boolean hasSecurityGroupEnabled(final CloudStackClient cloudStackClient, final String zoneName) { Set<Zone> ourZone = Sets.filter(cloudStackClient.getZoneClient().listZones(), new Predicate<Zone>() { @Override/* w w w . j a v a 2 s . co m*/ public boolean apply(Zone input) { return input != null && input.getName().equals(zoneName); } }); return Iterables.getOnlyElement(ourZone).isSecurityGroupsEnabled(); }
From source file:org.inferred.internal.source.RoundEnvironments.java
/** * Sanitizes the result of {@link RoundEnvironment#getElementsAnnotatedWith}, which otherwise * can contain elements annotated with annotations of ERROR type. * * <p>The canonical example is forgetting to import @Nullable. *///w ww . j a v a 2 s. co m public static Set<? extends Element> annotatedElementsIn(RoundEnvironment roundEnv, final Class<? extends Annotation> a) { return Sets.filter(roundEnv.getElementsAnnotatedWith(a), new Predicate<Element>() { @Override public boolean apply(Element element) { return (element.getAnnotation(a) != null); } }); }
From source file:org.sonar.server.rule.RuleTagHelper.java
/** * Validates tags and resolves conflicts between user and system tags. *///from w ww . j a v a 2s.c o m static boolean applyTags(RuleDto rule, Set<String> tags) { for (String tag : tags) { RuleTagFormat.validate(tag); } Set<String> initialTags = rule.getTags(); final Set<String> systemTags = rule.getSystemTags(); Set<String> withoutSystemTags = Sets.filter(tags, input -> input != null && !systemTags.contains(input)); rule.setTags(withoutSystemTags); return withoutSystemTags.size() != initialTags.size() || !withoutSystemTags.containsAll(initialTags); }
From source file:com.axemblr.provisionr.cloudstack.core.Networks.java
/** * Returns the first network with the given name. * * @throws NoSuchElementException if no network is found * @throws IllegalArgumentException if more networks with the same name are found *//*from w w w . ja v a 2s .c o m*/ public static Network getByName(CloudStackClient client, final String networkName) { Set<Network> networks = Sets.filter(client.getNetworkClient().listNetworks(), new Predicate<Network>() { @Override public boolean apply(Network input) { return input.getName().equals(networkName); } }); return Iterables.getOnlyElement(networks); }
From source file:com.google.devtools.moe.client.Utils.java
/** * Returns a Set that excludes strings matching any of excludeRes. */// w w w . ja va 2 s .c o m public static Set<String> filterByRegEx(Set<String> c, List<String> excludeRes) { return ImmutableSet.copyOf(Sets.filter(c, nonMatchingPredicateFromRes(excludeRes))); }
From source file:org.apache.provisionr.cloudstack.core.Networks.java
/** * Returns the first network with the given name. * * @throws NoSuchElementException if no network is found * @throws IllegalArgumentException if more networks with the same name are found */// www .java 2 s . c om public static Network getByName(CloudStackClient client, final String networkName) { Set<Network> networks = Sets.filter(client.getNetworkClient().listNetworks(), new Predicate<Network>() { @Override public boolean apply(Network network) { return network != null && network.getName().equals(networkName); } }); return Iterables.getOnlyElement(networks); }
From source file:io.prestosql.sql.planner.iterative.rule.Util.java
/** * Prune the set of available inputs to those required by the given expressions. * <p>/* ww w . j a va 2s .c o m*/ * If all inputs are used, return Optional.empty() to indicate that no pruning is necessary. */ public static Optional<Set<Symbol>> pruneInputs(Collection<Symbol> availableInputs, Collection<Expression> expressions) { Set<Symbol> availableInputsSet = ImmutableSet.copyOf(availableInputs); Set<Symbol> prunedInputs = Sets.filter(availableInputsSet, SymbolsExtractor.extractUnique(expressions)::contains); if (prunedInputs.size() == availableInputsSet.size()) { return Optional.empty(); } return Optional.of(prunedInputs); }
From source file:com.axemblr.provisionr.cloudstack.core.VirtualMachines.java
public static List<String> destroyAllVirtualMachineByName(final CloudStackClient client, final String vmName) { checkNotEmpty(vmName);//from w ww .jav a 2s .c om Set<VirtualMachine> vms = Sets.filter(client.getVirtualMachineClient().listVirtualMachines( ListVirtualMachinesOptions.Builder.name(vmName)), new Predicate<VirtualMachine>() { @Override public boolean apply(VirtualMachine input) { return vmName.equals(input.getDisplayName()); } }); List<String> jobIds = Lists.newArrayList(); LOG.info("Deleting a total of {} virtual machine instances", vms.size()); for (VirtualMachine vm : vms) { LOG.info("Deleting instance with id {}", vm.getId()); jobIds.add(client.getVirtualMachineClient().destroyVirtualMachine(vm.getId())); } return ImmutableList.copyOf(jobIds); }
From source file:pt.ist.maidSyncher.domain.github.GHLabel.java
public static Set<GHLabel> getAllLabelsWith(final String name) { MaidRoot maidRoot = MaidRoot.getInstance(); return Sets.filter(maidRoot.getGhLabelsSet(), new Predicate<GHLabel>() { @Override// w ww . jav a 2 s . co m public boolean apply(GHLabel ghLabel) { if (ghLabel == null) return false; if (ghLabel.getName().equals(name)) { return true; } return false; } }); }