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
ConstructorDescriptionPreferencesDecoder
(String node) Creates an instance of a decoder which can be used to deserializeDecodable
classes from Java'sPreferences
-
Method Summary
Modifier and TypeMethodDescriptionRetrieve an instance of aKeyedDecodingContainer
to decode keyed dataCreate an instance of aDecodable
class by decoding values from PreferencesdecodeBoolean
(T forKey) Decodes a singleBoolean
at a given codingKey.decodeBooleanIfPresent
(T forKey) Decodes a singleBoolean
at a given codingKey.decodeInteger
(T forKey) Decodes a singleInteger
at a given codingKey.decodeIntegerIfPresent
(T forKey) Decodes a singleInteger
at a given codingKey.decodeString
(T forKey) Decodes a singleString
at a given codingKey.decodeStringIfPresent
(T forKey) Decodes a singleString
at a given codingKey.
-
Constructor Details
-
PreferencesDecoder
Creates an instance of a decoder which can be used to deserializeDecodable
classes from Java'sPreferences
- Parameters:
node
- Path ofPreferences
node to read values from
-
-
Method Details
-
decode
public <D extends Decodable<T>> D decode(Class<D> decoding) throws DecodingException, InvocationTargetException Create an instance of aDecodable
class by decoding values from Preferences- Type Parameters:
D
- Type of class to decode- Parameters:
decoding
-.class
of 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:KeyedDecodingContainer
Decodes a singleBoolean
at a given codingKey.- Specified by:
decodeBooleanIfPresent
in interfaceKeyedDecodingContainer<T extends Enum<T>>
- Parameters:
forKey
- codingKey to attempt to decode value from- Returns:
Optional
decodedBoolean
-
decodeBoolean
Description copied from interface:KeyedDecodingContainer
Decodes a singleBoolean
at a given codingKey.- Specified by:
decodeBoolean
in 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:KeyedDecodingContainer
Decodes a singleInteger
at a given codingKey.- Specified by:
decodeIntegerIfPresent
in interfaceKeyedDecodingContainer<T extends Enum<T>>
- Parameters:
forKey
- codingKey to attempt to decode value from- Returns:
Optional<Integer>
decodedInteger
-
decodeInteger
Description copied from interface:KeyedDecodingContainer
Decodes a singleInteger
at a given codingKey.- Specified by:
decodeInteger
in 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:KeyedDecodingContainer
Decodes a singleString
at a given codingKey.- Specified by:
decodeStringIfPresent
in interfaceKeyedDecodingContainer<T extends Enum<T>>
- Parameters:
forKey
- codingKey to attempt to decode value from- Returns:
- Decoded
String
-
decodeString
Description copied from interface:KeyedDecodingContainer
Decodes a singleString
at a given codingKey.- Specified by:
decodeString
in 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:Decoder
Retrieve an instance of aKeyedDecodingContainer
to decode keyed data
-