|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
com.std.util.Stateful<U>
com.std.util.Persistent<U>
U
- class to be wrappedpublic class Persistent<U extends java.io.Serializable>
Persistent is a Stateful object that provides utilities to save and load to a file, and keeps track of the status of that file and whether or not it exists.
Constructor Summary | |
---|---|
Persistent(U target)
creates a new persistent object with the given target |
Method Summary | |
---|---|
java.lang.String |
getFileName()
|
boolean |
isModified()
|
void |
load()
loads this object from a file |
void |
load(boolean discardOld)
loads this object from a file |
void |
load(java.lang.String fileName)
loads this object from a file |
void |
load(java.lang.String fileName,
boolean discardOld)
loads this object from a file |
void |
save()
saves this object to its previously specified file |
void |
save(java.lang.String fileName)
saves this object to a file |
void |
save(java.lang.String fileName,
boolean overwriteOld)
saves this object to a file |
protected void |
setModified()
sets that this object has been changed to be different than what is on file |
void |
setTarget(U target)
sets this object to a new instance |
void |
setTarget(U target,
boolean discardOld)
sets this object to a new instance |
Methods inherited from class com.std.util.Stateful |
---|
getTarget, onChanged |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Persistent(U target)
target
-
java.lang.IllegalArgumentException
- if the target is nullMethod Detail |
---|
public java.lang.String getFileName()
public boolean isModified()
public void load()
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOException
java.lang.IllegalArgumentException
- when the file
hasn't been previously saved
java.lang.IllegalStateException
- when changes have
been made since the last save or load operation
java.lang.ClassNotFoundException
public void load(boolean discardOld)
throws java.io.IOException,
java.lang.ClassNotFoundException
discardOld
- setting this to true will
automatically discard any changes to the current
object. setting this to false will throw an
IllegalStateException when the object has been
changed since the last save or load
java.io.IOException
java.lang.IllegalArgumentException
- when the file
hasn't been previously saved
java.lang.IllegalStateException
- when changes have
been made since the last save or load operation
and discardOld is false.
java.lang.ClassNotFoundException
public void load(java.lang.String fileName)
throws java.io.IOException,
java.lang.ClassNotFoundException
fileName
- the name of the file to load from.
if this is null, default to the current file name
java.io.IOException
java.lang.IllegalArgumentException
- when fileName is
null and the file hasn't been previously saved
java.lang.IllegalStateException
- when changes have
been made since the last save or load operation
java.lang.ClassNotFoundException
public void load(java.lang.String fileName,
boolean discardOld)
throws java.io.IOException,
java.lang.ClassNotFoundException
fileName
- the name of the file to load from.
if this is null, default to the current file namediscardOld
- setting this to true will
automatically discard any changes to the current
object. setting this to false will throw an
IllegalStateException when the object has been
changed since the last save or load
java.io.IOException
java.lang.IllegalArgumentException
- when fileName is
null and the file hasn't been previously saved
java.lang.IllegalStateException
- when changes have
been made since the last save or load operation
and discardOld is false.
java.lang.ClassNotFoundException
public void save()
throws java.io.IOException
java.io.IOException
java.lang.IllegalArgumentException
- when the file
hasn't been previously savedpublic void save(java.lang.String fileName)
throws java.io.IOException
fileName
- the name of the file to save to.
if this is null, default to the current file name
java.io.IOException
java.lang.IllegalArgumentException
- when fileName is
null and the file hasn't been previously saved
java.lang.IllegalStateException
- when fileName exists
but is not this objectpublic void save(java.lang.String fileName,
boolean overwriteOld)
throws java.io.IOException
fileName
- the name of the file to save to.
if this is null, default to the current file nameoverwriteOld
- setting this to true will
automatically overwrite any file with the specified
file name. setting this to false will throw an
IllegalStateException when fileName already exists
java.io.IOException
java.lang.IllegalArgumentException
- when fileName is
null and the file hasn't been previously saved
java.lang.IllegalStateException
- when fileName exists
but is not this object and overwriteOld is false.protected void setModified()
public void setTarget(U target)
setTarget
in class Stateful<U extends java.io.Serializable>
target
- the object to replace with
java.io.IOException
java.lang.IllegalArgumentException
- when the new
target is null
java.lang.IllegalStateException
- when changes have
been made since the last save or load operationpublic void setTarget(U target,
boolean discardOld)
target
- the object to replace withdiscardOld
- setting this to true will
automatically discard any changes to the current
object. setting this to false will throw an
IllegalStateException when the object has been
changed since the last save or load
java.io.IOException
java.lang.IllegalArgumentException
- when the new
target is null
java.lang.IllegalStateException
- when changes have
been made since the last save or load operation
and discardOld is false.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |