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) Prefer compression when using binary json.JsonSettings(Fi file, boolean plainJson, boolean autosave, boolean backuped) Prefer compression when using binary json.JsonSettings(Fi file, boolean plainJson, boolean autosave, boolean backuped, boolean compressed) JsonSettings(Fi file, Fi backupFile) Enables backups implicitly.JsonSettings(Fi file, Fi backupFile, boolean autosave) Enables backups implicitly.JsonSettings(Fi file, Fi backupFile, boolean plainJson, boolean autosave) Enables backups implicitly.JsonSettings(Fi file, Fi backupFile, boolean plainJson, boolean autosave, boolean backuped, boolean compressed) Container to store settings as json -
Method Summary
Modifier and TypeMethodDescription<T> voidaddSerializer(Class<T> type, Json.Serializer<T> serializer) booleanvoidclear()Clears all preference values.voidSet up a list of defaults values.booleanexists()file()voidprotected <T,K, E> T <T> T<T,E> T protected <T,K, E> T <T,K, E> T booleanbooleanbooleangetBoolOnce(String name) Returnstrueonce, 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 found<T,K, E> T Put and returndefif thenamekey is not foundbooleanbooleanbooleanbooleanprotected booleanisKnownType(Class<?> known) booleankeys()voidload()Loads all values.booleanloaded()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) voidsetDefault(String name, Object value) voidsetErrorHandler(Cons<Throwable> handler) Sets the error handler function.intsize()
-
Field Details
-
simple
-
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
Enables backups implicitly. -
JsonSettings
-
JsonSettings
Enables backups implicitly. -
JsonSettings
Prefer compression when using binary json. -
JsonSettings
Enables backups implicitly. Prefer compression when using binary json. -
JsonSettings
Prefer compression when using binary json. -
JsonSettings
public JsonSettings(Fi file, boolean plainJson, boolean autosave, boolean backuped, boolean compressed) -
JsonSettings
public JsonSettings(Fi file, Fi backupFile, boolean plainJson, boolean autosave, boolean backuped, boolean compressed) Container to store settings as json- Parameters:
file- the file to write/readbackupFile- the backup file to use in case of corruption.plainJson- whether settings are stored in plain or binary json.autosave- to take advantage of regularly save.
-
-
Method Details
-
getJson
-
addSerializer
-
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
-
loaded
public boolean loaded() -
load
public void load()Loads all values. -
save
public void save()Saves all values.- Specified by:
savein interfaceAutosaver.Saveable
-
forceSave
public void forceSave()- Specified by:
forceSavein 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 -
setDefault
-
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
Returnstrueonce, and never again. -
getString
- Returns:
nullif not found
-