directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r370807 [19/22] - in /directory/sandbox/trustin/mina-spi: ./ core/src/main/java/org/apache/mina/common/ core/src/main/java/org/apache/mina/common/support/ core/src/main/java/org/apache/mina/common/support/discovery/ core/src/main/java/org/a...
Date Fri, 20 Jan 2006 13:48:55 GMT
Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/NumberUtils.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/NumberUtils.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/NumberUtils.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/NumberUtils.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,1401 @@
+/*
+ * Copyright 2002-2005 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.apache.mina.common.support.lang.math;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.apache.mina.common.support.lang.StringUtils;
+
+/**
+ * <p>Provides extra functionality for Java Number classes.</p>
+ *
+ * @author <a href="mailto:bayard@generationjava.com">Henri Yandell</a>
+ * @author <a href="mailto:rand_mcneely@yahoo.com">Rand McNeely</a>
+ * @author Stephen Colebourne
+ * @author <a href="mailto:steve.downey@netfolio.com">Steve Downey</a>
+ * @author Eric Pugh
+ * @author Phil Steitz
+ * @author Matthew Hawthorne
+ * @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
+ * @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
+ * @since 2.0
+ * @version $Id$
+ */
+public class NumberUtils {
+    
+    /** Reusable Long constant for zero. */
+    public static final Long LONG_ZERO = new Long(0L);
+    /** Reusable Long constant for one. */
+    public static final Long LONG_ONE = new Long(1L);
+    /** Reusable Long constant for minus one. */
+    public static final Long LONG_MINUS_ONE = new Long(-1L);
+    /** Reusable Integer constant for zero. */
+    public static final Integer INTEGER_ZERO = new Integer(0);
+    /** Reusable Integer constant for one. */
+    public static final Integer INTEGER_ONE = new Integer(1);
+    /** Reusable Integer constant for minus one. */
+    public static final Integer INTEGER_MINUS_ONE = new Integer(-1);
+    /** Reusable Short constant for zero. */
+    public static final Short SHORT_ZERO = new Short((short) 0);
+    /** Reusable Short constant for one. */
+    public static final Short SHORT_ONE = new Short((short) 1);
+    /** Reusable Short constant for minus one. */
+    public static final Short SHORT_MINUS_ONE = new Short((short) -1);
+    /** Reusable Byte constant for zero. */
+    public static final Byte BYTE_ZERO = new Byte((byte) 0);
+    /** Reusable Byte constant for one. */
+    public static final Byte BYTE_ONE = new Byte((byte) 1);
+    /** Reusable Byte constant for minus one. */
+    public static final Byte BYTE_MINUS_ONE = new Byte((byte) -1);
+    /** Reusable Double constant for zero. */
+    public static final Double DOUBLE_ZERO = new Double(0.0d);
+    /** Reusable Double constant for one. */
+    public static final Double DOUBLE_ONE = new Double(1.0d);
+    /** Reusable Double constant for minus one. */
+    public static final Double DOUBLE_MINUS_ONE = new Double(-1.0d);
+    /** Reusable Float constant for zero. */
+    public static final Float FLOAT_ZERO = new Float(0.0f);
+    /** Reusable Float constant for one. */
+    public static final Float FLOAT_ONE = new Float(1.0f);
+    /** Reusable Float constant for minus one. */
+    public static final Float FLOAT_MINUS_ONE = new Float(-1.0f);
+
+    /**
+     * <p><code>NumberUtils</code> instances should NOT be constructed in standard programming.
+     * Instead, the class should be used as <code>NumberUtils.stringToInt("6");</code>.</p>
+     *
+     * <p>This constructor is public to permit tools that require a JavaBean instance
+     * to operate.</p>
+     */
+    public NumberUtils() {
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Convert a <code>String</code> to an <code>int</code>, returning
+     * <code>zero</code> if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
+     * 
+     * <pre>
+     *   NumberUtils.stringToInt(null) = 0
+     *   NumberUtils.stringToInt("")   = 0
+     *   NumberUtils.stringToInt("1")  = 1
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @return the int represented by the string, or <code>zero</code> if
+     *  conversion fails
+     * @deprecated Use {@link #toInt(String)}
+     *  This method will be removed in Commons Lang 3.0
+     */
+    public static int stringToInt(String str) {
+        return toInt(str);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to an <code>int</code>, returning
+     * <code>zero</code> if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toInt(null) = 0
+     *   NumberUtils.toInt("")   = 0
+     *   NumberUtils.toInt("1")  = 1
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @return the int represented by the string, or <code>zero</code> if
+     *  conversion fails
+     * @since 2.1
+     */
+    public static int toInt(String str) {
+        return toInt(str, 0);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to an <code>int</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, the default value is returned.</p>
+     * 
+     * <pre>
+     *   NumberUtils.stringToInt(null, 1) = 1
+     *   NumberUtils.stringToInt("", 1)   = 1
+     *   NumberUtils.stringToInt("1", 0)  = 1
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @param defaultValue  the default value
+     * @return the int represented by the string, or the default if conversion fails
+     * @deprecated Use {@link #toInt(String, int)}
+     *  This method will be removed in Commons Lang 3.0
+     */
+    public static int stringToInt(String str, int defaultValue) {
+        return toInt(str, defaultValue);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to an <code>int</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, the default value is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toInt(null, 1) = 1
+     *   NumberUtils.toInt("", 1)   = 1
+     *   NumberUtils.toInt("1", 0)  = 1
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @param defaultValue  the default value
+     * @return the int represented by the string, or the default if conversion fails
+     * @since 2.1
+     */
+    public static int toInt(String str, int defaultValue) {
+        if(str == null) {
+            return defaultValue;
+        }
+        try {
+            return Integer.parseInt(str);
+        } catch (NumberFormatException nfe) {
+            return defaultValue;
+        }
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>long</code>, returning
+     * <code>zero</code> if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toLong(null) = 0L
+     *   NumberUtils.toLong("")   = 0L
+     *   NumberUtils.toLong("1")  = 1L
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @return the long represented by the string, or <code>0</code> if
+     *  conversion fails
+     * @since 2.1
+     */
+    public static long toLong(String str) {
+        return toLong(str, 0L);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>long</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, the default value is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toLong(null, 1L) = 1L
+     *   NumberUtils.toLong("", 1L)   = 1L
+     *   NumberUtils.toLong("1", 0L)  = 1L
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @param defaultValue  the default value
+     * @return the long represented by the string, or the default if conversion fails
+     * @since 2.1
+     */
+    public static long toLong(String str, long defaultValue) {
+        if (str == null) {
+            return defaultValue;
+        }
+        try {
+            return Long.parseLong(str);
+        } catch (NumberFormatException nfe) {
+            return defaultValue;
+        }
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>float</code>, returning
+     * <code>0.0f</code> if the conversion fails.</p>
+     *
+     * <p>If the string <code>str</code> is <code>null</code>,
+     * <code>0.0f</code> is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toFloat(null)   = 0.0f
+     *   NumberUtils.toFloat("")     = 0.0f
+     *   NumberUtils.toFloat("1.5")  = 1.5f
+     * </pre>
+     *
+     * @param str the string to convert, may be <code>null</code>
+     * @return the float represented by the string, or <code>0.0f</code>
+     *  if conversion fails
+     * @since 2.1
+     */
+    public static float toFloat(String str) {
+        return toFloat(str, 0.0f);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>float</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string <code>str</code> is <code>null</code>, the default
+     * value is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toFloat(null, 1.1f)   = 1.0f
+     *   NumberUtils.toFloat("", 1.1f)     = 1.1f
+     *   NumberUtils.toFloat("1.5", 0.0f)  = 1.5f
+     * </pre>
+     *
+     * @param str the string to convert, may be <code>null</code>
+     * @param defaultValue the default value
+     * @return the float represented by the string, or defaultValue
+     *  if conversion fails
+     * @since 2.1
+     */
+    public static float toFloat(String str, float defaultValue) {
+      if (str == null) {
+          return defaultValue;
+      }     
+      try {
+          return Float.parseFloat(str);
+      } catch (NumberFormatException nfe) {
+          return defaultValue;
+      }
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>double</code>, returning
+     * <code>0.0d</code> if the conversion fails.</p>
+     *
+     * <p>If the string <code>str</code> is <code>null</code>,
+     * <code>0.0d</code> is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toDouble(null)   = 0.0d
+     *   NumberUtils.toDouble("")     = 0.0d
+     *   NumberUtils.toDouble("1.5")  = 1.5d
+     * </pre>
+     *
+     * @param str the string to convert, may be <code>null</code>
+     * @return the double represented by the string, or <code>0.0d</code>
+     *  if conversion fails
+     * @since 2.1
+     */
+    public static double toDouble(String str) {
+        return toDouble(str, 0.0d);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>double</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string <code>str</code> is <code>null</code>, the default
+     * value is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toDouble(null, 1.1d)   = 1.1d
+     *   NumberUtils.toDouble("", 1.1d)     = 1.1d
+     *   NumberUtils.toDouble("1.5", 0.0d)  = 1.5d
+     * </pre>
+     *
+     * @param str the string to convert, may be <code>null</code>
+     * @param defaultValue the default value
+     * @return the double represented by the string, or defaultValue
+     *  if conversion fails
+     * @since 2.1
+     */
+    public static double toDouble(String str, double defaultValue) {
+      if (str == null) {
+          return defaultValue;
+      }
+      try {
+          return Double.parseDouble(str);
+      } catch (NumberFormatException nfe) {
+          return defaultValue;
+      }
+    }
+
+    //-----------------------------------------------------------------------
+    // must handle Long, Float, Integer, Float, Short,
+    //                  BigDecimal, BigInteger and Byte
+    // useful methods:
+    // Byte.decode(String)
+    // Byte.valueOf(String,int radix)
+    // Byte.valueOf(String)
+    // Double.valueOf(String)
+    // Float.valueOf(String)
+    // new Float(String)
+    // Integer.valueOf(String,int radix)
+    // Integer.valueOf(String)
+    // Integer.decode(String)
+    // Integer.getInteger(String)
+    // Integer.getInteger(String,int val)
+    // Integer.getInteger(String,Integer val)
+    // new Integer(String)
+    // new Double(String)
+    // new Byte(String)
+    // new Long(String)
+    // Long.getLong(String)
+    // Long.getLong(String,int)
+    // Long.getLong(String,Integer)
+    // Long.valueOf(String,int)
+    // Long.valueOf(String)
+    // new Short(String)
+    // Short.decode(String)
+    // Short.valueOf(String,int)
+    // Short.valueOf(String)
+    // new BigDecimal(String)
+    // new BigInteger(String)
+    // new BigInteger(String,int radix)
+    // Possible inputs:
+    // 45 45.5 45E7 4.5E7 Hex Oct Binary xxxF xxxD xxxf xxxd
+    // plus minus everything. Prolly more. A lot are not separable.
+
+    /**
+     * <p>Turns a string value into a java.lang.Number.</p>
+     *
+     * <p>First, the value is examined for a type qualifier on the end
+     * (<code>'f','F','d','D','l','L'</code>).  If it is found, it starts 
+     * trying to create successively larger types from the type specified
+     * until one is found that can represent the value.</p>
+     *
+     * <p>If a type specifier is not found, it will check for a decimal point
+     * and then try successively larger types from <code>Integer</code> to
+     * <code>BigInteger</code> and from <code>Float</code> to
+     * <code>BigDecimal</code>.</p>
+     *
+     * <p>If the string starts with <code>0x</code> or <code>-0x</code>, it
+     * will be interpreted as a hexadecimal integer.  Values with leading
+     * <code>0</code>'s will not be interpreted as octal.</p>
+     *
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     *
+     * <p>This method does not trim the input string, i.e., strings with leading
+     * or trailing spaces will generate NumberFormatExceptions.</p>
+     *
+     * @param str  String containing a number, may be null
+     * @return Number created from the string
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static Number createNumber(String str) throws NumberFormatException {
+        if (str == null) {
+            return null;
+        }
+        if (StringUtils.isBlank(str)) {
+            throw new NumberFormatException("A blank string is not a valid number");
+        }  
+        if (str.startsWith("--")) {
+            // this is protection for poorness in java.lang.BigDecimal.
+            // it accepts this as a legal value, but it does not appear 
+            // to be in specification of class. OS X Java parses it to 
+            // a wrong value.
+            return null;
+        }
+        if (str.startsWith("0x") || str.startsWith("-0x")) {
+            return createInteger(str);
+        }   
+        char lastChar = str.charAt(str.length() - 1);
+        String mant;
+        String dec;
+        String exp;
+        int decPos = str.indexOf('.');
+        int expPos = str.indexOf('e') + str.indexOf('E') + 1;
+
+        if (decPos > -1) {
+
+            if (expPos > -1) {
+                if (expPos < decPos) {
+                    throw new NumberFormatException(str + " is not a valid number.");
+                }
+                dec = str.substring(decPos + 1, expPos);
+            } else {
+                dec = str.substring(decPos + 1);
+            }
+            mant = str.substring(0, decPos);
+        } else {
+            if (expPos > -1) {
+                mant = str.substring(0, expPos);
+            } else {
+                mant = str;
+            }
+            dec = null;
+        }
+        if (!Character.isDigit(lastChar)) {
+            if (expPos > -1 && expPos < str.length() - 1) {
+                exp = str.substring(expPos + 1, str.length() - 1);
+            } else {
+                exp = null;
+            }
+            //Requesting a specific type..
+            String numeric = str.substring(0, str.length() - 1);
+            boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
+            switch (lastChar) {
+                case 'l' :
+                case 'L' :
+                    if (dec == null
+                        && exp == null
+                        && isDigits(numeric.substring(1))
+                        && (numeric.charAt(0) == '-' || Character.isDigit(numeric.charAt(0)))) {
+                        try {
+                            return createLong(numeric);
+                        } catch (NumberFormatException nfe) {
+                            //Too big for a long
+                        }
+                        return createBigInteger(numeric);
+
+                    }
+                    throw new NumberFormatException(str + " is not a valid number.");
+                case 'f' :
+                case 'F' :
+                    try {
+                        Float f = NumberUtils.createFloat(numeric);
+                        if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
+                            //If it's too big for a float or the float value = 0 and the string
+                            //has non-zeros in it, then float does not have the precision we want
+                            return f;
+                        }
+
+                    } catch (NumberFormatException nfe) {
+                    }
+                    //Fall through
+                case 'd' :
+                case 'D' :
+                    try {
+                        Double d = NumberUtils.createDouble(numeric);
+                        if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
+                            return d;
+                        }
+                    } catch (NumberFormatException nfe) {
+                    }
+                    try {
+                        return createBigDecimal(numeric);
+                    } catch (NumberFormatException e) {
+                    }
+                    //Fall through
+                default :
+                    throw new NumberFormatException(str + " is not a valid number.");
+
+            }
+        } else {
+            //User doesn't have a preference on the return type, so let's start
+            //small and go from there...
+            if (expPos > -1 && expPos < str.length() - 1) {
+                exp = str.substring(expPos + 1, str.length());
+            } else {
+                exp = null;
+            }
+            if (dec == null && exp == null) {
+                //Must be an int,long,bigint
+                try {
+                    return createInteger(str);
+                } catch (NumberFormatException nfe) {
+                }
+                try {
+                    return createLong(str);
+                } catch (NumberFormatException nfe) {
+                }
+                return createBigInteger(str);
+
+            } else {
+                //Must be a float,double,BigDec
+                boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
+                try {
+                    Float f = createFloat(str);
+                    if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
+                        return f;
+                    }
+                } catch (NumberFormatException nfe) {
+                }
+                try {
+                    Double d = createDouble(str);
+                    if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) {
+                        return d;
+                    }
+                } catch (NumberFormatException nfe) {
+                }
+
+                return createBigDecimal(str);
+
+            }
+        }
+    }
+
+    /**
+     * <p>Utility method for {@link #createNumber(java.lang.String)}.</p>
+     *
+     * <p>Returns <code>true</code> if s is <code>null</code>.</p>
+     * 
+     * @param str  the String to check
+     * @return if it is all zeros or <code>null</code>
+     */
+    private static boolean isAllZeros(String str) {
+        if (str == null) {
+            return true;
+        }
+        for (int i = str.length() - 1; i >= 0; i--) {
+            if (str.charAt(i) != '0') {
+                return false;
+            }
+        }
+        return str.length() > 0;
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Convert a <code>String</code> to a <code>Float</code>.</p>
+     *
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     * 
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>Float</code>
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static Float createFloat(String str) {
+        if (str == null) {
+            return null;
+        }
+        return Float.valueOf(str);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>Double</code>.</p>
+     * 
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     *
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>Double</code>
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static Double createDouble(String str) {
+        if (str == null) {
+            return null;
+        }
+        return Double.valueOf(str);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>Integer</code>, handling
+     * hex and octal notations.</p>
+     *
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     * 
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>Integer</code>
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static Integer createInteger(String str) {
+        if (str == null) {
+            return null;
+        }
+        // decode() handles 0xAABD and 0777 (hex and octal) as well.
+        return Integer.decode(str);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>Long</code>.</p>
+     * 
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     *
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>Long</code>
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static Long createLong(String str) {
+        if (str == null) {
+            return null;
+        }
+        return Long.valueOf(str);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>BigInteger</code>.</p>
+     *
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     * 
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>BigInteger</code>
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static BigInteger createBigInteger(String str) {
+        if (str == null) {
+            return null;
+        }
+        return new BigInteger(str);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>BigDecimal</code>.</p>
+     * 
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     *
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>BigDecimal</code>
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static BigDecimal createBigDecimal(String str) {
+        if (str == null) {
+            return null;
+        }
+        // handle JDK1.3.1 bug where "" throws IndexOutOfBoundsException
+        if (StringUtils.isBlank(str)) {
+            throw new NumberFormatException("A blank string is not a valid number");
+        }  
+        return new BigDecimal(str);
+    }
+
+    // Min in array
+    //--------------------------------------------------------------------
+    /**
+     * <p>Returns the minimum value in an array.</p>
+     * 
+     * @param array  an array, must not be null or empty
+     * @return the minimum value in the array
+     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
+     * @throws IllegalArgumentException if <code>array</code> is empty
+     */
+    public static long min(long[] array) {
+        // Validates input
+        if (array == null) {
+            throw new IllegalArgumentException("The Array must not be null");
+        } else if (array.length == 0) {
+            throw new IllegalArgumentException("Array cannot be empty.");
+        }
+    
+        // Finds and returns min
+        long min = array[0];
+        for (int i = 1; i < array.length; i++) {
+            if (array[i] < min) {
+                min = array[i];
+            }
+        }
+    
+        return min;
+    }
+
+    /**
+     * <p>Returns the minimum value in an array.</p>
+     * 
+     * @param array  an array, must not be null or empty
+     * @return the minimum value in the array
+     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
+     * @throws IllegalArgumentException if <code>array</code> is empty
+     */
+    public static int min(int[] array) {
+        // Validates input
+        if (array == null) {
+            throw new IllegalArgumentException("The Array must not be null");
+        } else if (array.length == 0) {
+            throw new IllegalArgumentException("Array cannot be empty.");
+        }
+    
+        // Finds and returns min
+        int min = array[0];
+        for (int j = 1; j < array.length; j++) {
+            if (array[j] < min) {
+                min = array[j];
+            }
+        }
+    
+        return min;
+    }
+
+    /**
+     * <p>Returns the minimum value in an array.</p>
+     * 
+     * @param array  an array, must not be null or empty
+     * @return the minimum value in the array
+     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
+     * @throws IllegalArgumentException if <code>array</code> is empty
+     */
+    public static short min(short[] array) {
+        // Validates input
+        if (array == null) {
+            throw new IllegalArgumentException("The Array must not be null");
+        } else if (array.length == 0) {
+            throw new IllegalArgumentException("Array cannot be empty.");
+        }
+    
+        // Finds and returns min
+        short min = array[0];
+        for (int i = 1; i < array.length; i++) {
+            if (array[i] < min) {
+                min = array[i];
+            }
+        }
+    
+        return min;
+    }
+
+     /**
+     * <p>Returns the minimum value in an array.</p>
+     * 
+     * @param array  an array, must not be null or empty
+     * @return the minimum value in the array
+     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
+     * @throws IllegalArgumentException if <code>array</code> is empty
+     */
+    public static double min(double[] array) {
+        // Validates input
+        if (array == null) {
+            throw new IllegalArgumentException("The Array must not be null");
+        } else if (array.length == 0) {
+            throw new IllegalArgumentException("Array cannot be empty.");
+        }
+    
+        // Finds and returns min
+        double min = array[0];
+        for (int i = 1; i < array.length; i++) {
+            if (array[i] < min) {
+                min = array[i];
+            }
+        }
+    
+        return min;
+    }
+
+    /**
+     * <p>Returns the minimum value in an array.</p>
+     * 
+     * @param array  an array, must not be null or empty
+     * @return the minimum value in the array
+     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
+     * @throws IllegalArgumentException if <code>array</code> is empty
+     */
+    public static float min(float[] array) {
+        // Validates input
+        if (array == null) {
+            throw new IllegalArgumentException("The Array must not be null");
+        } else if (array.length == 0) {
+            throw new IllegalArgumentException("Array cannot be empty.");
+        }
+    
+        // Finds and returns min
+        float min = array[0];
+        for (int i = 1; i < array.length; i++) {
+            if (array[i] < min) {
+                min = array[i];
+            }
+        }
+    
+        return min;
+    }
+
+    // Max in array
+    //--------------------------------------------------------------------
+    /**
+     * <p>Returns the maximum value in an array.</p>
+     * 
+     * @param array  an array, must not be null or empty
+     * @return the minimum value in the array
+     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
+     * @throws IllegalArgumentException if <code>array</code> is empty
+     */
+    public static long max(long[] array) {
+        // Validates input
+        if (array == null) {
+            throw new IllegalArgumentException("The Array must not be null");
+        } else if (array.length == 0) {
+            throw new IllegalArgumentException("Array cannot be empty.");
+        }
+
+        // Finds and returns max
+        long max = array[0];
+        for (int j = 1; j < array.length; j++) {
+            if (array[j] > max) {
+                max = array[j];
+            }
+        }
+
+        return max;
+    }
+
+    /**
+     * <p>Returns the maximum value in an array.</p>
+     * 
+     * @param array  an array, must not be null or empty
+     * @return the minimum value in the array
+     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
+     * @throws IllegalArgumentException if <code>array</code> is empty
+     */
+    public static int max(int[] array) {
+        // Validates input
+        if (array == null) {
+            throw new IllegalArgumentException("The Array must not be null");
+        } else if (array.length == 0) {
+            throw new IllegalArgumentException("Array cannot be empty.");
+        }
+    
+        // Finds and returns max
+        int max = array[0];
+        for (int j = 1; j < array.length; j++) {
+            if (array[j] > max) {
+                max = array[j];
+            }
+        }
+    
+        return max;
+    }
+
+    /**
+     * <p>Returns the maximum value in an array.</p>
+     * 
+     * @param array  an array, must not be null or empty
+     * @return the minimum value in the array
+     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
+     * @throws IllegalArgumentException if <code>array</code> is empty
+     */
+    public static short max(short[] array) {
+        // Validates input
+        if (array == null) {
+            throw new IllegalArgumentException("The Array must not be null");
+        } else if (array.length == 0) {
+            throw new IllegalArgumentException("Array cannot be empty.");
+        }
+    
+        // Finds and returns max
+        short max = array[0];
+        for (int i = 1; i < array.length; i++) {
+            if (array[i] > max) {
+                max = array[i];
+            }
+        }
+    
+        return max;
+    }
+
+    /**
+     * <p>Returns the maximum value in an array.</p>
+     * 
+     * @param array  an array, must not be null or empty
+     * @return the minimum value in the array
+     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
+     * @throws IllegalArgumentException if <code>array</code> is empty
+     */
+    public static double max(double[] array) {
+        // Validates input
+        if (array== null) {
+            throw new IllegalArgumentException("The Array must not be null");
+        } else if (array.length == 0) {
+            throw new IllegalArgumentException("Array cannot be empty.");
+        }
+    
+        // Finds and returns max
+        double max = array[0];
+        for (int j = 1; j < array.length; j++) {
+            if (array[j] > max) {
+                max = array[j];
+            }
+        }
+    
+        return max;
+    }
+
+    /**
+     * <p>Returns the maximum value in an array.</p>
+     * 
+     * @param array  an array, must not be null or empty
+     * @return the minimum value in the array
+     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
+     * @throws IllegalArgumentException if <code>array</code> is empty
+     */
+    public static float max(float[] array) {
+        // Validates input
+        if (array == null) {
+            throw new IllegalArgumentException("The Array must not be null");
+        } else if (array.length == 0) {
+            throw new IllegalArgumentException("Array cannot be empty.");
+        }
+
+        // Finds and returns max
+        float max = array[0];
+        for (int j = 1; j < array.length; j++) {
+            if (array[j] > max) {
+                max = array[j];
+            }
+        }
+
+        return max;
+    }
+     
+    // 3 param min
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Gets the minimum of three <code>long</code> values.</p>
+     * 
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the smallest of the values
+     */
+    public static long min(long a, long b, long c) {
+        if (b < a) {
+            a = b;
+        }
+        if (c < a) {
+            a = c;
+        }
+        return a;
+    }
+
+    /**
+     * <p>Gets the minimum of three <code>int</code> values.</p>
+     * 
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the smallest of the values
+     */
+    public static int min(int a, int b, int c) {
+        if (b < a) {
+            a = b;
+        }
+        if (c < a) {
+            a = c;
+        }
+        return a;
+    }
+
+    /**
+     * <p>Gets the minimum of three <code>short</code> values.</p>
+     * 
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the smallest of the values
+     */
+    public static short min(short a, short b, short c) {
+        if (b < a) {
+            a = b;
+        }
+        if (c < a) {
+            a = c;
+        }
+        return a;
+    }
+
+    /**
+     * <p>Gets the minimum of three <code>byte</code> values.</p>
+     * 
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the smallest of the values
+     */
+    public static byte min(byte a, byte b, byte c) {
+        if (b < a) {
+            a = b;
+        }
+        if (c < a) {
+            a = c;
+        }
+        return a;
+    }
+
+    /**
+     * <p>Gets the minimum of three <code>double</code> values.</p>
+     * 
+     * <p>If any value is <code>NaN</code>, <code>NaN</code> is
+     * returned. Infinity is handled.</p>
+     * 
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the smallest of the values
+     */
+    public static double min(double a, double b, double c) {
+        return Math.min(Math.min(a, b), c);
+    }
+
+    /**
+     * <p>Gets the minimum of three <code>float</code> values.</p>
+     * 
+     * <p>If any value is <code>NaN</code>, <code>NaN</code> is
+     * returned. Infinity is handled.</p>
+     *
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the smallest of the values
+     */
+    public static float min(float a, float b, float c) {
+        return Math.min(Math.min(a, b), c);
+    }
+
+    // 3 param max
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Gets the maximum of three <code>long</code> values.</p>
+     * 
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the largest of the values
+     */
+    public static long max(long a, long b, long c) {
+        if (b > a) {
+            a = b;
+        }
+        if (c > a) {
+            a = c;
+        }
+        return a;
+    }
+
+    /**
+     * <p>Gets the maximum of three <code>int</code> values.</p>
+     * 
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the largest of the values
+     */
+    public static int max(int a, int b, int c) {
+        if (b > a) {
+            a = b;
+        }
+        if (c > a) {
+            a = c;
+        }
+        return a;
+    }
+
+    /**
+     * <p>Gets the maximum of three <code>short</code> values.</p>
+     * 
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the largest of the values
+     */
+    public static short max(short a, short b, short c) {
+        if (b > a) {
+            a = b;
+        }
+        if (c > a) {
+            a = c;
+        }
+        return a;
+    }
+
+    /**
+     * <p>Gets the maximum of three <code>byte</code> values.</p>
+     * 
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the largest of the values
+     */
+    public static byte max(byte a, byte b, byte c) {
+        if (b > a) {
+            a = b;
+        }
+        if (c > a) {
+            a = c;
+        }
+        return a;
+    }
+
+    /**
+     * <p>Gets the maximum of three <code>double</code> values.</p>
+     * 
+     * <p>If any value is <code>NaN</code>, <code>NaN</code> is
+     * returned. Infinity is handled.</p>
+     *
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the largest of the values
+     */
+    public static double max(double a, double b, double c) {
+        return Math.max(Math.max(a, b), c);
+    }
+
+    /**
+     * <p>Gets the maximum of three <code>float</code> values.</p>
+     * 
+     * <p>If any value is <code>NaN</code>, <code>NaN</code> is
+     * returned. Infinity is handled.</p>
+     *
+     * @param a  value 1
+     * @param b  value 2
+     * @param c  value 3
+     * @return  the largest of the values
+     */
+    public static float max(float a, float b, float c) {
+        return Math.max(Math.max(a, b), c);
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Compares two <code>doubles</code> for order.</p>
+     *
+     * <p>This method is more comprehensive than the standard Java greater
+     * than, less than and equals operators.</p>
+     * <ul>
+     *  <li>It returns <code>-1</code> if the first value is less than the second.</li>
+     *  <li>It returns <code>+1</code> if the first value is greater than the second.</li>
+     *  <li>It returns <code>0</code> if the values are equal.</li>
+     * </ul>
+     *
+     * <p>
+     * The ordering is as follows, largest to smallest:
+     * <ul>
+     *  <li>NaN
+     *  <li>Positive infinity
+     *  <li>Maximum double
+     *  <li>Normal positive numbers
+     *  <li>+0.0
+     *  <li>-0.0
+     *  <li>Normal negative numbers
+     *  <li>Minimum double (<code>-Double.MAX_VALUE</code>)
+     *  <li>Negative infinity
+     * </ul>
+     * </p>
+     *
+     * <p>Comparing <code>NaN</code> with <code>NaN</code> will
+     * return <code>0</code>.</p>
+     * 
+     * @param lhs  the first <code>double</code>
+     * @param rhs  the second <code>double</code>
+     * @return <code>-1</code> if lhs is less, <code>+1</code> if greater,
+     *  <code>0</code> if equal to rhs
+     */
+    public static int compare(double lhs, double rhs) {
+        if (lhs < rhs) {
+            return -1;
+        }
+        if (lhs > rhs) {
+            return +1;
+        }
+        // Need to compare bits to handle 0.0 == -0.0 being true
+        // compare should put -0.0 < +0.0
+        // Two NaNs are also == for compare purposes
+        // where NaN == NaN is false
+        long lhsBits = Double.doubleToLongBits(lhs);
+        long rhsBits = Double.doubleToLongBits(rhs);
+        if (lhsBits == rhsBits) {
+            return 0;
+        }
+        // Something exotic! A comparison to NaN or 0.0 vs -0.0
+        // Fortunately NaN's long is > than everything else
+        // Also negzeros bits < poszero
+        // NAN: 9221120237041090560
+        // MAX: 9218868437227405311
+        // NEGZERO: -9223372036854775808
+        if (lhsBits < rhsBits) {
+            return -1;
+        } else {
+            return +1;
+        }
+    }
+    
+    /**
+     * <p>Compares two floats for order.</p>
+     *
+     * <p>This method is more comprehensive than the standard Java greater than,
+     * less than and equals operators.</p>
+     * <ul>
+     *  <li>It returns <code>-1</code> if the first value is less than the second.
+     *  <li>It returns <code>+1</code> if the first value is greater than the second.
+     *  <li>It returns <code>0</code> if the values are equal.
+     * </ul>
+     *
+     * <p> The ordering is as follows, largest to smallest:
+     * <ul>
+     * <li>NaN
+     * <li>Positive infinity
+     * <li>Maximum float
+     * <li>Normal positive numbers
+     * <li>+0.0
+     * <li>-0.0
+     * <li>Normal negative numbers
+     * <li>Minimum float (<code>-Float.MAX_VALUE</code>)
+     * <li>Negative infinity
+     * </ul>
+     *
+     * <p>Comparing <code>NaN</code> with <code>NaN</code> will return
+     * <code>0</code>.</p>
+     * 
+     * @param lhs  the first <code>float</code>
+     * @param rhs  the second <code>float</code>
+     * @return <code>-1</code> if lhs is less, <code>+1</code> if greater,
+     *  <code>0</code> if equal to rhs
+     */
+    public static int compare(float lhs, float rhs) {
+        if (lhs < rhs) {
+            return -1;
+        }
+        if (lhs > rhs) {
+            return +1;
+        }
+        //Need to compare bits to handle 0.0 == -0.0 being true
+        // compare should put -0.0 < +0.0
+        // Two NaNs are also == for compare purposes
+        // where NaN == NaN is false
+        int lhsBits = Float.floatToIntBits(lhs);
+        int rhsBits = Float.floatToIntBits(rhs);
+        if (lhsBits == rhsBits) {
+            return 0;
+        }
+        //Something exotic! A comparison to NaN or 0.0 vs -0.0
+        //Fortunately NaN's int is > than everything else
+        //Also negzeros bits < poszero
+        //NAN: 2143289344
+        //MAX: 2139095039
+        //NEGZERO: -2147483648
+        if (lhsBits < rhsBits) {
+            return -1;
+        } else {
+            return +1;
+        }
+    }
+    
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Checks whether the <code>String</code> contains only
+     * digit characters.</p>
+     *
+     * <p><code>Null</code> and empty String will return
+     * <code>false</code>.</p>
+     *
+     * @param str  the <code>String</code> to check
+     * @return <code>true</code> if str contains only unicode numeric
+     */
+    public static boolean isDigits(String str) {
+        if (StringUtils.isEmpty(str)) {
+            return false;
+        }
+        for (int i = 0; i < str.length(); i++) {
+            if (!Character.isDigit(str.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * <p>Checks whether the String a valid Java number.</p>
+     *
+     * <p>Valid numbers include hexadecimal marked with the <code>0x</code>
+     * qualifier, scientific notation and numbers marked with a type
+     * qualifier (e.g. 123L).</p>
+     *
+     * <p><code>Null</code> and empty String will return
+     * <code>false</code>.</p>
+     *
+     * @param str  the <code>String</code> to check
+     * @return <code>true</code> if the string is a correctly formatted number
+     */
+    public static boolean isNumber(String str) {
+        if (StringUtils.isEmpty(str)) {
+            return false;
+        }
+        char[] chars = str.toCharArray();
+        int sz = chars.length;
+        boolean hasExp = false;
+        boolean hasDecPoint = false;
+        boolean allowSigns = false;
+        boolean foundDigit = false;
+        // deal with any possible sign up front
+        int start = (chars[0] == '-') ? 1 : 0;
+        if (sz > start + 1) {
+            if (chars[start] == '0' && chars[start + 1] == 'x') {
+                int i = start + 2;
+                if (i == sz) {
+                    return false; // str == "0x"
+                }
+                // checking hex (it can't be anything else)
+                for (; i < chars.length; i++) {
+                    if ((chars[i] < '0' || chars[i] > '9')
+                        && (chars[i] < 'a' || chars[i] > 'f')
+                        && (chars[i] < 'A' || chars[i] > 'F')) {
+                        return false;
+                    }
+                }
+                return true;
+            }
+        }
+        sz--; // don't want to loop to the last char, check it afterwords
+              // for type qualifiers
+        int i = start;
+        // loop to the next to last char or to the last char if we need another digit to
+        // make a valid number (e.g. chars[0..5] = "1234E")
+        while (i < sz || (i < sz + 1 && allowSigns && !foundDigit)) {
+            if (chars[i] >= '0' && chars[i] <= '9') {
+                foundDigit = true;
+                allowSigns = false;
+
+            } else if (chars[i] == '.') {
+                if (hasDecPoint || hasExp) {
+                    // two decimal points or dec in exponent   
+                    return false;
+                }
+                hasDecPoint = true;
+            } else if (chars[i] == 'e' || chars[i] == 'E') {
+                // we've already taken care of hex.
+                if (hasExp) {
+                    // two E's
+                    return false;
+                }
+                if (!foundDigit) {
+                    return false;
+                }
+                hasExp = true;
+                allowSigns = true;
+            } else if (chars[i] == '+' || chars[i] == '-') {
+                if (!allowSigns) {
+                    return false;
+                }
+                allowSigns = false;
+                foundDigit = false; // we need a digit after the E
+            } else {
+                return false;
+            }
+            i++;
+        }
+        if (i < chars.length) {
+            if (chars[i] >= '0' && chars[i] <= '9') {
+                // no type qualifier, OK
+                return true;
+            }
+            if (chars[i] == 'e' || chars[i] == 'E') {
+                // can't have an E at the last byte
+                return false;
+            }
+            if (!allowSigns
+                && (chars[i] == 'd'
+                    || chars[i] == 'D'
+                    || chars[i] == 'f'
+                    || chars[i] == 'F')) {
+                return foundDigit;
+            }
+            if (chars[i] == 'l'
+                || chars[i] == 'L') {
+                // not allowing L with an exponent
+                return foundDigit && !hasExp;
+            }
+            // last character is illegal
+            return false;
+        }
+        // allowSigns is true iff the val ends in 'E'
+        // found digit it to make sure weird stuff like '.' and '1E-' doesn't pass
+        return !allowSigns && foundDigit;
+    }
+    
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/NumberUtils.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/RandomUtils.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/RandomUtils.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/RandomUtils.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/RandomUtils.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2002,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.apache.mina.common.support.lang.math;
+
+import java.util.Random;
+
+/**
+ * <p><code>RandomUtils</code> is a wrapper that supports all possible 
+ * {@link java.util.Random} methods via the {@link java.lang.Math#random()}
+ * method and its system-wide <code>Random</code> object.
+ * 
+ * @author Henri Yandell
+ * @author Gary D. Gregory
+ * @since 2.0
+ * @version $Id$
+ */
+public class RandomUtils {
+
+    /**
+     * An instance of {@link JVMRandom}.
+     */
+    public static final Random JVM_RANDOM = new JVMRandom();
+
+// should be possible for JVM_RANDOM?
+//    public static void nextBytes(byte[]) {
+//    public synchronized double nextGaussian();
+//    }
+
+    /**
+     * <p>Returns the next pseudorandom, uniformly distributed int value
+     * from the Math.random() sequence.</p>
+     *
+     * @return the random int
+     */
+    public static int nextInt() {
+        return nextInt(JVM_RANDOM);
+    }
+    
+    /**
+     * <p>Returns the next pseudorandom, uniformly distributed int value
+     * from the given <code>random</code> sequence.</p>
+     *
+     * @param random the Random sequence generator.
+     * @return the random int
+     */
+    public static int nextInt(Random random) {
+        return random.nextInt();
+    }
+    
+    /**
+     * <p>Returns a pseudorandom, uniformly distributed int value
+     * between <code>0</code> (inclusive) and the specified value
+     * (exclusive), from the Math.random() sequence.</p>
+     *
+     * @param n  the specified exclusive max-value
+     * @return the random int
+     */
+    public static int nextInt(int n) {
+        return nextInt(JVM_RANDOM, n);
+    }
+    
+    /**
+     * <p>Returns a pseudorandom, uniformly distributed int value
+     * between <code>0</code> (inclusive) and the specified value
+     * (exclusive), from the given Random sequence.</p>
+     *
+     * @param random the Random sequence generator.
+     * @param n  the specified exclusive max-value
+     * @return the random int
+     */
+    public static int nextInt(Random random, int n) {
+        // check this cannot return 'n'
+        return random.nextInt(n);
+    }
+    
+    /**
+     * <p>Returns the next pseudorandom, uniformly distributed long value
+     * from the Math.random() sequence.</p>
+     *
+     * @return the random long
+     */
+    public static long nextLong() {
+        return nextLong(JVM_RANDOM);
+    }
+
+    /**
+     * <p>Returns the next pseudorandom, uniformly distributed long value
+     * from the given Random sequence.</p>
+     *
+     * @param random the Random sequence generator.
+     * @return the random long
+     */
+    public static long nextLong(Random random) {
+        return random.nextLong();
+    }
+    
+    /**
+     * <p>Returns the next pseudorandom, uniformly distributed boolean value
+     * from the Math.random() sequence.</p>
+     *
+     * @return the random boolean
+     */
+    public static boolean nextBoolean() {
+        return nextBoolean(JVM_RANDOM);
+    }
+
+    /**
+     * <p>Returns the next pseudorandom, uniformly distributed boolean value
+     * from the given random sequence.</p>
+     *
+     * @param random the Random sequence generator.
+     * @return the random boolean
+     */
+    public static boolean nextBoolean(Random random) {
+        return random.nextBoolean();
+    }
+    
+    /**
+     * <p>Returns the next pseudorandom, uniformly distributed float value
+     * between <code>0.0</code> and <code>1.0</code> from the Math.random()
+     * sequence.</p>
+     *
+     * @return the random float
+     */
+    public static float nextFloat() {
+        return nextFloat(JVM_RANDOM);
+    }
+
+    /**
+     * <p>Returns the next pseudorandom, uniformly distributed float value
+     * between <code>0.0</code> and <code>1.0</code> from the given Random
+     * sequence.</p>
+     *
+     * @param random the Random sequence generator.
+     * @return the random float
+     */
+    public static float nextFloat(Random random) {
+        return random.nextFloat();
+    }
+    
+    /**
+     * <p>Returns the next pseudorandom, uniformly distributed float value
+     * between <code>0.0</code> and <code>1.0</code> from the Math.random()
+     * sequence.</p>
+     *
+     * @return the random double
+     */
+    public static double nextDouble() {
+        return nextDouble(JVM_RANDOM);
+    }
+
+    /**
+     * <p>Returns the next pseudorandom, uniformly distributed float value
+     * between <code>0.0</code> and <code>1.0</code> from the given Random
+     * sequence.</p>
+     *
+     * @param random the Random sequence generator.
+     * @return the random double
+     */
+    public static double nextDouble(Random random) {
+        return random.nextDouble();
+    }
+    
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/RandomUtils.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/Range.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/Range.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/Range.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/Range.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,430 @@
+/*
+ * Copyright 2002-2005 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.apache.mina.common.support.lang.math;
+
+/**
+ * <p><code>Range</code> represents a range of numbers of the same type.</p>
+ * 
+ * <p>Specific subclasses hold the range values as different types. Each
+ * subclass should be immutable and {@link java.io.Serializable Serializable}
+ * if possible.</p>
+ *
+ * @author Stephen Colebourne
+ * @since 2.0
+ * @version $Id$
+ */
+public abstract class Range {
+
+    /**
+     * <p>Constructs a new range.</p>
+     */
+    public Range() {
+        super();
+    }
+
+    // Accessors
+    //--------------------------------------------------------------------
+
+    /**
+     * <p>Gets the minimum number in this range.</p>
+     *
+     * @return the minimum number in this range
+     */
+    public abstract Number getMinimumNumber();
+
+    /**
+     * <p>Gets the minimum number in this range as a <code>long</code>.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumNumber()} method. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @return the minimum number in this range
+     */
+    public long getMinimumLong() {
+        return getMinimumNumber().longValue();
+    }
+
+    /**
+     * <p>Gets the minimum number in this range as a <code>int</code>.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumNumber()} method. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @return the minimum number in this range
+     */
+    public int getMinimumInteger() {
+        return getMinimumNumber().intValue();
+    }
+
+    /**
+     * <p>Gets the minimum number in this range as a <code>double</code>.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumNumber()} method. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @return the minimum number in this range
+     */
+    public double getMinimumDouble() {
+        return getMinimumNumber().doubleValue();
+    }
+
+    /**
+     * <p>Gets the minimum number in this range as a <code>float</code>.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumNumber()} method. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @return the minimum number in this range
+     */
+    public float getMinimumFloat() {
+        return getMinimumNumber().floatValue();
+    }
+
+    /**
+     * <p>Gets the maximum number in this range.</p>
+     *
+     * @return the maximum number in this range
+     */
+    public abstract Number getMaximumNumber();
+
+    /**
+     * <p>Gets the maximum number in this range as a <code>long</code>.</p>
+     * 
+     * <p>This implementation uses the {@link #getMaximumNumber()} method. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @return the maximum number in this range
+     */
+    public long getMaximumLong() {
+        return getMaximumNumber().longValue();
+    }
+
+    /**
+     * <p>Gets the maximum number in this range as a <code>int</code>.</p>
+     * 
+     * <p>This implementation uses the {@link #getMaximumNumber()} method. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @return the maximum number in this range
+     */
+    public int getMaximumInteger() {
+        return getMaximumNumber().intValue();
+    }
+
+    /**
+     * <p>Gets the maximum number in this range as a <code>double</code>.</p>
+     * 
+     * <p>This implementation uses the {@link #getMaximumNumber()} method. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @return the maximum number in this range
+     */
+    public double getMaximumDouble() {
+        return getMaximumNumber().doubleValue();
+    }
+
+    /**
+     * <p>Gets the maximum number in this range as a <code>float</code>.</p>
+     * 
+     * <p>This implementation uses the {@link #getMaximumNumber()} method. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @return the maximum number in this range
+     */
+    public float getMaximumFloat() {
+        return getMaximumNumber().floatValue();
+    }
+
+    // Include tests
+    //--------------------------------------------------------------------
+    
+    /**
+     * <p>Tests whether the specified <code>Number</code> occurs within
+     * this range.</p>
+     * 
+     * <p>The exact comparison implementation varies by subclass. It is
+     * intended that an <code>int</code> specific subclass will compare using
+     * <code>int</code> comparison.</p>
+     * 
+     * <p><code>null</code> is handled and returns <code>false</code>.</p>
+     *
+     * @param number  the number to test, may be <code>null</code>
+     * @return <code>true</code> if the specified number occurs within this range
+     * @throws IllegalArgumentException if the <code>Number</code> cannot be compared
+     */
+    public abstract boolean containsNumber(Number number);
+
+    /**
+     * <p>Tests whether the specified <code>Number</code> occurs within
+     * this range using <code>long</code> comparison..</p>
+     * 
+     * <p><code>null</code> is handled and returns <code>false</code>.</p>
+     * 
+     * <p>This implementation forwards to the {@link #containsLong(long)} method.</p>
+     *
+     * @param value  the long to test, may be <code>null</code>
+     * @return <code>true</code> if the specified number occurs within this
+     *  range by <code>long</code> comparison
+     */
+    public boolean containsLong(Number value) {
+        if (value == null) {
+            return false;
+        }
+        return containsLong(value.longValue());
+    }
+
+    /**
+     * <p>Tests whether the specified <code>long</code> occurs within
+     * this range using <code>long</code> comparison.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumLong()} and 
+     * {@link #getMaximumLong()} methods and should be good for most uses.</p>
+     * 
+     * @param value  the long to test
+     * @return <code>true</code> if the specified number occurs within this
+     *  range by <code>long</code> comparison
+     */
+    public boolean containsLong(long value) {
+        return value >= getMinimumLong() && value <= getMaximumLong();
+    }
+
+    /**
+     * <p>Tests whether the specified <code>Number</code> occurs within
+     * this range using <code>int</code> comparison..</p>
+     * 
+     * <p><code>null</code> is handled and returns <code>false</code>.</p>
+     * 
+     * <p>This implementation forwards to the {@link #containsInteger(int)} method.</p>
+     *
+     * @param value  the integer to test, may be <code>null</code>
+     * @return <code>true</code> if the specified number occurs within this
+     *  range by <code>int</code> comparison
+     */
+    public boolean containsInteger(Number value) {
+        if (value == null) {
+            return false;
+        }
+        return containsInteger(value.intValue());
+    }
+
+    /**
+     * <p>Tests whether the specified <code>int</code> occurs within
+     * this range using <code>int</code> comparison.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumInteger()} and 
+     * {@link #getMaximumInteger()} methods and should be good for most uses.</p>
+     * 
+     * @param value  the int to test
+     * @return <code>true</code> if the specified number occurs within this
+     *  range by <code>int</code> comparison
+     */
+    public boolean containsInteger(int value) {
+        return value >= getMinimumInteger() && value <= getMaximumInteger();
+    }
+
+    /**
+     * <p>Tests whether the specified <code>Number</code> occurs within
+     * this range using <code>double</code> comparison..</p>
+     * 
+     * <p><code>null</code> is handled and returns <code>false</code>.</p>
+     * 
+     * <p>This implementation forwards to the {@link #containsDouble(double)} method.</p>
+     *
+     * @param value  the double to test, may be <code>null</code>
+     * @return <code>true</code> if the specified number occurs within this
+     *  range by <code>double</code> comparison
+     */
+    public boolean containsDouble(Number value) {
+        if (value == null) {
+            return false;
+        }
+        return containsDouble(value.doubleValue());
+    }
+
+    /**
+     * <p>Tests whether the specified <code>double</code> occurs within
+     * this range using <code>double</code> comparison.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumDouble()} and 
+     * {@link #getMaximumDouble()} methods and should be good for most uses.</p>
+     * 
+     * @param value  the double to test
+     * @return <code>true</code> if the specified number occurs within this
+     *  range by <code>double</code> comparison
+     */
+    public boolean containsDouble(double value) {
+        int compareMin = NumberUtils.compare(getMinimumDouble(), value);
+        int compareMax = NumberUtils.compare(getMaximumDouble(), value);
+        return compareMin <= 0 && compareMax >= 0;
+    }
+
+    /**
+     * <p>Tests whether the specified <code>Number</code> occurs within
+     * this range using <code>float</code> comparison.</p>
+     * 
+     * <p><code>null</code> is handled and returns <code>false</code>.</p>
+     * 
+     * <p>This implementation forwards to the {@link #containsFloat(float)} method.</p>
+     *
+     * @param value  the float to test, may be <code>null</code>
+     * @return <code>true</code> if the specified number occurs within this
+     *  range by <code>float</code> comparison
+     */
+    public boolean containsFloat(Number value) {
+        if (value == null) {
+            return false;
+        }
+        return containsFloat(value.floatValue());
+    }
+
+    /**
+     * <p>Tests whether the specified <code>float</code> occurs within
+     * this range using <code>float</code> comparison.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumFloat()} and 
+     * {@link #getMaximumFloat()} methods and should be good for most uses.</p>
+     * 
+     * @param value  the float to test
+     * @return <code>true</code> if the specified number occurs within this
+     *  range by <code>float</code> comparison
+     */
+    public boolean containsFloat(float value) {
+        int compareMin = NumberUtils.compare(getMinimumFloat(), value);
+        int compareMax = NumberUtils.compare(getMaximumFloat(), value);
+        return compareMin <= 0 && compareMax >= 0;
+    }
+
+    // Range tests
+    //--------------------------------------------------------------------
+
+    /**
+     * <p>Tests whether the specified range occurs entirely within this range.</p>
+     * 
+     * <p>The exact comparison implementation varies by subclass. It is
+     * intended that an <code>int</code> specific subclass will compare using
+     * <code>int</code> comparison.</p>
+     * 
+     * <p><code>null</code> is handled and returns <code>false</code>.</p>
+     * 
+     * <p>This implementation uses the {@link #containsNumber(Number)} method.
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @param range  the range to test, may be <code>null</code>
+     * @return <code>true</code> if the specified range occurs entirely within
+     *  this range; otherwise, <code>false</code>
+     * @throws IllegalArgumentException if the <code>Range</code> cannot be compared
+     */
+    public boolean containsRange(Range range) {
+        if (range == null) {
+            return false;
+        }
+        return containsNumber(range.getMinimumNumber()) 
+            && containsNumber(range.getMaximumNumber());
+    }
+
+    /**
+     * <p>Tests whether the specified range overlaps with this range.</p>
+     * 
+     * <p>The exact comparison implementation varies by subclass. It is
+     * intended that an <code>int</code> specific subclass will compare using
+     * <code>int</code> comparison.</p>
+     * 
+     * <p><code>null</code> is handled and returns <code>false</code>.</p>
+     * 
+     * <p>This implementation uses the {@link #containsNumber(Number)} and
+     * {@link #containsRange(Range)} methods.
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @param range  the range to test, may be <code>null</code>
+     * @return <code>true</code> if the specified range overlaps with this
+     *  range; otherwise, <code>false</code>
+     * @throws IllegalArgumentException if the <code>Range</code> cannot be compared
+     */
+    public boolean overlapsRange(Range range) {
+        if (range == null) {
+            return false;
+        }
+        return range.containsNumber(getMinimumNumber())
+            || range.containsNumber(getMaximumNumber())
+            || containsNumber(range.getMinimumNumber());
+    }
+
+    // Basics
+    //--------------------------------------------------------------------
+
+    /**
+     * <p>Compares this range to another object to test if they are equal.</p>.
+     * 
+     * <p>To be equal, the class, minimum and maximum must be equal.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumNumber()} and 
+     * {@link #getMaximumNumber()} methods. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @param obj the reference object with which to compare
+     * @return <code>true</code> if this object is equal
+     */
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        } else if (obj == null || obj.getClass() != getClass()) {
+            return false;
+        } else {
+            Range range = (Range) obj;
+            return getMinimumNumber().equals(range.getMinimumNumber()) &&
+                   getMaximumNumber().equals(range.getMaximumNumber());
+        }
+    }
+
+    /**
+     * <p>Gets a hashCode for the range.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumNumber()} and 
+     * {@link #getMaximumNumber()} methods. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @return a hash code value for this object
+     */
+    public int hashCode() {
+        int result = 17;
+        result = 37 * result + getClass().hashCode();
+        result = 37 * result + getMinimumNumber().hashCode();
+        result = 37 * result + getMaximumNumber().hashCode();
+        return result;
+    }
+
+    /**
+     * <p>Gets the range as a <code>String</code>.</p>
+     *
+     * <p>The format of the String is 'Range[<i>min</i>,<i>max</i>]'.</p>
+     * 
+     * <p>This implementation uses the {@link #getMinimumNumber()} and 
+     * {@link #getMaximumNumber()} methods. 
+     * Subclasses may be able to optimise this.</p>
+     *
+     * @return the <code>String</code> representation of this range
+     */
+    public String toString() {
+        StringBuffer buf = new StringBuffer(32);
+        buf.append("Range[");
+        buf.append(getMinimumNumber());
+        buf.append(',');
+        buf.append(getMaximumNumber());
+        buf.append(']');
+        return buf.toString();
+    }
+
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/Range.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/package.html
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/package.html?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/package.html (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/package.html Fri Jan 20 05:47:50 2006
@@ -0,0 +1,22 @@
+<!--
+Copyright 2002-2005 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.
+-->
+<html>
+<body>
+Extends {@link java.math} for business mathematical classes. This package is intended for business
+mathematical use, not scientific use.
+@since 2.0
+</body>
+</html>

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/math/package.html
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/mutable/Mutable.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/mutable/Mutable.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/mutable/Mutable.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/mutable/Mutable.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2002-2005 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.apache.mina.common.support.lang.mutable;
+
+/**
+ * Provides mutable access to a value.
+ * <p>
+ * <code>Mutable</code> is used as a generic interface to the implementations in this package.
+ * <p>
+ * A typical use case would be to enable a primitive or string to be passed to a method and allow that method to
+ * effectively change the value of the primitive/string. Another use case is to store a frequently changing primitive in
+ * a collection (for example a total in a map) without needing to create new Integer/Long wrapper objects.
+ * 
+ * @author Matthew Hawthorne
+ * @since 2.1
+ * @version $Id$
+ */
+public interface Mutable {
+
+    /**
+     * Gets the value of this mutable.
+     * 
+     * @return the stored value
+     */
+    Object getValue();
+
+    /**
+     * Sets the value of this mutable.
+     * 
+     * @param value
+     *            the value to store
+     * @throws NullPointerException
+     *             if the object is null and null is invalid
+     * @throws ClassCastException
+     *             if the type is invalid
+     */
+    void setValue(Object value);
+
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/mutable/Mutable.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/mutable/MutableByte.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/mutable/MutableByte.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/mutable/MutableByte.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/mutable/MutableByte.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2004-2005 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.apache.mina.common.support.lang.mutable;
+
+/**
+ * A mutable <code>byte</code> wrapper.
+ * 
+ * @see Byte
+ * @since 2.1
+ * @version $Id$
+ */
+public class MutableByte extends Number implements Comparable, Mutable {
+
+    /** Serialization lock. */
+    private static final long serialVersionUID = -1585823265L;
+
+    /** The mutable value. */
+    private byte value;
+
+    /**
+     * Constructs a new MutableByte with the default value of zero.
+     */
+    public MutableByte() {
+        super();
+    }
+
+    /**
+     * Constructs a new MutableByte with the specified value.
+     * 
+     * @param value
+     *            a value.
+     */
+    public MutableByte(byte value) {
+        super();
+        this.value = value;
+    }
+
+    /**
+     * Constructs a new MutableByte with the specified value.
+     * 
+     * @param value
+     *            a value.
+     * @throws NullPointerException
+     *             if the object is null
+     */
+    public MutableByte(Number value) {
+        super();
+        this.value = value.byteValue();
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Gets the value as a Byte instance.
+     * 
+     * @return the value as a Byte
+     */
+    public Object getValue() {
+        return new Byte(this.value);
+    }
+
+    /**
+     * Sets the value.
+     * 
+     * @param value
+     *            the value to set
+     */
+    public void setValue(byte value) {
+        this.value = value;
+    }
+
+    /**
+     * Sets the value from any Number instance.
+     * 
+     * @param value
+     *            the value to set
+     * @throws NullPointerException
+     *             if the object is null
+     * @throws ClassCastException
+     *             if the type is not a {@link Number}
+     */
+    public void setValue(Object value) {
+        setValue(((Number) value).byteValue());
+    }
+
+    //-----------------------------------------------------------------------
+    // shortValue relies on Number implementation
+    /**
+     * Returns the value of this MutableByte as a byte.
+     *
+     * @return the numeric value represented by this object after conversion to type byte.
+     */
+    public byte byteValue() {
+        return value;
+    }
+
+    /**
+     * Returns the value of this MutableByte as a int.
+     *
+     * @return the numeric value represented by this object after conversion to type int.
+     */
+    public int intValue() {
+        return value;
+    }
+
+    /**
+     * Returns the value of this MutableByte as a long.
+     *
+     * @return the numeric value represented by this object after conversion to type long.
+     */
+    public long longValue() {
+        return value;
+    }
+
+    /**
+     * Returns the value of this MutableByte as a float.
+     *
+     * @return the numeric value represented by this object after conversion to type float.
+     */
+    public float floatValue() {
+        return value;
+    }
+
+    /**
+     * Returns the value of this MutableByte as a double.
+     *
+     * @return the numeric value represented by this object after conversion to type double.
+     */
+    public double doubleValue() {
+        return value;
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Compares this object against the specified object. The result is <code>true</code> if and only if the argument
+     * is not <code>null</code> and is a <code>MutableByte</code> object that contains the same <code>byte</code>
+     * value as this object.
+     * 
+     * @param obj
+     *            the object to compare with.
+     * @return <code>true</code> if the objects are the same; <code>false</code> otherwise.
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof MutableByte) {
+            return value == ((MutableByte) obj).byteValue();
+        }
+        return false;
+    }
+
+    /**
+     * Returns a suitable hashcode for this mutable.
+     * 
+     * @return a suitable hashcode
+     */
+    public int hashCode() {
+        return value;
+    }
+
+    /**
+     * Compares this mutable to another in ascending order.
+     * 
+     * @param obj
+     *            the mutable to compare to
+     * @return negative if this is less, zero if equal, positive if greater
+     * @throws ClassCastException if the argument is not a MutableByte
+     */
+    public int compareTo(Object obj) {
+        MutableByte other = (MutableByte) obj;
+        byte anotherVal = other.value;
+        return value < anotherVal ? -1 : (value == anotherVal ? 0 : 1);
+    }
+
+    /**
+     * Returns the String value of this mutable.
+     * 
+     * @return the mutable value as a string
+     */
+    public String toString() {
+        return String.valueOf(value);
+    }
+
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/mutable/MutableByte.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message