Class BidiMap.Builder<K,V>

java.lang.Object
org.apache.juneau.commons.collections.BidiMap.Builder<K,V>
Type Parameters:
K - The key type.
V - The value type.
Enclosing class:
BidiMap<K,V>

public static class BidiMap.Builder<K,V> extends Object
Builder class for BidiMap.

Provides a fluent API for constructing bidirectional maps.

Example:

BidiMap<String,Integer> map = BidiMap.create() .add("one", 1) .add("two", 2) .unmodifiable() .build();

  • Constructor Details

  • Method Details

    • add

      public BidiMap.Builder<K,V> add(K key, V value)
      Adds a key-value pair to this map.

      Null keys and values are allowed in the builder but will be filtered out during the build() operation.

      Parameters:
      key - The key. Can be null.
      value - The value. Can be null.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - if the value already exists mapped to a different key.
    • build

      public BidiMap<K,V> build()
      Builds a new BidiMap from the entries added to this builder.

      Null keys and values are automatically filtered out during construction.

      Returns:
      A new BidiMap instance.
    • unmodifiable

      Makes the resulting map unmodifiable.

      When set, the built map will be wrapped with Collections.unmodifiableMap(Map), preventing any modifications after construction.

      Returns:
      This object.