Search in sources :

Example 1 with CategoryOrderComparator

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);
}
Also used : Category(net.jforum.entities.Category) TreeSet(java.util.TreeSet) Set(java.util.Set) CategoryOrderComparator(net.jforum.util.CategoryOrderComparator) TreeSet(java.util.TreeSet)

Example 2 with CategoryOrderComparator

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);
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) CategoryOrderComparator(net.jforum.util.CategoryOrderComparator) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) Forum(net.jforum.entities.Forum)

Example 3 with CategoryOrderComparator

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);
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) Category(net.jforum.entities.Category) CategoryOrderComparator(net.jforum.util.CategoryOrderComparator) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Set (java.util.Set)3 TreeSet (java.util.TreeSet)3 CategoryOrderComparator (net.jforum.util.CategoryOrderComparator)3 Iterator (java.util.Iterator)2 Category (net.jforum.entities.Category)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Forum (net.jforum.entities.Forum)1