Skip to content

Commit 0cc69eb

Browse files
author
Bob Simons
committed
v1.58
1 parent 09dbf68 commit 0cc69eb

File tree

96 files changed

+10945
-3819
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+10945
-3819
lines changed

WEB-INF/classes/com/cohort/array/ByteArray.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public ByteArray() {
5050
* @param primitiveArray a primitiveArray of any type
5151
*/
5252
public ByteArray(PrimitiveArray primitiveArray) {
53-
array = new byte[8];
53+
array = new byte[primitiveArray.size()]; //exact size
5454
append(primitiveArray);
5555
}
5656

@@ -456,14 +456,20 @@ public void removeRange(int from, int to) {
456456
public void move(int first, int last, int destination) {
457457
String errorIn = String2.ERROR + " in ByteArray.move:\n";
458458

459-
Test.ensureTrue(first >= 0,
460-
errorIn + "first (" + first + ") must be >= 0.");
461-
Test.ensureTrue(last >= first && last <= size,
462-
errorIn + "last (" + last + ") must be >= first (" + first + ") and <= size (" + size + ").");
463-
Test.ensureTrue(destination >= 0 && destination <= size,
464-
errorIn + "destination (" + destination + ") must be between 0 and size (" + size + ").");
465-
Test.ensureTrue(destination <= first || destination >= last,
466-
errorIn + "destination (" + destination + ") must be <= first (" + first + ") or >= last (" + last + ").");
459+
if (first < 0)
460+
throw new RuntimeException(errorIn + "first (" + first + ") must be >= 0.");
461+
if (last < first || last > size)
462+
throw new RuntimeException(
463+
errorIn + "last (" + last + ") must be >= first (" + first +
464+
") and <= size (" + size + ").");
465+
if (destination < 0 || destination > size)
466+
throw new RuntimeException(
467+
errorIn + "destination (" + destination +
468+
") must be between 0 and size (" + size + ").");
469+
if (destination > first && destination < last)
470+
throw new RuntimeException(
471+
errorIn + "destination (" + destination + ") must be <= first (" +
472+
first + ") or >= last (" + last + ").");
467473
if (first == last || destination == first || destination == last)
468474
return; //nothing to do
469475
//String2.log("move first=" + first + " last=" + last + " dest=" + destination);
@@ -1124,7 +1130,9 @@ public PrimitiveArray makeIndices(IntArray indices) {
11241130
int count = 0;
11251131
while (iterator.hasNext())
11261132
unique[count++] = iterator.next();
1127-
Test.ensureEqual(nUnique, count, "ByteArray.makeRankArray nUnique != count!");
1133+
if (nUnique != count)
1134+
throw new RuntimeException("ByteArray.makeRankArray nUnique(" + nUnique +
1135+
") != count(" + count + ")!");
11281136

11291137
//sort them
11301138
Arrays.sort(unique);

WEB-INF/classes/com/cohort/array/CharArray.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public CharArray() {
4949
* @param primitiveArray a primitiveArray of any type
5050
*/
5151
public CharArray(PrimitiveArray primitiveArray) {
52-
array = new char[8];
52+
array = new char[primitiveArray.size()]; //exact size
5353
append(primitiveArray);
5454
}
5555

@@ -395,14 +395,20 @@ public void removeRange(int from, int to) {
395395
public void move(int first, int last, int destination) {
396396
String errorIn = String2.ERROR + " in CharArray.move:\n";
397397

398-
Test.ensureTrue(first >= 0,
399-
errorIn + "first (" + first + ") must be >= 0.");
400-
Test.ensureTrue(last >= first && last <= size,
401-
errorIn + "last (" + last + ") must be >= first (" + first + ") and <= size (" + size + ").");
402-
Test.ensureTrue(destination >= 0 && destination <= size,
403-
errorIn + "destination (" + destination + ") must be between 0 and size (" + size + ").");
404-
Test.ensureTrue(destination <= first || destination >= last,
405-
errorIn + "destination (" + destination + ") must be <= first (" + first + ") or >= last (" + last + ").");
398+
if (first < 0)
399+
throw new RuntimeException(errorIn + "first (" + first + ") must be >= 0.");
400+
if (last < first || last > size)
401+
throw new RuntimeException(
402+
errorIn + "last (" + last + ") must be >= first (" + first +
403+
") and <= size (" + size + ").");
404+
if (destination < 0 || destination > size)
405+
throw new RuntimeException(
406+
errorIn + "destination (" + destination +
407+
") must be between 0 and size (" + size + ").");
408+
if (destination > first && destination < last)
409+
throw new RuntimeException(
410+
errorIn + "destination (" + destination + ") must be <= first (" +
411+
first + ") or >= last (" + last + ").");
406412
if (first == last || destination == first || destination == last)
407413
return; //nothing to do
408414
//String2.log("move first=" + first + " last=" + last + " dest=" + destination);
@@ -1021,7 +1027,9 @@ public PrimitiveArray makeIndices(IntArray indices) {
10211027
int count = 0;
10221028
while (iterator.hasNext())
10231029
unique[count++] = iterator.next();
1024-
Test.ensureEqual(nUnique, count, "CharArray.makeRankArray nUnique != count!");
1030+
if (nUnique != count)
1031+
throw new RuntimeException("CharArray.makeRankArray nUnique(" + nUnique +
1032+
") != count(" + count + ")!");
10251033

10261034
//sort them
10271035
Arrays.sort(unique);

WEB-INF/classes/com/cohort/array/DoubleArray.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public DoubleArray() {
4848
* @param primitiveArray a primitiveArray of any type
4949
*/
5050
public DoubleArray(PrimitiveArray primitiveArray) {
51-
array = new double[8];
51+
array = new double[primitiveArray.size()]; //exact size
5252
append(primitiveArray);
5353
}
5454

@@ -372,14 +372,20 @@ public void removeRange(int from, int to) {
372372
public void move(int first, int last, int destination) {
373373
String errorIn = String2.ERROR + " in DoubleArray.move:\n";
374374

375-
Test.ensureTrue(first >= 0,
376-
errorIn + "first (" + first + ") must be >= 0.");
377-
Test.ensureTrue(last >= first && last <= size,
378-
errorIn + "last (" + last + ") must be >= first (" + first + ") and <= size (" + size + ").");
379-
Test.ensureTrue(destination >= 0 && destination <= size,
380-
errorIn + "destination (" + destination + ") must be between 0 and size (" + size + ").");
381-
Test.ensureTrue(destination <= first || destination >= last,
382-
errorIn + "destination (" + destination + ") must be <= first (" + first + ") or >= last (" + last + ").");
375+
if (first < 0)
376+
throw new RuntimeException(errorIn + "first (" + first + ") must be >= 0.");
377+
if (last < first || last > size)
378+
throw new RuntimeException(
379+
errorIn + "last (" + last + ") must be >= first (" + first +
380+
") and <= size (" + size + ").");
381+
if (destination < 0 || destination > size)
382+
throw new RuntimeException(
383+
errorIn + "destination (" + destination +
384+
") must be between 0 and size (" + size + ").");
385+
if (destination > first && destination < last)
386+
throw new RuntimeException(
387+
errorIn + "destination (" + destination + ") must be <= first (" +
388+
first + ") or >= last (" + last + ").");
383389
if (first == last || destination == first || destination == last)
384390
return; //nothing to do
385391
//String2.log("move first=" + first + " last=" + last + " dest=" + destination);
@@ -991,7 +997,9 @@ public PrimitiveArray makeIndices(IntArray indices) {
991997
int count = 0;
992998
while (iterator.hasNext())
993999
unique[count++] = iterator.next();
994-
Test.ensureEqual(nUnique, count, "DoubleArray.makeRankArray nUnique != count!");
1000+
if (nUnique != count)
1001+
throw new RuntimeException("DoubleArray.makeRankArray nUnique(" + nUnique +
1002+
") != count(" + count + ")!");
9951003

9961004
//sort them
9971005
Arrays.sort(unique);

WEB-INF/classes/com/cohort/array/FloatArray.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public FloatArray() {
4747
* @param primitiveArray a primitiveArray of any type
4848
*/
4949
public FloatArray(PrimitiveArray primitiveArray) {
50-
array = new float[8];
50+
array = new float[primitiveArray.size()]; //exact size
5151
append(primitiveArray);
5252
}
5353

@@ -368,14 +368,20 @@ public void removeRange(int from, int to) {
368368
public void move(int first, int last, int destination) {
369369
String errorIn = String2.ERROR + " in FloatArray.move:\n";
370370

371-
Test.ensureTrue(first >= 0,
372-
errorIn + "first (" + first + ") must be >= 0.");
373-
Test.ensureTrue(last >= first && last <= size,
374-
errorIn + "last (" + last + ") must be >= first (" + first + ") and <= size (" + size + ").");
375-
Test.ensureTrue(destination >= 0 && destination <= size,
376-
errorIn + "destination (" + destination + ") must be between 0 and size (" + size + ").");
377-
Test.ensureTrue(destination <= first || destination >= last,
378-
errorIn + "destination (" + destination + ") must be <= first (" + first + ") or >= last (" + last + ").");
371+
if (first < 0)
372+
throw new RuntimeException(errorIn + "first (" + first + ") must be >= 0.");
373+
if (last < first || last > size)
374+
throw new RuntimeException(
375+
errorIn + "last (" + last + ") must be >= first (" + first +
376+
") and <= size (" + size + ").");
377+
if (destination < 0 || destination > size)
378+
throw new RuntimeException(
379+
errorIn + "destination (" + destination +
380+
") must be between 0 and size (" + size + ").");
381+
if (destination > first && destination < last)
382+
throw new RuntimeException(
383+
errorIn + "destination (" + destination + ") must be <= first (" +
384+
first + ") or >= last (" + last + ").");
379385
if (first == last || destination == first || destination == last)
380386
return; //nothing to do
381387
//String2.log("move first=" + first + " last=" + last + " dest=" + destination);
@@ -1003,7 +1009,9 @@ public PrimitiveArray makeIndices(IntArray indices) {
10031009
int count = 0;
10041010
while (iterator.hasNext())
10051011
unique[count++] = iterator.next();
1006-
Test.ensureEqual(nUnique, count, "FloatArray.makeRankArray nUnique != count!");
1012+
if (nUnique != count)
1013+
throw new RuntimeException("FloatArray.makeRankArray nUnique(" + nUnique +
1014+
") != count(" + count + ")!");
10071015

10081016
//sort them
10091017
Arrays.sort(unique);

WEB-INF/classes/com/cohort/array/IntArray.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public IntArray() {
4949
* @param primitiveArray a primitiveArray of any type
5050
*/
5151
public IntArray(PrimitiveArray primitiveArray) {
52-
array = new int[8];
52+
array = new int[primitiveArray.size()]; //exact size
5353
append(primitiveArray);
5454
}
5555

@@ -384,14 +384,20 @@ public void removeRange(int from, int to) {
384384
public void move(int first, int last, int destination) {
385385
String errorIn = String2.ERROR + " in IntArray.move:\n";
386386

387-
Test.ensureTrue(first >= 0,
388-
errorIn + "first (" + first + ") must be >= 0.");
389-
Test.ensureTrue(last >= first && last <= size,
390-
errorIn + "last (" + last + ") must be >= first (" + first + ") and <= size (" + size + ").");
391-
Test.ensureTrue(destination >= 0 && destination <= size,
392-
errorIn + "destination (" + destination + ") must be between 0 and size (" + size + ").");
393-
Test.ensureTrue(destination <= first || destination >= last,
394-
errorIn + "destination (" + destination + ") must be <= first (" + first + ") or >= last (" + last + ").");
387+
if (first < 0)
388+
throw new RuntimeException(errorIn + "first (" + first + ") must be >= 0.");
389+
if (last < first || last > size)
390+
throw new RuntimeException(
391+
errorIn + "last (" + last + ") must be >= first (" + first +
392+
") and <= size (" + size + ").");
393+
if (destination < 0 || destination > size)
394+
throw new RuntimeException(
395+
errorIn + "destination (" + destination +
396+
") must be between 0 and size (" + size + ").");
397+
if (destination > first && destination < last)
398+
throw new RuntimeException(
399+
errorIn + "destination (" + destination + ") must be <= first (" +
400+
first + ") or >= last (" + last + ").");
395401
if (first == last || destination == first || destination == last)
396402
return; //nothing to do
397403
//String2.log("move first=" + first + " last=" + last + " dest=" + destination);
@@ -1047,7 +1053,9 @@ public PrimitiveArray makeIndices(IntArray indices) {
10471053
int count = 0;
10481054
while (iterator.hasNext())
10491055
unique[count++] = iterator.next();
1050-
Test.ensureEqual(nUnique, count, "IntArray.makeRankArray nUnique != count!");
1056+
if (nUnique != count)
1057+
throw new RuntimeException("IntArray.makeRankArray nUnique(" + nUnique +
1058+
") != count(" + count + ")!");
10511059

10521060
//sort them
10531061
Arrays.sort(unique);

WEB-INF/classes/com/cohort/array/LongArray.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public LongArray() {
4949
* @param primitiveArray a primitiveArray of any type
5050
*/
5151
public LongArray(PrimitiveArray primitiveArray) {
52-
array = new long[8];
52+
array = new long[primitiveArray.size()]; //exact size
5353
append(primitiveArray);
5454
}
5555

@@ -371,14 +371,20 @@ public void removeRange(int from, int to) {
371371
public void move(int first, int last, int destination) {
372372
String errorIn = String2.ERROR + " in LongArray.move:\n";
373373

374-
Test.ensureTrue(first >= 0,
375-
errorIn + "first (" + first + ") must be >= 0.");
376-
Test.ensureTrue(last >= first && last <= size,
377-
errorIn + "last (" + last + ") must be >= first (" + first + ") and <= size (" + size + ").");
378-
Test.ensureTrue(destination >= 0 && destination <= size,
379-
errorIn + "destination (" + destination + ") must be between 0 and size (" + size + ").");
380-
Test.ensureTrue(destination <= first || destination >= last,
381-
errorIn + "destination (" + destination + ") must be <= first (" + first + ") or >= last (" + last + ").");
374+
if (first < 0)
375+
throw new RuntimeException(errorIn + "first (" + first + ") must be >= 0.");
376+
if (last < first || last > size)
377+
throw new RuntimeException(
378+
errorIn + "last (" + last + ") must be >= first (" + first +
379+
") and <= size (" + size + ").");
380+
if (destination < 0 || destination > size)
381+
throw new RuntimeException(
382+
errorIn + "destination (" + destination +
383+
") must be between 0 and size (" + size + ").");
384+
if (destination > first && destination < last)
385+
throw new RuntimeException(
386+
errorIn + "destination (" + destination + ") must be <= first (" +
387+
first + ") or >= last (" + last + ").");
382388
if (first == last || destination == first || destination == last)
383389
return; //nothing to do
384390
//String2.log("move first=" + first + " last=" + last + " dest=" + destination);
@@ -991,7 +997,9 @@ public PrimitiveArray makeIndices(IntArray indices) {
991997
int count = 0;
992998
while (iterator.hasNext())
993999
unique[count++] = iterator.next();
994-
Test.ensureEqual(nUnique, count, "LongArray.makeRankArray nUnique != count!");
1000+
if (nUnique != count)
1001+
throw new RuntimeException("LongArray.makeRankArray nUnique(" + nUnique +
1002+
") != count(" + count + ")!");
9951003

9961004
//sort them
9971005
Arrays.sort(unique);

0 commit comments

Comments
 (0)