Example usage for com.google.common.collect Maps immutableEntry

List of usage examples for com.google.common.collect Maps immutableEntry

Introduction

In this page you can find the example usage for com.google.common.collect Maps immutableEntry.

Prototype

@GwtCompatible(serializable = true)
public static <K, V> Entry<K, V> immutableEntry(@Nullable K key, @Nullable V value) 

Source Link

Document

Returns an immutable map entry with the specified key and value.

Usage

From source file:com.nesscomputing.cache.NonEvictingJvmCacheProvider.java

@Override
public void clear(String namespace, Collection<String> keys, @Nullable CacheStatistics cacheStatistics) {
    for (String key : keys) {
        LOG.trace("%s clearing %s:%s", this, namespace, key);
        map.remove(Maps.immutableEntry(namespace, key));
    }/*from  www  .  ja  va 2 s.  c om*/
}

From source file:org.zalando.logbook.QueryParameters.java

private static Iterable<Map.Entry<String, String>> splitEntries(final String queryString) {
    final List<String> entryStrings = Splitter.on(anyOf("&;")).splitToList(queryString);

    return transform(entryStrings, input -> {
        final Iterator<String> split = Splitter.on('=').split(input).iterator();
        return Maps.immutableEntry(split.next(), split.next());
    });//from   w  ww .  j  av  a  2s .  c  o m
}

From source file:io.airlift.drift.codec.internal.reflection.ReflectionThriftUnionCodec.java

public ReflectionThriftUnionCodec(ThriftCodecManager manager, ThriftStructMetadata metadata) {
    super(manager, metadata);

    ThriftFieldMetadata idField = getOnlyElement(metadata.getFields(FieldKind.THRIFT_UNION_ID));

    this.idField = Maps.immutableEntry(idField, manager.getCodec(idField.getThriftType()));
    requireNonNull(this.idField.getValue(), () -> "No codec for ID field found: " + idField);

    this.metadataMap = uniqueIndex(metadata.getFields(), ThriftFieldMetadata::getId);
}

From source file:org.calrissian.accumulorecipes.commons.iterators.WholeColumnFamilyIterator.java

private void prepKeys() throws IOException {
    if (topKey != null)
        return;// w w  w  . j  av a  2 s  . co  m
    Text currentRow;
    Text currentCF;
    long curTS;
    do {
        if (sourceIter.hasTop() == false)
            return;
        currentRow = new Text(sourceIter.getTopKey().getRow());
        currentCF = new Text(sourceIter.getTopKey().getColumnFamily());
        curTS = sourceIter.getTopKey().getTimestamp();
        keysValues.clear();
        while (sourceIter.hasTop() && sourceIter.getTopKey().getRow().equals(currentRow)
                && sourceIter.getTopKey().getColumnFamily().equals(currentCF)) {
            keysValues.add(
                    Maps.immutableEntry(new Key(sourceIter.getTopKey()), new Value(sourceIter.getTopValue())));
            sourceIter.next();
        }
    } while (!filter(currentRow, keysValues));

    topKey = new Key(currentRow, currentCF, new Text(""), curTS);
    topValue = RowEncoderUtil.encodeRow(keysValues);

}

From source file:de.cosmocode.commons.RandomOrdering.java

@Override
public Integer apply(@Nullable Entry<T, T> entry) {
    Preconditions.checkNotNull(entry, "Entry");
    // whenever this function is being called neither (x,y) nor (y,x) has been compared yet

    final Integer value;
    final Integer inverted;

    if (random.nextInt(2) == 0) {
        value = LEFT_IS_GREATER;/*from w w w .java2  s .co m*/
        inverted = RIGHT_IS_GREATER;
    } else {
        value = RIGHT_IS_GREATER;
        inverted = LEFT_IS_GREATER;
    }

    // sgn(compare(x, y)) == -sgn(compare(y, x))
    values.putIfAbsent(Maps.immutableEntry(entry.getValue(), entry.getKey()), inverted);

    return value;
}

From source file:org.calrissian.accumulorecipes.graphstore.support.EdgeGroupingIterator.java

private void prepKeys() throws IOException {
    if (topKey != null)
        return;/*from   ww  w.  j a  v  a  2s  .  c  o  m*/
    Text currentRow;
    Text currentCF;
    Text currentCQ;

    do {
        if (!sourceIter.hasTop())
            return;
        currentRow = new Text(sourceIter.getTopKey().getRow());
        currentCF = new Text(sourceIter.getTopKey().getColumnFamily());
        currentCQ = new Text(sourceIter.getTopKey().getColumnQualifier());

        keysValues.clear();
        while (sourceIter.hasTop() && sourceIter.getTopKey().getRow().equals(currentRow)
                && sourceIter.getTopKey().getColumnFamily().equals(currentCF)
                && sourceIter.getTopKey().getColumnQualifier().toString().startsWith(currentCQ.toString())) {

            keysValues.add(Maps.immutableEntry(sourceIter.getTopKey(), sourceIter.getTopValue()));
            sourceIter.next();
        }
    } while (!filter(currentRow, keysValues));

    topKey = new Key(currentRow, currentCF, new Text(currentCQ));
    topValue = RowEncoderUtil.encodeRow(keysValues);

}

From source file:omero.cmd.graphs.ChildOptionsPolicy.java

/**
 * Adjust an existing graph traversal policy so that child objects may be included or excluded
 * regardless of if they are truly orphans.
 * @param graphPolicyToAdjust the graph policy to adjust
 * @param childOptions the child options that the policy adjustments are to effect
 * @param requiredPermissions the abilities that the user must have to operate upon an object for it to be included
 * @return the adjusted graph policy/*  w  w  w .j  a v a  2 s .c o m*/
 */
public static GraphPolicy getChildOptionsPolicy(final GraphPolicy graphPolicyToAdjust,
        final Collection<ChildOptionI> childOptions, final Set<GraphPolicy.Ability> requiredPermissions) {

    if (CollectionUtils.isEmpty(childOptions)) {
        /* there are no adjustments to make to the policy */
        return graphPolicyToAdjust;
    }

    /* wrap the traversal policy so that the child options are effected */

    return new BaseGraphPolicyAdjuster(graphPolicyToAdjust) {
        private final Map<String, String> namespaceCache = new HashMap<String, String>();
        private final Map<Entry<String, Long>, String> objectNamespaces = new HashMap<Entry<String, Long>, String>();

        /**
         * Note each annotation's namespace.
         */
        @Override
        public void noteDetails(Session session, IObject object, String realClass, long id) {
            if (object instanceof Annotation) {
                final String query = "SELECT ns FROM Annotation WHERE id = :id";
                final String namespace = (String) session.createQuery(query).setParameter("id", id)
                        .uniqueResult();
                if (namespace != null) {
                    String cachedNamespace = namespaceCache.get(namespace);
                    if (cachedNamespace == null) {
                        cachedNamespace = namespace;
                        namespaceCache.put(namespace, cachedNamespace);
                    }
                    objectNamespaces.put(Maps.immutableEntry(realClass, id), cachedNamespace);
                }
            }
            super.noteDetails(session, object, realClass, id);
        }

        /**
         * Check if the given object is in the target annotation namespace.
         * @param childOption the child option whose target annotation namespace applies
         * @param object the object to check
         * @return if the annotation is in the target namespace or if the object is not an annotation
         */
        private boolean isTargetNamespace(ChildOptionI childOption, IObject object) {
            if (object instanceof Annotation) {
                final Entry<String, Long> classAndId = Maps.immutableEntry(object.getClass().getName(),
                        object.getId());
                return childOption.isTargetNamespace(objectNamespaces.get(classAndId));
            } else {
                return true;
            }
        }

        @Override
        protected boolean isAdjustedBeforeReview(Details object) {
            if (object.action == GraphPolicy.Action.EXCLUDE && object.orphan == GraphPolicy.Orphan.RELEVANT) {
                /* the model object is [E]{r} */
                for (final ChildOptionI childOption : childOptions) {
                    final Boolean isIncludeVerdict = childOption.isIncludeType(object.subject.getClass());
                    if (isIncludeVerdict == Boolean.TRUE
                            && (requiredPermissions == null
                                    || Sets.difference(requiredPermissions, object.permissions).isEmpty())
                            && isTargetNamespace(childOption, object.subject)) {
                        object.orphan = GraphPolicy.Orphan.IS_LAST;
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("including all children of its type, so making " + object);
                        }
                        return true;
                    } else if (isIncludeVerdict == Boolean.FALSE
                            && isTargetNamespace(childOption, object.subject)) {
                        object.orphan = GraphPolicy.Orphan.IS_NOT_LAST;
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("excluding all children of its type, so making " + object);
                        }
                        return true;
                    }
                }
            }
            return false;
        }
    };
}

From source file:com.palantir.lock.LockCollection.java

public Iterable<Map.Entry<T, LockMode>> entries() {
    return new Iterable<Map.Entry<T, LockMode>>() {
        @Override/*  w w w. ja  va  2s.c  om*/
        public Iterator<Entry<T, LockMode>> iterator() {
            return new AbstractIterator<Map.Entry<T, LockMode>>() {
                private int index = 0;

                @Override
                protected Entry<T, LockMode> computeNext() {
                    if (index == keys.length) {
                        return endOfData();
                    }
                    LockMode mode = values.get(index) ? LockMode.WRITE : LockMode.READ;
                    return Maps.immutableEntry(keys[index++], mode);
                }

            };
        }
    };
}

From source file:org.calrissian.accumulorecipes.geospatialstore.support.PrefixedColumnQualifierIterator.java

private void prepKeys() throws IOException {
    if (topKey != null)
        return;//  w w  w  .jav a2  s.  c om
    Text currentRow;
    Text currentColF;
    Text currentColQ;
    if (sourceIter.hasTop() == false)
        return;

    currentRow = new Text(sourceIter.getTopKey().getRow());
    currentColF = new Text(sourceIter.getTopKey().getColumnFamily());
    currentColQ = new Text(sourceIter.getTopKey().getColumnQualifier());

    String colQPrefix = currentColQ.toString().substring(0, currentColQ.toString().indexOf(NULL_BYTE));

    keysValues.clear();
    while (sourceIter.hasTop() && sourceIter.getTopKey().getRow().equals(currentRow)
            && sourceIter.getTopKey().getColumnFamily().equals(currentColF)
            && sourceIter.getTopKey().getColumnQualifier().toString().startsWith(colQPrefix)) {
        keysValues
                .add(Maps.immutableEntry(new Key(sourceIter.getTopKey()), new Value(sourceIter.getTopValue())));
        sourceIter.next();
    }

    topKey = new Key(currentRow, currentColF);
    topValue = RowEncoderUtil.encodeRow(keysValues);
}

From source file:org.apache.twill.internal.appmaster.RunnableContainerRequest.java

/**
 * Remove a resource request and return it.
 * @return The {@link Resource} and {@link Collection} of {@link RuntimeSpecification} or
 *         {@code null} if there is no more request.
 *///from ww w . j  ava  2  s .  c  o  m
Map.Entry<AllocationSpecification, ? extends Collection<RuntimeSpecification>> takeRequest() {
    Map.Entry<AllocationSpecification, Collection<RuntimeSpecification>> next = Iterators.getNext(requests,
            null);
    return next == null ? null : Maps.immutableEntry(next.getKey(), ImmutableList.copyOf(next.getValue()));
}