Package arc.util
Class JsonSettings
java.lang.Object
arc.util.JsonSettings
- All Implemented Interfaces:
Autosaver.Saveable
- Direct Known Subclasses:
Settings
Simple re-implementation of
Settings adding choice to store as plain or binary json.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected final Fiprotected final JsonWriterBuilderprotected booleanprotected final Fiprotected Jsonprotected booleanprotected booleanprotected final booleanprotected final BaseJsonReaderprotected final OrderedMap<String,JsonValue> -
Constructor Summary
ConstructorsConstructorDescriptionJsonSettings(Fi file) JsonSettings(Fi file, boolean autosave) JsonSettings(Fi file, boolean plainJson, boolean autosave) JsonSettings(Fi file, boolean plainJson, boolean autosave, boolean backuped) JsonSettings(Fi file, boolean plainJson, boolean autosave, boolean backuped, boolean compressed) Container to store settings as json -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidclear()Clears all preference values.voidSet up a list of defaults values.booleanexists()file()protected <T,K, E> T <T> T<T,E> T protected <T,K, E> T <T,K, E> T booleanbooleanbooleangetBoolOnce(String name) Returnsfalseonce, and never again.voidgetBoolOnce(String name, Runnable run) Runs the specified code once, and never again.getDefault(String name) doubledoublefloatfloatintintgetJson()longlong<T> T<T,E> T <T,K, E> T Put and returndefif thenamekey is not foundprotected <T,K, E> T Put and returndefif thenamekey is not foundbooleanbooleanbooleanbooleanprotected booleanisKnownType(Class<?> known) booleankeys()voidload()Loads all values.voidloadValues(Fi file) booleanmodified()name()Used for logging.<K,E> void <E> voidvoidvoidvoidvoidsave()Saves all values.voidsaveValues(Fi file) voidsetAutosaved(boolean autosave) voidsetBackuped(boolean backuped) voidsetCompressed(boolean compressed) voidsetErrorHandler(Cons<Throwable> handler) Sets the error handler function.voidintsize()
-
Field Details
-
decoded
-
defaults
-
values
-
reader
-
builder
-
file
-
backupFile
-
plainJson
protected final boolean plainJson -
errorHandler
-
json
-
loaded
protected boolean loaded -
modified
protected boolean modified -
autosaved
protected boolean autosaved -
backuped
protected boolean backuped -
compressed
protected boolean compressed
-
-
Constructor Details
-
JsonSettings
-
JsonSettings
-
JsonSettings
-
JsonSettings
-
JsonSettings
public JsonSettings(Fi file, boolean plainJson, boolean autosave, boolean backuped, boolean compressed) Container to store settings as json- Parameters:
file- the to write/readplainJson- whether settings are stored in plain or binary json.autosave- to take advantage of regularly save.
-
-
Method Details
-
setJson
-
getJson
-
isPlainJson
public boolean isPlainJson() -
setAutosaved
public void setAutosaved(boolean autosave) -
isAutosaved
public boolean isAutosaved() -
setBackuped
public void setBackuped(boolean backuped) -
isBackuped
public boolean isBackuped() -
setCompressed
public void setCompressed(boolean compressed) -
isCompressed
public boolean isCompressed() -
setErrorHandler
-
modified
public boolean modified()- Specified by:
modifiedin interfaceAutosaver.Saveable
-
load
public void load()Loads all values. -
save
public void save()Saves all values.- Specified by:
savein interfaceAutosaver.Saveable
-
loadValues
-
saveValues
-
exists
public boolean exists()- Returns:
- whether the file exists or not.
-
backupExists
public boolean backupExists()- Returns:
- whether the backup file exists or not.
-
name
Description copied from interface:Autosaver.SaveableUsed for logging.- Specified by:
namein interfaceAutosaver.Saveable
-
file
- Returns:
- the file used for writing settings to.
-
backupFile
- Returns:
- the file used for recovering settings.
-
clear
public void clear()Clears all preference values. -
keys
-
size
public int size() -
isKnownType
-
has
-
remove
-
defaults
Set up a list of defaults values.
Format: name1, default1, name2, default2, etc -
getDefault
-
putAll
-
put
-
put
-
put
-
get
-
get
-
get
-
get
-
get
-
getOrPut
-
getOrPut
-
getOrPut
public <T,K, T getOrPutE> (String name, Class<T> type, Class<E> elementType, Class<K> keyType, Prov<T> def) Put and returndefif thenamekey is not found -
getOrPut
Put and returndefif thenamekey is not found -
getFloat
-
getDouble
-
getInt
-
getLong
-
getBool
-
getString
-
getFloat
-
getDouble
-
getInt
-
getLong
-
getBool
-
getBoolOnce
Runs the specified code once, and never again. -
getBoolOnce
Returnsfalseonce, and never again. -
getString
- Returns:
nullif not found
-