krysalis-update/src/java/org/krysalis/depot/update/util/flag FlagMap.java,NONE,1.1 Flag.java,NONE,1.1 FlagSet.java,NONE,1.1

Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:07:18 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/util/flag
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/java/org/krysalis/depot/update/util/flag

Added Files:
	FlagMap.java Flag.java FlagSet.java 
Log Message:
Copied from the apache incubator.

--- NEW FILE: FlagSet.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.krysalis.depot.update.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;
	}
}

--- NEW FILE: Flag.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.krysalis.depot.update.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 ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.krysalis.depot.update.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;
	}
}



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/