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:org.apache.accumulo.server.security.delegation.AuthenticationTokenSecretManager.java

/**
 * Generates a delegation token for the user with the provided {@code username}.
 *
 * @param username/*from w w  w  . ja va2  s .com*/
 *          The client to generate the delegation token for.
 * @param cfg
 *          A configuration object for obtaining the delegation token
 * @return A delegation token for {@code username} created using the {@link #currentKey}.
 */
public Entry<Token<AuthenticationTokenIdentifier>, AuthenticationTokenIdentifier> generateToken(String username,
        DelegationTokenConfig cfg) throws AccumuloException {
    requireNonNull(username);
    requireNonNull(cfg);

    final AuthenticationTokenIdentifier id = new AuthenticationTokenIdentifier(username, cfg);

    final StringBuilder svcName = new StringBuilder(DelegationTokenImpl.SERVICE_NAME);
    if (null != id.getInstanceId()) {
        svcName.append("-").append(id.getInstanceId());
    }
    // Create password will update the state on the identifier given currentKey. Need to call this before serializing the identifier
    byte[] password;
    try {
        password = createPassword(id);
    } catch (RuntimeException e) {
        throw new AccumuloException(e.getMessage());
    }
    // The use of the ServiceLoader inside Token doesn't work to automatically get the Identifier
    // Explicitly returning the identifier also saves an extra deserialization
    Token<AuthenticationTokenIdentifier> token = new Token<AuthenticationTokenIdentifier>(id.getBytes(),
            password, id.getKind(), new Text(svcName.toString()));
    return Maps.immutableEntry(token, id);
}

From source file:org.codice.ddf.security.idp.server.IdpEndpoint.java

private void parseServiceProviderMetadata(List<String> serviceProviderMetadata) {
    if (serviceProviderMetadata != null) {
        try {//from  w ww  .j ava2s.  c om
            MetadataConfigurationParser metadataConfigurationParser = new MetadataConfigurationParser(
                    serviceProviderMetadata, ed -> serviceProviders.put(ed.getEntityID(),
                            new EntityInformation.Builder(ed, SUPPORTED_BINDINGS).build()));

            serviceProviders.putAll(metadataConfigurationParser.getEntryDescriptions().entrySet().stream()
                    .map(e -> Maps.immutableEntry(e.getKey(),
                            new EntityInformation.Builder(e.getValue(), SUPPORTED_BINDINGS).build()))
                    .filter(e -> nonNull(e.getValue()))
                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));

        } catch (IOException e) {
            LOGGER.error("Unable to parse SP metadata configuration.", e);
        }
    }
}

From source file:org.immutables.sequence.Entries.java

public static <K, V> Entry<K, V> entry(K key, V value) {
    return Maps.immutableEntry(key, value);
}

From source file:org.gaul.s3proxy.S3ProxyHandler.java

S3ProxyHandler(final BlobStore blobStore, final String identity, final String credential,
        Optional<String> virtualHost) {
    if (identity != null) {
        anonymousIdentity = false;/*ww w .  j  a va 2 s.  com*/
        blobStoreLocator = new BlobStoreLocator() {
            @Override
            public Map.Entry<String, BlobStore> locateBlobStore(String identityArg, String container,
                    String blob) {
                if (!identity.equals(identityArg)) {
                    return null;
                }
                return Maps.immutableEntry(credential, blobStore);
            }
        };
    } else {
        anonymousIdentity = true;
        final Map.Entry<String, BlobStore> anonymousBlobStore = Maps.immutableEntry(null, blobStore);
        blobStoreLocator = new BlobStoreLocator() {
            @Override
            public Map.Entry<String, BlobStore> locateBlobStore(String identityArg, String container,
                    String blob) {
                return anonymousBlobStore;
            }
        };
    }
    this.virtualHost = requireNonNull(virtualHost);
    this.defaultBlobStore = blobStore;
    xmlOutputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);
}

From source file:io.atomix.core.map.impl.AbstractAtomicMapService.java

@Override
public Set<Map.Entry<K, Versioned<byte[]>>> entrySet() {
    return entries().entrySet().stream()
            .filter(entry -> entry.getValue().type() != MapEntryValue.Type.TOMBSTONE)
            .map(e -> Maps.immutableEntry(e.getKey(), toVersioned(e.getValue()))).collect(Collectors.toSet());
}

From source file:com.facebook.buck.core.graph.transformation.DefaultAsyncTransformationEngine.java

@Override
public final ImmutableMap<ComputeKey, CompletableFuture<ComputeResult>> computeAll(Iterable<ComputeKey> keys) {
    return RichStream.from(keys).parallel().map(key -> Maps.immutableEntry(key, compute(key)))
            .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue));
}

From source file:org.onosproject.store.primitives.impl.TranscodingAsyncConsistentTreeMap.java

@Override
public CompletableFuture<Set<Map.Entry<String, Versioned<V1>>>> entrySet() {
    return backingMap.entrySet().thenApply(entries -> entries.stream()
            .map(entry -> Maps.immutableEntry(entry.getKey(), versionedValueTransform.apply(entry.getValue())))
            .collect(Collectors.toSet()));
}

From source file:hu.bme.mit.massif.simulink.api.util.bus.BusSignalMappingPathFinder.java

private void filterNextConnectionInPath(Deque<Entry<OutPort, InPort>> inPortList, OutPort lastOutPort,
        OutPort nextOutPort) {//  ww  w.  j  av  a2  s.c o  m
    Block outportContainer = nextOutPort.getContainer();
    if (outportContainer instanceof BusSpecification) {
        InPort connectedInPort = findConnectedInPortOnNextContainer(lastOutPort, outportContainer);
        checkState(connectedInPort != null, "Invalid path, last outport is not connected to any inports!");
        inPortList.add(Maps.immutableEntry(lastOutPort, connectedInPort));
    }
}

From source file:ninja.leaping.permissionsex.extrabackends.groupmanager.GroupManagerDataStore.java

@Override
public Iterable<Map.Entry<Map.Entry<String, String>, ImmutableSubjectData>> getAll() {
    return Iterables.transform(
            Iterables.concat(//from ww w .ja  va 2s  .c om
                    Iterables.transform(getAllIdentifiers(SUBJECTS_USER),
                            name -> Maps.immutableEntry(SUBJECTS_USER, name)),
                    Iterables.transform(getAllIdentifiers(SUBJECTS_GROUP),
                            name -> Maps.immutableEntry(SUBJECTS_GROUP, name))),
            input -> Maps.immutableEntry(input,
                    Futures.getUnchecked(getData(input.getKey(), input.getValue(), null))));
}

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

@Override
public Object step(int step) throws Cancel {
    helper.assertStep(step);/*from   w  ww. ja  v  a 2 s . c  o  m*/
    try {
        switch (step) {
        case 0:
            /* if targetObjects were an IObjectList then this would need IceMapper.reverse */
            final SetMultimap<String, Long> targetMultimap = HashMultimap.create();
            for (final Entry<String, List<Long>> oneClassToTarget : targetObjects.entrySet()) {
                /* determine actual class from given target object class name */
                String targetObjectClassName = oneClassToTarget.getKey();
                final int lastDot = targetObjectClassName.lastIndexOf('.');
                if (lastDot > 0) {
                    targetObjectClassName = targetObjectClassName.substring(lastDot + 1);
                }
                final Class<? extends IObject> targetObjectClass = graphPathBean
                        .getClassForSimpleName(targetObjectClassName);
                /* check that it is legal to target the given class */
                final Iterator<Class<? extends IObject>> legalTargetsIterator = targetClasses.iterator();
                do {
                    if (!legalTargetsIterator.hasNext()) {
                        final Exception e = new IllegalArgumentException(
                                "cannot target " + targetObjectClassName);
                        throw helper.cancel(new ERR(), e, "bad-target");
                    }
                } while (!legalTargetsIterator.next().isAssignableFrom(targetObjectClass));
                /* note IDs to target for the class */
                final Collection<Long> ids = oneClassToTarget.getValue();
                targetMultimap.putAll(targetObjectClass.getName(), ids);
                targetObjectCount += ids.size();
            }
            final Entry<SetMultimap<String, Long>, SetMultimap<String, Long>> plan = graphTraversal
                    .planOperation(helper.getSession(), targetMultimap, false, true);
            return Maps.immutableEntry(plan.getKey(),
                    GraphUtil.arrangeDeletionTargets(helper.getSession(), plan.getValue()));
        case 1:
            graphTraversal.assertNoPolicyViolations();
            return null;
        case 2:
            processor = graphTraversal.processTargets();
            return null;
        case 3:
            unlinker = graphTraversal.unlinkTargets(true);
            graphTraversal = null;
            return null;
        case 4:
            unlinker.execute();
            return null;
        case 5:
            processor.execute();
            return null;
        default:
            final Exception e = new IllegalArgumentException(
                    "model object graph operation has no step " + step);
            throw helper.cancel(new ERR(), e, "bad-step");
        }
    } catch (Cancel c) {
        throw c;
    } catch (GraphException ge) {
        final omero.cmd.GraphException graphERR = new omero.cmd.GraphException();
        graphERR.message = ge.message;
        throw helper.cancel(graphERR, ge, "graph-fail");
    } catch (Throwable t) {
        throw helper.cancel(new ERR(), t, "graph-fail");
    }
}