]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/gnu/trove/TFloatArrayList.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / gnu / trove / TFloatArrayList.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2001, Eric D. Friedman All Rights Reserved.
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 ///////////////////////////////////////////////////////////////////////////////
18
19 package gnu.trove;
20
21 import java.io.Externalizable;
22 import java.io.IOException;
23 import java.io.ObjectInput;
24 import java.io.ObjectOutput;
25 import java.util.Arrays;
26 import java.util.Random;
27
28
29 //////////////////////////////////////////////////
30 // THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //
31 //////////////////////////////////////////////////
32
33
34 /**
35  * A resizable, array-backed list of float primitives.
36  *
37  * Created: Sat Dec 29 14:21:12 2001
38  *
39  * @author Eric D. Friedman
40  * @author Rob Eden
41  */
42
43 public class TFloatArrayList implements Externalizable, Cloneable {
44         static final long serialVersionUID = 1L;
45
46     /** the data of the list */
47     protected float[] _data;
48
49     /** the index after the last entry in the list */
50     protected int _pos;
51
52     /** the default capacity for new lists */
53     protected static final int DEFAULT_CAPACITY = 10;
54
55     /**
56      * Creates a new <code>TFloatArrayList</code> instance with the
57      * default capacity.
58      */
59     public TFloatArrayList() {
60         this(DEFAULT_CAPACITY);
61     }
62
63     /**
64      * Creates a new <code>TFloatArrayList</code> instance with the
65      * specified capacity.
66      *
67      * @param capacity an <code>int</code> value
68      */
69     public TFloatArrayList(int capacity) {
70         _data = new float[capacity];
71         _pos = 0;
72     }
73
74     /**
75      * Creates a new <code>TFloatArrayList</code> instance whose
76      * capacity is the greater of the length of <tt>values</tt> and
77      * DEFAULT_CAPACITY and whose initial contents are the specified
78      * values.
79      *
80      * @param values an <code>float[]</code> value
81      */
82     public TFloatArrayList(float[] values) {
83         this(Math.max(values.length, DEFAULT_CAPACITY));
84         add(values);
85     }
86
87     // sizing
88
89     /**
90      * Grow the internal array as needed to accommodate the specified
91      * number of elements.  The size of the array floats on each
92      * resize unless <tt>capacity</tt> requires more than twice the
93      * current capacity.
94      *
95      * @param capacity an <code>int</code> value
96      */
97     public void ensureCapacity(int capacity) {
98         if (capacity > _data.length) {
99             int newCap = Math.max(_data.length << 1, capacity);
100             float[] tmp = new float[newCap];
101             System.arraycopy(_data, 0, tmp, 0, _data.length);
102             _data = tmp;
103         }
104     }
105
106     /**
107      * Returns the number of values in the list.
108      *
109      * @return the number of values in the list.
110      */
111     public int size() {
112         return _pos;
113     }
114
115     /**
116      * Tests whether this list contains any values.
117      *
118      * @return true if the list is empty.
119      */
120     public boolean isEmpty() {
121         return _pos == 0;
122     }
123
124     /**
125      * Sheds any excess capacity above and beyond the current size of
126      * the list.
127      */
128     public void trimToSize() {
129         if (_data.length > size()) {
130             float[] tmp = new float[size()];
131             toNativeArray(tmp, 0, tmp.length);
132             _data = tmp;
133         }
134     }
135
136     // modifying
137
138     /**
139      * Adds <tt>val</tt> to the end of the list, growing as needed.
140      *
141      * @param val an <code>float</code> value
142      */
143     public void add(float val) {
144         ensureCapacity(_pos + 1);
145         _data[_pos++] = val;
146     }
147
148     /**
149      * Adds the values in the array <tt>vals</tt> to the end of the
150      * list, in order.
151      *
152      * @param vals an <code>float[]</code> value
153      */
154     public void add(float[] vals) {
155         add(vals, 0, vals.length);
156     }
157
158     /**
159      * Adds a subset of the values in the array <tt>vals</tt> to the
160      * end of the list, in order.
161      *
162      * @param vals an <code>float[]</code> value
163      * @param offset the offset at which to start copying
164      * @param length the number of values to copy.
165      */
166     public void add(float[] vals, int offset, int length) {
167         ensureCapacity(_pos + length);
168         System.arraycopy(vals, offset, _data, _pos, length);
169         _pos += length;
170     }
171
172     /**
173      * Inserts <tt>value</tt> into the list at <tt>offset</tt>.  All
174      * values including and to the right of <tt>offset</tt> are shifted
175      * to the right.
176      *
177      * @param offset an <code>int</code> value
178      * @param value an <code>float</code> value
179      */
180     public void insert(int offset, float value) {
181         if (offset == _pos) {
182             add(value);
183             return;
184         }
185         ensureCapacity(_pos + 1);
186         // shift right
187         System.arraycopy(_data, offset, _data, offset + 1, _pos - offset);
188         // insert
189         _data[offset] = value;
190         _pos++;
191     }
192
193     /**
194      * Inserts the array of <tt>values</tt> into the list at
195      * <tt>offset</tt>.  All values including and to the right of
196      * <tt>offset</tt> are shifted to the right.
197      *
198      * @param offset an <code>int</code> value
199      * @param values an <code>float[]</code> value
200      */
201     public void insert(int offset, float[] values) {
202         insert(offset, values, 0, values.length);
203     }
204
205     /**
206      * Inserts a slice of the array of <tt>values</tt> into the list
207      * at <tt>offset</tt>.  All values including and to the right of
208      * <tt>offset</tt> are shifted to the right.
209      *
210      * @param offset an <code>int</code> value
211      * @param values an <code>float[]</code> value
212      * @param valOffset the offset in the values array at which to
213      * start copying.
214      * @param len the number of values to copy from the values array
215      */
216     public void insert(int offset, float[] values, int valOffset, int len) {
217         if (offset == _pos) {
218             add(values, valOffset, len);
219             return;
220         }
221
222         ensureCapacity(_pos + len);
223         // shift right
224         System.arraycopy(_data, offset, _data, offset + len, _pos - offset);
225         // insert
226         System.arraycopy(values, valOffset, _data, offset, len);
227         _pos += len;
228     }
229
230     /**
231      * Returns the value at the specified offset.
232      *
233      * @param offset an <code>int</code> value
234      * @return an <code>float</code> value
235      */
236     public float get(int offset) {
237         if (offset >= _pos) {
238             throw new ArrayIndexOutOfBoundsException(offset);
239         }
240         return _data[offset];
241     }
242
243     /**
244      * Returns the value at the specified offset without doing any
245      * bounds checking.
246      *
247      * @param offset an <code>int</code> value
248      * @return an <code>float</code> value
249      */
250     public float getQuick(int offset) {
251         return _data[offset];
252     }
253
254     /**
255      * Sets the value at the specified offset.
256      *
257      * @param offset an <code>int</code> value
258      * @param val an <code>float</code> value
259      */
260     public void set(int offset, float val) {
261         if (offset >= _pos) {
262             throw new ArrayIndexOutOfBoundsException(offset);
263         }
264         _data[offset] = val;
265     }
266
267     /**
268      * Sets the value at the specified offset and returns the
269      * previously stored value.
270      *
271      * @param offset an <code>int</code> value
272      * @param val an <code>float</code> value
273      * @return the value previously stored at offset.
274      */
275     public float getSet(int offset, float val) {
276         if (offset >= _pos) {
277             throw new ArrayIndexOutOfBoundsException(offset);
278         }
279         float old = _data[offset];
280         _data[offset] = val;
281         return old;
282     }
283
284     /**
285      * Replace the values in the list starting at <tt>offset</tt> with
286      * the contents of the <tt>values</tt> array.
287      *
288      * @param offset the first offset to replace
289      * @param values the source of the new values
290      */
291     public void set(int offset, float[] values) {
292         set(offset, values, 0, values.length);
293     }
294
295     /**
296      * Replace the values in the list starting at <tt>offset</tt> with
297      * <tt>length</tt> values from the <tt>values</tt> array, starting
298      * at valOffset.
299      *
300      * @param offset the first offset to replace
301      * @param values the source of the new values
302      * @param valOffset the first value to copy from the values array
303      * @param length the number of values to copy
304      */
305     public void set(int offset, float[] values, int valOffset, int length) {
306         if (offset < 0 || offset + length > _pos) {
307             throw new ArrayIndexOutOfBoundsException(offset);
308         }
309         System.arraycopy(values, valOffset, _data, offset, length);
310     }
311
312     /**
313      * Sets the value at the specified offset without doing any bounds
314      * checking.
315      *
316      * @param offset an <code>int</code> value
317      * @param val an <code>float</code> value
318      */
319     public void setQuick(int offset, float val) {
320         _data[offset] = val;
321     }
322
323     /**
324      * Flushes the internal state of the list, resetting the capacity
325      * to the default.
326      */
327     public void clear() {
328         clear(DEFAULT_CAPACITY);
329     }
330
331     /**
332      * Flushes the internal state of the list, setting the capacity of
333      * the empty list to <tt>capacity</tt>.
334      *
335      * @param capacity an <code>int</code> value
336      */
337     public void clear(int capacity) {
338         _data = new float[capacity];
339         _pos = 0;
340     }
341
342     /**
343      * Sets the size of the list to 0, but does not change its
344      * capacity.  This method can be used as an alternative to the
345      * {@link #clear clear} method if you want to recyle a list without
346      * allocating new backing arrays.
347      *
348      * @see #clear
349      */
350     public void reset() {
351         _pos = 0;
352         fill((float)0);
353     }
354
355     /**
356      * Sets the size of the list to 0, but does not change its
357      * capacity.  This method can be used as an alternative to the
358      * {@link #clear clear} method if you want to recyle a list
359      * without allocating new backing arrays.  This method differs
360      * from {@link #reset reset} in that it does not clear the old
361      * values in the backing array.  Thus, it is possible for {@link
362      * #getQuick getQuick} to return stale data if this method is used
363      * and the caller is careless about bounds checking.
364      *
365      * @see #reset
366      * @see #clear
367      * @see #getQuick
368      */
369     public void resetQuick() {
370         _pos = 0;
371     }
372
373     /**
374      * Removes the value at <tt>offset</tt> from the list.
375      *
376      * @param offset an <code>int</code> value
377      * @return the value previously stored at offset.
378      */
379     public float remove(int offset) {
380         float old = get(offset);
381         remove(offset, 1);
382         return old;
383     }
384
385     /**
386      * Removes <tt>length</tt> values from the list, starting at
387      * <tt>offset</tt>
388      *
389      * @param offset an <code>int</code> value
390      * @param length an <code>int</code> value
391      */
392     public void remove(int offset, int length) {
393         if (offset < 0 || offset >= _pos) {
394             throw new ArrayIndexOutOfBoundsException(offset);
395         }
396
397         if (offset == 0) {
398             // data at the front
399             System.arraycopy(_data, length, _data, 0, _pos - length);
400         } else if (_pos - length == offset) {
401             // no copy to make, decrementing pos "deletes" values at
402             // the end
403         } else {
404             // data in the middle
405             System.arraycopy(_data, offset + length,
406                              _data, offset, _pos - (offset + length));
407         }
408         _pos -= length;
409         // no need to clear old values beyond _pos, because this is a
410         // primitive collection and 0 takes as much room as any other
411         // value
412     }
413
414     /**
415      * Transform each value in the list using the specified function.
416      *
417      * @param function a <code>TFloatFunction</code> value
418      */
419     public void transformValues(TFloatFunction function) {
420         for (int i = _pos; i-- > 0;) {
421             _data[i] = function.execute(_data[i]);
422         }
423     }
424
425     /**
426      * Reverse the order of the elements in the list.
427      */
428     public void reverse() {
429         reverse(0, _pos);
430     }
431
432     /**
433      * Reverse the order of the elements in the range of the list.
434      *
435      * @param from the inclusive index at which to start reversing
436      * @param to the exclusive index at which to stop reversing
437      */
438     public void reverse(int from, int to) {
439         if (from == to) {
440             return;             // nothing to do
441         }
442         if (from > to) {
443             throw new IllegalArgumentException("from cannot be greater than to");
444         }
445         for (int i = from, j = to - 1; i < j; i++, j--) {
446             swap(i, j);
447         }
448     }
449
450     /**
451      * Shuffle the elements of the list using the specified random
452      * number generator.
453      *
454      * @param rand a <code>Random</code> value
455      */
456     public void shuffle(Random rand) {
457         for (int i = _pos; i-- > 1;) {
458             swap(i, rand.nextInt(i));
459         }
460     }
461
462     /**
463      * Swap the values at offsets <tt>i</tt> and <tt>j</tt>.
464      *
465      * @param i an offset into the data array
466      * @param j an offset into the data array
467      */
468     private final void swap(int i, int j) {
469         float tmp = _data[i];
470         _data[i] = _data[j];
471         _data[j] = tmp;
472     }
473
474     // copying
475
476     /**
477      * Returns a clone of this list.  Since this is a primitive
478      * collection, this will be a deep clone.
479      *
480      * @return a deep clone of the list.
481      */
482     public Object clone() {
483         TFloatArrayList list = null;
484         try {
485             list = (TFloatArrayList) super.clone();
486             list._data = toNativeArray();
487         } catch (CloneNotSupportedException e) {
488             // it's supported
489         } // end of try-catch
490         return list;
491     }
492
493
494     /**
495      * Returns a sublist of this list.
496      *
497      * @param begin low endpoint (inclusive) of the subList.
498      * @param end high endpoint (exclusive) of the subList.
499      * @return sublist of this list from begin, inclusive to end, exclusive.
500      * @throws IndexOutOfBoundsException - endpoint out of range
501      * @throws IllegalArgumentException - endpoints out of order (end > begin)
502      */
503     public TFloatArrayList subList(int begin, int end) {
504         if (end < begin) throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin);
505                 if (begin < 0) throw new IndexOutOfBoundsException("begin index can not be < 0");
506                 if (end > _data.length) throw new IndexOutOfBoundsException("end index < " + _data.length);
507         TFloatArrayList list = new TFloatArrayList(end - begin);
508         for (int i = begin; i < end; i++) {
509                 list.add(_data[i]);
510         }
511         return list;
512     }
513
514
515     /**
516      * Copies the contents of the list into a native array.
517      *
518      * @return an <code>float[]</code> value
519      */
520     public float[] toNativeArray() {
521         return toNativeArray(0, _pos);
522     }
523
524     /**
525      * Copies a slice of the list into a native array.
526      *
527      * @param offset the offset at which to start copying
528      * @param len the number of values to copy.
529      * @return an <code>float[]</code> value
530      */
531     public float[] toNativeArray(int offset, int len) {
532         float[] rv = new float[len];
533         toNativeArray(rv, offset, len);
534         return rv;
535     }
536
537     /**
538      * Copies a slice of the list into a native array.
539      *
540      * @param dest the array to copy into.
541      * @param offset the offset of the first value to copy
542      * @param len the number of values to copy.
543      */
544     public void toNativeArray(float[] dest, int offset, int len) {
545         if (len == 0) {
546             return;             // nothing to copy
547         }
548         if (offset < 0 || offset >= _pos) {
549             throw new ArrayIndexOutOfBoundsException(offset);
550         }
551         System.arraycopy(_data, offset, dest, 0, len);
552     }
553
554     // comparing
555
556     /**
557      * Compares this list to another list, value by value.
558      *
559      * @param other the object to compare against
560      * @return true if other is a TFloatArrayList and has exactly the
561      * same values.
562      */
563     public boolean equals(Object other) {
564         if (other == this) {
565             return true;
566         } else if (other instanceof TFloatArrayList) {
567             TFloatArrayList that = (TFloatArrayList)other;
568             if (that.size() != this.size()) {
569                 return false;
570             } else {
571                 for (int i = _pos; i-- > 0;) {
572                     if (this._data[i] != that._data[i]) {
573                         return false;
574                     }
575                 }
576                 return true;
577             }
578         } else {
579             return false;
580         }
581     }
582
583     public int hashCode() {
584         int h = 0;
585         for (int i = _pos; i-- > 0;) {
586             h = 37 * h + HashFunctions.hash(_data[i]);
587         }
588         return h;
589     }
590
591     // procedures
592
593     /**
594      * Applies the procedure to each value in the list in ascending
595      * (front to back) order.
596      *
597      * @param procedure a <code>TFloatProcedure</code> value
598      * @return true if the procedure did not terminate prematurely.
599      */
600     public boolean forEach(TFloatProcedure procedure) {
601         for (int i = 0; i < _pos; i++) {
602             if (! procedure.execute(_data[i])) {
603                 return false;
604             }
605         }
606         return true;
607     }
608
609     /**
610      * Applies the procedure to each value in the list in descending
611      * (back to front) order.
612      *
613      * @param procedure a <code>TFloatProcedure</code> value
614      * @return true if the procedure did not terminate prematurely.
615      */
616     public boolean forEachDescending(TFloatProcedure procedure) {
617         for (int i = _pos; i-- > 0;) {
618             if (! procedure.execute(_data[i])) {
619                 return false;
620             }
621         }
622         return true;
623     }
624
625     // sorting
626
627     /**
628      * Sort the values in the list (ascending) using the Sun quicksort
629      * implementation.
630      *
631      * @see java.util.Arrays#sort
632      */
633     public void sort() {
634         Arrays.sort(_data, 0, _pos);
635     }
636
637     /**
638      * Sort a slice of the list (ascending) using the Sun quicksort
639      * implementation.
640      *
641      * @param fromIndex the index at which to start sorting (inclusive)
642      * @param toIndex the index at which to stop sorting (exclusive)
643      * @see java.util.Arrays#sort
644      */
645     public void sort(int fromIndex, int toIndex) {
646         Arrays.sort(_data, fromIndex, toIndex);
647     }
648
649     // filling
650
651     /**
652      * Fills every slot in the list with the specified value.
653      *
654      * @param val the value to use when filling
655      */
656     public void fill(float val) {
657         Arrays.fill(_data, 0, _pos, val);
658     }
659
660     /**
661      * Fills a range in the list with the specified value.
662      *
663      * @param fromIndex the offset at which to start filling (inclusive)
664      * @param toIndex the offset at which to stop filling (exclusive)
665      * @param val the value to use when filling
666      */
667     public void fill(int fromIndex, int toIndex, float val) {
668         if (toIndex > _pos) {
669           ensureCapacity(toIndex);
670           _pos = toIndex;
671         }
672         Arrays.fill(_data, fromIndex, toIndex, val);
673     }
674
675     // searching
676
677     /**
678      * Performs a binary search for <tt>value</tt> in the entire list.
679      * Note that you <b>must</b> @{link #sort sort} the list before
680      * doing a search.
681      *
682      * @param value the value to search for
683      * @return the absolute offset in the list of the value, or its
684      * negative insertion point into the sorted list.
685      */
686     public int binarySearch(float value) {
687         return binarySearch(value, 0, _pos);
688     }
689
690     /**
691      * Performs a binary search for <tt>value</tt> in the specified
692      * range.  Note that you <b>must</b> @{link #sort sort} the list
693      * or the range before doing a search.
694      *
695      * @param value the value to search for
696      * @param fromIndex the lower boundary of the range (inclusive)
697      * @param toIndex the upper boundary of the range (exclusive)
698      * @return the absolute offset in the list of the value, or its
699      * negative insertion point into the sorted list.
700      */
701     public int binarySearch(float value, int fromIndex, int toIndex) {
702         if (fromIndex < 0) {
703             throw new ArrayIndexOutOfBoundsException(fromIndex);
704         }
705         if (toIndex > _pos) {
706             throw new ArrayIndexOutOfBoundsException(toIndex);
707         }
708
709         int low = fromIndex;
710         int high = toIndex - 1;
711
712         while (low <= high) {
713             int mid = (low + high) >>> 1;
714             float midVal = _data[mid];
715
716             if (midVal < value) {
717                 low = mid + 1;
718             } else if (midVal > value) {
719                 high = mid - 1;
720             } else {
721                 return mid; // value found
722             }
723         }
724         return -(low + 1);  // value not found.
725     }
726
727     /**
728      * Searches the list front to back for the index of
729      * <tt>value</tt>.
730      *
731      * @param value an <code>float</code> value
732      * @return the first offset of the value, or -1 if it is not in
733      * the list.
734      * @see #binarySearch for faster searches on sorted lists
735      */
736     public int indexOf(float value) {
737         return indexOf(0, value);
738     }
739
740     /**
741      * Searches the list front to back for the index of
742      * <tt>value</tt>, starting at <tt>offset</tt>.
743      *
744      * @param offset the offset at which to start the linear search
745      * (inclusive)
746      * @param value an <code>float</code> value
747      * @return the first offset of the value, or -1 if it is not in
748      * the list.
749      * @see #binarySearch for faster searches on sorted lists
750      */
751     public int indexOf(int offset, float value) {
752         for (int i = offset; i < _pos; i++) {
753             if (_data[i] == value) {
754                 return i;
755             }
756         }
757         return -1;
758     }
759
760     /**
761      * Searches the list back to front for the last index of
762      * <tt>value</tt>.
763      *
764      * @param value an <code>float</code> value
765      * @return the last offset of the value, or -1 if it is not in
766      * the list.
767      * @see #binarySearch for faster searches on sorted lists
768      */
769     public int lastIndexOf(float value) {
770         return lastIndexOf(_pos, value);
771     }
772
773     /**
774      * Searches the list back to front for the last index of
775      * <tt>value</tt>, starting at <tt>offset</tt>.
776      *
777      * @param offset the offset at which to start the linear search
778      * (exclusive)
779      * @param value an <code>float</code> value
780      * @return the last offset of the value, or -1 if it is not in
781      * the list.
782      * @see #binarySearch for faster searches on sorted lists
783      */
784     public int lastIndexOf(int offset, float value) {
785         for (int i = offset; i-- > 0;) {
786             if (_data[i] == value) {
787                 return i;
788             }
789         }
790         return -1;
791     }
792
793     /**
794      * Searches the list for <tt>value</tt>
795      *
796      * @param value an <code>float</code> value
797      * @return true if value is in the list.
798      */
799     public boolean contains(float value) {
800         return lastIndexOf(value) >= 0;
801     }
802
803     /**
804      * Searches the list for values satisfying <tt>condition</tt> in
805      * the manner of the *nix <tt>grep</tt> utility.
806      *
807      * @param condition a condition to apply to each element in the list
808      * @return a list of values which match the condition.
809      */
810     public TFloatArrayList grep(TFloatProcedure condition) {
811         TFloatArrayList list = new TFloatArrayList();
812         for (int i = 0; i < _pos; i++) {
813             if (condition.execute(_data[i])) {
814                 list.add(_data[i]);
815             }
816         }
817         return list;
818     }
819
820     /**
821      * Searches the list for values which do <b>not</b> satisfy
822      * <tt>condition</tt>.  This is akin to *nix <code>grep -v</code>.
823      *
824      * @param condition a condition to apply to each element in the list
825      * @return a list of values which do not match the condition.
826      */
827     public TFloatArrayList inverseGrep(TFloatProcedure condition) {
828         TFloatArrayList list = new TFloatArrayList();
829         for (int i = 0; i < _pos; i++) {
830             if (! condition.execute(_data[i])) {
831                 list.add(_data[i]);
832             }
833         }
834         return list;
835     }
836
837     /**
838      * Finds the maximum value in the list.
839      *
840      * @return the largest value in the list.
841      * @exception IllegalStateException if the list is empty
842      */
843     public float max() {
844         if (size() == 0) {
845             throw new IllegalStateException("cannot find maximum of an empty list");
846         }
847         float max = Float.NEGATIVE_INFINITY;
848         for (int i = 0; i < _pos; i++ ) {
849                 if ( _data[i] > max ) {
850                         max = _data[i];
851                 }
852         }
853         return max;
854     }
855
856     /**
857      * Finds the minimum value in the list.
858      *
859      * @return the smallest value in the list.
860      * @exception IllegalStateException if the list is empty
861      */
862     public float min() {
863         if (size() == 0) {
864             throw new IllegalStateException("cannot find minimum of an empty list");
865         }
866         float min = Float.POSITIVE_INFINITY;
867         for (int i = 0; i < _pos; i++ ) {
868                 if ( _data[i] < min ) {
869                         min = _data[i];
870                 }
871         }
872         return min;
873     }
874
875     // stringification
876
877     /**
878      * Returns a String representation of the list, front to back.
879      *
880      * @return a <code>String</code> value
881      */
882     public String toString() {
883         final StringBuilder buf = new StringBuilder("{");
884         for (int i = 0, end = _pos - 1; i < end; i++) {
885             buf.append(_data[i]);
886             buf.append(", ");
887         }
888         if (size() > 0) {
889             buf.append(_data[_pos - 1]);
890         }
891         buf.append("}");
892         return buf.toString();
893     }
894
895
896     public void writeExternal( ObjectOutput out ) throws IOException {
897         // VERSION
898         out.writeByte( 1 );
899
900         // POSITION
901         out.writeInt( _pos );
902
903         // ENTRIES
904         int len = _pos;
905         out.writeInt( _pos );    // Written twice for backwards compatability with
906                                  // version 0
907         for( int i = 0; i < len; i++ ) {
908                 out.writeFloat( _data[ i ] );
909         }
910     }
911
912     public void readExternal( ObjectInput in )
913         throws IOException, ClassNotFoundException {
914
915         // VERSION
916         in.readByte();
917
918         // POSITION
919         _pos = in.readInt();
920
921         // ENTRIES
922         int len = in.readInt();
923         _data = new float[ len ];
924         for( int i = 0; i < len; i++ ) {
925                 _data[ i ] = in.readFloat();
926         }
927     }
928 } // TFloatArrayList