/** * Copyright 1999-2009 The Pegadi Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.pegadi.articlelist; /** * Title: <p> * Description: <p> * Copyright: Copyright (c) <p> * Company: <p> * @author * @version 1.0 */ import org.pegadi.model.Article; import java.util.ArrayList; import java.util.Comparator; public class GroupedArticles { protected Comparator comparator; protected Comparator defaultComparator = new ArticleByArticleNameComparator(); protected Grouper grouper; protected Grouper defaultGrouper = new ArticleTypeGrouper(); protected Article[] baseArticles; protected ArrayList[] groupedArticles; protected ArrayList groupIndexes; protected String[] groupHeaders; protected ArticleSum[] groupSums; protected int numberOfGroups; public GroupedArticles() { } public GroupedArticles(Article[] articles) { init(articles, defaultGrouper, defaultComparator); } public GroupedArticles(Article[] articles, Grouper grouper) { init(articles, grouper, defaultComparator); } public GroupedArticles(Article[] articles, Grouper grouper, Comparator comparator) { init(articles, grouper, comparator); } public GroupedArticles(Article[] articles, Comparator comparator, Grouper grouper) { init(articles, grouper, comparator); } protected void init(Article[] articles, Grouper grouper, Comparator comparator) { this.baseArticles = articles; this.comparator = comparator; this.grouper = grouper; this.grouper.group(baseArticles, comparator); } public void regroup(Grouper grouper) { this.grouper = grouper; this.grouper.group(baseArticles, this.comparator); } public void regroup(Grouper grouper, Comparator comparator) { this.grouper = grouper; this.comparator = comparator; this.grouper.group(baseArticles, comparator); } public void resort(Comparator comparator) { this.comparator = comparator; grouper.group(baseArticles, comparator); } ///////////////////////////////// // Get() and set() methods below here // // Group articles; // public ArrayList[] getGroupedArticles() { return groupedArticles; } public void setGroupedArticles(ArrayList[] articles) { groupedArticles = articles; } public ArrayList getGroupOfArticles(int index) { return groupedArticles[index]; } // // Group headers // public String[] getGroupHeaders() { return groupHeaders; } public String getGroupHeader(int index) { return groupHeaders[index]; } public void setGroupHeaders(String[] groupHeaders) { this.groupHeaders = groupHeaders; } // // Group sums // public ArticleSum[] getGroupSums() { return groupSums; } public ArticleSum getGroupSum(int index) { return groupSums[index]; } public void setGroupSums(ArticleSum[] groupSums) { this.groupSums = groupSums; } // // Number of groups // public int getNumberOfGroups() { return numberOfGroups; } public void setNumberOfGroups(int value) { this.numberOfGroups = value; } }