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

public class Journal<T> extends Object implements 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:
  • Field Details

  • Constructor Details

    • Journal

      public Journal()
      Create a new Journal object that keep a list of Journal.Record tracking info.
  • Method Details

    • start

      public void start(Class c)
      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

      public void close(Exception e)
      closes the journal, closing the last record with an exception
      Parameters:
      e - the exception, reason for closing
    • write

      public void write(T t)
      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

      public Stream<Journal<T>.Record<T>> streamRecords()
      Streams sequentially over the records appended in this journal
      Returns:
      a sequential stream over Journal.Record collection
    • getFirstRecord

      public Journal<T>.Record<T> getFirstRecord()
      Get the first record in the collection
      Returns:
      the first Journal.Record in the list or null if the list is empty
    • getLastRecord

      public Journal<T>.Record<T> getLastRecord()
      Get the last record in the collection
      Returns:
      the last Journal.Record in the list or null if the list is empty
    • getRecord

      public Journal<T>.Record<T> getRecord(int i)
      Returns the record at the specified position in this list.
      Parameters:
      i - index of the element to return
      Returns:
      the Journal.Record at the specified position in the collection
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • firstContent

      public T firstContent()
      Get the first valued content in the collection
      Returns:
      the first Journal in the list that is not null. null if there is no such an element
    • lastContent

      public T lastContent()
      Get the last valued content in the collection
      Returns:
      the last Journal in the list that is not null. null if there is no such an element
    • hasContent

      public boolean hasContent()
      Return true if the journal contains any element.
      Returns:
      true if the journal contains at least one not null object, false otherwise
    • stream

      public Stream<T> 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

      public Exception getException()
      Returns:
      the exception reason for closing