commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang/mutable MutableByteTest.java MutableDoubleTest.java MutableFloatTest.java MutableIntegerTest.java MutableLongTest.java MutableNumberTest.java MutableShortTest.java MutableTestSuite.java
Date Fri, 11 Jun 2004 02:26:32 GMT
matth       2004/06/10 19:26:32

  Added:       lang/src/java/org/apache/commons/lang/mutable Mutable.java
                        MutableByte.java MutableDouble.java
                        MutableFloat.java MutableInteger.java
                        MutableLong.java MutableNumber.java
                        MutableShort.java
               lang/src/test/org/apache/commons/lang/mutable
                        MutableByteTest.java MutableDoubleTest.java
                        MutableFloatTest.java MutableIntegerTest.java
                        MutableLongTest.java MutableNumberTest.java
                        MutableShortTest.java MutableTestSuite.java
  Log:
  Adding initial crack at mutables.
  
  Revision  Changes    Path
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/Mutable.java
  
  Index: Mutable.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  /**
   * A mutable object.
   *
   * @author Matthew Hawthorne
   * @since 2.1
   * @version $Id: Mutable.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   */
  public interface Mutable {
  
      /**
       * Sets the value of this object.
       *
       * @param value the value of this object.
       */
      public void setValue(Object value);
  
      /**
       * Gets the value of this object.
       *
       * @return a value.
       */
      public Object getValue();
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableByte.java
  
  Index: MutableByte.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  /**
   * A mutable <code>Byte</code>.
   * 
   * @since 2.1
   * @version $Id: MutableByte.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   */
  public class MutableByte extends MutableNumber {
  
      /**
       * Internal value.
       */
      private byte value;
      
      /**
       * Instantiates with the specified value
       * @param value a value.
       */
      public MutableByte(byte value) {
          super();
          this.value = value;
      }
  
      public void setValue(byte value) {
          this.value = value;
      }
  
      public long longValue() {
          return this.value;
      }
  
      public double doubleValue() {
          return this.value;
      }
  
      public int intValue() {
          return this.value;
      }
  
      /**
       * @return a <code>Byte</code>
       */
      public Object getValue() {
          return new Byte(this.value);
      }
  
      /**
       * @param value a <code>Byte</code>
       */
      public void setValue(Object value) {
          setValue(((Number)value).byteValue());
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableDouble.java
  
  Index: MutableDouble.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  /**
   * A mutable <code>Double</code>
   * 
   * @since 2.1
   * @version $Id: MutableDouble.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   */
  public class MutableDouble extends MutableNumber {
  
      /**
       * Internal value.
       */
      private double value;
  
      /**
       * Instantiates with the specified value
       * @param value a value.
       */
      public MutableDouble(double value) {
          super();
          this.value = value;
      }
  
      public void setValue(double value) {
          this.value = value;
      }
  
      public double doubleValue() {
          return this.value;
      }
  
      public long longValue() {
          return (long)this.value;
      }
  
      public int intValue() {
          return (int)this.value;
      }
  
      public Object getValue() {
          return new Double(this.value);
      }
  
      public void setValue(Object value) {
          setValue(((Number)value).doubleValue());
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableFloat.java
  
  Index: MutableFloat.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  /**
   * A mutable <code>Float</code>
   * 
   * @since 2.1
   * @version $Id: MutableFloat.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   */
  public class MutableFloat extends MutableNumber {
  
      /**
       * Internal value.
       */
      private float value;
  
      /**
       * Instantiates with the specified value
       * 
       * @param value a value.
       */
      public MutableFloat(float value) {
          super();
          this.value = value;
      }
  
      public void setValue(float value) {
          this.value = value;
      }
  
      public double doubleValue() {
          return this.value;
      }
  
      public int intValue() {
          return (int)this.value;
      }
  
      public long longValue() {
          return (long)this.value;
      }
  
      public Object getValue() {
          return new Float(this.value);
      }
  
      public void setValue(Object value) {
          setValue(((Number)value).floatValue());
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableInteger.java
  
  Index: MutableInteger.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  /**
   * A mutable <code>Integer</code>.
   * 
   * @since 2.1
   * @version $Id: MutableInteger.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   */
  public class MutableInteger extends MutableNumber {
  
      /**
       * Internal value.
       */
      private int value;
  
      /**
       * Instantiates with the specified value
       * 
       * @param value a value.
       */
      public MutableInteger(int value) {
          super();
          this.value = value;
      }
  
      public void setValue(int value) {
          this.value = value;
      }
  
      public double doubleValue() {
          return this.value;
      }
  
      public long longValue() {
          return this.value;
      }
  
      public int intValue() {
          return this.value;
      }
  
      public Object getValue() {
          return new Float(this.value);
      }
  
      public void setValue(Object value) {
          setValue(((Number)value).intValue());
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableLong.java
  
  Index: MutableLong.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  /**
   * A mutable <code>Long</code>
   * 
   * @since 2.1
   * @version $Id: MutableLong.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   */
  public class MutableLong extends MutableNumber {
  
      /**
       * Internal value.
       */
      private long value;
  
      /**
       * Instantiates with the specified value
       * @param value a value.
       */
      public MutableLong(long value) {
          super();
          setValue(value);
      }
  
      public void setValue(long value) {
          this.value = value;
      }
  
      public double doubleValue() {
          return this.value;
      }
  
      public long longValue() {
          return this.value;
      }
  
      public int intValue() {
          return (int)this.value;
      }
  
      public Object getValue() {
          return new Long(this.value);
      }
  
      public void setValue(Object value) {
          setValue(((Number)value).longValue());
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableNumber.java
  
  Index: MutableNumber.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  import java.io.Serializable;
  
  /**
   * A mutable <code>Number</code>.
   *
   * @since 2.1
   * @version $Id: MutableNumber.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   */
  public abstract class MutableNumber
      extends Number
      implements Comparable, Mutable, Serializable {
  
      MutableNumber() {
          super();
      }
  
      // ----------------------------------------------------------------
      // Number overrides
      // ----------------------------------------------------------------
  
      public float floatValue() {
          return (float)doubleValue();
      }
      
      // ----------------------------------------------------------------
      // Object overrides
      // ----------------------------------------------------------------
  
      public String toString() {
          return String.valueOf(doubleValue()).intern();
      }
  
      public int hashCode() {
          return super.hashCode();
      }
  
      /**
       * Compares <code>this</code> to another object.
       * 
       * @param obj an object to compare to
       * @return <code>true</code> if <code>this</code> is equal to

       * <code>obj</code>.
       * @see #compareTo(Object)
       */
      public boolean equals(Object obj) {
          return super.equals(obj);
      }
  
      // ----------------------------------------------------------------
      //  Comparable overrides
      // ----------------------------------------------------------------
  
      /**
       * Compares to another object
       * 
       * @param o an object to compare to
       * @return -1 if <code>this < o</code>, 0 if <code>this.equals(o)</code>,

       *  1 if <code>this > o<code>
       * @throws ClassCastException if <code>o</code> is not a 
       * <code>Number</code>.
       */
      public int compareTo(Object o) {
          final double d = ((Number)o).doubleValue();
          return (doubleValue() < d) ? -1 : (doubleValue() > d) ? 1 : 0;
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/mutable/MutableShort.java
  
  Index: MutableShort.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  /**
   * A mutable <code>Short</code>
   * 
   * @since 2.1
   * @version $Id: MutableShort.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   */
  public class MutableShort extends MutableNumber {
  
      /**
       * Internal value.
       */
      private short value;
  
      /**
       * Instantiates with the specified value
       * @param value a value.
       */
      public MutableShort(short value) {
          super();
          this.value = value;
      }
  
      public void setValue(short value) {
          this.value = value;
      }
  
      public double doubleValue() {
          return this.value;
      }
  
      public int intValue() {
          return this.value;
      }
  
      public long longValue() {
          return this.value;
      }
  
      public Object getValue() {
          return new Short(this.value);
      }
  
      public void setValue(Object value) {
          setValue(((Number)value).shortValue());
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableByteTest.java
  
  Index: MutableByteTest.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * JUnit tests.
   * 
   * @version $Id: MutableByteTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   * @see MutableByte
   */
  public class MutableByteTest extends MutableNumberTest {
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
      
      public static Test suite() {
          return new TestSuite(MutableByteTest.class);
      }
  
      public MutableByteTest(String testName) {
          super(testName);
      }
  
      public MutableNumber getMutableNumber(double value) {
          return new MutableByte((byte)value);
      }
  
      // ----------------------------------------------------------------
      //  Converters
      // ----------------------------------------------------------------
  
      public byte byteValue(double value) {
          return (byte)value;
      }
  
      public short shortValue(double value) {
          return (byte)value;
      }
  
      public int intValue(double value) {
          return (byte)value;
      }
  
      public long longValue(double value) {
          return (byte)value;
      }
  
      public float floatValue(double value) {
          return (byte)value;
      }
  
      public double doubleValue(double value) {
          return (byte)value;
      }
  
  } // MutableByteTest
  
  
  
  1.1                  jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableDoubleTest.java
  
  Index: MutableDoubleTest.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * JUnit tests.
   * 
   * @version $Id: MutableDoubleTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   * @see MutableDouble
   */
  public class MutableDoubleTest extends MutableNumberTest {
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
      
      public static Test suite() {
          return new TestSuite(MutableDoubleTest.class);
      }
  
      public MutableDoubleTest(String testName) {
          super(testName);
      }
  
      public MutableNumber getMutableNumber(double value) {
          return new MutableDouble(value);
      }
  
      // Converters
      // ----------------------------------------------------------------
      
      public byte byteValue(double value) {
          return (byte)value;
      }
  
      public short shortValue(double value) {
          return (short)value;
      }
  
      public int intValue(double value) {
          return (int)value;
      }
  
      public long longValue(double value) {
          return (long)value;
      }
  
      public float floatValue(double value) {
          return (float)value;
      }
  
      public double doubleValue(double value) {
          return value;
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableFloatTest.java
  
  Index: MutableFloatTest.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * JUnit tests.
   * 
   * @version $Id: MutableFloatTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   * @see MutableFloat
   */
  public class MutableFloatTest extends MutableNumberTest {
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return new TestSuite(MutableFloatTest.class);
      }
  
      /**
       * @param testName
       */
      public MutableFloatTest(String testName) {
          super(testName);
      }
  
      public MutableNumber getMutableNumber(double value) {
          return new MutableFloat((float)value);
      }
  
      //  Converters
      // ----------------------------------------------------------------
      public byte byteValue(double value) {
          return (byte)(float)value;
      }
  
      public short shortValue(double value) {
          return (short)(float)value;
      }
  
      public int intValue(double value) {
          return (int)(float)value;
      }
  
      public long longValue(double value) {
          return (long)(float)value;
      }
  
      public float floatValue(double value) {
          return (float)value;
      }
  
      public double doubleValue(double value) {
          return (float)value;
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableIntegerTest.java
  
  Index: MutableIntegerTest.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * JUnit tests.
   * 
   * @version $Id: MutableIntegerTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   * @see MutableInteger
   */
  public class MutableIntegerTest extends MutableNumberTest {
  
      public MutableIntegerTest(String testName) {
          super(testName);
      }
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return new TestSuite(MutableIntegerTest.class);
      }
  
      public MutableNumber getMutableNumber(double value) {
          return new MutableInteger((int)value);
      }
  
      // ----------------------------------------------------------------
      //  Converters
      // ----------------------------------------------------------------
  
      public byte byteValue(double value) {
          return (byte)(int)value;
      }
  
      public double doubleValue(double value) {
          return (int)value;
      }
  
      public float floatValue(double value) {
          return (int)value;
      }
  
      public int intValue(double value) {
          return (int)value;
      }
  
      public long longValue(double value) {
          return (int)value;
      }
  
      public short shortValue(double value) {
          return (short)(int)value;
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableLongTest.java
  
  Index: MutableLongTest.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * JUnit tests.
   * 
   * @version $Id: MutableLongTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   * @see MutableLong
   */
  public class MutableLongTest extends MutableNumberTest {
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return new TestSuite(MutableLongTest.class);
      }
  
      public MutableLongTest(String testName) {
          super(testName);
      }
  
      public MutableNumber getMutableNumber(double value) {
          return new MutableLong((long)value);
      }
  
      // ----------------------------------------------------------------
      // Converters
      // ----------------------------------------------------------------    
  
      public byte byteValue(double value) {
          return (byte)(long)value;
      }
  
      public short shortValue(double value) {
          return (short)(long)value;
      }
  
      public int intValue(double value) {
          return (int)(long)value;
      }
  
      public long longValue(double value) {
          return (long)value;
      }
  
      public float floatValue(double value) {
          return (long)value;
      }
  
      public double doubleValue(double value) {
          return (long)value;
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableNumberTest.java
  
  Index: MutableNumberTest.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  import junit.framework.TestCase;
  
  /**
   * JUnit tests.
   *
   * @version $Id: MutableNumberTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   * @see MutableNumber
   */
  public abstract class MutableNumberTest extends TestCase {
  
      public MutableNumberTest(String testName) {
          super(testName);
      }
  
      /**
       * Gets an instance to test.
       * @param value the value of the number.
       * @return a <code>MutableNumber</code>
       */
      public abstract MutableNumber getMutableNumber(double value);
  
      // ----------------------------------------------------------------
      // Converters
      // ----------------------------------------------------------------
  
      public abstract byte byteValue(double value);
  
      public abstract short shortValue(double value);
  
      public abstract int intValue(double value);
  
      public abstract long longValue(double value);
  
      public abstract float floatValue(double value);
  
      public abstract double doubleValue(double value);
  
      //  ----------------------------------------------------------------
      // Tests
      // ----------------------------------------------------------------
  
      public void testCompareTo() {
          final double num = 0;
          final MutableNumber mutNum = getMutableNumber(num);
  
          assertEquals("Equality", 0, mutNum.compareTo(new Double(num)));
  
          assertEquals(
              "Less than",
              -1,
              mutNum.compareTo(new Double(Double.POSITIVE_INFINITY)));
  
          assertEquals(
              "Greater than",
              1,
              mutNum.compareTo(new Double(Double.NEGATIVE_INFINITY)));
      }
  
      public void testPrimitiveAccessors() {
          testPrimitiveAccessors(0);
          testPrimitiveAccessors(Double.MAX_VALUE);
          testPrimitiveAccessors(-Double.MAX_VALUE);
  
          testPrimitiveAccessors(Float.MAX_VALUE);
          testPrimitiveAccessors(-Float.MAX_VALUE);
  
          testPrimitiveAccessors(Long.MAX_VALUE);
          testPrimitiveAccessors(Long.MIN_VALUE);
  
          testPrimitiveAccessors(Integer.MAX_VALUE);
          testPrimitiveAccessors(Integer.MIN_VALUE);
  
          testPrimitiveAccessors(Short.MAX_VALUE);
          testPrimitiveAccessors(Short.MIN_VALUE);
  
          testPrimitiveAccessors(Byte.MAX_VALUE);
          testPrimitiveAccessors(Byte.MIN_VALUE);
      }
  
      public void XtestObjectAccessors() {
          testObjectAccessors(0);
          testObjectAccessors(Double.MAX_VALUE);
          testObjectAccessors(-Double.MAX_VALUE);
  
          testObjectAccessors(Float.MAX_VALUE);
          testObjectAccessors(-Float.MAX_VALUE);
  
          testObjectAccessors(Long.MAX_VALUE);
          testObjectAccessors(Long.MIN_VALUE);
  
          testObjectAccessors(Integer.MAX_VALUE);
          testObjectAccessors(Integer.MIN_VALUE);
  
          testObjectAccessors(Short.MAX_VALUE);
          testObjectAccessors(Short.MIN_VALUE);
  
          testObjectAccessors(Byte.MAX_VALUE);
          testObjectAccessors(Byte.MIN_VALUE);
      }
  
      public void testSetValue() {
          setValueAndTestAccessors(Double.MAX_VALUE);
          setValueAndTestAccessors(-Double.MAX_VALUE);
  
          setValueAndTestAccessors(Float.MAX_VALUE);
          setValueAndTestAccessors(-Float.MAX_VALUE);
  
          setValueAndTestAccessors(Long.MAX_VALUE);
          setValueAndTestAccessors(Long.MIN_VALUE);
  
          setValueAndTestAccessors(Integer.MAX_VALUE);
          setValueAndTestAccessors(Integer.MIN_VALUE);
  
          setValueAndTestAccessors(Short.MAX_VALUE);
          setValueAndTestAccessors(Short.MIN_VALUE);
  
          setValueAndTestAccessors(Byte.MAX_VALUE);
          setValueAndTestAccessors(Byte.MIN_VALUE);
      }
  
      // ----------------------------------------------------------------
      // Private methods
      // ----------------------------------------------------------------
  
      private void setValueAndTestAccessors(double num) {
          final MutableNumber mutNum = getMutableNumber(0);
          mutNum.setValue(new Double(num));
          testPrimitiveAccessors(mutNum, num);
          //testObjectAccessors(mutNum, num);
      }
  
      private void testPrimitiveAccessors(double num) {
          testPrimitiveAccessors(getMutableNumber(num), num);
      }
  
      private void testPrimitiveAccessors(MutableNumber mutNum, double num) {
          assertEquals("byte comparison", byteValue(num), mutNum.byteValue());
          assertEquals("short comparison", shortValue(num), mutNum.shortValue());
          assertEquals("int comparison", intValue(num), mutNum.intValue());
          assertEquals("long comparison", longValue(num), mutNum.longValue());
  
          assertEquals(
              "float comparison",
              floatValue(num),
              mutNum.floatValue(),
              0);
  
          assertEquals(
              "double comparison",
              doubleValue(num),
              mutNum.doubleValue(),
              0);
      }
  
      private void testObjectAccessors(double num) {
          testObjectAccessors(getMutableNumber(num), num);
      }
  
      private void testObjectAccessors(MutableNumber mutNum, double num) {
          assertEquals(
              "byte comparison",
              new Byte(byteValue(num)),
              mutNum.getValue());
  
          assertEquals(
              "short comparison",
              new Short(shortValue(num)),
              mutNum.getValue());
  
          assertEquals(
              "int comparison",
              new Integer(intValue(num)),
              mutNum.getValue());
  
          assertEquals(
              "long comparison",
              new Long(longValue(num)),
              mutNum.getValue());
  
          assertEquals(
              "float comparison",
              new Float(floatValue(num)),
              mutNum.getValue());
  
          assertEquals(
              "double comparison",
              new Double(doubleValue(num)),
              mutNum.getValue());
      }
  
  }
  
  
  
  1.1                  jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableShortTest.java
  
  Index: MutableShortTest.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * JUnit tests.
   * 
   * @version $Id: MutableShortTest.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   * @see MutableShort
   */
  public class MutableShortTest extends MutableNumberTest {
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          return new TestSuite(MutableShortTest.class);
      }
  
      public MutableShortTest(String testName) {
          super(testName);
      }
  
      // ----------------------------------------------------------------
      //  Converters
      // ----------------------------------------------------------------
  
      public MutableNumber getMutableNumber(double value) {
          return new MutableShort((short)value);
      }
  
      public byte byteValue(double value) {
          return (byte)(short)value;
      }
  
      public short shortValue(double value) {
          return (short)value;
      }
  
      public int intValue(double value) {
          return (short)value;
      }
  
      public long longValue(double value) {
          return (short)value;
      }
  
      public float floatValue(double value) {
          return (short)value;
      }
  
      public double doubleValue(double value) {
          return (short)value;
      }
  
  }
  
  
  
  
  1.1                  jakarta-commons/lang/src/test/org/apache/commons/lang/mutable/MutableTestSuite.java
  
  Index: MutableTestSuite.java
  ===================================================================
  /*
   * 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.commons.lang.mutable;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * JUnit tests.
   *
   * @version $Id: MutableTestSuite.java,v 1.1 2004/06/11 02:26:32 matth Exp $
   */
  public final class MutableTestSuite {
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          final TestSuite suite = new TestSuite();
  
          suite.addTest(MutableByteTest.suite());
          suite.addTest(MutableShortTest.suite());
          suite.addTest(MutableIntegerTest.suite());
          suite.addTest(MutableLongTest.suite());
          suite.addTest(MutableFloatTest.suite());
          suite.addTest(MutableDoubleTest.suite());
  
          return suite;
      }
  
      private MutableTestSuite() {}
  
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message