Class TypedMapAccessor

java.lang.Object
fr.maxlego08.menu.api.utils.TypedMapAccessor
All Implemented Interfaces:
MapConfiguration

public class TypedMapAccessor extends Object implements MapConfiguration
This class provides typed access to a Map<String, Object>, allowing retrieval of values of different types with or without default values if the key is not present in the map.
  • Constructor Details

    • TypedMapAccessor

      public TypedMapAccessor(Map<String,Object> map)
      Constructs a TypedMapAccessor with the specified map.
      Parameters:
      map - The map containing key-value pairs.
  • Method Details

    • getString

      public String getString(String key)
      Retrieves a string value from the map based on the provided key.
      Specified by:
      getString in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      Returns:
      The string value associated with the key or null if the key is not present.
    • getString

      public String getString(String key, String defaultValue)
      Retrieves a string value from the map based on the provided key. If the key is not present, returns the specified default value.
      Specified by:
      getString in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      defaultValue - The default value if the key is not present.
      Returns:
      The string value associated with the key or the default value.
    • getInt

      public int getInt(String key)
      Retrieves an integer value from the map based on the provided key.
      Specified by:
      getInt in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      Returns:
      The integer value associated with the key or 0 if the key is not present.
    • getInt

      public int getInt(String key, int defaultValue)
      Retrieves an integer value from the map based on the provided key. If the key is not present, returns the specified default value.
      Specified by:
      getInt in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      defaultValue - The default value if the key is not present.
      Returns:
      The integer value associated with the key or the default value.
    • getLong

      public long getLong(String key)
      Retrieves a long value from the map based on the provided key.
      Specified by:
      getLong in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      Returns:
      The long value associated with the key or 0L if the key is not present.
    • getLong

      public long getLong(String key, long defaultValue)
      Retrieves a long value from the map based on the provided key. If the key is not present, returns the specified default value.
      Specified by:
      getLong in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      defaultValue - The default value if the key is not present.
      Returns:
      The long value associated with the key or the default value.
    • getStringList

      public List<String> getStringList(String key)
      Retrieves a list of strings from the map based on the provided key.
      Specified by:
      getStringList in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      Returns:
      The list of strings associated with the key or an empty list if the key is not present.
    • getStringList

      public List<String> getStringList(String key, List<String> defaultValue)
      Retrieves a list of strings from the map based on the provided key. If the key is not present, returns the specified default value.
      Specified by:
      getStringList in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      defaultValue - The default value if the key is not present.
      Returns:
      The list of strings associated with the key or the default value.
    • getIntList

      public List<Integer> getIntList(String key)
      Retrieves a list of integers from the map based on the provided key.
      Specified by:
      getIntList in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      Returns:
      The list of integers associated with the key or an empty list if the key is not present.
    • getIntList

      public List<Integer> getIntList(String key, List<Integer> defaultValue)
      Retrieves a list of integers from the map based on the provided key. If the key is not present, returns the specified default value.
      Specified by:
      getIntList in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      defaultValue - The default value if the key is not present.
      Returns:
      The list of integers associated with the key or the default value.
    • getBoolean

      public boolean getBoolean(String key)
      Retrieves a boolean value from the map based on the provided key.
      Specified by:
      getBoolean in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      Returns:
      The boolean value associated with the key or false if the key is not present.
    • getBoolean

      public boolean getBoolean(String key, boolean defaultValue)
      Retrieves a boolean value from the map based on the provided key. If the key is not present, returns the specified default value.
      Specified by:
      getBoolean in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      defaultValue - The default value if the key is not present.
      Returns:
      The boolean value associated with the key or the default value.
    • getDouble

      public double getDouble(String key)
      Retrieves a double value from the map based on the provided key.
      Specified by:
      getDouble in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      Returns:
      The double value associated with the key or 0.0 if the key is not present.
    • getDouble

      public double getDouble(String key, double defaultValue)
      Retrieves a double value from the map based on the provided key. If the key is not present, returns the specified default value.
      Specified by:
      getDouble in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      defaultValue - The default value if the key is not present.
      Returns:
      The double value associated with the key or the default value.
    • getObject

      public Object getObject(String key)
      Retrieves an object from the map based on the provided key.
      Specified by:
      getObject in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      Returns:
      The object associated with the key or null if the key is not present.
    • getObject

      public Object getObject(String key, Object defaultValue)
      Retrieves an object from the map based on the provided key.
      Specified by:
      getObject in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      defaultValue - The default value if the key is not present.
      Returns:
      The object associated with the key or null if the key is not present.
    • getFloat

      public float getFloat(String key)
      Retrieves a float value from the map based on the provided key.
      Specified by:
      getFloat in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      Returns:
      The float value associated with the key or 0.0f if the key is not present.
    • getFloat

      public float getFloat(String key, float defaultValue)
      Retrieves a float value from the map based on the provided key. If the key is not present, returns the specified default value.
      Specified by:
      getFloat in interface MapConfiguration
      Parameters:
      key - The key to retrieve the value.
      defaultValue - The default value if the key is not present.
      Returns:
      The float value associated with the key or the default value.
    • getList

      public List<?> getList(String key)
      Specified by:
      getList in interface MapConfiguration
    • contains

      public boolean contains(String key)
      Specified by:
      contains in interface MapConfiguration
    • toString

      public String toString()
      Overrides:
      toString in class Object