use of net.jforum.util.CategoryOrderComparator in project jforum2 by rafaelsteil.
the class ForumRepository method reloadCategory.
/**
* Updates some category.
* This method only updated the "name" and "order" fields.
*
* @param c The category to update. The method will search for a category
* with the same id and update its data.
*/
public static synchronized void reloadCategory(Category c) {
Category current = (Category) cache.get(FQN, Integer.toString(c.getId()));
Category currentAtOrder = findCategoryByOrder(c.getOrder());
Set tmpSet = new TreeSet(new CategoryOrderComparator());
tmpSet.addAll((Set) cache.get(FQN, CATEGORIES_SET));
if (currentAtOrder != null) {
tmpSet.remove(currentAtOrder);
cache.remove(FQN, Integer.toString(currentAtOrder.getId()));
}
tmpSet.add(c);
cache.add(FQN, Integer.toString(c.getId()), c);
if (currentAtOrder != null && c.getId() != currentAtOrder.getId()) {
tmpSet.remove(current);
currentAtOrder.setOrder(current.getOrder());
tmpSet.add(currentAtOrder);
cache.add(FQN, Integer.toString(currentAtOrder.getId()), currentAtOrder);
}
cache.add(FQN, CATEGORIES_SET, tmpSet);
}
use of net.jforum.util.CategoryOrderComparator in project jforum2 by rafaelsteil.
the class ForumRepository method addCategory.
/**
* Adds a new category to the cache.
* @param c The category instance to insert in the cache.
*/
public static synchronized void addCategory(Category c) {
String categoryId = Integer.toString(c.getId());
cache.add(FQN, categoryId, c);
Set s = (Set) cache.get(FQN, CATEGORIES_SET);
if (s == null) {
s = new TreeSet(new CategoryOrderComparator());
}
s.add(c);
cache.add(FQN, CATEGORIES_SET, s);
Map relation = (Map) cache.get(FQN, RELATION);
if (relation == null) {
relation = new HashMap();
}
for (Iterator iter = c.getForums().iterator(); iter.hasNext(); ) {
Forum f = (Forum) iter.next();
relation.put(Integer.toString(f.getId()), categoryId);
}
cache.add(FQN, RELATION, relation);
}
use of net.jforum.util.CategoryOrderComparator in project jforum2 by rafaelsteil.
the class ForumRepository method loadCategories.
/**
* Loads all categories.
* @param cm CategoryDAO
*/
private void loadCategories(CategoryDAO cm) {
List categories = cm.selectAll();
Set categoriesSet = new TreeSet(new CategoryOrderComparator());
for (Iterator iter = categories.iterator(); iter.hasNext(); ) {
Category c = (Category) iter.next();
cache.add(FQN, Integer.toString(c.getId()), c);
categoriesSet.add(c);
}
cache.add(FQN, CATEGORIES_SET, categoriesSet);
}
Aggregations