Class Util

java.lang.Object
uk.ac.starlink.util.Util

public class Util extends Object
General class containing utility methods. Several of these relate to the java.util classes.
Since:
18 Jul 2023
Author:
Mark Taylor
  • Method Details

    • get

      public static <K, V> V get(Map<K,V> map, K key)
      Typed map get operation. This simply calls Map.get(Object), but it provides compile-time assurance that the supplied key has the right type.
      Parameters:
      map - map
      key - key
      Returns:
      result of map.get(key)
    • containsKey

      public static <K, V> boolean containsKey(Map<K,V> map, K key)
      Typed map key test operation. This simply calls Map.containsKey(Object), but it provides compile-time assurance that the supplied key has the right type.
      Parameters:
      map - map
      key - key
      Returns:
      result of map.containsKey(key)
    • remove

      public static <K, V> V remove(Map<K,V> map, K key)
      Typed map remove operation. This simply calls Map.remove(Object), but it provides compile-time assurance that the supplied key has the right type.
      Parameters:
      map - map
      key - key
      Returns:
      result of map.remove(key)
    • equals

      public static <T> boolean equals(T t1, T t2)
      Typed equality operation. This simply calls Objects.equals(Object,Object), but provides compile-time assurance that the two supplied parameters have the same type.
      Parameters:
      t1 - first object
      t2 - second object
      Returns:
      result of Objects.equals(t1, t1)
    • contains

      public static <T> boolean contains(Collection<T> collection, T item)
      Typed contains test. This simply calls Collection.contains(java.lang.Object), but provides compile-time assurance that the item's type is compatible with the collection.
      Parameters:
      collection - collection
      item - item
      Returns:
      true iff item is in collection (equality semantics)