Example usage for com.google.common.collect ImmutableBiMap isEmpty

List of usage examples for com.google.common.collect ImmutableBiMap isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableBiMap isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:net.derquinse.common.collect.ImmutableIndexedHierarchy.java

/**
 * Builds an immutable indexed hierarchy from a set of values.
 * @param elements Source elements.//w  w  w . jav a  2s .c  om
 * @param key Key function.
 * @param parentKey Parent key function.
 * @param value Value function.
 */
public static <T, K, V> ImmutableIndexedHierarchy<K, V> of(Iterable<? extends T> elements,
        Function<? super T, ? extends K> key, Function<? super T, ? extends K> parentKey,
        Function<? super T, ? extends V> value) {
    checkNotNull(elements, "The source elements must be provided.");
    checkNotNull(key, "The key function must be provided.");
    checkNotNull(parentKey, "The parent key function must be provided.");
    checkNotNull(value, "The value function must be provided.");
    ImmutableHierarchy.Builder<K> h = ImmutableHierarchy.builder(true);
    ImmutableBiMap.Builder<K, V> m = ImmutableBiMap.builder();
    for (T element : elements) {
        final K k = key.apply(element);
        m.put(k, value.apply(element));
        h.add(parentKey.apply(element), k);
    }
    final ImmutableBiMap<K, V> biMap = m.build();
    if (biMap.isEmpty()) {
        return of();
    }
    return new RegularImmutableIndexedHierarchy<K, V>(biMap, h.get());
}