1010
1111
1212/**
13- * Helper class for a list of floats. Lists are designed to have some of the
14- * features of <b>ArrayLists</b>, but to maintain the simplicity and efficiency of
15- * working with arrays.
16- *
17- * Functions like <b>sort()</b> and <b>shuffle()</b> always act on the list itself. To get
18- * a sorted copy, use <b>list.copy().sort()</b>.
13+ * Helper class for a list of <b>float</b> values. Lists are designed
14+ * to have some features of <b>ArrayList</b>, but to maintain the
15+ * simplicity and efficiency of working with arrays.
16+ * Functions such as <b>sort()</b> and <b>shuffle()</b> always act on
17+ * the list itself. To get a sorted copy, use <b>list.copy().sort()</b>.
1918 *
2019 * @webref data:composite
2120 * @webBrief Helper class for a list of floats
@@ -52,13 +51,13 @@ public FloatList(float[] list) {
5251
5352 /**
5453 * Construct an FloatList from an iterable pile of objects.
55- * For instance, a float array, an array of strings, who knows) .
56- * Un-parseable or null values will be set to NaN.
54+ * For instance, a float array, an array of strings, who knows.
55+ * Un-parsable or null values will be set to NaN.
5756 * @nowebref
5857 */
59- public FloatList (Iterable <Object > iter ) {
58+ public FloatList (Iterable <Object > iterator ) {
6059 this (10 );
61- for (Object o : iter ) {
60+ for (Object o : iterator ) {
6261 if (o == null ) {
6362 append (Float .NaN );
6463 } else if (o instanceof Number ) {
@@ -73,7 +72,7 @@ public FloatList(Iterable<Object> iter) {
7372
7473 /**
7574 * Construct an FloatList from a random pile of objects.
76- * Un-parseable or null values will be set to NaN.
75+ * Un-parsable or null values will be set to NaN.
7776 */
7877 public FloatList (Object ... items ) {
7978 // nuts, no good way to pass missingValue to this fn (varargs must be last)
@@ -220,6 +219,7 @@ public float remove(int index) {
220219
221220 // Remove the first instance of a particular value,
222221 // and return the index at which it was found.
222+ @ SuppressWarnings ("unused" )
223223 public int removeValue (int value ) {
224224 int index = index (value );
225225 if (index != -1 ) {
@@ -232,7 +232,8 @@ public int removeValue(int value) {
232232
233233 // Remove all instances of a particular value,
234234 // and return the number of values found and removed
235- public int removeValues (int value ) {
235+ @ SuppressWarnings ("unused" )
236+ public int removeValues (float value ) {
236237 int ii = 0 ;
237238 if (Float .isNaN (value )) {
238239 for (int i = 0 ; i < count ; i ++) {
@@ -254,6 +255,7 @@ public int removeValues(int value) {
254255
255256
256257 /** Replace the first instance of a particular value */
258+ @ SuppressWarnings ("unused" )
257259 public boolean replaceValue (float value , float newValue ) {
258260 if (Float .isNaN (value )) {
259261 for (int i = 0 ; i < count ; i ++) {
@@ -274,6 +276,7 @@ public boolean replaceValue(float value, float newValue) {
274276
275277
276278 /** Replace all instances of a particular value */
279+ @ SuppressWarnings ("unused" )
277280 public boolean replaceValues (float value , float newValue ) {
278281 boolean changed = false ;
279282 if (Float .isNaN (value )) {
@@ -325,43 +328,14 @@ public void append(FloatList list) {
325328
326329
327330 /** Add this value, but only if it's not already in the list. */
331+ @ SuppressWarnings ("unused" )
328332 public void appendUnique (float value ) {
329333 if (!hasValue (value )) {
330334 append (value );
331335 }
332336 }
333337
334338
335- // public void insert(int index, int value) {
336- // if (index+1 > count) {
337- // if (index+1 < data.length) {
338- // }
339- // }
340- // if (index >= data.length) {
341- // data = PApplet.expand(data, index+1);
342- // data[index] = value;
343- // count = index+1;
344- //
345- // } else if (count == data.length) {
346- // if (index >= count) {
347- // //int[] temp = new int[count << 1];
348- // System.arraycopy(data, 0, temp, 0, index);
349- // temp[index] = value;
350- // System.arraycopy(data, index, temp, index+1, count - index);
351- // data = temp;
352- //
353- // } else {
354- // // data[] has room to grow
355- // // for() loop believed to be faster than System.arraycopy over itself
356- // for (int i = count; i > index; --i) {
357- // data[i] = data[i-1];
358- // }
359- // data[index] = value;
360- // count++;
361- // }
362- // }
363-
364-
365339 public void insert (int index , float value ) {
366340 insert (index , new float [] { value });
367341 }
@@ -401,60 +375,8 @@ public void insert(int index, FloatList list) {
401375 }
402376
403377
404- // below are aborted attempts at more optimized versions of the code
405- // that are harder to read and debug...
406-
407- // if (index + values.length >= count) {
408- // // We're past the current 'count', check to see if we're still allocated
409- // // index 9, data.length = 10, values.length = 1
410- // if (index + values.length < data.length) {
411- // // There's still room for these entries, even though it's past 'count'.
412- // // First clear out the entries leading up to it, however.
413- // for (int i = count; i < index; i++) {
414- // data[i] = 0;
415- // }
416- // data[index] =
417- // }
418- // if (index >= data.length) {
419- // int length = index + values.length;
420- // int[] temp = new int[length];
421- // System.arraycopy(data, 0, temp, 0, count);
422- // System.arraycopy(values, 0, temp, index, values.length);
423- // data = temp;
424- // count = data.length;
425- // } else {
426- //
427- // }
428- //
429- // } else if (count == data.length) {
430- // int[] temp = new int[count << 1];
431- // System.arraycopy(data, 0, temp, 0, index);
432- // temp[index] = value;
433- // System.arraycopy(data, index, temp, index+1, count - index);
434- // data = temp;
435- //
436- // } else {
437- // // data[] has room to grow
438- // // for() loop believed to be faster than System.arraycopy over itself
439- // for (int i = count; i > index; --i) {
440- // data[i] = data[i-1];
441- // }
442- // data[index] = value;
443- // count++;
444- // }
445-
446-
447378 /** Return the first index of a particular value. */
448379 public int index (float what ) {
449- /*
450- if (indexCache != null) {
451- try {
452- return indexCache.get(what);
453- } catch (Exception e) { // not there
454- return -1;
455- }
456- }
457- */
458380 for (int i = 0 ; i < count ; i ++) {
459381 if (data [i ] == what ) {
460382 return i ;
@@ -580,7 +502,7 @@ public float min() {
580502
581503 public int minIndex () {
582504 checkMinMax ("minIndex" );
583- float m = Float . NaN ;
505+ float m ;
584506 int mi = -1 ;
585507 for (int i = 0 ; i < count ; i ++) {
586508 // find one good value to start
@@ -618,7 +540,7 @@ public float max() {
618540
619541 public int maxIndex () {
620542 checkMinMax ("maxIndex" );
621- float m = Float . NaN ;
543+ float m ;
622544 int mi = -1 ;
623545 for (int i = 0 ; i < count ; i ++) {
624546 // find one good value to start
@@ -723,24 +645,6 @@ public void swap(int a, int b) {
723645 }
724646
725647
726- // use insert()
727- // public void splice(int index, int value) {
728- // }
729-
730-
731- // public void subset(int start) {
732- // subset(start, count - start);
733- // }
734-
735-
736- // public void subset(int start, int num) {
737- // for (int i = 0; i < num; i++) {
738- // data[i] = data[i+start];
739- // }
740- // count = num;
741- // }
742-
743-
744648 /**
745649 * Reverse the order of the list
746650 *
@@ -764,6 +668,7 @@ public void reverse() {
764668 * @webref floatlist:method
765669 * @webBrief Randomize the order of the list elements
766670 */
671+ @ SuppressWarnings ("unused" )
767672 public void shuffle () {
768673 Random r = new Random ();
769674 int num = count ;
@@ -781,6 +686,7 @@ public void shuffle() {
781686 * Randomize the list order using the random() function from the specified
782687 * sketch, allowing shuffle() to use its current randomSeed() setting.
783688 */
689+ @ SuppressWarnings ("unused" )
784690 public void shuffle (PApplet sketch ) {
785691 int num = count ;
786692 while (num > 1 ) {
@@ -831,11 +737,7 @@ public float[] values() {
831737 /** Implemented this way so that we can use a FloatList in a for loop. */
832738 @ Override
833739 public Iterator <Float > iterator () {
834- // }
835- //
836- //
837- // public Iterator<Float> valueIterator() {
838- return new Iterator <Float >() {
740+ return new Iterator <>() {
839741 int index = -1 ;
840742
841743 public void remove () {
@@ -854,23 +756,34 @@ public boolean hasNext() {
854756 }
855757
856758
759+ @ Deprecated
760+ public float [] array () {
761+ return toArray ();
762+ }
763+
764+
857765 /**
858766 * Create a new array with a copy of all the values.
859767 * @return an array sized by the length of the list with each of the values.
860768 * @webref floatlist:method
861769 * @webBrief Create a new array with a copy of all the values
862770 */
863- public float [] array () {
864- return array (null );
771+ public float [] toArray () {
772+ return toArray (null );
773+ }
774+
775+
776+ @ Deprecated
777+ public float [] array (float [] array ) {
778+ return toArray (array );
865779 }
866780
867781
868782 /**
869- * Copy values into the specified array. If the specified array is null or
870- * not the same size, a new array will be allocated.
871- * @param array
783+ * Copy values into the specified array. If the specified array is
784+ * null or not the same size, a new array will be allocated.
872785 */
873- public float [] array (float [] array ) {
786+ public float [] toArray (float [] array ) {
874787 if (array == null || array .length != count ) {
875788 array = new float [count ];
876789 }
@@ -880,11 +793,12 @@ public float[] array(float[] array) {
880793
881794
882795 /**
883- * Returns a normalized version of this array. Called getPercent() for
884- * consistency with the Dict classes. It's a getter method because it needs
885- * to returns a new list (because IntList/Dict can't do percentages or
886- * normalization in place on int values).
796+ * Returns a normalized version of this array. Called getPercent()
797+ * for consistency with the Dict classes. It's a getter method
798+ * because it needs to return a new list (because IntList/Dict
799+ * can't do percentages or normalization in place on int values).
887800 */
801+ @ SuppressWarnings ("unused" )
888802 public FloatList getPercent () {
889803 double sum = 0 ;
890804 for (float value : array ()) {
@@ -899,6 +813,7 @@ public FloatList getPercent() {
899813 }
900814
901815
816+ @ SuppressWarnings ("unused" )
902817 public FloatList getSubset (int start ) {
903818 return getSubset (start , count - start );
904819 }
0 commit comments