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.eclipse.incquery.patternlanguage.annotations.impl.ExtensionBasedPatternAnnotationValidator.java

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

                @Override//from  w  ww. j  av  a 2  s . c  o  m
                public boolean apply(ExtensionBasedPatternAnnotationParameter input) {
                    Preconditions.checkNotNull(input, "input");
                    return input.isMandatory() && !Iterables.contains(actualAttributeNames, input.getName());
                }
            });
    return Iterables.transform(filteredParameters, new AnnotationDefinitionParameterName());
}

From source file:com.github.richardwilly98.esdms.UserImpl.java

@Override
@JsonIgnore//from  www  .  ja v a 2s. c o  m
public boolean hasRole(Role role) {
    try {
        checkNotNull(role);
        return Iterables.contains(roles, role);
    } catch (NoSuchElementException ex) {
        return false;
    }
}

From source file:edu.sabanciuniv.sentilab.sare.models.base.documentStore.PersistentDocumentStore.java

/**
 * Gets a flag indicating whether the provided store is in the list of derived stores for this store.
 * @param derivedStore the {@link PersistentDocumentStore} object to look for.
 * @return {@code true} if the provided store is in the list of derived stores, {@code false} otherwise.
 *//*from ww w.j  a  v a  2 s.c o m*/
public boolean hasDerivedStore(PersistentDocumentStore derivedStore) {
    return Iterables.contains(this.getDerivedStores(), derivedStore);
}

From source file:org.opendaylight.restconf.utils.parser.ParserIdentifier.java

/**
 * Parsing {@link Module} module by {@link String} module name and
 * {@link Date} revision and from the parsed module create
 * {@link SchemaExportContext}//  ww w  . j a v  a  2 s . c  om
 *
 * @param schemaContext
 *            - {@link SchemaContext}
 * @param identifier
 *            - path parameter
 * @param domMountPointService
 *            - {@link DOMMountPointService}
 * @return {@link SchemaExportContext}
 */
public static SchemaExportContext toSchemaExportContextFromIdentifier(final SchemaContext schemaContext,
        final String identifier, final DOMMountPointService domMountPointService) {
    final Iterable<String> pathComponents = RestconfConstants.SLASH_SPLITTER.split(identifier);
    final Iterator<String> componentIter = pathComponents.iterator();
    if (!Iterables.contains(pathComponents, RestconfConstants.MOUNT)) {
        final String moduleName = RestconfValidation.validateAndGetModulName(componentIter);
        final Date revision = RestconfValidation.validateAndGetRevision(componentIter);
        final Module module = schemaContext.findModuleByName(moduleName, revision);
        return new SchemaExportContext(schemaContext, module);
    } else {
        final StringBuilder pathBuilder = new StringBuilder();
        while (componentIter.hasNext()) {
            final String current = componentIter.next();
            pathBuilder.append("/");
            pathBuilder.append(current);
            if (RestconfConstants.MOUNT.equals(current)) {
                break;
            }
        }
        final InstanceIdentifierContext<?> point = ParserIdentifier.toInstanceIdentifier(pathBuilder.toString(),
                schemaContext);
        final DOMMountPoint mountPoint = domMountPointService.getMountPoint(point.getInstanceIdentifier())
                .get();
        final String moduleName = RestconfValidation.validateAndGetModulName(componentIter);
        final Date revision = RestconfValidation.validateAndGetRevision(componentIter);
        final Module module = mountPoint.getSchemaContext().findModuleByName(moduleName, revision);
        return new SchemaExportContext(mountPoint.getSchemaContext(), module);
    }
}

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

@Override
public Iterable<AnnotationParameter> getUnknownAttributes(Annotation annotation) {
    final Iterable<String> parameterNames = Iterables.transform(definedAttributes,
            PatternAnnotationParameter::getName);
    return Iterables.filter(annotation.getParameters(),
            input -> !Iterables.contains(parameterNames, input.getName()));
}

From source file:org.opendaylight.ofconfig.southbound.impl.utils.OfconfigHelper.java

public boolean isOfconfigDeviceNode(NetconfNode netconfigNode) {

    if (netconfigNode.getAvailableCapabilities() == null) {
        return false;
    }//from   ww  w . j  a va  2 s. c  o m
    List<String> capabilities = netconfigNode.getAvailableCapabilities().getAvailableCapability();
    return Iterables.contains(capabilities, OfconfigConstants.OF_CONFIG_VERSION_12_CAPABILITY)
            && !Iterables.contains(capabilities, OfconfigConstants.ODL_CONFIG_CAPABILITY);
}

From source file:org.netbeans.modules.android.grammars.AndroidGrammar.java

protected Iterable<String> getChoices(AttributeInfo attr, final String prefix) {
    Iterable<String> values = Collections.emptySet();
    if (Iterables.contains(attr.getFormats(), AttributeInfo.Format.BOOLEAN)) {
        values = Iterables.concat(values, Lists.newArrayList("true", "false"));
    }/*w ww.j av a  2 s  .c  om*/
    if (Iterables.contains(attr.getFormats(), AttributeInfo.Format.ENUM)) {
        values = Iterables.concat(values, Iterables.filter(attr.getEnumValues(), startsWithPredicate(prefix)));
    }
    if (Iterables.contains(attr.getFormats(), AttributeInfo.Format.DIMENSION)) {
        int i = 0;
        while (i < prefix.length() && Character.isDigit(prefix.charAt(i))) {
            i++;
        }
        if (i > 0) {
            List<String> dimensions = Lists.newArrayList();
            String number = prefix.substring(0, i);
            String unitPrefix = i < prefix.length() ? prefix.substring(i) : "";
            for (String unit : new String[] { "dp", "sp", "pt", "mm", "in", "px" }) {
                if (unit.startsWith(unitPrefix)) {
                    dimensions.add(number + unit);
                }
            }
            values = Iterables.concat(values, dimensions);
        }
    }
    if (Iterables.contains(attr.getFormats(), AttributeInfo.Format.REFERENCE)) {
        Iterable<String> offeredValues = Collections.emptyList();
        if (prefix.startsWith("@") && prefix.indexOf('/') > 0) {
            offeredValues = Iterables
                    .transform(Iterables.filter(refResolver.getReferences(), new Predicate<ResourceRef>() {
                        @Override
                        public boolean apply(ResourceRef input) {
                            if (input.toString().startsWith(prefix)) {
                                return true;
                            }
                            return false;
                        }
                    }), Functions.toStringFunction());
        } else if (prefix.startsWith("@")) {
            final String valuePrefix = prefix.startsWith("@+") ? "@+" : "@";
            offeredValues = Sets.newTreeSet(Iterables
                    .transform(Iterables.filter(refResolver.getReferences(), new Predicate<ResourceRef>() {
                        @Override
                        public boolean apply(ResourceRef input) {
                            if ((valuePrefix + input.resourceType).startsWith(prefix)) {
                                return true;
                            }
                            return false;
                        }
                    }), new Function<ResourceRef, String>() {
                        @Override
                        public String apply(ResourceRef input) {
                            return valuePrefix + input.resourceType + "/";
                        }
                    }));
        }
        values = Iterables.concat(values, offeredValues);
    }
    return Iterables.filter(values, startsWithPredicate(prefix));
}

From source file:org.spongepowered.common.data.value.immutable.ImmutableSpongeWeightedEntityCollectionValue.java

@Override
public ImmutableWeightedEntityCollectionValue withoutAll(Iterable<WeightedEntity> elements) {
    final WeightedCollection<WeightedEntity> weightedEntities = new WeightedCollection<WeightedEntity>();
    for (WeightedEntity entity : this.actualValue) {
        if (!Iterables.contains(elements, entity)) {
            weightedEntities.add(entity);
        }//from   w w w. j  a  v a2s.  c o m
    }
    return new ImmutableSpongeWeightedEntityCollectionValue(getKey(), weightedEntities);
}

From source file:com.eucalyptus.cluster.callback.DescribeSensorCallback.java

private void processReportingStats(final DescribeSensorsResponse msg) throws Exception {
    final Iterable<String> uuidList = Iterables.transform(VmInstances.list(VmState.RUNNING),
            VmInstances.toInstanceUuid());
    for (final SensorsResourceType sensorData : msg.getSensorsResources()) {
        if (!RESOURCE_TYPE_INSTANCE.equals(sensorData.getResourceType())
                || !Iterables.contains(uuidList, sensorData.getResourceUuid()))
            continue;

        for (final MetricsResourceType metricType : sensorData.getMetrics()) {
            for (final MetricCounterType counterType : metricType.getCounters()) {
                for (final MetricDimensionsType dimensionType : counterType.getDimensions()) {
                    // find and fire most recent value for metric/dimension
                    final List<MetricDimensionsValuesType> values = Lists
                            .newArrayList(dimensionType.getValues());

                    //Reporting use case of metric data from the cc
                    Collections.sort(values, Ordering.natural().onResultOf(GetTimestamp.INSTANCE));

                    if (!values.isEmpty()) {
                        final MetricDimensionsValuesType latestValue = Iterables.getLast(values);
                        final Double usageValue = latestValue.getValue();
                        if (usageValue == null) {
                            LOG.debug("Event received with null 'value', skipping for reporting");
                            continue;
                        }// www . j a  va 2 s . c  o  m
                        final Long usageTimestamp = latestValue.getTimestamp().getTime();
                        final long sequenceNumber = dimensionType.getSequenceNum() + (values.size() - 1);
                        fireUsageEvent(new Supplier<InstanceUsageEvent>() {
                            @Override
                            public InstanceUsageEvent get() {
                                return new InstanceUsageEvent(sensorData.getResourceUuid(),
                                        sensorData.getResourceName(), metricType.getMetricName(),
                                        sequenceNumber, dimensionType.getDimensionName(), usageValue,
                                        usageTimestamp);
                            }
                        });
                    }
                }
            }
        }
    }
}

From source file:org.obiba.magma.type.PolygonType.java

@Override
@SuppressWarnings({ "unchecked", "PMD.NcssMethodCount" })
public int compare(Value o1, Value o2) {
    if (o1.isNull() && o2.isNull())
        return 0;
    if (o1.isNull())
        return -1;
    if (o2.isNull())
        return 1;

    Iterable<List<Coordinate>> list1 = (Iterable<List<Coordinate>>) o1.getValue();
    Iterable<List<Coordinate>> list2 = (Iterable<List<Coordinate>>) o2.getValue();

    if (list1 == list2)
        return 0;
    int size1 = Iterables.size(list1);
    int size2 = Iterables.size(list2);
    if (size1 == size2) {
        for (List<Coordinate> l : list1) {
            if (!Iterables.contains(list2, l))
                return -1;
        }/*from  ww w  . jav  a  2 s.  c o  m*/
        return 0;
    }
    return size1 < size2 ? -1 : 1;
}