Class JsonSettings
java.lang.Object
com.xpdustry.claj.server.util.JsonSettings
- All Implemented Interfaces:
Autosaver.Saveable
Simple re-implementation of
Settings adding choice to store as plain or binary json.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected final arc.files.Fiprotected final JsonWriterBuilderprotected booleanprotected arc.func.Cons<Throwable> protected final arc.files.Fiprotected arc.util.serialization.Jsonprotected booleanprotected booleanprotected final booleanprotected final arc.util.serialization.BaseJsonReaderprotected final arc.struct.OrderedMap<String, arc.util.serialization.JsonValue> -
Constructor Summary
ConstructorsConstructorDescriptionJsonSettings(arc.files.Fi file) JsonSettings(arc.files.Fi file, boolean autosave) JsonSettings(arc.files.Fi file, boolean plainJson, boolean autosave) Prefer compression when using binary json.JsonSettings(arc.files.Fi file, boolean plainJson, boolean autosave, boolean backuped) Prefer compression when using binary json.JsonSettings(arc.files.Fi file, boolean plainJson, boolean autosave, boolean backuped, boolean compressed) JsonSettings(arc.files.Fi file, arc.files.Fi backupFile) Enables backups implicitly.JsonSettings(arc.files.Fi file, arc.files.Fi backupFile, boolean autosave) Enables backups implicitly.JsonSettings(arc.files.Fi file, arc.files.Fi backupFile, boolean plainJson, boolean autosave) Enables backups implicitly.JsonSettings(arc.files.Fi file, arc.files.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, arc.util.serialization.Json.Serializer<T> serializer) booleanarc.files.Fivoidclear()Clears all preference values.voidSet up a list of defaults values.booleanexists()arc.files.Fifile()voidprotected <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) doubledoublefloatfloatintintarc.util.serialization.JsongetJson()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(arc.files.Fi file) booleanmodified()name()Used for logging.<K,E> void <E> voidvoidvoidvoidvoidsave()Saves all values.voidsaveValues(arc.files.Fi file) voidsetAutosaved(boolean autosave) voidsetBackuped(boolean backuped) voidsetCompressed(boolean compressed) voidsetDefault(String name, Object value) voidsetErrorHandler(arc.func.Cons<Throwable> handler) Sets the error handler function.intsize()
-
Field Details
-
simple
-
defaults
-
values
-
reader
protected final arc.util.serialization.BaseJsonReader reader -
builder
-
file
protected final arc.files.Fi file -
backupFile
protected final arc.files.Fi backupFile -
plainJson
protected final boolean plainJson -
errorHandler
-
json
protected arc.util.serialization.Json json -
loaded
protected boolean loaded -
modified
protected boolean modified -
autosaved
protected boolean autosaved -
backuped
protected boolean backuped -
compressed
protected boolean compressed
-
-
Constructor Details
-
JsonSettings
public JsonSettings(arc.files.Fi file) -
JsonSettings
public JsonSettings(arc.files.Fi file, arc.files.Fi backupFile) Enables backups implicitly. -
JsonSettings
public JsonSettings(arc.files.Fi file, boolean autosave) -
JsonSettings
public JsonSettings(arc.files.Fi file, arc.files.Fi backupFile, boolean autosave) Enables backups implicitly. -
JsonSettings
public JsonSettings(arc.files.Fi file, boolean plainJson, boolean autosave) Prefer compression when using binary json. -
JsonSettings
public JsonSettings(arc.files.Fi file, arc.files.Fi backupFile, boolean plainJson, boolean autosave) Enables backups implicitly. Prefer compression when using binary json. -
JsonSettings
public JsonSettings(arc.files.Fi file, boolean plainJson, boolean autosave, boolean backuped) Prefer compression when using binary json. -
JsonSettings
public JsonSettings(arc.files.Fi file, boolean plainJson, boolean autosave, boolean backuped, boolean compressed) -
JsonSettings
public JsonSettings(arc.files.Fi file, arc.files.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
public arc.util.serialization.Json 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
-
forceSave
public void forceSave()- Specified by:
forceSavein interfaceAutosaver.Saveable
-
loadValues
public void loadValues(arc.files.Fi file) -
saveValues
public void saveValues(arc.files.Fi file) -
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
public arc.files.Fi file()- Returns:
- the file used for writing settings to.
-
backupFile
public arc.files.Fi 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
-
getOrPut
-
getFloat
-
getDouble
-
getInt
-
getLong
-
getBool
-
getString
-
getFloat
-
getDouble
-
getInt
-
getLong
-
getBool
-
getBoolOnce
-
getBoolOnce
Returnsfalseonce, and never again. -
getString
-