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

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

Introduction

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

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this list contains the specified element.

Usage

From source file:com.google.javascript.jscomp.newtypes.UniqueNameGenerator.java

public static String findGeneratedName(String name, ImmutableList<String> names) {
    if (name.contains("#")) {
        return names.contains(name) ? name : null;
    }/*from w ww .ja  v  a 2s  . c o m*/
    for (String name2 : names) {
        if (name.equals(name2.substring(0, name2.indexOf('#')))) {
            return name2;
        }
    }
    return null;
}

From source file:com.spectralogic.ds3autogen.utils.Ds3TypeClassificationUtil.java

/**
 * Determines if a Ds3Type contains the specified element
 */// w w  w. jav a 2  s  .  c  o m
protected static boolean containsElement(final Ds3Type ds3Type, final String elementName) {
    final ImmutableList<String> elements = getElementNames(ds3Type);
    return elements.contains(elementName);
}

From source file:com.spectralogic.ds3autogen.utils.Ds3TypeClassificationUtil.java

/**
 * Determines if a Ds3Type is the HttpErrorResultApiBean Type
 *//*from ww  w  .  j  av  a  2  s .c o m*/
public static boolean isHttpErrorType(final Ds3Type ds3Type) {
    if (isEmpty(ds3Type.getNameToMarshal()) || isEmpty(ds3Type.getElements())) {
        return false;
    }
    final ImmutableList<String> elementNames = getElementNames(ds3Type);
    return ds3Type.getNameToMarshal().equalsIgnoreCase("Error") && elementNames.contains("Code")
            && elementNames.contains("HttpErrorCode") && elementNames.contains("Message")
            && elementNames.contains("Resource") && elementNames.contains("ResourceId");
}

From source file:com.spectralogic.ds3autogen.net.generators.clientmodels.BaseClientGenerator.java

/**
 * Gets the value of the HttpStatusCode associated with the void response type.
 * code > 300: empty string (error)//from   w w w  . j a  v  a  2 s . c  o  m
 * code == 204: HttpStatusCode.NoContent
 * Else: HttpStatusCode.OK
 */
protected static String getHttpStatusCode(final ImmutableList<Ds3ResponseCode> responseCodes) {
    if (isEmpty(responseCodes)) {
        LOG.error("There are no response codes");
        return "";
    }
    final ImmutableList<Integer> codes = responseCodes.stream()
            .filter(responseCode -> ResponsePayloadUtil.isNonErrorCode(responseCode.getCode()))
            .map(Ds3ResponseCode::getCode).collect(GuavaCollectors.immutableList());
    if (isEmpty(codes)) {
        LOG.error("There are no non-error response codes within the list: " + codes.toString());
        return "";
    }
    if (codes.contains(204)) {
        return "NoContent";
    }
    return "OK";
}

From source file:org.apache.calcite.interpreter.TableScanNode.java

private static TableScanNode createFilterable(Interpreter interpreter, TableScan rel,
        ImmutableList<RexNode> filters, ImmutableIntList projects, FilterableTable filterableTable) {
    final DataContext root = interpreter.getDataContext();
    final List<RexNode> mutableFilters = Lists.newArrayList(filters);
    final Enumerable<Object[]> enumerable = filterableTable.scan(root, mutableFilters);
    for (RexNode filter : mutableFilters) {
        if (!filters.contains(filter)) {
            throw RESOURCE.filterableTableInventedFilter(filter.toString()).ex();
        }/*from   www  .ja  v  a2 s . co  m*/
    }
    final Enumerable<Row> rowEnumerable = Enumerables.toRow(enumerable);
    return createEnumerable(interpreter, rel, rowEnumerable, null, mutableFilters, projects);
}

From source file:org.elasticsearch.snapshots.SnapshotUtils.java

/**
 * Filters out list of available indices based on the list of selected indices.
 *
 * @param availableIndices list of available indices
 * @param selectedIndices  list of selected indices
 * @param indicesOptions    ignore indices flag
 * @return filtered out indices//www  . j  a  v  a 2  s .  c  o m
 */
public static ImmutableList<String> filterIndices(ImmutableList<String> availableIndices,
        String[] selectedIndices, IndicesOptions indicesOptions) {
    if (selectedIndices == null || selectedIndices.length == 0) {
        return availableIndices;
    }
    Set<String> result = null;
    for (int i = 0; i < selectedIndices.length; i++) {
        String indexOrPattern = selectedIndices[i];
        boolean add = true;
        if (!indexOrPattern.isEmpty()) {
            if (availableIndices.contains(indexOrPattern)) {
                if (result != null) {
                    result.add(indexOrPattern);
                }
                continue;
            }
            if (indexOrPattern.charAt(0) == '+') {
                add = true;
                indexOrPattern = indexOrPattern.substring(1);
                // if its the first, add empty set
                if (i == 0) {
                    result = new HashSet<>();
                }
            } else if (indexOrPattern.charAt(0) == '-') {
                // if its the first, fill it with all the indices...
                if (i == 0) {
                    result = new HashSet<>(availableIndices);
                }
                add = false;
                indexOrPattern = indexOrPattern.substring(1);
            }
        }
        if (indexOrPattern.isEmpty() || !Regex.isSimpleMatchPattern(indexOrPattern)) {
            if (!availableIndices.contains(indexOrPattern)) {
                if (!indicesOptions.ignoreUnavailable()) {
                    throw new IndexMissingException(new Index(indexOrPattern));
                } else {
                    if (result == null) {
                        // add all the previous ones...
                        result = new HashSet<>();
                        result.addAll(availableIndices.subList(0, i));
                    }
                }
            } else {
                if (result != null) {
                    if (add) {
                        result.add(indexOrPattern);
                    } else {
                        result.remove(indexOrPattern);
                    }
                }
            }
            continue;
        }
        if (result == null) {
            // add all the previous ones...
            result = new HashSet<>();
            result.addAll(availableIndices.subList(0, i));
        }
        boolean found = false;
        for (String index : availableIndices) {
            if (Regex.simpleMatch(indexOrPattern, index)) {
                found = true;
                if (add) {
                    result.add(index);
                } else {
                    result.remove(index);
                }
            }
        }
        if (!found && !indicesOptions.allowNoIndices()) {
            throw new IndexMissingException(new Index(indexOrPattern));
        }
    }
    if (result == null) {
        return ImmutableList.copyOf(selectedIndices);
    }
    return ImmutableList.copyOf(result);
}

From source file:ec.tss.tsproviders.sdmx.engine.GenericDocFactory.java

private static SdmxGroup getSdmxGroup(Node groupNode, Calendar cal) {
    ImmutableList<Concept> key = getGroupKeyNode(groupNode).map(GenericDocFactory::lookupConcepts).get()
            .collect(toImmutableList());
    ImmutableList<Concept> attributes = getAttributeNode(groupNode).map(GenericDocFactory::lookupConcepts).get()
            .collect(toImmutableList());
    ImmutableList<SdmxSeries> tss = asStream(groupNode.getChildNodes())
            .filter(o -> "Series".equals(o.getLocalName()))
            .map(o -> getSdmxSeries(o, x -> !key.contains(x), cal)).collect(toImmutableList());
    return new SdmxGroup(key, attributes, tss);
}

From source file:com.facebook.buck.apple.toolchain.impl.AppleSdkDiscovery.java

private static ImmutableList<String> validArchitecturesForPlatform(ApplePlatform platform, Path sdkDir)
        throws IOException {
    ImmutableList<String> architectures = platform.getArchitectures();
    try (DirectoryStream<Path> sdkFiles = Files.newDirectoryStream(sdkDir)) {
        ImmutableList.Builder<String> architectureSubdirsBuilder = ImmutableList.builder();
        for (Path path : sdkFiles) {
            if (Files.isDirectory(path)) {
                String directoryName = path.getFileName().toString();
                // Default Apple SDKs contain fat binaries and have no architecture subdirectories,
                // but custom SDKs might.
                if (architectures.contains(directoryName)) {
                    architectureSubdirsBuilder.add(directoryName);
                }//  w  w  w  .  j  a  v  a 2  s .  co  m
            }
        }

        ImmutableList<String> architectureSubdirs = architectureSubdirsBuilder.build();
        if (!architectureSubdirs.isEmpty()) {
            architectures = architectureSubdirs;
        }
    }
    return architectures;
}

From source file:org.glowroot.weaving.AdviceBuilder.java

private static @Nullable Class<? extends Annotation> getValidBindAnnotationType(
        Annotation[] parameterAnnotations, ImmutableList<Class<? extends Annotation>> validBindAnnotationTypes)
        throws AdviceConstructionException {

    Class<? extends Annotation> foundBindAnnotationType = null;
    for (Annotation annotation : parameterAnnotations) {
        Class<? extends Annotation> annotationType = annotation.annotationType();
        if (!parameterKindMap.containsKey(annotationType)) {
            continue;
        }//from   w  w w . jav a  2  s.  c om
        checkState(foundBindAnnotationType == null, "Multiple annotations found on a single parameter");
        checkState(validBindAnnotationTypes.contains(annotationType),
                "Annotation '" + annotationType.getName() + "' found in an invalid location");
        foundBindAnnotationType = annotationType;
    }
    return foundBindAnnotationType;
}

From source file:dagger.internal.codegen.Util.java

public static boolean bindingCanBeProvidedInTest(ContributionBinding binding) {
    final ImmutableList<ContributionBinding.Kind> kinds = ImmutableList.of(ContributionBinding.Kind.PROVISION,
            ContributionBinding.Kind.INJECTION, ContributionBinding.Kind.BUILDER_BINDING);
    final ContributionBinding.Kind kind = binding.bindingKind();
    return kinds.contains(kind);
}