krysalis-version/src/java/org/krysalis/version/impl/release/util ReleaseLevelComparison.java,NONE,1.1 ReleaseLevelRange.java,NONE,1.1 ReleaseLevelIterator.java,NONE,1.1

[email protected] Sun, 23 Mar 2003 17:25:48 -0800
Newsgroups gmane.comp.krysalis.sandbox
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/impl/release/util
In directory sc8-pr-cvs1:/tmp/cvs-serv27679/src/java/org/krysalis/version/impl/release/util

Added Files:
	ReleaseLevelComparison.java ReleaseLevelRange.java 
	ReleaseLevelIterator.java 
Log Message:
Cleaned up package naming

--- NEW FILE: ReleaseLevelComparison.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01

Copyright (c) 2002-2003 Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.

3. The end-user documentation included with the redistribution,
   if any, must include the following acknowledgment:
      "This product includes software developed for project 
       Krysalis (http://www.krysalis.org/)."
   Alternately, this acknowledgment may appear in the software itself,
   if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
   "Krysalis Centipede" must not be used to endorse or promote products
   derived from this software without prior written permission. For
   written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
   "Krysalis Centipede", nor may "Krysalis" appear in their name, without
    prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
   individuals, who decided to donate the code to this project in respect 
   of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.version.impl.release.util;

import org.krysalis.version.exception.VersionError;
import org.krysalis.version.impl.data.ReleaseLevel;

/**
 * @author ajack
 */
public class ReleaseLevelComparison {
    private static final int TYPE_UNSET = 0;
    private static final int TYPE_LESS_THAN = 1;
    private static final int TYPE_LESS_THAN_OR_EQUAL = 2;
    private static final int TYPE_EQUAL = 3;
    private static final int TYPE_NOT_EQUAL = 4;
    private static final int TYPE_GREATER_THAN = 5;
    private static final int TYPE_GREATER_THAN_OR_EQUAL = 6;

    /*public static final ReleaseLevelComparison UNSET =
        new ReleaseLevelComparison(TYPE_UNSET);
    
    public static final ReleaseLevelComparison LESS_THAN =
        new ReleaseLevelComparison(TYPE_LESS_THAN);
    
    public static final ReleaseLevelComparison LESS_THAN_OR_EQUAL =
        new ReleaseLevelComparison(TYPE_LESS_THAN_OR_EQUAL);
    
    public static final ReleaseLevelComparison EQUAL =
        new ReleaseLevelComparison(TYPE_EQUAL);
    
    public static final ReleaseLevelComparison GREATER_THAN =
        new ReleaseLevelComparison(TYPE_GREATER_THAN);
    
    public static final ReleaseLevelComparison GREATER_THAN_OR_EQUAL =
        new ReleaseLevelComparison(TYPE_GREATER_THAN_OR_EQUAL);
    */
    private int m_type = TYPE_UNSET;
    private ReleaseLevel m_comparitor = null;

    public static ReleaseLevelComparison getEqual(ReleaseLevel comparitor) {
        return new ReleaseLevelComparison(TYPE_EQUAL, comparitor);
    }

    public static ReleaseLevelComparison getNotEqual(ReleaseLevel comparitor) {
        return new ReleaseLevelComparison(TYPE_NOT_EQUAL, comparitor);
    }

    public static ReleaseLevelComparison getLessThan(ReleaseLevel comparitor) {
        return new ReleaseLevelComparison(TYPE_LESS_THAN, comparitor);
    }

    public static ReleaseLevelComparison getLessThanOrEqual(ReleaseLevel comparitor) {
        return new ReleaseLevelComparison(TYPE_LESS_THAN_OR_EQUAL, comparitor);
    }

    public static ReleaseLevelComparison getGreaterThan(ReleaseLevel comparitor) {
        return new ReleaseLevelComparison(TYPE_GREATER_THAN, comparitor);
    }

    public static ReleaseLevelComparison getGreaterThanOrEqual(ReleaseLevel comparitor) {
        return new ReleaseLevelComparison(
            TYPE_GREATER_THAN_OR_EQUAL,
            comparitor);
    }

    ReleaseLevelComparison(int type, ReleaseLevel comparitor) {
        m_type = type;
        m_comparitor = comparitor;
    }

    ReleaseLevelComparison(ReleaseLevel comparitor) {
        m_type = TYPE_EQUAL;
        m_comparitor = comparitor;
    }

    public static boolean isEqual(ReleaseLevelComparison comp) {
        return TYPE_EQUAL == comp.m_type;
    }

    public static boolean isNotEqual(ReleaseLevelComparison comp) {
        return TYPE_NOT_EQUAL == comp.m_type;
    }

    public static boolean isLessThan(ReleaseLevelComparison comp) {
        return TYPE_LESS_THAN == comp.m_type;
    }

    public static boolean isLessThanOrEqual(ReleaseLevelComparison comp) {
        return TYPE_LESS_THAN_OR_EQUAL == comp.m_type;
    }

    public static boolean isLowerFacing(ReleaseLevelComparison comp) {
        return (isLessThanOrEqual(comp) || isLessThan(comp));
    }

    public static boolean isGreaterThan(ReleaseLevelComparison comp) {
        return TYPE_GREATER_THAN == comp.m_type;
    }

    public static boolean isGreaterThanOrEqual(ReleaseLevelComparison comp) {
        return TYPE_GREATER_THAN_OR_EQUAL == comp.m_type;
    }

    public static boolean isUpperFacing(ReleaseLevelComparison comp) {
        return (isGreaterThanOrEqual(comp) || isGreaterThan(comp));
    }

    public boolean evaluate(ReleaseLevel test) {
        boolean result = false;

        int comparison = m_comparitor.compareTo(test);

        switch (m_type) {
            case TYPE_UNSET :
                {
                    result = false;
                    break;
                }

            case TYPE_LESS_THAN :
                {
                    result = (comparison < 0);
                    break;
                }

            case TYPE_LESS_THAN_OR_EQUAL :
                {
                    result = (comparison <= 0);
                    break;
                }

            case TYPE_EQUAL :
                {
                    result = (comparison == 0);
                    break;
                }

            case TYPE_NOT_EQUAL :
                {
                    result = (comparison != 0);
                    break;
                }

            case TYPE_GREATER_THAN :
                {
                    result = (comparison > 0);
                    break;
                }

            case TYPE_GREATER_THAN_OR_EQUAL :
                {
                    result = (comparison >= 0);
                    break;
                }

            default :
                {
                    throw new VersionError("Unknown Comparison Type " + m_type);
                }
        }

        return result;
    }

    private String getStringForType() {
        String representation = "?";

        switch (m_type) {
            case TYPE_UNSET :
                {
                    representation = "?";
                    break;
                }

            case TYPE_LESS_THAN :
                {
                    representation = "<";
                    break;
                }

            case TYPE_LESS_THAN_OR_EQUAL :
                {
                    representation = "<=";
                    break;
                }

            case TYPE_EQUAL :
                {
                    representation = "=";
                    break;
                }

            case TYPE_NOT_EQUAL :
                {
                    representation = "<>";
                    break;
                }

            case TYPE_GREATER_THAN :
                {
                    representation = ">";
                    break;
                }

            case TYPE_GREATER_THAN_OR_EQUAL :
                {
                    representation = ">=";
                    break;
                }

            default :
                {
                    throw new VersionError("Unknown Comparison Type " + m_type);
                }
        }

        return representation;
    }

    /**
     * Returns the comparitor.
     * @return ReleaseLevel
     */
    public ReleaseLevel getComparitor() {
        return m_comparitor;
    }

    /**
     * Sets the comparitor.
     * @param comparitor The comparitor to set
     */
    public void setComparitor(ReleaseLevel comparitor) {
        m_comparitor = comparitor;
    }

    public String toString() {
        return getStringForType() + " " + m_comparitor;
    }
}

--- NEW FILE: ReleaseLevelRange.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01

Copyright (c) 2002-2003 Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.

3. The end-user documentation included with the redistribution,
   if any, must include the following acknowledgment:
      "This product includes software developed for project 
       Krysalis (http://www.krysalis.org/)."
   Alternately, this acknowledgment may appear in the software itself,
   if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
   "Krysalis Centipede" must not be used to endorse or promote products
   derived from this software without prior written permission. For
   written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
   "Krysalis Centipede", nor may "Krysalis" appear in their name, without
    prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
   individuals, who decided to donate the code to this project in respect 
   of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.version.impl.release.util;

import org.krysalis.version.exception.VersionError;
import org.krysalis.version.impl.data.ReleaseLevel;

/**
 * @author ajack
 */
public class ReleaseLevelRange {
    private ReleaseLevelComparison m_lower = null;
    private ReleaseLevelComparison m_upper = null;

    public ReleaseLevelRange(ReleaseLevel lower, ReleaseLevel upper) {
        m_lower = ReleaseLevelComparison.getGreaterThanOrEqual(lower);
        m_upper = ReleaseLevelComparison.getLessThanOrEqual(upper);

        check();
    }

    public ReleaseLevelRange(ReleaseLevelComparison lower, ReleaseLevelComparison upper) {
        m_lower = lower;
        m_upper = upper;

        check();
    }

    private void check() {
        if (m_lower.getComparitor().compareTo(m_upper.getComparitor()) < 0)
            throw new VersionError(
                "Lower and Upper Mis-configured, Lower ["
                    + m_lower
                    + "] Upper ["
                    + m_upper
                    + "]");

        if ((ReleaseLevelComparison.isEqual(m_lower)
            || ReleaseLevelComparison.isEqual(m_upper))
            && !m_lower.equals(m_upper)) {
            throw new VersionError(
                "Lower and Upper Inconsistent (Equal Operator w/o Unary Range), Lower ["
                    + m_lower
                    + "] Upper ["
                    + m_upper
                    + "]");
        }

        if (!ReleaseLevelComparison.isUpperFacing(m_lower)) {
            throw new VersionError(
                "Lower misconfigured for lower bound [" + m_lower + "]");
        }

        if (!ReleaseLevelComparison.isLowerFacing(m_upper)) {
            throw new VersionError(
                "Upper misconfigured for upper bound [" + m_upper + "]");
        }
    }

    public boolean inRange(ReleaseLevel test) {
        boolean result = false;
        result = m_lower.evaluate(test);
        result &= m_upper.evaluate(test);
        return result;
    } /**
                    * Returns the lower.
                    * @return ReleaseLevelComparison
                    */
    public ReleaseLevelComparison getLower() {
        return m_lower;
    } /**
                    * Returns the upper.
                    * @return ReleaseLevelComparison
                    */
    public ReleaseLevelComparison getUpper() {
        return m_upper;
    } /**
                    * Sets the lower.
                    * @param lower The lower to set
                    */
    public void setLower(ReleaseLevelComparison lower) {
        m_lower = lower;
    } /**
                    * Sets the upper.
                    * @param upper The upper to set
                    */
    public void setUpper(ReleaseLevelComparison upper) {
        m_upper = upper;
    }
}

--- NEW FILE: ReleaseLevelIterator.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01

Copyright (c) 2002-2003 Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.

3. The end-user documentation included with the redistribution,
   if any, must include the following acknowledgment:
      "This product includes software developed for project
       Krysalis (http://www.krysalis.org/)."
   Alternately, this acknowledgment may appear in the software itself,
   if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
   "Krysalis Centipede" must not be used to endorse or promote products
   derived from this software without prior written permission. For
   written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
   "Krysalis Centipede", nor may "Krysalis" appear in their name, without
    prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
   individuals, who decided to donate the code to this project in respect 
   of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.version.impl.release.util;

/**
 * @author [email protected]
 */
public class ReleaseLevelIterator {

}




-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open! 
Get cracking and register here for some mind boggling fun and 
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en