⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timecarddto.java

📁 考勤管理系统源码
💻 JAVA
字号:
package com.wiley.compBooks.EJwithUML.Dtos;

import java.util.*;
import java.io.*;
import com.wiley.compBooks.EJwithUML.Base.DateUtil;
import com.wiley.compBooks.EJwithUML.Base.ApplicationExceptions.InvalidDataException;
import com.wiley.compBooks.EJwithUML.Base.ApplicationExceptions.Origin;

public class TimecardDTO implements Serializable
{
  private Date startDate;
  private Date endDate;
  private ArrayList entries = new ArrayList();

  public TimecardDTO(Date start, Date end)
  {
    this.startDate = start;
    this.endDate = end;
  }

  public int getTotalEntries()
  {
    return this.entries.size();
  }

  public Date getStartDate()
  {
    return this.startDate;
  }

  public void setStartDate(Date date)
  {
    this.endDate = date;
  }

 public Date getEndDate()
 {
   return this.endDate;
 }

 public void setEndDate(Date date)
 {
   this.endDate = date;
 }

  public int getTotalHoursWorked()
  {
    int total = 0;
    Iterator entryIterator = entries.iterator();
    while(entryIterator.hasNext())
    {
      TimeEntryDTO entry = (TimeEntryDTO) entryIterator.next();
      total = total + entry.getHours();
    }
    return total;
  }

  public Iterator getEntries()
  {
    return this.entries.iterator();
  }

  public void addEntry(TimeEntryDTO entry) throws InvalidDataException
  {
    if (DateUtil.isWithinDateRangeInclusive(startDate, endDate, entry.getDate()))
    {
      this.entries.add(entry);
      //sets the id to an incomplete value. TimecarWorkflowBean adds the timecard
      // id to it before actual insertion into the database.
      if (entry.isNew())
      {
        entry.setId((getTotalEntries())+"");
      }
    }
    else
    {
      throw new InvalidDataException(Origin.DTO,
      "timeentry date is outside the timecard date range.");
    }
  }

  public String toString()
 {
   StringBuffer buffer = new StringBuffer();
   Iterator entryIterator = entries.iterator();
   int count = 0;
   buffer.append("Timecard[start date ="+ DateUtil.toDateString(startDate) +
                 ",end date = " + DateUtil.toDateString(endDate));
   while(entryIterator.hasNext())
   {
     count++;
     TimeEntryDTO entry = (TimeEntryDTO) entryIterator.next();
     buffer.append( ",#"+count+"{" + entry + "}");
   }
   buffer.append("]");
   return buffer.toString();
 }

 public  int hashCode()
 {
   return (startDate.hashCode() ^ endDate.hashCode() ^ entries.hashCode());
 }

 public boolean equals(Object obj)
 {
   if (obj == null)
   {
     return false;
   }
   else
   {
     if (!obj.getClass().equals(this.getClass()))
     {
       return false;
     }
     else
     {
       TimecardDTO entry = (TimecardDTO)obj;
       return ((entry.startDate.equals(this.startDate)) &&
               (entry.endDate.equals(this.endDate)) &&
               (entry.entries.equals(this.entries)));
     }
   }
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -