/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (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.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.ui.conf;

import java.util.*;
import com.silverwrist.venice.core.ConferenceContext;

class TopicSortHolder
{
  /*--------------------------------------------------------------------------------
   * Internal class for holding view and sort options
   *--------------------------------------------------------------------------------
   */

  static class SortHolderItem
  {
    int view_opt;
    int sort_opt;

    SortHolderItem(int view_opt, int sort_opt)
    {
      this.view_opt = view_opt;
      this.sort_opt = sort_opt;

    } // end constructor

    final int getViewOption()
    {
      return view_opt;

    } // end getViewOption

    final void setViewOption(int val)
    {
      view_opt = val;

    } // end setViewOption

    final int getSortOption()
    {
      return sort_opt;

    } // end getSortOption

    final void setSortOption(int val)
    {
      sort_opt = val;

    } // end setSortOption

  } // end class SortHolderItem

  /*--------------------------------------------------------------------------------
   * Static data members
   *--------------------------------------------------------------------------------
   */

  protected static final int DEFAULT_VIEW = ConferenceContext.DISPLAY_ACTIVE;
  protected static final int DEFAULT_SORT = ConferenceContext.SORT_NUMBER;

  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private HashMap confid_to_item = new HashMap();

  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  TopicSortHolder()
  { // do nothing
  } // end constructor

  /*--------------------------------------------------------------------------------
   * Internal functions
   *--------------------------------------------------------------------------------
   */

  private final synchronized SortHolderItem getItem(int confid)
  {
    Integer the_confid = new Integer(confid);
    SortHolderItem item = (SortHolderItem)(confid_to_item.get(the_confid));
    if (item==null)
    { // create a new item...
      item = new SortHolderItem(DEFAULT_VIEW,DEFAULT_SORT);
      confid_to_item.put(the_confid,item);

    } // end if

    return item;

  } // end getItem

  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  final int getViewOption(int confid)
  {
    return getItem(confid).getViewOption();

  } // end getViewOption

  final void setViewOption(int confid, int opt)
  {
    getItem(confid).setViewOption(opt);

  } // end setViewOption

  final int getSortOption(int confid)
  {
    return getItem(confid).getSortOption();

  } // end getSortOption

  final void setSortOption(int confid, int opt)
  {
    getItem(confid).setSortOption(opt);

  } // end setSortOption

} // end class TopicSortHolder
