/**
* 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;
import org.pegadi.model.Article;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class NoGrouper implements Grouper {
private String name;
public NoGrouper(String name) {
this.name = name;
}
public NoGrouper() {
this("No grouper");
}
public String toString() {
return this.getName();
}
public String getName() {
return name;
}
public GroupedArticles group(Article[] articles, Comparator comparator) {
ArrayList[] tempArrayListOut = new ArrayList[1];
tempArrayListOut[0] = new ArrayList();
GroupedArticles groupedArticles = new GroupedArticles();
// now, iterate over all the articles, and duplicating
// them into the correct ArrayList
for (Article article : articles) tempArrayListOut[0].add(article);
// Sort all the arraylists
for (ArrayList aTempArrayListOut : tempArrayListOut) Collections.sort(aTempArrayListOut, comparator);
// update the group headers
String[] tempHeaders = new String[1];
tempHeaders[0] = "";
// update the group sums
ArticleSum[] tempSums = new ArticleSum[1];
tempSums[0] = new ArticleSum();
for (Object o : tempArrayListOut[0]) {
Article tempArticle = (Article) o;
int tempInt = tempArticle.getWantedNumberOfCharacters();
tempSums[0].add(tempInt);
}
// update, and return the results.
groupedArticles.setNumberOfGroups(1);
groupedArticles.setGroupedArticles(tempArrayListOut);
groupedArticles.setGroupHeaders(tempHeaders);
groupedArticles.setGroupSums(tempSums);
return groupedArticles;
}
}