Class CollectionUtils

java.lang.Object
org.checkerframework.javacutil.CollectionUtils

public class CollectionUtils extends Object
Utility methods related to Java Collections.
  • Constructor Details

    • CollectionUtils

      public CollectionUtils()
  • Method Details

    • createLRUCache

      public static <K, V> Map<K,V> createLRUCache(int size)
      Creates a LRU cache.
      Parameters:
      size - size of the cache
      Returns:
      a new cache with the provided size
    • cloneElements

      public static <T extends @Nullable Object, C extends @Nullable Collection<T>> @PolyNull C cloneElements(@PolyNull C orig)
      Returns a copy of orig, where each element of the result is a clone of the corresponding element of orig.
      Type Parameters:
      T - the type of elements of the collection
      C - the type of the collection
      Parameters:
      orig - a collection
      Returns:
      a copy of orig, as described above
    • cloneElements

      public static <K, V, M extends @Nullable Map<K, V>> @PolyNull M cloneElements(@PolyNull M orig)
      Returns a copy of orig, where each key and value in the result is a clone of the corresponding element of orig.
      Type Parameters:
      K - the type of keys of the map
      V - the type of values of the map
      M - the type of the map
      Parameters:
      orig - a map
      Returns:
      a copy of orig, as described above
    • cloneValues

      public static <K, V, M extends @Nullable Map<K, V>> @PolyNull M cloneValues(@PolyNull M orig)
      Returns a copy of orig, where each value of the result is a clone of the corresponding value of orig, but the keys are the same objects.
      Type Parameters:
      K - the type of keys of the map
      V - the type of values of the map
      M - the type of the map
      Parameters:
      orig - a map
      Returns:
      a copy of orig, as described above
    • deepCopy

      public static <T extends @Nullable DeepCopyable<T>, C extends @Nullable Collection<T>> @PolyNull C deepCopy(@PolyNull C orig)
      Returns a copy of orig, where each element of the result is a deep copy (according to the DeepCopyable interface) of the corresponding element of orig.
      Type Parameters:
      T - the type of elements of the collection
      C - the type of the collection
      Parameters:
      orig - a collection
      Returns:
      a copy of orig, as described above
    • deepCopy

      public static <K extends @Nullable DeepCopyable<K>, V extends @Nullable DeepCopyable<V>, M extends @Nullable Map<K, V>> @PolyNull M deepCopy(@PolyNull M orig)
      Returns a copy of orig, where each key and value in the result is a deep copy (according to the DeepCopyable interface) of the corresponding element of orig.
      Type Parameters:
      K - the type of keys of the map
      V - the type of values of the map
      M - the type of the map
      Parameters:
      orig - a map
      Returns:
      a copy of orig, as described above
    • deepCopyValues

      public static <K, V extends @Nullable DeepCopyable<V>, M extends @Nullable Map<K, V>> @PolyNull M deepCopyValues(@PolyNull M orig)
      Returns a copy of orig, where each value of the result is a deep copy (according to the DeepCopyable interface) of the corresponding value of orig, but the keys are the same objects.
      Type Parameters:
      K - the type of keys of the map
      V - the type of values of the map
      M - the type of the map
      Parameters:
      orig - a map
      Returns:
      a copy of orig, as described above
    • clone

      public static <T> @PolyNull @PolySigned T clone(@PolyNull @PolySigned T data)
      Clones the given object by calling clone() reflectively. It is not possible to call Object.clone() directly because it has protected visibility.
      Type Parameters:
      T - the type of the object to clone
      Parameters:
      data - the object to clone
      Returns:
      a clone of the object