Example usage for com.google.common.collect Iterables contains

List of usage examples for com.google.common.collect Iterables contains

Introduction

In this page you can find the example usage for com.google.common.collect Iterables contains.

Prototype

public static boolean contains(Iterable<?> iterable, @Nullable Object element) 

Source Link

Document

Returns true if iterable contains any object for which equals(element) is true.

Usage

From source file:org.lanternpowered.server.data.value.immutable.ImmutableLanternPatternListValue.java

@Override
public ImmutablePatternListValue withoutAll(Iterable<PatternLayer> elements) {
    return new ImmutableLanternPatternListValue(getKey(), getDefault(),
            getActualValue().stream().filter(existingElement -> !Iterables.contains(elements, existingElement))
                    .collect(ImmutableList.toImmutableList()));
}

From source file:org.lanternpowered.server.data.value.immutable.ImmutableLanternWeightedCollectionValue.java

@Override
public ImmutableWeightedCollectionValue<E> withoutAll(Iterable<TableEntry<E>> elements) {
    final WeightedTable<E> newTable = new WeightedTable<>();
    getActualValue().stream().filter(entry -> !Iterables.contains(elements, entry)).forEach(newTable::add);
    return new ImmutableLanternWeightedCollectionValue<>(getKey(), getDefault(), newTable);
}

From source file:com.android.tools.idea.res.LayoutDataBindingInfo.java

public void replaceItems(@NonNull Iterable<PsiDataBindingResourceItem> items, long modificationCount) {
    boolean changed = myItems == null;
    if (myItems == null) {
        changed = true;/*  w ww.  j a va  2  s.  c o m*/
    } else {
        List<PsiDataBindingResourceItem> removed = Lists.newArrayList();
        for (Map.Entry<DataBindingResourceType, List<PsiDataBindingResourceItem>> entry : myItems.entrySet()) {
            for (PsiDataBindingResourceItem item : entry.getValue()) {
                if (!Iterables.contains(items, item)) {
                    removed.add(item);
                }
            }
            changed |= removed.size() > 0;
            for (PsiDataBindingResourceItem item : removed) {
                entry.getValue().remove(item);
            }
        }
        for (PsiDataBindingResourceItem item : items) {
            changed = addItem(item) | changed;
        }
    }
    if (changed) {
        myLayoutModificationCount = modificationCount;
    }
}

From source file:org.eclipse.viatra.query.patternlanguage.emf.annotations.PatternAnnotationValidator.java

@Override
public Iterable<String> getMissingMandatoryAttributes(Annotation annotation) {
    final Iterable<String> actualAttributeNames = getParameterNames(annotation);
    final Iterable<PatternAnnotationParameter> filteredParameters = Iterables.filter(definedAttributes,
            input -> input.isMandatory() && !Iterables.contains(actualAttributeNames, input.getName()));
    return Iterables.transform(filteredParameters, PatternAnnotationParameter::getName);
}

From source file:com.eucalyptus.auth.euare.identity.region.RegionConfigurationManager.java

/**
 * Get information for a region based on an IAM identifier (AKI, etc)
 *
 * @param identifier The identifier to use
 * @return The region info optional//  w ww .j  a va2s. c om
 */
@Nonnull
public Optional<RegionInfo> getRegionByIdentifier(@Nullable final String identifier) {
    Optional<RegionInfo> regionInfoOptional = Optional.absent();
    final Optional<RegionConfiguration> configurationOptional = regionConfigurationSupplier.get();
    if (configurationOptional.isPresent() && identifier != null && identifier.length() > 5) {
        final RegionConfiguration configuration = configurationOptional.get();
        final String regionIdPartition = identifier.substring(3, 5);
        for (final Region region : configuration) {
            if (Iterables.contains(
                    Iterables.transform(region.getIdentifierPartitions(), PartitionFunctions.IDENTIFIER),
                    regionIdPartition)) {
                regionInfoOptional = Optional
                        .of(regionToRegionInfoTransform(configurationOptional).apply(region));
            }
        }
    }
    return regionInfoOptional;
}

From source file:co.cask.cdap.etl.mock.batch.joiner.MockJoiner.java

private Schema getOutputSchema(Map<String, Schema> inputSchemas) {
    // sort the input schemas by input names to get the deterministic order of fields for output schema
    Map<String, Schema> sortedMap = new TreeMap<>(inputSchemas);
    List<Schema.Field> outputFields = new ArrayList<>();
    Iterable<String> requiredInputs = config.getRequiredInputs();

    // TODO use selectedFields
    for (Map.Entry<String, Schema> entry : sortedMap.entrySet()) {
        Schema inputSchema = entry.getValue();
        if (Iterables.contains(requiredInputs, entry.getKey())) {
            for (Schema.Field inputField : inputSchema.getFields()) {
                outputFields.add(Schema.Field.of(inputField.getName(), inputField.getSchema()));
            }// w w  w  .  j a va2 s. c  om
        } else { // mark fields as nullable
            for (Schema.Field inputField : inputSchema.getFields()) {
                outputFields
                        .add(Schema.Field.of(inputField.getName(), Schema.nullableOf(inputField.getSchema())));
            }
        }
    }
    return Schema.recordOf("join.output", outputFields);
}

From source file:org.eclipse.incquery.patternlanguage.annotations.impl.PatternAnnotationValidator.java

@Override
public Iterable<String> getMissingMandatoryAttributes(Annotation annotation) {
    final Iterable<String> actualAttributeNames = getParameterNames(annotation);
    final Iterable<PatternAnnotationParameter> filteredParameters = Iterables.filter(definedAttributes,
            new Predicate<PatternAnnotationParameter>() {

                @Override//from w w  w .  j  av  a2 s .  co m
                public boolean apply(PatternAnnotationParameter input) {
                    Preconditions.checkNotNull(input, "input");
                    return input.isMandatory() && !Iterables.contains(actualAttributeNames, input.getName());
                }
            });
    return Iterables.transform(filteredParameters, new AnnotationDefinitionParameterName());
}

From source file:org.sonar.java.checks.CatchUsesExceptionWithContextCheck.java

private boolean isQualifiedExcludedType(Tree tree) {
    if (!tree.is(Kind.MEMBER_SELECT)) {
        return false;
    }// ww w  . j a  v a 2 s  .com
    return Iterables.contains(exceptions, ExpressionsHelper.concatenate((MemberSelectExpressionTree) tree));
}

From source file:org.eclipse.qvtd.compiler.internal.scheduler.AbstractNode.java

@Override
public final void addIncomingConnection(@NonNull Connection connection) {
    assert Iterables.contains(connection.getTargets(), this);
    //      assert edge.getRegion() == getRegion();
    List<Connection> incomingConnections2 = incomingConnections;
    if (incomingConnections2 == null) {
        incomingConnections = incomingConnections2 = new ArrayList<Connection>();
    } else {//w ww.j  a v a2 s.  com
        assert !incomingConnections2.contains(connection);
    }
    incomingConnections2.add(connection);
}

From source file:org.splevo.jamopp.refactoring.java.caslicensehandler.cheatsheet.actions.CASLicenseHandlerConfiguration.java

private boolean isLicenseAlreadyAssigned(final String licenseToCheck, final String... variantIdsToIgnore) {
    final Iterable<String> idsToIgnore = Lists.newArrayList(variantIdsToIgnore);
    return Iterables.any(variantToLicenseMap.entrySet(), new Predicate<Entry<String, String>>() {
        @Override/*w  w w .  j a v  a2s .c  o m*/
        public boolean apply(Entry<String, String> input) {
            if (Iterables.contains(idsToIgnore, input.getKey())) {
                return false;
            }
            return input.getValue().equals(licenseToCheck);
        }
    });
}