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

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

Introduction

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

Prototype

@GwtIncompatible("NavigableMap")
public static <K, V> NavigableMap<K, V> asMap(NavigableSet<K> set, Function<? super K, V> function) 

Source Link

Document

Returns a view of the navigable set as a map, mapping keys from the set according to the specified function.

Usage

From source file:com.davidbracewell.math.distance.DistanceMeasure.java

/**
 * Calculate double.//ww w. j a v  a  2 s.  c o m
 *
 * @param s1 the s 1
 * @param s2 the s 2
 * @return the double
 */
public final double calculate(Set<?> s1, Set<?> s2) {
    return calculate(Maps.asMap(Preconditions.checkNotNull(s1, "Vectors cannot be null"), SET_NUMBER.INSTANCE),
            Maps.asMap(Preconditions.checkNotNull(s2, "Vectors cannot be null"), SET_NUMBER.INSTANCE));
}

From source file:com.stackframe.sarariman.clients.ClientsImpl.java

public Map<? extends Number, Client> getMap() {
    Function<Number, Client> f = new Function<Number, Client>() {
        public Client apply(Number n) {
            return get(n.intValue());
        }//from w  ww .  j  a  va  2 s  . co  m

    };
    return Maps.asMap(Numbers.positiveIntegers, f);
}

From source file:org.apache.druid.server.lookup.cache.polling.OnHeapPollingCache.java

public OnHeapPollingCache(Iterable<Map.Entry<K, V>> entries) {

    if (entries == null) {
        immutableMap = ImmutableMap.of();
        immutableReverseMap = ImmutableMap.of();
    } else {//from www . j a  va 2s .c o m
        ImmutableSet.Builder<V> setOfValuesBuilder = ImmutableSet.builder();
        ImmutableMap.Builder<K, V> mapBuilder = ImmutableMap.builder();
        for (Map.Entry<K, V> entry : entries) {
            setOfValuesBuilder.add(entry.getValue());
            mapBuilder.put(entry.getKey(), entry.getValue());
        }
        final Set<V> setOfValues = setOfValuesBuilder.build();
        immutableMap = mapBuilder.build();
        immutableReverseMap = ImmutableMap
                .copyOf(Maps.asMap(setOfValues, val -> immutableMap.keySet().stream().filter(key -> {
                    V retVal = immutableMap.get(key);
                    return retVal != null && retVal.equals(val);
                }).collect(Collectors.toList())));
    }

}

From source file:io.druid.security.kerberos.ResponseCookieHandler.java

@Override
public ClientResponse<Intermediate> handleResponse(HttpResponse httpResponse) {
    try {//ww  w  .j a  va  2  s.  c o m
        final HttpHeaders headers = httpResponse.headers();
        manager.put(uri, Maps.asMap(headers.names(), new Function<String, List<String>>() {
            @Override
            public List<String> apply(String input) {
                return headers.getAll(input);
            }
        }));
    } catch (IOException e) {
        log.error(e, "Error while processing Cookies from header");
    } finally {
        return delegate.handleResponse(httpResponse);
    }
}

From source file:io.druid.server.lookup.cache.polling.OnHeapPollingCache.java

public OnHeapPollingCache(Iterable<Map.Entry<K, V>> entries) {

    if (entries == null) {
        immutableMap = ImmutableMap.of();
        immutableReverseMap = ImmutableMap.of();
    } else {/*w ww  .j av a 2 s. co m*/
        ImmutableSet.Builder<V> setOfValuesBuilder = ImmutableSet.builder();
        ImmutableMap.Builder<K, V> mapBuilder = ImmutableMap.builder();
        for (Map.Entry<K, V> entry : entries) {
            setOfValuesBuilder.add(entry.getValue());
            mapBuilder.put(entry.getKey(), entry.getValue());
        }
        final Set<V> setOfValues = setOfValuesBuilder.build();
        immutableMap = mapBuilder.build();
        immutableReverseMap = ImmutableMap.copyOf(Maps.asMap(setOfValues, new Function<V, List<K>>() {
            @Override
            public List<K> apply(final V input) {
                return Lists.newArrayList(Maps.filterKeys(immutableMap, new Predicate<K>() {
                    @Override
                    public boolean apply(K key) {
                        V retVal = immutableMap.get(key);
                        if (retVal == null) {
                            return false;
                        }
                        return retVal.equals(input);
                    }
                }).keySet());
            }
        }));
    }

}

From source file:com.stackframe.sarariman.errors.ErrorsImpl.java

public Map<? extends Number, Error> getMap() {
    Function<Number, Error> f = new Function<Number, Error>() {
        public Error apply(Number f) {
            return get(f.intValue());
        }/*w  w  w.  jav  a  2 s .  co  m*/

    };
    return Maps.asMap(Numbers.positiveIntegers, f);
}

From source file:org.apache.druid.security.kerberos.ResponseCookieHandler.java

@Override
public ClientResponse<Intermediate> handleResponse(HttpResponse httpResponse, TrafficCop trafficCop) {
    try {//from   w ww  . j  av  a 2s. com
        final HttpHeaders headers = httpResponse.headers();
        manager.put(uri, Maps.asMap(headers.names(), new Function<String, List<String>>() {
            @Override
            public List<String> apply(String input) {
                return headers.getAll(input);
            }
        }));
    } catch (IOException e) {
        log.error(e, "Error while processing Cookies from header");
    } finally {
        return delegate.handleResponse(httpResponse, trafficCop);
    }
}

From source file:org.apache.hadoop.hive.druid.security.ResponseCookieHandler.java

@Override
public ClientResponse<Intermediate> handleResponse(HttpResponse httpResponse) {
    try {//from ww  w .jav a  2 s  .  c o m
        final HttpHeaders headers = httpResponse.headers();
        manager.put(uri, Maps.asMap(headers.names(), headers::getAll));
        return delegate.handleResponse(httpResponse);
    } catch (IOException e) {
        LOG.error("Error while processing Cookies from header", e);
        throw new RuntimeException(e);
    }
}

From source file:org.apache.jackrabbit.oak.spi.security.authentication.credentials.SimpleCredentialsSupport.java

@Override
@Nonnull//from   ww  w.  jav  a  2  s  . co m
public Map<String, ?> getAttributes(@Nonnull Credentials credentials) {
    if (credentials instanceof SimpleCredentials) {
        final SimpleCredentials sc = (SimpleCredentials) credentials;
        return Maps.asMap(ImmutableSet.copyOf(sc.getAttributeNames()), new Function<String, Object>() {
            @Nullable
            @Override
            public Object apply(String input) {
                return sc.getAttribute(input);
            }
        });
    } else {
        return Collections.emptyMap();
    }
}

From source file:edu.mit.streamjit.impl.compiler2.MapConcreteStorage.java

public static MapConcreteStorage create(Storage s) {
    ImmutableSet<ActorGroup> relevantGroups = ImmutableSet.<ActorGroup>builder().addAll(s.upstreamGroups())
            .addAll(s.downstreamGroups()).build();
    return new MapConcreteStorage(s.type(), ADJUST, s.readIndices(Maps.asMap(relevantGroups, i -> 1)).first(),
            s.throughput());//from ww w.j av  a  2  s. co  m
}