FileDocCategorySizeDatePackage
Report.javaAPI DocExample6026Tue Jun 08 11:26:42 BST 2004com.mycompany.expense

Report

public class Report extends Object implements Serializable
This class represents a report in the ReportRegistry.
author
Hans Bergsten, Gefion Software
version
1.0

Fields Summary
public static final int
STATUS_NEW
public static final int
STATUS_OPEN
public static final int
STATUS_SUBMITTED
public static final int
STATUS_ACCEPTED
public static final int
STATUS_REJECTED
private int
currentEntryId
private int
id
private String
title
private String
owner
private int
status
private Map
entries
Constructors Summary
public Report()
Creates a new, empty instance.


              
      
        entries = new HashMap();
    
public Report(Report src)
Creates an instance that is a copy of the provided instance.

        setId(src.getId());
        setTitle(src.getTitle());
        setOwner(src.getOwner());
        setStatus(src.getStatus());
        setEntries(src.copyEntries());
        setCurrentEntryId(src.getCurrentEntryId());
    
Methods Summary
public synchronized voidaddEntry(ReportEntry entry)
Sets the "id" property of the provided ReportEntry and saves a copy of the ReportEntry (so that changes to the provided instance doesn't change the content of the report).

        entry.setId(currentEntryId++);
        entries.put(new Integer(entry.getId()), new ReportEntry(entry));
    
private java.util.MapcopyEntries()
Returns a Map with copies of all entries.

        Map copy = new HashMap();
        Iterator i = entries.entrySet().iterator();
        while (i.hasNext()) {
            Map.Entry e = (Map.Entry) i.next();
            copy.put(e.getKey(), new ReportEntry((ReportEntry) e.getValue()));
        }
        return copy;
    
private intgetCurrentEntryId()
Returns the current ID value.

        return currentEntryId;
    
public synchronized java.util.DategetEndDate()
Returns the report end date.

        Date date = null;
        if (!entries.isEmpty()) {
            List l = getEntriesSortedByDate();
            date = ((ReportEntry) l.get(entries.size() - 1)).getDate();
        }
        return date;
    
public synchronized java.util.ListgetEntries()
Returns a List with copies of all entries.

        return new ArrayList(copyEntries().values());
    
private java.util.ListgetEntriesSortedByDate()
Returns all entries sorted by date.

        List l = getEntries();
        Collections.sort(l, new Comparator() {
                public int compare(Object o1, Object o2) {
                    Date d1 = ((ReportEntry) o1).getDate();
                    Date d2 = ((ReportEntry) o2).getDate();
                    return d1.compareTo(d2);
                }
        });
        return l;
    
public synchronized ReportEntrygetEntry(int id)
Returns a copy of the entry with the specified ID.

        return new ReportEntry((ReportEntry) entries.get(new Integer(id)));
    
public synchronized intgetId()
Returns the report ID.

        return id;
    
public synchronized java.lang.StringgetOwner()
Returns the report owner.

        return owner;
    
public synchronized java.util.DategetStartDate()
Returns the report start date.

        Date date = null;
        if (!entries.isEmpty()) {
            List l = getEntriesSortedByDate();
            date = ((ReportEntry) l.get(0)).getDate();
        }
        return date;
    
public synchronized intgetStatus()
Returns the report status.

        return status;
    
public synchronized java.lang.StringgetTitle()
Returns the report title.

        return title;
    
public synchronized doublegetTotal()
Returns the total of all entry amounts.

        double total = 0;
        Iterator i = entries.values().iterator();
        while (i.hasNext()) {
            ReportEntry e = (ReportEntry) i.next();
            total += e.getAmount();
        }
        return total;
    
public synchronized voidremoveEntry(int id)
Removes the entry with the specified ID.

        entries.remove(new Integer(id));
    
private voidsetCurrentEntryId(int currentEntryId)
Sets the current ID value.

        this.currentEntryId = currentEntryId;
    
private voidsetEntries(java.util.Map entries)
Sets the entries.

        this.entries = entries;
    
public synchronized voidsetId(int id)
Sets the report ID.

        this.id = id;
    
public synchronized voidsetOwner(java.lang.String owner)
Sets the report owner.

        this.owner = owner;
    
public synchronized voidsetStatus(int status)
Sets the report status.

        this.status = status;
    
public synchronized voidsetTitle(java.lang.String title)
Sets the report title.

        this.title = title;
    
public java.lang.StringtoString()
Returns a String with all report properties.

        return "id: " + id + " title: " + getTitle() + 
            " owner: " + getOwner() +
            " startDate: " + getStartDate() + " endDate: " + getEndDate() +
            " status: " + getStatus();