public abstract class FileDataType extends Object implements DataType
File
argument.Modifier and Type | Field and Description |
---|---|
protected static boolean |
DEBUG_SERIALIZATION |
protected ReadWriteLock |
fileLock |
protected File |
location
The
File location of this FileDataType |
protected static String |
NEWLINE |
Modifier | Constructor and Description |
---|---|
protected |
FileDataType(File location) |
Modifier and Type | Method and Description |
---|---|
protected abstract Object |
deserializeArray(Object array) |
protected Object |
deserializeMap(Map<String,Object> data) |
static Class<? extends FileDataType> |
fromString(String in)
|
Object |
get(String path)
Gets the object at the specified path
|
Object |
get(String path,
Object def)
Gets the object at the specified path, or returns the passed "default"
value if nothing is found
|
ConfigFile |
getMutable(String path) |
ConfigFile |
getMutable(String path,
Object def) |
Map<String,Object> |
getRoot()
Deprecated.
Public as convenience, may not be exposed when more proper api comes around (key iteration)
|
boolean |
isSet(String path)
Returns whether or not there is an object located at the specified path
|
static <T extends FileDataType> |
newInstance(Class<T> clazz,
File location)
Returns a new instance of a
FileDataType based on the passed
class instance. |
protected abstract Map<String,Object> |
newSection() |
protected Object |
parseDeserializable(Object o) |
Object |
parseSerializable(Object o) |
protected Map<String,Object> |
readRaw()
Reads all the information currently saved in the file, disregarding
any changes in memory
|
protected abstract Map<String,Object> |
readRaw(File target)
Reads all the information currently saved in the file, disregarding
any changes in memory
|
void |
save()
Saves any information in memory to the file it was loaded from.
|
void |
save(File target)
Saves any information in memory to the file specified.
|
protected Map<String,Object> |
serializationCopy(Map<String,Object> original) |
protected abstract Object |
serializeArray(Object array) |
protected abstract Object |
serializeMap(Map<String,Object> toFileFormat) |
void |
set(String path,
Object value)
Sets the value at the location specified by the passed path
|
protected abstract String |
toString(Map<String,Object> section) |
protected static final boolean DEBUG_SERIALIZATION
protected static final String NEWLINE
protected final ReadWriteLock fileLock
protected final File location
File
location of this FileDataType
protected FileDataType(File location)
public void set(String path, Object value)
path
- The path to set, delimited by '.
'value
- The value to setpublic boolean isSet(String path)
path
- The path to set, delimited by '.
'true
if a value is found, false
otherwisepublic Object get(String path)
path
- The path to set, delimited by '.
'null
if
nothing is foundpublic ConfigFile getMutable(String path)
public ConfigFile getMutable(String path, Object def)
public Object get(String path, Object def)
path
- The path to set, delimited by '.
'def
- The default value to return upon not finding a valuepublic void save() throws IOException
IOException
- Any read/write locks or permission errors on the filepublic void save(File target) throws IOException
target
- The file to save toIOException
- Any read/write locks or permission errors on the filepublic static <T extends FileDataType> T newInstance(Class<T> clazz, File location)
FileDataType
based on the passed
class instance.T
- Represents the type that implements FileDataType
clazz
- The class object to be used for a new instancelocation
- The location of the file to parse and useFileDataType
protected Map<String,Object> readRaw() throws IOException
Map<String, Object>
value of the file. This method
must return an empty Map<String, Object>
if the file is
empty or a reader returns null.IOException
- If the file could not be readprotected abstract Map<String,Object> readRaw(File target) throws IOException
target
- The File
to be readMap<String, Object>
value of the target
File
This method must return an empty Map<String, Object>
if the
file is empty or a reader returns null.IOException
- If the file could not be readpublic static Class<? extends FileDataType> fromString(String in)
in
- The string to parseFileDataType
class, or null
public Map<String,Object> getRoot()
FileDataType
Map
that represents this FileDataType
Copyright © 2017. All rights reserved.