cz.psika.numerist
Class Entry

java.lang.Object
  extended by cz.psika.numerist.Entry
All Implemented Interfaces:
History, Item, ItemObservable

public class Entry
extends java.lang.Object
implements Item, History

Entry. Basic object representing each entry, it's style and some computated characteristics. Object is observable and could conserve history status.

Author:
Tomas Psika

Nested Class Summary
protected  class Entry.EntryMemento
          Class used to conserve history status of entry.
 
Field Summary
protected  boolean computed
          State of computation.
static boolean COMPUTED
          Successul computation status flag.
protected  int[] freqs
          Computed frequencies of all numbers/digits.
protected  int id
          Unique identifier for entry used to distinguish different entries.
protected  java.lang.String name
          Input string truncated for making things bit faster.
static boolean NOT_COMPUTED
          Failed computation status flag.
static boolean NOT_SELECTED
          Negative selection status flag.
static int NUMBERS_COUNT
          Number of numbers/digits.
protected  int numbersUsed
          Caching number of numbers with their frequency greater than zero.
protected  java.util.Set<ItemObserver> observers
          Registered observers.
static boolean SELECTED
          Positive selection status flag.
protected  boolean selectStatus
          Selection of entry, used for invoking actions later.
protected  java.lang.String sourceName
          Original entry string used in GUI.
protected  Style style
          Style of characteristics.
 
Constructor Summary
protected Entry(Entry original, int newId)
          Copy constructor making copy which is not connected to original entry.
  Entry(java.lang.Integer uniqueIdentifier, java.lang.String entryString, Style entryStyle)
          Entry construction cause initialization of string content and entry identifier.
 
Method Summary
 void addObserver(ItemObserver observer)
          Attach observer to the object.
protected  boolean compute()
          Doing computations.
 boolean computed()
          Find out if entry was successfully computed.
 Memento createMemento()
          Creates memento.
 void deleteObserver(ItemObserver observer)
          Detach observer.
 boolean equals(java.lang.Object other)
          Entries are equal when they have same identifiers.
 Entry fetchEntry()
          DIRECT access to this instance
 int getFrequency(int number)
          Get count of occurences of the concrete number/digit.
 int getId()
          Getting unique identifier for this entry.
 java.lang.String getSourceString()
          Returns input string when this entry was created.
 Style getStyle()
          Get entry's style.
 boolean isCopy()
          Entries could be copied.
 boolean isSelected()
          Find out if this entry is selected.
 void notifyObservers(Constants.ItemEvents event)
          Notify all attached observers.
 int numbersUsed()
          Returns count of number used.
protected  void prepareComputation()
          Initialize computed state to false to let us know that computations are maybe processed for now and initialize members to default initial state.
protected  boolean setComputationStatus(boolean computationStatus)
          Set status of computation.
 void setMemento(Memento memento)
          Set history status.
 void setSelection(boolean select)
          Mark this entry as (un)selected.
 void setString(java.lang.String newString)
          Change string and make computations.
 void setStyle(Style setStyle)
          Set/modify style for entry and make all necessary computations.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected final int id
Unique identifier for entry used to distinguish different entries.


name

protected java.lang.String name
Input string truncated for making things bit faster.


sourceName

protected java.lang.String sourceName
Original entry string used in GUI.


freqs

protected int[] freqs
Computed frequencies of all numbers/digits.


numbersUsed

protected int numbersUsed
Caching number of numbers with their frequency greater than zero.


style

protected Style style
Style of characteristics.


COMPUTED

public static final boolean COMPUTED
Successul computation status flag.

See Also:
Constant Field Values

NOT_COMPUTED

public static final boolean NOT_COMPUTED
Failed computation status flag.

See Also:
Constant Field Values

computed

protected boolean computed
State of computation.

See Also:
computed()

SELECTED

public static final boolean SELECTED
Positive selection status flag.

See Also:
Constant Field Values

NOT_SELECTED

public static final boolean NOT_SELECTED
Negative selection status flag.

See Also:
Constant Field Values

selectStatus

protected boolean selectStatus
Selection of entry, used for invoking actions later.


observers

protected java.util.Set<ItemObserver> observers
Registered observers.


NUMBERS_COUNT

public static final int NUMBERS_COUNT
Number of numbers/digits. We suppose 3x3 matrix for all created diagrams made from the entries, so 9 digits are being used.

See Also:
Constant Field Values
Constructor Detail

Entry

public Entry(java.lang.Integer uniqueIdentifier,
             java.lang.String entryString,
             Style entryStyle)
Entry construction cause initialization of string content and entry identifier.

Parameters:
uniqueIdentifier - needed to observe changes quickly
entryString - string input data
entryStyle - style

Entry

protected Entry(Entry original,
                int newId)
Copy constructor making copy which is not connected to original entry. That means the copy has its own internal identifier. Only source string and style are initialized. Never call this copy constructor if not sure you are doing. Original and its copy does not equal.

Parameters:
original - existing entry
newId - new identifier of entry to set
See Also:
equals(Object other)
Method Detail

getId

public final int getId()
Getting unique identifier for this entry.

Returns:
entry identifier

getSourceString

public java.lang.String getSourceString()
Returns input string when this entry was created.

Returns:
raw input text of this entry

setString

public void setString(java.lang.String newString)
Change string and make computations.

Parameters:
newString - assing new input string

isCopy

public boolean isCopy()
Entries could be copied. Copied entries have different internal identifiers.

Returns:
true when this entry has been created as copy

setSelection

public void setSelection(boolean select)
Mark this entry as (un)selected.

Parameters:
select - true to select, false to unselect

isSelected

public boolean isSelected()
Find out if this entry is selected.

Returns:
true if entry was selected, false otherwise

getStyle

public Style getStyle()
Get entry's style.

Returns:
copy of Style object or null

setStyle

public void setStyle(Style setStyle)
Set/modify style for entry and make all necessary computations.

Parameters:
setStyle - style to set

getFrequency

public int getFrequency(int number)
Get count of occurences of the concrete number/digit.

Parameters:
number - concrete number or digit
Returns:
frequency count, 0 is returned if frequency not successfully computed
See Also:
computed()

numbersUsed

public int numbersUsed()
Returns count of number used.

Returns:
numbers/digits used, 0 is returned if computation failed
See Also:
computed()

computed

public boolean computed()
Find out if entry was successfully computed. Computations are done on every important change in object automatically. Call this everytime you need some informations about computation results to check their validity. If you dont, results are undefined.

Returns:
true when entry computations successfully done, false if computations are not done or not completed or when some error occured.

prepareComputation

protected void prepareComputation()
Initialize computed state to false to let us know that computations are maybe processed for now and initialize members to default initial state.


setComputationStatus

protected boolean setComputationStatus(boolean computationStatus)
Set status of computation.

Parameters:
computationStatus - false on computation error
Returns:
computation status

compute

protected boolean compute()
Doing computations.

Returns:
NOT_COMPUTED on computation error, otherwise COMPUTED.

fetchEntry

public Entry fetchEntry()
DIRECT access to this instance

Specified by:
fetchEntry in interface Item
Returns:
Entry object

equals

public boolean equals(java.lang.Object other)
Entries are equal when they have same identifiers.

Overrides:
equals in class java.lang.Object
Parameters:
other - the other object to compare
Returns:
true if entries are equal

createMemento

public Memento createMemento()
Creates memento.

Specified by:
createMemento in interface History
Returns:
new history object

setMemento

public void setMemento(Memento memento)
Set history status.

Specified by:
setMemento in interface History
Parameters:
memento - history EntryMemento object
See Also:
History.createMemento()

addObserver

public void addObserver(ItemObserver observer)
Description copied from interface: ItemObservable
Attach observer to the object.

Specified by:
addObserver in interface ItemObservable
Parameters:
observer - an observer to attach
See Also:
ItemObservable.addObserver(ItemObserver observer)

deleteObserver

public void deleteObserver(ItemObserver observer)
Description copied from interface: ItemObservable
Detach observer.

Specified by:
deleteObserver in interface ItemObservable
Parameters:
observer - to remove
See Also:
ItemObservable.deleteObserver(ItemObserver observer)

notifyObservers

public void notifyObservers(Constants.ItemEvents event)
Description copied from interface: ItemObservable
Notify all attached observers.

Specified by:
notifyObservers in interface ItemObservable
Parameters:
event - type of event to notify all registered observers
See Also:
ItemObservable.notifyObservers(Constants.ItemEvents event)