⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groupmanager.java

📁 JAVA平台下优秀的CHART开源代码,可以实现类似EXCEL中的二维或三维的饼图/椎图功能.
💻 JAVA
字号:
/**
 * Copyright (C) 2003  Manfred Andres
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package freecs.core;

import freecs.*;
import freecs.interfaces.*;

import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Iterator;
/**
 * The GroupManager manages all groups. It is a single instantiable Thread
 *
 * freecs.core
 */
public class GroupManager implements IGroupState {
   public static final GroupManager mgr = new GroupManager ();
   private Hashtable grps;
   private int highWaterMark=0;
   private Vector moderatedGroups;

	private GroupManager () {
		grps = new Hashtable ();
		Vector sGrps = Server.srv.getStartingGroups ();
		moderatedGroups=new Vector();
		if (sGrps.isEmpty ()) {
			Server.log ("There are no starting-groups deffined!", Server.MSG_ERROR, Server.LVL_HALT);
      	}
		for (Enumeration e = sGrps.elements (); e.hasMoreElements ();) {
			Group cg = (Group) e.nextElement ();
			grps.put (cg.getName (), cg);
		}
		highWaterMark = grps.size();
	}

   /**
    * adds a group
    * @param g the Group to add
    */
	public void addGroup (Group g) {
		grps.put (g.getName ().toLowerCase (), g);
		if (grps.size () > highWaterMark)
			highWaterMark = grps.size();
	}
	
	public int getHighWaterMark () {
		return highWaterMark;
	}

   /**
    * removes a group
    * @param gName the name of the group to remove
    */
   public void removeGroup (String gName) {
      grps.remove (gName.toLowerCase ().trim());
   }

   /**
    * Return the group identified by gName
    * @param gName the name of this group
    * @return the group identified by gName || null if none existent
    */
	public Group getGroup (String gName) {
		if (gName==null) 
			return null;
		return (Group) grps.get (gName.toLowerCase ().trim());
	}

	/**
	 * Return the startinggroup identified by gName
	 * @param gName
	 * @return the group identified by gName || null if none existent
	 */
   public Group getStartingGroup (String gName) {
   	  Group g;
      g = (Group) grps.get (gName.toLowerCase ().trim());
      if (g == null) return null;
      if (!Server.srv.isStartingGroup (g)) {
         return null;
      }
      return g;
   }

	/**
	 * Opens a new group
	 * @param groupname The name of the group
	 * @param topic The theme to use for this group (possible null)
	 * @param opener The opener of this group
	 * @return
	 */
   public Group openGroup (String groupname, String topic, User opener) {
      return openGroup (groupname, topic, opener, opener);
   }

	/**
	 * Opens a new group checking the rights of another user
	 * @param groupname The name of the group
	 * @param topic The theme to use for this group (possible null)
	 * @param opener The opener of this group
	 * @param rUser The user to check the rights for opening this group
	 * @return
	 */
	public Group openGroup (String groupname, String topic, User opener, User rUser) {
		boolean moderated = moderatedGroups.contains(groupname.trim().toLowerCase());
		if (moderated && !rUser.hasRight(IUserRights.MAY_OPEN_SU_GROUP))
				return null;
		Group g;
		g = getGroup(groupname);
		if (g != null || !rUser.hasRight (IUserRights.MAY_OPEN_GROUP)) 
			return null;
		g = new Group (groupname, topic);
		if (moderated) {
			g.setState(IGroupState.MODERATED);
		}
		g.addUser (opener);
		addGroup (g);
		return g;
}

	/**
	 * returns the number of open groups managed by this groupmanager
	 * @return the number of open groups
	 */
   public int size () {
      return grps.size ();
   }

	public int openGroupsCount() {
		int i = grps.size();
		Vector v = Server.srv.getStartingGroups();
		for (Enumeration e = v.elements(); e.hasMoreElements(); ) {
			Group g = (Group) e.nextElement();
			if (g.size()==0)
				i--;
		}
		return i;
	}

	/**
	 * returns an iterator to loop over all groups managed by this groupmanager
	 * @return iterator to loop over all groups
	 */
   public Iterator groups () {
      return grps.values ().iterator ();
   }
   
	public void updateModeratedGroups (Vector mg) {
   		Vector removed = (Vector) moderatedGroups.clone();
   		removed.removeAll(mg);
   		Vector added = (Vector) mg.clone();
   		added.removeAll(moderatedGroups);
   		for (Enumeration e = removed.elements(); e.hasMoreElements(); ) {
   			Group g = getGroup ((String) e.nextElement());
   			if (g==null)
   				continue;
			while (moderatedGroups.contains(g))
				moderatedGroups.remove(g);
   			g.unsetState (IGroupState.MODERATED);
   			g.setState(IGroupState.OPEN);
   		}
   		for (Enumeration e = added.elements(); e.hasMoreElements(); ) {
   			String gName = (String) e.nextElement();
   			moderatedGroups.add(gName);
   			Group g = getGroup (gName);
   			moderatedGroups.add(g);
   			if (g==null)
   				continue;
   			g.setState(IGroupState.MODERATED);
   			g.unsetState (IGroupState.OPEN);
   			
   		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -