@@ -13,7 +13,12 @@ public class StringList implements Iterable<String> {
1313
1414
1515 public StringList () {
16- data = new String [10 ];
16+ this (10 );
17+ }
18+
19+
20+ public StringList (int length ) {
21+ data = new String [length ];
1722 }
1823
1924
@@ -358,85 +363,6 @@ public boolean hasValue(String value) {
358363 }
359364
360365
361- // public void increment(int index) {
362- // data[index]++;
363- // }
364- //
365- //
366- // public void add(int index, int amount) {
367- // data[index] += amount;
368- // }
369- //
370- //
371- // public void sub(int index, int amount) {
372- // data[index] -= amount;
373- // }
374- //
375- //
376- // public void mul(int index, int amount) {
377- // data[index] *= amount;
378- // }
379- //
380- //
381- // public void div(int index, int amount) {
382- // data[index] /= amount;
383- // }
384-
385-
386- // public String min() {
387- // if (count == 0) {
388- // throw new ArrayIndexOutOfBoundsException("Cannot use min() on IntList of length 0.");
389- // }
390- // if (data.length == 0) {
391- // return String.NaN;
392- // }
393- // String m = Float.NaN;
394- // for (int i = 0; i < data.length; i++) {
395- // // find one good value to start
396- // if (data[i] == data[i]) {
397- // m = data[i];
398- //
399- // // calculate the rest
400- // for (int j = i+1; j < data.length; j++) {
401- // float d = data[j];
402- // if (!Float.isNaN(d) && (d < m)) {
403- // m = data[j];
404- // }
405- // }
406- // break;
407- // }
408- // }
409- // return m;
410- // }
411-
412-
413- // public float max() {
414- // if (count == 0) {
415- // throw new ArrayIndexOutOfBoundsException("Cannot use max() on IntList of length 0.");
416- // }
417- // if (data.length == 0) {
418- // return Float.NaN;
419- // }
420- // float m = Float.NaN;
421- // for (int i = 0; i < data.length; i++) {
422- // // find one good value to start
423- // if (data[i] == data[i]) {
424- // m = data[i];
425- //
426- // // calculate the rest
427- // for (int j = i+1; j < data.length; j++) {
428- // float d = data[j];
429- // if (!Float.isNaN(d) && (d > m)) {
430- // m = data[j];
431- // }
432- // }
433- // break;
434- // }
435- // }
436- // return m;
437- // }
438-
439-
440366 /** Sorts the array in place. */
441367 public void sort () {
442368 sortImpl (false );
@@ -477,17 +403,17 @@ public void swap(int a, int b) {
477403// }
478404
479405
480- public void subset (int start ) {
481- subset (start , count - start );
482- }
483-
484-
485- public void subset (int start , int num ) {
486- for (int i = 0 ; i < num ; i ++) {
487- data [i ] = data [i +start ];
488- }
489- count = num ;
490- }
406+ // public void subset(int start) {
407+ // subset(start, count - start);
408+ // }
409+ //
410+ //
411+ // public void subset(int start, int num) {
412+ // for (int i = 0; i < num; i++) {
413+ // data[i] = data[i+start];
414+ // }
415+ // count = num;
416+ // }
491417
492418
493419 public void reverse () {
@@ -534,6 +460,26 @@ public void shuffle(PApplet sketch) {
534460 }
535461
536462
463+ /** Make the entire list lower case. */
464+ public void lower () {
465+ for (int i = 0 ; i < count ; i ++) {
466+ if (data [i ] != null ) {
467+ data [i ] = data [i ].toLowerCase ();
468+ }
469+ }
470+ }
471+
472+
473+ /** Make the entire list upper case. */
474+ public void upper () {
475+ for (int i = 0 ; i < count ; i ++) {
476+ if (data [i ] != null ) {
477+ data [i ] = data [i ].toUpperCase ();
478+ }
479+ }
480+ }
481+
482+
537483 public StringList copy () {
538484 StringList outgoing = new StringList (data );
539485 outgoing .count = count ;
@@ -599,6 +545,20 @@ public String[] array(String[] array) {
599545 }
600546
601547
548+ public StringList getSubset (int start ) {
549+ return getSubset (start , count - start );
550+ }
551+
552+
553+ public StringList getSubset (int start , int num ) {
554+ StringList outgoing = new StringList (num );
555+ for (int i = 0 ; i < num ; i ++) {
556+ System .arraycopy (data , start , outgoing .data , 0 , num );
557+ }
558+ return outgoing ;
559+ }
560+
561+
602562 /** Get a list of all unique entries. */
603563 public String [] getUnique () {
604564 return getTally ().keyArray ();
0 commit comments