Package graphql.util

Class LinkedHashMapFactory

java.lang.Object
graphql.util.LinkedHashMapFactory

public final class LinkedHashMapFactory extends Object
Factory class for creating LinkedHashMap instances with insertion order preservation. Use this instead of Map.of() to ensure consistent serialization order.

This class provides static factory methods similar to Map.of() but returns mutable LinkedHashMap instances that preserve insertion order, which is important for consistent serialization.

  • Method Summary

    Modifier and Type
    Method
    Description
    static <K, V> Map<K,V>
    of()
    Returns an empty LinkedHashMap.
    static <K, V> Map<K,V>
    of(K k1, V v1)
    Returns a LinkedHashMap containing a single mapping.
    static <K, V> Map<K,V>
    of(K k1, V v1, K k2, V v2)
    Returns a LinkedHashMap containing two mappings.
    static <K, V> Map<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3)
    Returns a LinkedHashMap containing three mappings.
    static <K, V> Map<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
    Returns a LinkedHashMap containing four mappings.
    static <K, V> Map<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
    Returns a LinkedHashMap containing five mappings.
    static <K, V> Map<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
    Returns a LinkedHashMap containing six mappings.
    static <K, V> Map<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
    Returns a LinkedHashMap containing seven mappings.
    static <K, V> Map<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
    Returns a LinkedHashMap containing eight mappings.
    static <K, V> Map<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
    Returns a LinkedHashMap containing nine mappings.
    static <K, V> Map<K,V>
    of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
    Returns a LinkedHashMap containing ten mappings.
    static <K, V> Map<K,V>
    ofEntries(Object... keyValues)
    Returns a LinkedHashMap containing mappings derived from the given arguments.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • of

      public static <K, V> Map<K,V> of()
      Returns an empty LinkedHashMap.
      Type Parameters:
      K - the key type
      V - the value type
      Returns:
      an empty LinkedHashMap
    • of

      public static <K, V> Map<K,V> of(K k1, V v1)
      Returns a LinkedHashMap containing a single mapping.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - the mapping's key
      v1 - the mapping's value
      Returns:
      a LinkedHashMap containing the specified mapping
    • of

      public static <K, V> Map<K,V> of(K k1, V v1, K k2, V v2)
      Returns a LinkedHashMap containing two mappings.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      Returns:
      a LinkedHashMap containing the specified mappings
    • of

      public static <K, V> Map<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3)
      Returns a LinkedHashMap containing three mappings.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      Returns:
      a LinkedHashMap containing the specified mappings
    • of

      public static <K, V> Map<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
      Returns a LinkedHashMap containing four mappings.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      Returns:
      a LinkedHashMap containing the specified mappings
    • of

      public static <K, V> Map<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
      Returns a LinkedHashMap containing five mappings.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      Returns:
      a LinkedHashMap containing the specified mappings
    • of

      public static <K, V> Map<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
      Returns a LinkedHashMap containing six mappings.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      k6 - the sixth mapping's key
      v6 - the sixth mapping's value
      Returns:
      a LinkedHashMap containing the specified mappings
    • of

      public static <K, V> Map<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
      Returns a LinkedHashMap containing seven mappings.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      k6 - the sixth mapping's key
      v6 - the sixth mapping's value
      k7 - the seventh mapping's key
      v7 - the seventh mapping's value
      Returns:
      a LinkedHashMap containing the specified mappings
    • of

      public static <K, V> Map<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
      Returns a LinkedHashMap containing eight mappings.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      k6 - the sixth mapping's key
      v6 - the sixth mapping's value
      k7 - the seventh mapping's key
      v7 - the seventh mapping's value
      k8 - the eighth mapping's key
      v8 - the eighth mapping's value
      Returns:
      a LinkedHashMap containing the specified mappings
    • of

      public static <K, V> Map<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
      Returns a LinkedHashMap containing nine mappings.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      k6 - the sixth mapping's key
      v6 - the sixth mapping's value
      k7 - the seventh mapping's key
      v7 - the seventh mapping's value
      k8 - the eighth mapping's key
      v8 - the eighth mapping's value
      k9 - the ninth mapping's key
      v9 - the ninth mapping's value
      Returns:
      a LinkedHashMap containing the specified mappings
    • of

      public static <K, V> Map<K,V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
      Returns a LinkedHashMap containing ten mappings.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      k1 - the first mapping's key
      v1 - the first mapping's value
      k2 - the second mapping's key
      v2 - the second mapping's value
      k3 - the third mapping's key
      v3 - the third mapping's value
      k4 - the fourth mapping's key
      v4 - the fourth mapping's value
      k5 - the fifth mapping's key
      v5 - the fifth mapping's value
      k6 - the sixth mapping's key
      v6 - the sixth mapping's value
      k7 - the seventh mapping's key
      v7 - the seventh mapping's value
      k8 - the eighth mapping's key
      v8 - the eighth mapping's value
      k9 - the ninth mapping's key
      v9 - the ninth mapping's value
      k10 - the tenth mapping's key
      v10 - the tenth mapping's value
      Returns:
      a LinkedHashMap containing the specified mappings
    • ofEntries

      public static <K, V> Map<K,V> ofEntries(Object... keyValues)
      Returns a LinkedHashMap containing mappings derived from the given arguments.

      This method is provided for cases where more than 10 key-value pairs are needed. It accepts alternating keys and values.

      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      keyValues - alternating keys and values
      Returns:
      a LinkedHashMap containing the specified mappings
      Throws:
      IllegalArgumentException - if an odd number of arguments is provided