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:io.divolte.server.JavaScriptHandler.java

@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("Requested received for {} from {}", resource.getResourceName(),
                exchange.getSourceAddress().getHostString());
    }/*from   w w w  .  j a v  a 2  s .co m*/
    // Start with headers that we always set the same way.
    final HeaderMap responseHeaders = exchange.getResponseHeaders();
    responseHeaders.put(Headers.CACHE_CONTROL, CACHE_CONTROL_HEADER_VALUE);

    // Figure out if we possibly need to deal with a compressed response,
    // based on client capability.
    final GzippableHttpBody uncompressedBody = resource.getEntityBody();
    final Optional<HttpBody> gzippedBody = uncompressedBody.getGzippedBody();
    final HttpBody bodyToSend;
    if (gzippedBody.isPresent()) {
        /*
         * Compressed responses can use Content-Encoding and/or Transfer-Encoding.
         * The semantics differ slightly, but it is suffice to say that most user
         * agents don't advertise their Transfer-Encoding support.
         * So for now we only support the Content-Encoding mechanism.
         * Some other notes:
         *  - Some clients implement 'deflate' incorrectly. Hence we only support 'gzip',
         *    despite it having slightly more overhead.
         *  - We don't use Undertow's built-in compression support because we've
         *    pre-calculated the compressed response and expect to serve it up
         *    repeatedly, instead of calculating it on-the-fly for every request.
         */
        responseHeaders.put(Headers.VARY, Headers.ACCEPT_ENCODING_STRING);
        final HeaderValues acceptEncoding = exchange.getRequestHeaders().get(Headers.ACCEPT_ENCODING);
        if (null != acceptEncoding && acceptEncoding.stream()
                .anyMatch((header) -> Iterables.contains(HEADER_SPLITTER.split(header), "gzip"))) {
            responseHeaders.put(Headers.CONTENT_ENCODING, "gzip");
            bodyToSend = gzippedBody.get();
        } else {
            bodyToSend = uncompressedBody;
        }
    } else {
        bodyToSend = uncompressedBody;
    }

    // Now we know which version of the entity is visible to this user-agent,
    // figure out if the client already has the current version or not.
    final ETag eTag = bodyToSend.getETag();
    responseHeaders.put(Headers.ETAG, eTag.toString());
    if (ETagUtils.handleIfNoneMatch(exchange, eTag, true)) {
        final ByteBuffer entityBody = bodyToSend.getBody();
        responseHeaders.put(Headers.CONTENT_TYPE, "application/javascript");
        exchange.getResponseSender().send(entityBody);
    } else {
        exchange.setResponseCode(StatusCodes.NOT_MODIFIED);
        exchange.endExchange();
    }
}

From source file:org.apache.brooklyn.core.location.SimulatedLocation.java

public synchronized boolean obtainSpecificPort(int portNumber) {
    if (!Iterables.contains(permittedPorts, portNumber))
        return false;
    if (usedPorts.contains(portNumber))
        return false;
    usedPorts.add(portNumber);//from w  ww. j a  v a 2s . c  om
    return true;
}

From source file:org.obm.push.utils.DateUtils.java

public static boolean isValidTimeZoneIdentifier(String tzId) {
    return Iterables.contains(Arrays.asList(TimeZone.getAvailableIDs()), tzId);
}

From source file:org.apache.brooklyn.camp.spi.resolve.interpret.PlanInterpretationNode.java

/** convenience for interpreters, tests if nodes are not excluded, and if not:
 * for string nodes, true iff the current value equals the given target;
 * for nodes which are currently maps or lists,
 * true iff not excluded and the value contains such an entry (key, in the case of map)
 **///from  w ww .  ja va 2s .com
public boolean matchesLiteral(String target) {
    if (isExcluded())
        return false;
    if (getNewValue() instanceof CharSequence)
        return getNewValue().toString().equals(target);
    if (getNewValue() instanceof Map)
        return ((Map<?, ?>) getOriginalValue()).containsKey(target);
    if (getNewValue() instanceof Iterable)
        return Iterables.contains((Iterable<?>) getOriginalValue(), target);
    return false;
}

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

@Override
public ImmutableMapValue<K, V> withoutAll(Iterable<K> keys) {
    final ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
    this.actualValue.entrySet().stream().filter(entry -> !Iterables.contains(keys, entry.getKey()))
            .forEach(entry -> builder.put(entry.getKey(), entry.getValue()));
    return new ImmutableSpongeMapValue<>(getKey(), builder.build());
}

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

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

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

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

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

@Override
public ImmutablePatternListValue withoutAll(Iterable<PatternLayer> elements) {
    final ImmutableList.Builder<PatternLayer> builder = ImmutableList.builder();
    this.actualValue.stream().filter(existingElement -> !Iterables.contains(elements, existingElement))
            .forEach(builder::add);/*from  w  w w .  j  a  v  a  2  s. c  o  m*/
    return new ImmutableSpongePatternListValue(getKey(), builder.build());
}

From source file:com.palantir.common.collect.IterableView.java

public boolean contains(@Nullable Object element) {
    return Iterables.contains(delegate(), element);
}

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

@Override
public ImmutableMapValue<K, V> withoutAll(Iterable<K> keys) {
    final ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
    getActualValue().entrySet().stream().filter(entry -> !Iterables.contains(keys, entry.getKey()))
            .forEach(entry -> builder.put(entry.getKey(), entry.getValue()));
    return new ImmutableLanternMapValue<>(getKey(), getDefault(), builder.build());
}