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

📄 totalwrappertemplate.java

📁 一个比较不错的java分页标签,有源代码,开发者 可以学习学习
💻 JAVA
字号:
/**
 * Licensed under the Artistic License; you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://displaytag.sourceforge.net/license.html
 *
 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
package org.displaytag.sample.decorators;

import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.displaytag.decorator.TableDecorator;
import org.displaytag.sample.ReportableListObject;


/**
 * Same idea implemented in TableWriterTemplate applied to decorators.
 * @see org.displaytag.render.TableWriterTemplate
 * @author Jorge L. Barroso
 * @version $Revision$ ($Author$)
 */
public abstract class TotalWrapperTemplate extends TableDecorator
{

    /**
     * total amount.
     */
    private double grandTotal;

    /**
     * total amount for city.
     */
    private double cityTotal;

    /**
     * Obtain the <code>StringBuffer</code> used to build the totals line.
     */
    private StringBuffer buffer;

    /**
     * After every row completes we evaluate to see if we should be drawing a new total line and summing the results
     * from the previous group.
     * @return String
     */
    public final String finishRow()
    {
        int listindex = ((List) getDecoratedObject()).indexOf(this.getCurrentRowObject());
        ReportableListObject reportableObject = (ReportableListObject) this.getCurrentRowObject();
        String nextCity = null;

        this.cityTotal += reportableObject.getAmount();
        this.grandTotal += reportableObject.getAmount();

        if (listindex != ((List) getDecoratedObject()).size() - 1)
        {
            nextCity = ((ReportableListObject) ((List) getDecoratedObject()).get(listindex + 1)).getCity();
        }

        this.buffer = new StringBuffer(1000);

        // City subtotals...
        if (!ObjectUtils.equals(nextCity, reportableObject.getCity()))
        {
            writeCityTotal(reportableObject.getCity(), this.cityTotal);
            this.cityTotal = 0;
        }

        // Grand totals...
        if (getViewIndex() == ((List) getDecoratedObject()).size() - 1)
        {
            writeGrandTotal(this.grandTotal);
        }

        return buffer.toString();
    }

    /**
     * Render the city total in the appropriate format.
     * @param city The city name to render.
     * @param total The city total to render.
     */
    abstract protected void writeCityTotal(String city, double total);

    /**
     * Render the grand total in the appropriate format.
     * @param total The grand total to render.
     */
    abstract protected void writeGrandTotal(double total);

    /**
     * Obtain the <code>StringBuffer</code> used to build the totals line.
     * @return The <code>StringBuffer</code> used to build the totals line.
     */
    protected StringBuffer getStringBuffer()
    {
        return this.buffer;
    }
}

⌨️ 快捷键说明

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