Holger's
Java API

com.antelmann.timeregister
Class PunchDataAnalyzer

java.lang.Object
  extended by com.antelmann.timeregister.AbstractPunchDB
      extended by com.antelmann.timeregister.PunchDataAnalyzer
All Implemented Interfaces:
PunchDB, Serializable

public class PunchDataAnalyzer
extends AbstractPunchDB
implements Serializable, PunchDB

used to analyze PunchData objects. The PunchDataAnalyzer also serves as an in-memory implementation of a PunchDB.

Author:
Holger Antelmann
See Also:
PunchData, PunchDB, Serialized Form

Field Summary
 
Fields inherited from class com.antelmann.timeregister.AbstractPunchDB
listeners
 
Constructor Summary
PunchDataAnalyzer()
           
PunchDataAnalyzer(Collection<PunchData> punchDataEntries)
           
PunchDataAnalyzer(PunchDataAnalyzer analyzer)
           
PunchDataAnalyzer(PunchDB db)
           
 
Method Summary
 void addAll(Collection<PunchData> punchDataEntries)
           
 void addAll(PunchDataAnalyzer analyzer)
           
 void close()
          doesn't do anything
 boolean contains(PunchData entry)
           
 void delete(PunchData entry)
           
 void exportToFile(File file, String fieldSeparator, boolean usesQuotes)
           
 void filter(Filter<PunchData> filter)
          filters this analyzer according to the given filter.
 void filter(User user, Date from, Date until, String location, String activity, String comment)
          filters this analyzer according to the given restrictions.
 PunchData findPunch(User user, Date time)
           
 String getActivityFor(User user)
          returns the current activity
 String getActivityFor(User user, Date date)
          returns the activity based on the PunchData last recorded for the given date; may return null if either the user is checked-out or if the current activity is indeed null.
 SortedSet<PunchData> getAll()
          returns an unmodifyable view on all PunchData objects
 PunchData getFirstPunch(User user)
          if employee is null, the first punch among all employees is returned
 PunchData getLastPunch(User user)
          if employee is null, the last punch among all employees is returned
 SortedSet<PunchData> getPunchData(User user)
          returns a view of the data (not backed by the real data, returned is a new Set)
 PunchDataAnalyzer getPunchData(User user, Date from, Date until, String location, String activity)
          retrieves the relevant set of Punchdata objects in a PunchDataAnalyzer
 ArrayList<PunchData> getPunchSequenceFor(User user, Date time)
          a punch sequence starts with the first check-in punch there is or after the most recent check-out before or at the given time; the sequence ends with the check-out (if complete).
 Map<Object,TimeUser> getUsers()
          returns a new set of all user ids available in this analyzer
 long getWorkingTime()
          returns the complete working time (in milliseconds) of all users from this analyzer.
 ArrayList<WorkUnit> getWorkUnits()
          returns a list of WorkUnit objects resulting from the current content of the analyzer.
 boolean isCurrentlyPresent(User user)
          by definition: if no punch data is available for the user, false is returned
 void removeAll()
           
 PunchData removeFirst()
           
 PunchData removeLast()
           
 int size()
           
 void store(PunchData entry)
          used by the final punch(PunchData) method to delegate the database storing.
 void storeInto(PunchDB db)
           
 void updatePassword(User user)
          not supported with the analyzer; always throws DatabaseException
 void verifyConsistency()
           
static void verifyPunch(PunchDB db, PunchData pd)
          checks whether the data can be stored into the database w/o causing inconsistency for the employee in the given PunchData entry.
 
Methods inherited from class com.antelmann.timeregister.AbstractPunchDB
addPunchListener, getPunchListeners, punch, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.antelmann.timeregister.PunchDB
addPunchListener, punch
 

Constructor Detail

PunchDataAnalyzer

public PunchDataAnalyzer()

PunchDataAnalyzer

public PunchDataAnalyzer(PunchDB db)

PunchDataAnalyzer

public PunchDataAnalyzer(PunchDataAnalyzer analyzer)

PunchDataAnalyzer

public PunchDataAnalyzer(Collection<PunchData> punchDataEntries)
Method Detail

close

public void close()
doesn't do anything


addAll

public void addAll(PunchDataAnalyzer analyzer)

addAll

public void addAll(Collection<PunchData> punchDataEntries)

contains

public boolean contains(PunchData entry)

store

public void store(PunchData entry)
Description copied from class: AbstractPunchDB
used by the final punch(PunchData) method to delegate the database storing. (Note that a PunchAdminDB makes this method public)

Specified by:
store in class AbstractPunchDB
See Also:
PunchDB.punch(PunchData)

removeAll

public void removeAll()

delete

public void delete(PunchData entry)

storeInto

public void storeInto(PunchDB db)
               throws DatabaseException,
                      FormatException
Throws:
DatabaseException
FormatException

updatePassword

public void updatePassword(User user)
                    throws DatabaseException
not supported with the analyzer; always throws DatabaseException

Specified by:
updatePassword in interface PunchDB
Throws:
DatabaseException
See Also:
UserImpl.setPassword(char[]), UserImpl.getPasswordHash()

size

public int size()

filter

public void filter(Filter<PunchData> filter)
filters this analyzer according to the given filter.


filter

public void filter(User user,
                   Date from,
                   Date until,
                   String location,
                   String activity,
                   String comment)
filters this analyzer according to the given restrictions.


getPunchData

public PunchDataAnalyzer getPunchData(User user,
                                      Date from,
                                      Date until,
                                      String location,
                                      String activity)
Description copied from interface: PunchDB
retrieves the relevant set of Punchdata objects in a PunchDataAnalyzer

Specified by:
getPunchData in interface PunchDB
Parameters:
user - limits retrieval by employee; if null, this limit does not apply
from - limits retrieval by begin date; if null, this limit does not apply
until - limits retrieval by end date; if null, this limit does not apply
Returns:
a set of PunchData objects
See Also:
PunchData

findPunch

public PunchData findPunch(User user,
                           Date time)

getPunchSequenceFor

public ArrayList<PunchData> getPunchSequenceFor(User user,
                                                Date time)
a punch sequence starts with the first check-in punch there is or after the most recent check-out before or at the given time; the sequence ends with the check-out (if complete). If the given user is deemed absent at the given time, an empty list is returned; otherwise, the first list entry is always a checkin. A complete sequence ends with a check-out, but the returned sequence can only be complete if all data is within the analyser.


getUsers

public Map<Object,TimeUser> getUsers()
returns a new set of all user ids available in this analyzer

Specified by:
getUsers in interface PunchDB

isCurrentlyPresent

public boolean isCurrentlyPresent(User user)
                           throws NoSuchElementException
by definition: if no punch data is available for the user, false is returned

Throws:
NoSuchElementException

getActivityFor

public String getActivityFor(User user)
returns the current activity


getActivityFor

public String getActivityFor(User user,
                             Date date)
returns the activity based on the PunchData last recorded for the given date; may return null if either the user is checked-out or if the current activity is indeed null.


getAll

public SortedSet<PunchData> getAll()
returns an unmodifyable view on all PunchData objects


getPunchData

public SortedSet<PunchData> getPunchData(User user)
returns a view of the data (not backed by the real data, returned is a new Set)


getWorkingTime

public long getWorkingTime()
                    throws FormatException
returns the complete working time (in milliseconds) of all users from this analyzer. If the calculation is to be limited to a subset (in regards to a specific user or in regards to a limited time frame), use the filtering methods before calling this method.

This method only calculates the time based on completed working units within this analyzer, i.e. if the first punch per user is a check-out or the last punch is a check-in, that punch is ignored in the calculation.

Throws:
FormatException - if the data is found to be in an inconsistent state (e.g. if one user checked in twice in a row)
See Also:
filter(Filter), filter(User, Date, Date, String, String, String)

getWorkUnits

public ArrayList<WorkUnit> getWorkUnits()
                                 throws FormatException
returns a list of WorkUnit objects resulting from the current content of the analyzer. The result is sorted by the natural order of WorkUnit objects.

Throws:
FormatException

getFirstPunch

public PunchData getFirstPunch(User user)
if employee is null, the first punch among all employees is returned

Specified by:
getFirstPunch in interface PunchDB

getLastPunch

public PunchData getLastPunch(User user)
if employee is null, the last punch among all employees is returned

Specified by:
getLastPunch in interface PunchDB

removeFirst

public PunchData removeFirst()

removeLast

public PunchData removeLast()

verifyPunch

public static void verifyPunch(PunchDB db,
                               PunchData pd)
                        throws DatabaseException,
                               FormatException
checks whether the data can be stored into the database w/o causing inconsistency for the employee in the given PunchData entry. The method is to be called before the given PunchData is stored into the database. This method does not perform a complete verification of the database, it assumes that the database is in a consistent state before calling this method. This method does NOT perform the store operation, it only checks whether it doesn't jeopardize consistency. If the verification is successful, this method returns quietly, otherwise an appropriate Exception is thrown.

Throws:
FormatException - if inserting the data would result in inconsistencies
DatabaseException

verifyConsistency

public void verifyConsistency()
                       throws FormatException
Throws:
FormatException

exportToFile

public void exportToFile(File file,
                         String fieldSeparator,
                         boolean usesQuotes)
                  throws IOException
Throws:
IOException


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads