mev-4.0.01/source/org/tigr/microarray/mev/cluster/gui/impl/util/FloatArray.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2002, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4
2 26 Feb 07 jari 5 This software is provided "AS IS".  TIGR makes no warranties, express
2 26 Feb 07 jari 6 or implied, including no representation or warranty with respect to
2 26 Feb 07 jari 7 the performance of the software and derivatives or their safety,
2 26 Feb 07 jari 8 effectiveness, or commercial viability.  TIGR does not warrant the
2 26 Feb 07 jari 9 merchantability or fitness of the software and derivatives for any
2 26 Feb 07 jari 10 particular purpose, or that they may be exploited without infringing
2 26 Feb 07 jari 11 the copyrights, patent rights or property rights of others. TIGR shall
2 26 Feb 07 jari 12 not be liable for any claim, demand or action for any loss, harm,
2 26 Feb 07 jari 13 illness or other damage or injury arising from access to or use of the
2 26 Feb 07 jari 14 software or associated information, including without limitation any
2 26 Feb 07 jari 15 direct, indirect, incidental, exemplary, special or consequential
2 26 Feb 07 jari 16 damages.
2 26 Feb 07 jari 17
2 26 Feb 07 jari 18 This software program may not be sold, leased, transferred, exported
2 26 Feb 07 jari 19 or otherwise disclaimed to anyone, in whole or in part, without the
2 26 Feb 07 jari 20 prior written consent of TIGR.
2 26 Feb 07 jari 21 */
2 26 Feb 07 jari 22 /*
2 26 Feb 07 jari 23  * $RCSfile: FloatArray.java,v $
2 26 Feb 07 jari 24  * $Revision: 1.3 $
2 26 Feb 07 jari 25  * $Date: 2005/03/10 20:36:56 $
2 26 Feb 07 jari 26  * $Author: braistedj $
2 26 Feb 07 jari 27  * $State: Exp $
2 26 Feb 07 jari 28  */
2 26 Feb 07 jari 29 package org.tigr.microarray.mev.cluster.gui.impl.util;
2 26 Feb 07 jari 30
2 26 Feb 07 jari 31 public class FloatArray {
2 26 Feb 07 jari 32
2 26 Feb 07 jari 33     private float[] elementData;
2 26 Feb 07 jari 34     private int size;
2 26 Feb 07 jari 35
2 26 Feb 07 jari 36     /**
2 26 Feb 07 jari 37      * Constructs an empty array with the specified initial capacity.
2 26 Feb 07 jari 38      */
2 26 Feb 07 jari 39     public FloatArray(int initialCapacity) {
2 26 Feb 07 jari 40         this.elementData = new float[initialCapacity];
2 26 Feb 07 jari 41     }
2 26 Feb 07 jari 42
2 26 Feb 07 jari 43     /**
2 26 Feb 07 jari 44      * Returns an array containing all of the floats in this container
2 26 Feb 07 jari 45      * in the correct order.
2 26 Feb 07 jari 46      */
2 26 Feb 07 jari 47     public float[] toArray() {
2 26 Feb 07 jari 48         float[] result = new float[size];
2 26 Feb 07 jari 49         System.arraycopy(elementData, 0, result, 0, size);
2 26 Feb 07 jari 50         return result;
2 26 Feb 07 jari 51     }
2 26 Feb 07 jari 52
2 26 Feb 07 jari 53     /**
2 26 Feb 07 jari 54      * Returns the float value at the specified position in this container.
2 26 Feb 07 jari 55      */
2 26 Feb 07 jari 56     public float get(int index) {
2 26 Feb 07 jari 57         RangeCheck(index);
2 26 Feb 07 jari 58         return elementData[index];
2 26 Feb 07 jari 59     }
2 26 Feb 07 jari 60
2 26 Feb 07 jari 61     /**
2 26 Feb 07 jari 62      * Replaces the float value at the specified position in this container with
2 26 Feb 07 jari 63      * the specified one.
2 26 Feb 07 jari 64      */
2 26 Feb 07 jari 65     public void set(int index, float value) {
2 26 Feb 07 jari 66         RangeCheck(index);
2 26 Feb 07 jari 67         elementData[index] = value;
2 26 Feb 07 jari 68     }
2 26 Feb 07 jari 69
2 26 Feb 07 jari 70     /**
2 26 Feb 07 jari 71      * Appends the specified value to the end of this container.
2 26 Feb 07 jari 72      */
2 26 Feb 07 jari 73     public boolean add(float i) {
2 26 Feb 07 jari 74         ensureCapacity(size + 1);
2 26 Feb 07 jari 75         elementData[size++] = i;
2 26 Feb 07 jari 76         return true;
2 26 Feb 07 jari 77     }
2 26 Feb 07 jari 78
2 26 Feb 07 jari 79     public int getSize() {
2 26 Feb 07 jari 80         return size;
2 26 Feb 07 jari 81     }
2 26 Feb 07 jari 82
2 26 Feb 07 jari 83     /**
2 26 Feb 07 jari 84      * Check if the given index is in range. If not, throw an appropriate
2 26 Feb 07 jari 85      * runtime exception.
2 26 Feb 07 jari 86      */
2 26 Feb 07 jari 87     private void RangeCheck(int index) {
2 26 Feb 07 jari 88         if (index >= size || index < 0)
2 26 Feb 07 jari 89             throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
2 26 Feb 07 jari 90     }
2 26 Feb 07 jari 91
2 26 Feb 07 jari 92     /**
2 26 Feb 07 jari 93      * Increases the capacity of this <tt>FloatArray</tt> instance, if
2 26 Feb 07 jari 94      * necessary, to ensure that it can hold at least the number of floats
2 26 Feb 07 jari 95      * specified by the minimum capacity argument.
2 26 Feb 07 jari 96      *
2 26 Feb 07 jari 97      * @param minCapacity the desired minimum capacity.
2 26 Feb 07 jari 98      */
2 26 Feb 07 jari 99     private void ensureCapacity(int minCapacity) {
2 26 Feb 07 jari 100         int oldCapacity = elementData.length;
2 26 Feb 07 jari 101         if (minCapacity > oldCapacity) {
2 26 Feb 07 jari 102             float[] oldData = elementData;
2 26 Feb 07 jari 103             int newCapacity = (oldCapacity * 3)/2 + 1;
2 26 Feb 07 jari 104             if (newCapacity < minCapacity)
2 26 Feb 07 jari 105                 newCapacity = minCapacity;
2 26 Feb 07 jari 106             elementData = new float[newCapacity];
2 26 Feb 07 jari 107             System.arraycopy(oldData, 0, elementData, 0, size);
2 26 Feb 07 jari 108         }
2 26 Feb 07 jari 109     }
2 26 Feb 07 jari 110
2 26 Feb 07 jari 111 }