ruper2/src/java/core/org/krysalis/ruper2/util/flag Flag.java,NONE,1.1 FlagMap.java,NONE,1.1 FlagSet.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/util/flag
In directory sc8-pr-cvs1:/tmp/cvs-serv15430/src/java/core/org/krysalis/ruper2/util/flag

Added Files:
	Flag.java FlagMap.java FlagSet.java 
Log Message:
Another stab at dependencies...

--- NEW FILE: Flag.java ---
/*
 * Created on Aug 26, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.krysalis.ruper2.util.flag;

/**
 * @author arb_jack
 */
public class Flag {
	private final String m_name;

	public final static Flag TRUE = new Flag("TRUE");
	public final static Flag FALSE = new Flag("FALSE");

	protected Flag(final String name) {
		m_name = name;
	}

	public String toString() {
		return m_name;
	}

	public boolean equals(Object other) {
		boolean equal = false;

		if (other instanceof Flag) {
			equal = m_name.equals(((Flag) other).m_name);
		}
		else
			throw new IllegalArgumentException("Not a Flag: " + other);

		return equal;
	}

	public int hashCode() {
		return m_name.hashCode();
	}
}

--- NEW FILE: FlagMap.java ---
/*
 * Created on Aug 26, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.krysalis.ruper2.util.flag;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
 * @author arb_jack
 */
public class FlagMap extends HashMap {

	/**
	 * 
	 */
	public FlagMap() {
		super();
	}

	/**
	 * @param arg0
	 */
	public FlagMap(int initialSize) {
		super(initialSize);
	}

	/**
	* Determines if this set has a particular capability.
	*
	* @param capability The capability to check for.
	*/
	public boolean hasFlag(Flag flag) {
		return containsKey(flag);
	}

	/**
	* Determines if this set has a particular set of flag.
	*
	* @param flag The capabilities to check for.
	*/
	public boolean hasFlags(List flags) {
		boolean hasEm = true;

		for (Iterator i = flags.iterator(); i.hasNext() && hasEm;) {
			hasEm &= hasFlag((Flag) i.next());
		}

		return hasEm;
	}
}

--- NEW FILE: FlagSet.java ---
/*
 * Created on Aug 26, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package org.krysalis.ruper2.util.flag;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @author arb_jack
 */
public class FlagSet extends ArrayList {

	/**
	 * 
	 */
	public FlagSet() {
		super();
	}

	public FlagSet(Flag flag) {
		super();
		add(flag);
	}

	/**
	 * @param arg0
	 */
	public FlagSet(int initialSize) {
		super(initialSize);
	}

	/**
	 * @param otherCollection -- set to copy from
	 */
	public FlagSet(Collection otherCollection) {
		super(otherCollection);
	}

	/**
	* Determines if this set has a particular capability.
	*
	* @param capability The capability to check for.
	*/
	public boolean hasFlag(Flag flag) {
		boolean hasIt = false;
		for (Iterator i = iterator(); i.hasNext() && !hasIt;) {
			hasIt = ((Flag) i.next()).equals(flag);
		}
		return hasIt;
	}

	/**
	* Determines if this set has a particular set of flag.
	*
	* @param flag The capabilities to check for.
	*/
	public boolean hasCapabilities(FlagSet capabilities) {
		boolean hasEm = true;

		for (Iterator i = capabilities.iterator(); i.hasNext() && hasEm;) {
			hasEm &= hasFlag((Flag) i.next());
		}

		return hasEm;
	}
}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.