com.angstoverseer.service.command.handler.dto.TimeTrackingReportTotal.java Source code

Java tutorial

Introduction

Here is the source code for com.angstoverseer.service.command.handler.dto.TimeTrackingReportTotal.java

Source

/* 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.angstoverseer.service.command.handler.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.appengine.repackaged.org.apache.commons.httpclient.util.DateUtil;
import com.google.appengine.repackaged.org.joda.time.Period;
import org.apache.commons.lang.StringUtils;

public class TimeTrackingReportTotal implements Serializable {
    private static final long serialVersionUID = 1L;

    private Period sum;
    private Map<String, Period> issueMap;

    public TimeTrackingReportTotal() {
        setSum(new Period());
        setIssueMap(new HashMap<String, Period>());
    }

    public List<String> getDetails() {
        List<String> descriptionList = new ArrayList<String>();
        for (Map.Entry entry : issueMap.entrySet()) {
            descriptionList.add("#" + entry.getKey() + ": " + formatPeriod(((Period) entry.getValue())));
        }
        descriptionList.add("Valid: " + formatPeriod(sum));

        return descriptionList;
    }

    public Period getSum() {
        return sum;
    }

    public void setSum(Period total) {
        this.sum = total;
    }

    public Map<String, Period> getIssueMap() {
        return issueMap;
    }

    public void setIssueMap(Map<String, Period> issueMap) {
        this.issueMap = issueMap;
    }

    public String formatPeriod(Period period) {
        int hours = period.getHours();
        int minutes = period.getMinutes();
        while (minutes > 59) {
            hours++;
            minutes -= 60;
        }

        return StringUtils.leftPad(Integer.toString(hours), 2, "0") + ":"
                + StringUtils.leftPad(Integer.toString(minutes), 2, "0");
    }
}