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

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

Introduction

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

Prototype

@GwtIncompatible("NavigableMap")
public static <K, V1, V2> NavigableMap<K, V2> transformEntries(NavigableMap<K, V1> fromMap,
        EntryTransformer<? super K, ? super V1, V2> transformer) 

Source Link

Document

Returns a view of a navigable map whose values are derived from the original navigable map's entries.

Usage

From source file:com.simiacryptus.util.CountCollection.java

/**
 * Gets map.//from w w  w.jav a  2s .c  om
 *
 * @return the map
 */
public Map<T, Integer> getMap() {
    return Maps.transformEntries(this.map, new EntryTransformer<T, AtomicInteger, Integer>() {
        @Override
        public Integer transformEntry(final T key, final AtomicInteger value) {
            return value.get();
        }
    });
}

From source file:com.github.lukaszkusek.xml.comparator.document.XMLDocument.java

private Map<String, Node> createNodeMap(Multimap<String, Node> xpathToNodeMultimap) {
    return Maps.newHashMap(Maps.transformEntries(xpathToNodeMultimap.asMap(),
            (key, nodes) -> nodes.stream().reduce(Node::merge).get()));
}

From source file:com.icosilune.fn.nodes.AbstractNode.java

protected final Map<String, Object> readInputs() {
    return Maps.transformEntries(inputConnections,
            (inputSocketName, connection) -> connection == null ? getDefaultInput(inputSocketName)
                    : connection.getOutputNode().getOutput(connection.getOutputSocket().getName()));
}

From source file:org.graylog2.alarmcallbacks.hipchat.HipChatAlarmCallback.java

@Override
public Map<String, Object> getAttributes() {
    return Maps.transformEntries(configuration.getSource(),
            new Maps.EntryTransformer<String, Object, Object>() {
                @Override/*from  w w  w .ja  va  2 s  .  c  o m*/
                public Object transformEntry(String key, Object value) {
                    if (CK_API_TOKEN.equals(key)) {
                        return "****";
                    }
                    return value;
                }
            });
}

From source file:com.github.lukaszkusek.xml.comparator.comparators.order.XMLCheckChildrenOrderComparator.java

private List<String> getSortedChildrenXPaths(Node node) {
    return Maps
            .transformEntries(node.getChildren().asMap(),
                    (xpath, nodes) -> new XpathWithIndex(xpath, first(nodes).getIndex()))
            .values().stream().sorted((xpath1, xpath2) -> Integer.compare(xpath1.index, xpath2.index))
            .map(xPathWithIndex -> xPathWithIndex.xPath).collect(Collectors.toList());
}

From source file:springfox.documentation.swagger1.web.DefaultSwaggerController.java

private ResponseEntity<ApiListing> getSwaggerApiListing(String swaggerGroup, String apiDeclaration) {
    String groupName = Optional.fromNullable(swaggerGroup).or("default");
    Documentation documentation = documentationCache.documentationByGroup(groupName);
    if (documentation == null) {
        return new ResponseEntity<ApiListing>(HttpStatus.NOT_FOUND);
    }/* w w  w .j  a v  a  2 s  . c o m*/
    Map<String, springfox.documentation.service.ApiListing> apiListingMap = documentation.getApiListings();
    Map<String, ApiListing> dtoApiListing = Maps.transformEntries(apiListingMap,
            Mappers.toApiListingDto(mapper));

    ApiListing apiListing = dtoApiListing.get(apiDeclaration);
    return Optional.fromNullable(apiListing).transform(toResponseEntity(ApiListing.class))
            .or(new ResponseEntity<ApiListing>(HttpStatus.NOT_FOUND));
}

From source file:org.openengsb.core.services.internal.security.EntryUtils.java

/**
 * Takes any bean Object and converts it to a Map of {@link EntryValue} so the beandata can be saved to the DB.
 *///from  w w  w.j a  v  a2  s . c  o  m
public static Map<String, EntryValue> convertBeanToEntryMap(Object bean) {
    Map<String, Object> buildAttributeValueMap = BeanUtilsExtended.buildObjectAttributeMap(bean);
    return Maps.transformEntries(buildAttributeValueMap, new ObjectToEntryValueTransformer());
}

From source file:hudson.maven.MavenProbeAction.java

/**
 * Gets the system properties of the JVM on this computer.
 * If this is the master, it returns the system property of the master computer.
 *//*from   w w  w.  j ava  2 s.  c  o m*/
public Map<Object, Object> getSystemProperties() throws IOException, InterruptedException {
    Map<Object, Object> props = RemotingDiagnostics.getSystemProperties(channel);

    if (build != null) {
        final Set<String> sensitiveBuildVars = build.getSensitiveBuildVariables();
        props = new TreeMap<Object, Object>(
                Maps.transformEntries(props, new Maps.EntryTransformer<Object, Object, Object>() {
                    public Object transformEntry(Object key, Object value) {
                        return sensitiveBuildVars.contains(key.toString()) ? "********" : value;
                    }
                }));
    }

    return props;
}

From source file:springfox.documentation.service.Operation.java

private Map<String, List<AuthorizationScope>> toAuthorizationsMap(List<SecurityReference> securityReferences) {
    return Maps.transformEntries(Maps.uniqueIndex(securityReferences, byType()), toScopes());
}

From source file:org.apache.oozie.action.hadoop.PasswordMasker.java

/**
 * Returns a map where keys are masked if they are considered a password.
 * There are two cases when passwords are masked:
 * 1. The key contains the string "pass". In this case, the entire value is considered a password and replaced completely with
 * a masking string./*from w w w  .ja  v a 2  s .co m*/
 * 2. The value matches a regular expression. Strings like "HADOOP_CREDSTORE_PASSWORD=pwd123" or
 * "-Djavax.net.ssl.trustStorePassword=password" are considered password definition strings and the text after the equal sign
 * is replaced with a masking string.
 *
 * @param unmasked key-value map
 * @return A new map where values are changed based on the replace algorithm described above
 */
public Map<String, String> mask(Map<String, String> unmasked) {
    return Maps.transformEntries(unmasked, new Maps.EntryTransformer<String, String, String>() {
        @Override
        public String transformEntry(@Nonnull String key, @Nonnull String value) {
            checkNotNull(key, "key has to be set");
            checkNotNull(value, "value has to be set");

            if (isPasswordKey(key)) {
                return PASSWORD_MASK;
            }

            return maskPasswordsIfNecessary(value);
        }
    });
}