krysalis-update/src/java/org/krysalis/depot/update/util/select/logic/.svn/text-base AndSelector.java.svn-base,NONE,1.1 BooleanSelector.java.svn-base,NONE,1.1 NotSelector.java.svn-base,NONE,1.1 OrSelector.java.svn-base,NONE,1.1

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

Added Files:
	AndSelector.java.svn-base BooleanSelector.java.svn-base 
	NotSelector.java.svn-base OrSelector.java.svn-base 
Log Message:
Copied from the apache incubator.

--- NEW FILE: AndSelector.java.svn-base ---
/*
 * 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.select.logic;

import java.util.Iterator;

import org.krysalis.depot.update.util.select.CompositeSelector;
import org.krysalis.depot.update.util.select.ISelector;

public class AndSelector extends CompositeSelector {

	public AndSelector(){
	}
	
	public AndSelector(ISelector first, ISelector second) {
		super();

		addSelector(first);
		addSelector(second);
	}
	

	public boolean select(Object o) throws Exception {
		boolean isSelected = true;
		Iterator childIter = childIterator();
		while (childIter.hasNext() && isSelected) {
			ISelector child = (ISelector) childIter.next();
			isSelected = child.select(o);
		}
		return isSelected;
	}
}

--- NEW FILE: OrSelector.java.svn-base ---
/*
 * 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.select.logic;

import java.util.Iterator;

import org.krysalis.depot.update.util.select.CompositeSelector;
import org.krysalis.depot.update.util.select.ISelector;

public class OrSelector extends CompositeSelector{

	public OrSelector(){
	}
	
	public OrSelector(ISelector first, ISelector second) {
		super();

		addSelector(first);
		addSelector(second);
	}
	
    public boolean select(Object o) throws Exception {
        boolean isSelected = true;
        if( hasChildren() ) {
            Iterator childIter = childIterator();
            isSelected = false;
            while (childIter.hasNext() && !isSelected ) {
                ISelector child = (ISelector) childIter.next();
                isSelected = child.select(o);
            }
        }
        return isSelected;
    }
}

--- NEW FILE: BooleanSelector.java.svn-base ---
/*
 * 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.select.logic;

import org.krysalis.depot.update.util.select.ISelector;

public class BooleanSelector implements ISelector {
    private boolean m_result = false;

    /** Selector that always returns true */
    public final static ISelector TRUE = new BooleanSelector( true );
    /** Selector that always returns false */
    public final static ISelector FALSE = new BooleanSelector( false );

    /**
     * Constructor
     * @param result Result that select should return
     */
    public BooleanSelector(boolean result) {
        m_result = result;
    }

    public boolean select(Object o) throws Exception {
        return m_result;
    }

    public boolean equals(Object obj) {
        boolean isEqual = false;
        if( obj instanceof BooleanSelector ) {
            BooleanSelector rhs = (BooleanSelector) obj;
            if( this.m_result == rhs.m_result ) {
                isEqual = true;
            }
        }
        return isEqual;
    }

    public int hashCode() {
        // BPS: Should make these hashes prime????
        if( m_result ) {
            return 15935;
        } else {
            return 17932;
        }
    }
}

--- NEW FILE: NotSelector.java.svn-base ---
/*
 * 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.select.logic;

import org.krysalis.depot.update.util.select.ISelector;

public class NotSelector implements ISelector {

    // Initialise to Boolean true so that
    // a) We don't have to check for nulls
    // b) The default select will return false
    private ISelector m_child = BooleanSelector.TRUE;

    /**
     * Constructor
     */
    public NotSelector() {

    }

    /**
     * Constructor
     * @param selector The selector to invert
     */
    public NotSelector( ISelector selector) {
        m_child = selector;
    }

    public boolean select(Object o) throws Exception {
        return !m_child.select(o);
    }

    /**
     * Set the selector that will be inverted
     * @param selector Selector to be inverted
     */
    public void setSelector(ISelector selector) {
        if( selector == null ) {
            throw new IllegalArgumentException("Can't set null selector");
        }
        m_child = selector;
    }


    public int hashCode() {
        int notHash = getClass().hashCode();
        return notHash * 67 + m_child.hashCode();
    }

    public boolean equals(Object obj) {
        boolean isEqual = false;
        if( obj instanceof NotSelector ) {
            NotSelector rhs = (NotSelector) obj;
            isEqual = m_child.equals( rhs.m_child );
        }
        return isEqual;
    }
}



-------------------------------------------------------
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/