Package org.daisy.dotify.common.io
Class StateObject
- java.lang.Object
-
- org.daisy.dotify.common.io.StateObject
-
public class StateObject extends Object
The StateObject is a convenience object that can be used to avoid certain programming errors. By setting this object when the state changes and asserting that it has the correct state before engaging in state dependent activity, the programmer can get proper feedback whenever the object is in the wrong state for a particular request.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StateObject.State
Possible states for a StateObject.
-
Constructor Summary
Constructors Constructor Description StateObject()
Create a new StateObject with the default type, which is "Object".StateObject(String type)
Create a new StateObject with the specified type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertClosed()
Assert that the object has been closed.void
assertNotOpen()
Assert that the object is not open.void
assertOpen()
Assert that the object is open.void
assertUnopened()
Assert that the object has never been opened.void
close()
Close the StateObject.boolean
isClosed()
Check if the StateObject has been closed.boolean
isOpen()
Check if the StateObject has been opened.void
open()
Open the StateObject.
-
-
-
Constructor Detail
-
StateObject
public StateObject(String type)
Create a new StateObject with the specified type.- Parameters:
type
- the type name of this StateObject, e.g. a class name
-
StateObject
public StateObject()
Create a new StateObject with the default type, which is "Object".
-
-
Method Detail
-
open
public void open()
Open the StateObject.
-
close
public void close()
Close the StateObject.
-
isClosed
public boolean isClosed()
Check if the StateObject has been closed.- Returns:
- returns true if the object is closed
-
isOpen
public boolean isOpen()
Check if the StateObject has been opened.- Returns:
- returns true if the object is opened
-
assertOpen
public void assertOpen() throws IllegalStateException
Assert that the object is open.- Throws:
IllegalStateException
- if the object is not open
-
assertNotOpen
public void assertNotOpen() throws IllegalStateException
Assert that the object is not open.- Throws:
IllegalStateException
- if the object is open
-
assertClosed
public void assertClosed() throws IllegalStateException
Assert that the object has been closed.- Throws:
IllegalStateException
- if the object is not closed
-
assertUnopened
public void assertUnopened() throws IllegalStateException
Assert that the object has never been opened.- Throws:
IllegalStateException
- if the object is not unopened
-
-