Class ExtendedProperties

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public class ExtendedProperties extends Properties
This is a simple extended Properties with supporting several primitive typed objects. Currently, there are only 6 additional types: It also supports a List consisting of the types listed above. Example: The following snippet

 ExtendedProperties prop = new ExtendedProperties();
 prop.setTypedProperty("key1", Stream.of(AccessMode.EXECUTE, AccessMode.READ).collect(Collectors.toCollection(ArrayList::new)));
 prop.setTypedProperty("key2", false);
 prop.setProperty("key3", "Some comment");
 
will produce the following properties file:

 key1.list.enum.1=java.nio.file.AccessMode\#READ
 key1.list.enum.0=java.nio.file.AccessMode\#EXECUTE
 key2.boolean=false
 key3=Some comment
 

Created by @ssz on 14.04.2017.

See Also:
  • Constructor Details

    • ExtendedProperties

      public ExtendedProperties()
    • ExtendedProperties

      public ExtendedProperties(Properties defaults)
  • Method Details

    • getListProperty

      public <T> List<T> getListProperty(String key, Class<T> type)
      Reads a List from the Properties Map. The keys in the Properties must be in the format "key.list.type.index", where "list" is a fixed delimiter, and "index" is an integer position of the element in the resulting List.
      Type Parameters:
      T - a generic type of the returned list
      Parameters:
      key - String, key-prefix
      type - Class-type, one of the following: Class, Enum, Boolean, Integer, Long, Double
      Returns:
      List, not null
      See Also:
    • getMapType

      protected ExtendedProperties.MapType getMapType(Class<?> type)
    • getTypedProperty

      public <T> T getTypedProperty(String key, Class<T> type)
      Gets a typed Object value from the Properties Map. The keys in the Properties must be in the format key.type.
      Type Parameters:
      T - a type of the returned value
      Parameters:
      key - String, key-prefix
      type - Class-type, one of the following: Class, Enum, Boolean, Integer, Long, Double
      Returns:
      Object value
      See Also:
    • setTypedProperty

      public <T> void setTypedProperty(String key, T value)
      Puts the object of the type ExtendedProperties to the Properties Map.
      Type Parameters:
      T - a type of the input value
      Parameters:
      key - String, key-prefix
      value - Object, allowed to be of one of the following types: Class, Enum, Boolean, Integer, Long, Double
      See Also:
    • setListProperty

      public <T> void setListProperty(String key, List<T> values)
      Writes the given list to the Properties Map
      Type Parameters:
      T - a generic type of the input list
      Parameters:
      key - String, key-prefix
      values - List of values that are allowed to be one of the following types: Class, Enum, Boolean, Integer, Long, Double
      See Also:
    • getListProperty

      public List<?> getListProperty(String key)
      Gets a List if objects corresponding the given key.
      Parameters:
      key - String, not null
      Returns:
      List with uncertain generic type
    • getStringListProperty

      public List<String> getStringListProperty(String key)
      Gets a List if strings corresponding the given key.
      Parameters:
      key - String, not null
      Returns:
      List of Strings
    • getClassProperty

      public Class<?> getClassProperty(String key)
      Gets a Class that corresponds the property record with the given key.
      Parameters:
      key - String, not null
      Returns:
      Class
    • getEnumProperty

      public Enum<?> getEnumProperty(String key)
      Gets a Enum that corresponds the property record with the given key.
      Parameters:
      key - String, not null
      Returns:
      Enum
    • getBooleanProperty

      public Boolean getBooleanProperty(String key)
      Gets a Boolean that corresponds the property record with the given key.
      Parameters:
      key - String, not null
      Returns:
      boolean
    • getIntegerProperty

      public Integer getIntegerProperty(String key)
      Gets a Integer that corresponds the property record with the given key.
      Parameters:
      key - String, not null
      Returns:
      int
    • getLongProperty

      public Long getLongProperty(String key)
      Gets a Long that corresponds the property record with the given key.
      Parameters:
      key - String, not null
      Returns:
      long
    • getDoubleProperty

      public Double getDoubleProperty(String key)
      Gets a Double that corresponds the property record with the given key.
      Parameters:
      key - String, not null
      Returns:
      double