Holger's
Java API

com.antelmann.timeregister
Class WorkUnit

java.lang.Object
  extended by com.antelmann.timeregister.WorkUnit
All Implemented Interfaces:
Serializable, Comparable<WorkUnit>

public class WorkUnit
extends Object
implements Serializable, Comparable<WorkUnit>

represents a timeframe in which an employee worked. Note that the begin and end time are floored to the nearest second to provide better compatibility for database access. In consequense, the following assertion may fail:

 java.util.Date date = new Date();
 WorkUnit unit = new WorkUnit(date, 60000, user);
 assert date.equals(unit.getBegin()) : "the time was rounded"
 
The same is true for the length, which is saved only by the second.

Author:
Holger Antelmann
See Also:
PunchAdminDB, WorkUnitAnalyzer, Serialized Form

Nested Class Summary
static class WorkUnit.Type
           
 
Constructor Summary
WorkUnit(Date begin, Date end, User user)
          type WORK is used as the default
WorkUnit(Date begin, Date end, User user, WorkUnit.Type type, String activity)
           
WorkUnit(Date begin, Date end, User user, WorkUnit.Type type, String activity, long breakTime, String comment)
           
WorkUnit(Date begin, Date end, User user, WorkUnit.Type type, String activity, String comment)
           
WorkUnit(Date begin, long length, User user)
          type WORK is used as the default
WorkUnit(Date begin, long length, User user, WorkUnit.Type type, String activity)
           
WorkUnit(Date begin, long length, User user, WorkUnit.Type type, String activity, long breakTime, String comment)
           
 
Method Summary
 int compareTo(WorkUnit unit)
          sorts by user, begin, type, length
 boolean equals(Object obj)
          based on user, begin, type and length
 String getActivity()
           
 Date getBegin()
           
 long getBreakTime()
           
 String getComment()
           
 Date getEnd()
           
 long getLength()
          total length including breakTimes
 long getNetLength()
          returns the length minus the breakTime time
 WorkUnit.Type getType()
           
static WorkUnit.Type getTypeForString(String s)
          reverts the given String to a Type and returns it - or null if no corresponding type exists
static String[] getTypeStrings()
          returns localized strings for all types
 User getUser()
           
 int hashCode()
           
 boolean isApproved()
          false by default
 boolean overlapsWith(WorkUnit unit)
          only looks at the time, not at the user
 void setActivity(String activity)
           
 void setApproved(boolean flag)
           
 void setBreakTime(long breakTime)
           
 void setComment(String comment)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WorkUnit

public WorkUnit(Date begin,
                Date end,
                User user)
type WORK is used as the default


WorkUnit

public WorkUnit(Date begin,
                Date end,
                User user,
                WorkUnit.Type type,
                String activity)

WorkUnit

public WorkUnit(Date begin,
                Date end,
                User user,
                WorkUnit.Type type,
                String activity,
                String comment)

WorkUnit

public WorkUnit(Date begin,
                Date end,
                User user,
                WorkUnit.Type type,
                String activity,
                long breakTime,
                String comment)

WorkUnit

public WorkUnit(Date begin,
                long length,
                User user)
type WORK is used as the default


WorkUnit

public WorkUnit(Date begin,
                long length,
                User user,
                WorkUnit.Type type,
                String activity)

WorkUnit

public WorkUnit(Date begin,
                long length,
                User user,
                WorkUnit.Type type,
                String activity,
                long breakTime,
                String comment)
Method Detail

overlapsWith

public boolean overlapsWith(WorkUnit unit)
only looks at the time, not at the user


hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
based on user, begin, type and length

Overrides:
equals in class Object

compareTo

public int compareTo(WorkUnit unit)
sorts by user, begin, type, length

Specified by:
compareTo in interface Comparable<WorkUnit>

isApproved

public boolean isApproved()
false by default


setApproved

public void setApproved(boolean flag)

setActivity

public void setActivity(String activity)

setComment

public void setComment(String comment)

getBegin

public Date getBegin()

getLength

public long getLength()
total length including breakTimes


getEnd

public Date getEnd()

getUser

public User getUser()

getType

public WorkUnit.Type getType()

getActivity

public String getActivity()

getComment

public String getComment()

getBreakTime

public long getBreakTime()

setBreakTime

public void setBreakTime(long breakTime)
                  throws IllegalArgumentException
Throws:
IllegalArgumentException

getNetLength

public long getNetLength()
returns the length minus the breakTime time


toString

public String toString()
Overrides:
toString in class Object

getTypeStrings

public static String[] getTypeStrings()
returns localized strings for all types

See Also:
getTypeForString(String)

getTypeForString

public static WorkUnit.Type getTypeForString(String s)
reverts the given String to a Type and returns it - or null if no corresponding type exists

See Also:
getTypeStrings()


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