2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2002, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
|
2 |
26 Feb 07 |
jari |
This software is provided "AS IS". TIGR makes no warranties, express |
2 |
26 Feb 07 |
jari |
or implied, including no representation or warranty with respect to |
2 |
26 Feb 07 |
jari |
the performance of the software and derivatives or their safety, |
2 |
26 Feb 07 |
jari |
effectiveness, or commercial viability. TIGR does not warrant the |
2 |
26 Feb 07 |
jari |
merchantability or fitness of the software and derivatives for any |
2 |
26 Feb 07 |
jari |
particular purpose, or that they may be exploited without infringing |
2 |
26 Feb 07 |
jari |
the copyrights, patent rights or property rights of others. TIGR shall |
2 |
26 Feb 07 |
jari |
not be liable for any claim, demand or action for any loss, harm, |
2 |
26 Feb 07 |
jari |
illness or other damage or injury arising from access to or use of the |
2 |
26 Feb 07 |
jari |
software or associated information, including without limitation any |
2 |
26 Feb 07 |
jari |
direct, indirect, incidental, exemplary, special or consequential |
2 |
26 Feb 07 |
jari |
damages. |
2 |
26 Feb 07 |
jari |
17 |
|
2 |
26 Feb 07 |
jari |
This software program may not be sold, leased, transferred, exported |
2 |
26 Feb 07 |
jari |
or otherwise disclaimed to anyone, in whole or in part, without the |
2 |
26 Feb 07 |
jari |
prior written consent of TIGR. |
2 |
26 Feb 07 |
jari |
21 |
*/ |
2 |
26 Feb 07 |
jari |
22 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: FloatArray.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.3 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2005/03/10 20:36:56 $ |
2 |
26 Feb 07 |
jari |
* $Author: braistedj $ |
2 |
26 Feb 07 |
jari |
* $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 |
* 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 |
* Returns an array containing all of the floats in this container |
2 |
26 Feb 07 |
jari |
* 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 |
* 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 |
* Replaces the float value at the specified position in this container with |
2 |
26 Feb 07 |
jari |
* 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 |
* 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 |
* Check if the given index is in range. If not, throw an appropriate |
2 |
26 Feb 07 |
jari |
* 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 |
* Increases the capacity of this <tt>FloatArray</tt> instance, if |
2 |
26 Feb 07 |
jari |
* necessary, to ensure that it can hold at least the number of floats |
2 |
26 Feb 07 |
jari |
* specified by the minimum capacity argument. |
2 |
26 Feb 07 |
jari |
96 |
* |
2 |
26 Feb 07 |
jari |
* @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 |
} |