Java tutorial
/******************************************************************************* * Copyright (c) 2010 David Harrison. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl-3.0.html * * Contributors: * David Harrison - initial API and implementation ******************************************************************************/ package com.sfs.whichdoctor.formatter; import com.sfs.Formatter; import com.sfs.whichdoctor.beans.AgedDebtorsGrouping; import com.sfs.whichdoctor.beans.AgedDebtorsRecord; import java.util.ArrayList; import java.util.Collection; import org.apache.commons.lang.StringUtils; /** * The Class AgedDebtorsAnalysisFormatter. */ public class AgedDebtorsAnalysisFormatter { /** * Gets the field. * * @param grouping the grouping * @param field the field * @param format the format * @return the field */ public static String getField(final AgedDebtorsGrouping grouping, final String field, final String format) { String value = ""; if (grouping == null || field == null) { return value; } if (StringUtils.equalsIgnoreCase(field, "Grouping")) { value = grouping.getName(); if (StringUtils.isBlank(value)) { value = "Uncategorised"; } } if (StringUtils.equalsIgnoreCase(field, "Total")) { value = Formatter.toCurrency(grouping.getTotal(), "$"); if (StringUtils.equalsIgnoreCase(format, "html")) { value = "<div style=\"text-align: right\">" + value + "</div>"; } } if (value == null) { value = ""; } return value; } /** * Gets the field. * * @param record the record * @param section the section * @param field the field * @param format the format * @return the field */ public static String getField(final AgedDebtorsRecord record, final String section, final String field, final String format) { String value = ""; if (section == null) { return value; } if (field == null) { return value; } if (StringUtils.equalsIgnoreCase(field, "GUID")) { value = String.valueOf(record.getPersonGUID()); if (record.getOrganisationGUID() > 0) { value = String.valueOf(record.getOrganisationGUID()); } } if (StringUtils.equalsIgnoreCase(field, "MIN")) { if (record.getPerson() != null) { value = String.valueOf(record.getPerson().getPersonIdentifier()); } } if (StringUtils.equalsIgnoreCase(field, "Person")) { if (record.getPerson() != null) { value = OutputFormatter.toCasualName(record.getPerson()); } } if (StringUtils.equalsIgnoreCase(field, "Organisation")) { if (record.getOrganisation() != null) { value = record.getOrganisation().getName(); } } if (StringUtils.equalsIgnoreCase(field, "Last Receipt Prefix")) { if (record.getLastReceipt() != null) { value = record.getLastReceipt().getAbbreviation(); } } if (StringUtils.equalsIgnoreCase(field, "Last Receipt Number")) { if (record.getLastReceipt() != null) { value = record.getLastReceipt().getNumber(); } } if (StringUtils.equalsIgnoreCase(field, "Last Receipt Issued Date")) { if (record.getLastReceipt() != null) { value = Formatter.conventionalDate(record.getLastReceipt().getIssued()); } } if (StringUtils.equalsIgnoreCase(field, "Last Receipt Value")) { if (record.getLastReceipt() != null) { value = Formatter.toCurrency(record.getLastReceipt().getNetValue(), "$"); if (StringUtils.equalsIgnoreCase(format, "html")) { value = "<div style=\"text-align: right\">" + value + "</div>"; } } } if (StringUtils.equalsIgnoreCase(field, "Total")) { value = Formatter.toCurrency(record.getTotal(), "$"); if (StringUtils.equalsIgnoreCase(format, "html")) { value = "<div style=\"text-align: right\">" + value + "</div>"; } } if (value == null) { value = ""; } return value; } /** * Gets the collection. * * @param revenue the revenue * @param section the section * @return the collection */ public static Collection<Object> getCollection(final AgedDebtorsGrouping grouping, final String section) { Collection<Object> collection = new ArrayList<Object>(); if (StringUtils.equalsIgnoreCase(section, "Records")) { if (grouping.getRecords() != null) { for (String order : grouping.getRecords().keySet()) { AgedDebtorsRecord record = grouping.getRecords().get(order); if (record != null) { collection.add(record); } } } } return collection; } }