Package de.hsh.graja.util
Class PropsUtils
java.lang.Object
de.hsh.graja.util.PropsUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckKeys(Set<? extends Object> keys, Set<? extends Object> mandatoryKeys, Set<? extends Object> optionalKeys) checks, whether keys contains all of the mandatoryKeys and no key not contained in mandatoryKeys or optionalKeys.reads key/value pairs from is and returns a map closes the input stream when finished.static StringgetMapStringStringView(Properties props) static <T> TgetTypedValueOrDefault(Map<String, String> props, Object key, Usage usage, Class<T> type, T defaultVal) Returns the value belonging to key from the props parameter.static <K,V> String prettyMapToString(Map<K, V> map) static voidputAll(Properties from, Properties to)
-
Constructor Details
-
PropsUtils
public PropsUtils()
-
-
Method Details
-
createPropertiesFromUTF8Stream
reads key/value pairs from is and returns a map closes the input stream when finished.- Parameters:
is-
-
getMapStringStringView
- Parameters:
props-- Returns:
- a wrapper around props, that delivers values as Strings
-
checkKeys
public static void checkKeys(Set<? extends Object> keys, Set<? extends Object> mandatoryKeys, Set<? extends Object> optionalKeys) throws InvalidFormatException checks, whether keys contains all of the mandatoryKeys and no key not contained in mandatoryKeys or optionalKeys.- Parameters:
keys-mandatoryKeys-optionalKeys-- Throws:
InvalidFormatException- if an invalid key was found in keys
-
getTypedValueOrDefault
public static <T> T getTypedValueOrDefault(Map<String, String> props, Object key, Usage usage, Class<T> type, T defaultVal) throws InvalidFormatExceptionReturns the value belonging to key from the props parameter. If the key does not exist in props, it depends:- If usage is optional, the defaultVal is returned
- otherwise an InvalidFormatException is thrown
- Parameters:
props-key-usage-type-defaultVal-- Returns:
- The returned value will be converted from String to type T.
- Throws:
InvalidFormatException- when a mandatory key is missing or when conversion to type failed.
-
putAll
-
getDump
-
prettyMapToString
-