Class Properties<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Implemented Interfaces:
    Map<K,​V>

    public class Properties<K,​V>
    extends Object
    implements Map<K,​V>
    The Class Properties.
    Since:
    0.8
    Author:
    Haiyang Li
    • Constructor Detail

      • Properties

        public Properties()
        Instantiates a new properties.
    • Method Detail

      • from

        public static <K,​V> Properties<K,​V> from​(Map<? extends K,​? extends V> map)
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        map -
        Returns:
      • get

        public V get​(Object propName)
        Specified by:
        get in interface Map<K,​V>
        Parameters:
        propName -
        Returns:
      • get

        public <T> T get​(Class<T> targetClass,
                         Object propName)
        To avoid NullPointerException for primitive type if the target property is null or not set.
        Type Parameters:
        T -
        Parameters:
        targetClass -
        propName -
        Returns:
      • getOrDefault

        public V getOrDefault​(Object propName,
                              V defaultValue)
        Gets the or default.
        Specified by:
        getOrDefault in interface Map<K,​V>
        Parameters:
        propName -
        defaultValue - is returned if the specified propName is not contained in this Properties instance or it's null.
        Returns:
      • getOrDefault

        public <T> T getOrDefault​(Class<T> targetClass,
                                  Object propName,
                                  T defaultValue)
        Gets the or default.
        Type Parameters:
        T -
        Parameters:
        targetClass -
        propName -
        defaultValue - is returned if the specified propName is not contained in this Properties instance or it's null.
        Returns:
      • set

        public Properties<K,​V> set​(K propName,
                                         V propValue)
        Parameters:
        propName -
        propValue -
        Returns:
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface Map<K,​V>
        Parameters:
        key -
        value -
        Returns:
      • putAll

        public void putAll​(Map<? extends K,​? extends V> m)
        Specified by:
        putAll in interface Map<K,​V>
        Parameters:
        m -
      • putIfAbsent

        public V putIfAbsent​(K key,
                             V value)
        Put if absent.
        Specified by:
        putIfAbsent in interface Map<K,​V>
        Parameters:
        key -
        value -
        Returns:
      • remove

        public V remove​(Object key)
        Specified by:
        remove in interface Map<K,​V>
        Parameters:
        key -
        Returns:
      • remove

        public boolean remove​(Object key,
                              Object value)
        Removes the entry for the specified key only if it is currently mapped to the specified value.
        Specified by:
        remove in interface Map<K,​V>
        Parameters:
        key -
        value -
        Returns:
        true, if successful
      • replace

        public V replace​(K key,
                         V value)
        Replaces the entry for the specified key only if it is currently mapped to some value.
        Specified by:
        replace in interface Map<K,​V>
        Parameters:
        key -
        value -
        Returns:
      • replace

        public boolean replace​(K key,
                               V oldValue,
                               V newValue)
        Replaces the entry for the specified key only if currently mapped to the specified value.
        Specified by:
        replace in interface Map<K,​V>
        Parameters:
        key -
        oldValue -
        newValue -
        Returns:
        true, if successful
      • containsKey

        public boolean containsKey​(Object key)
        Specified by:
        containsKey in interface Map<K,​V>
        Parameters:
        key -
        Returns:
        true, if successful
      • containsValue

        public boolean containsValue​(Object value)
        Specified by:
        containsValue in interface Map<K,​V>
        Parameters:
        value -
        Returns:
        true, if successful
      • keySet

        public Set<K> keySet()
        Specified by:
        keySet in interface Map<K,​V>
        Returns:
      • isEmpty

        public boolean isEmpty()
        Checks if is empty.
        Specified by:
        isEmpty in interface Map<K,​V>
        Returns:
        true, if is empty
      • size

        public int size()
        Specified by:
        size in interface Map<K,​V>
        Returns:
      • clear

        public void clear()
        Clear.
        Specified by:
        clear in interface Map<K,​V>
      • equals

        public boolean equals​(Object obj)
        Specified by:
        equals in interface Map<K,​V>
        Overrides:
        equals in class Object
        Parameters:
        obj -
        Returns:
        true, if successful