Module com.cryptoalgo.oursql.oursql
Class PreferencesDecoder<T extends Enum<T>>
java.lang.Object
com.cryptoalgo.codable.preferencesCoder.PreferencesDecoder<T>
- Type Parameters:
T- Type of enum of codingKeys to be used during decoding
- All Implemented Interfaces:
Decoder<T>,KeyedDecodingContainer<T>
public final class PreferencesDecoder<T extends Enum<T>>
extends Object
implements Decoder<T>, KeyedDecodingContainer<T>
An implementation of a
Decoder that decodes data
stored in Java's Preferences
Note:
Decoding methods returns Optional.empty() if the value in the provided
key exists but cannot be cased to the requested type. This behaviour might be
modified in the future to throw DecodingException instead.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionPreferencesDecoder(String node) Creates an instance of a decoder which can be used to deserializeDecodableclasses from Java'sPreferences -
Method Summary
Modifier and TypeMethodDescriptionRetrieve an instance of aKeyedDecodingContainerto decode keyed dataCreate an instance of aDecodableclass by decoding values from PreferencesdecodeBoolean(T forKey) Decodes a singleBooleanat a given codingKey.decodeBooleanIfPresent(T forKey) Decodes a singleBooleanat a given codingKey.decodeInteger(T forKey) Decodes a singleIntegerat a given codingKey.decodeIntegerIfPresent(T forKey) Decodes a singleIntegerat a given codingKey.decodeString(T forKey) Decodes a singleStringat a given codingKey.decodeStringIfPresent(T forKey) Decodes a singleStringat a given codingKey.
-
Constructor Details
-
PreferencesDecoder
Creates an instance of a decoder which can be used to deserializeDecodableclasses from Java'sPreferences- Parameters:
node- Path ofPreferencesnode to read values from
-
-
Method Details
-
decode
public <D extends Decodable<T>> D decode(Class<D> decoding) throws DecodingException, InvocationTargetException Create an instance of aDecodableclass by decoding values from Preferences- Type Parameters:
D- Type of class to decode- Parameters:
decoding-.classof class to decode- Returns:
- Instance of the requested class, populated with decoded data
- Throws:
DecodingException- If decoding failed for whatever reason (use .printStackTrace() to find out more)InvocationTargetException- If the decoding constructor of the class to be decoded threw an exception
-
decodeBooleanIfPresent
Description copied from interface:KeyedDecodingContainerDecodes a singleBooleanat a given codingKey.- Specified by:
decodeBooleanIfPresentin interfaceKeyedDecodingContainer<T extends Enum<T>>- Parameters:
forKey- codingKey to attempt to decode value from- Returns:
OptionaldecodedBoolean
-
decodeBoolean
Description copied from interface:KeyedDecodingContainerDecodes a singleBooleanat a given codingKey.- Specified by:
decodeBooleanin interfaceKeyedDecodingContainer<T extends Enum<T>>- Parameters:
forKey- codingKey to attempt to decode value from- Returns:
- Decoded
Boolean - Throws:
DecodingException- If decoding fails for whatever reasonNoSuchElementException- If the value at the requested key isn't present
-
decodeIntegerIfPresent
Description copied from interface:KeyedDecodingContainerDecodes a singleIntegerat a given codingKey.- Specified by:
decodeIntegerIfPresentin interfaceKeyedDecodingContainer<T extends Enum<T>>- Parameters:
forKey- codingKey to attempt to decode value from- Returns:
Optional<Integer>decodedInteger
-
decodeInteger
Description copied from interface:KeyedDecodingContainerDecodes a singleIntegerat a given codingKey.- Specified by:
decodeIntegerin interfaceKeyedDecodingContainer<T extends Enum<T>>- Parameters:
forKey- codingKey to attempt to decode value from- Returns:
- Decoded
Integer - Throws:
DecodingException- If decoding fails for whatever reasonNoSuchElementException- If the value at the requested key isn't present
-
decodeStringIfPresent
Description copied from interface:KeyedDecodingContainerDecodes a singleStringat a given codingKey.- Specified by:
decodeStringIfPresentin interfaceKeyedDecodingContainer<T extends Enum<T>>- Parameters:
forKey- codingKey to attempt to decode value from- Returns:
- Decoded
String
-
decodeString
Description copied from interface:KeyedDecodingContainerDecodes a singleStringat a given codingKey.- Specified by:
decodeStringin interfaceKeyedDecodingContainer<T extends Enum<T>>- Parameters:
forKey- codingKey to attempt to decode value from- Returns:
Optional<String>decodedString- Throws:
DecodingException- If decoding fails for whatever reasonNoSuchElementException- If the value at the requested key isn't present
-
container
Description copied from interface:DecoderRetrieve an instance of aKeyedDecodingContainerto decode keyed data
-