Package overit.geocall.bl
Class Journal<T>
java.lang.Object
overit.geocall.bl.Journal<T>
- Type Parameters:
T- the content type that will be stored inside a Journal
- All Implemented Interfaces:
Serializable
A Journal keeping a list of
Journal.Record tracking info.
Each track can be started with a start(java.lang.Class), written with a write(java.lang.Object) and closed with a close().
Tracks can be empty if no write operations occurs.
The tracks can be quered by records (getFirstRecord(), getLastRecord(), streamRecords())
or directly by content (firstContent(), lastContent(), stream() )- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJournal()Create a new Journal object that keep a list ofJournal.Recordtracking info. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()closes the journal, closing the last recordvoidcloses the journal, closing the last record with an exceptionGet the first valued content in the collectionGet the first record in the collectionGet the last record in the collectiongetRecord(int i) Returns the record at the specified position in this list.booleanReturn true if the journal contains any element.booleanGet the last valued content in the collectionvoidAdds a record at the end of the liststream()Streams sequentially over the values appended in this journalStreams sequentially over the records appended in this journalvoidwrites the content of a record
-
Field Details
-
map
-
list
-
exception
-
-
Constructor Details
-
Journal
public Journal()Create a new Journal object that keep a list ofJournal.Recordtracking info.
-
-
Method Details
-
start
Adds a record at the end of the list- Parameters:
c- the class that will be responsible for write operations
-
close
public void close()closes the journal, closing the last record -
close
closes the journal, closing the last record with an exception- Parameters:
e- the exception, reason for closing
-
write
writes the content of a record- Parameters:
t- the content to be stored inside the record- Throws:
IllegalStateException- if the record is already closed
-
streamRecords
Streams sequentially over the records appended in this journal- Returns:
- a sequential stream over
Journal.Recordcollection
-
getFirstRecord
Get the first record in the collection- Returns:
- the first
Journal.Recordin the list or null if the list is empty
-
getLastRecord
Get the last record in the collection- Returns:
- the last
Journal.Recordin the list or null if the list is empty
-
getRecord
Returns the record at the specified position in this list.- Parameters:
i- index of the element to return- Returns:
- the
Journal.Recordat the specified position in the collection - Throws:
IndexOutOfBoundsException- if the index is out of range
-
firstContent
Get the first valued content in the collection- Returns:
- the first
Journalin the list that is not null.nullif there is no such an element
-
lastContent
Get the last valued content in the collection- Returns:
- the last
Journalin the list that is not null.nullif there is no such an element
-
hasContent
public boolean hasContent()Return true if the journal contains any element.- Returns:
trueif the journal contains at least one not null object,falseotherwise
-
stream
Streams sequentially over the values appended in this journal- Returns:
- a sequential stream over
Journal, filtering out null values
-
hasException
public boolean hasException()- Returns:
- true if the journal has been closed with an exception
-
getException
- Returns:
- the exception reason for closing
-