Skip to content

Commit

Permalink
Merge pull request #179 from ChrisJohnNOAA/error_prone_updates
Browse files Browse the repository at this point in the history
Enable several error prone checks
  • Loading branch information
ChrisJohnNOAA authored Jul 29, 2024
2 parents 862e0e5 + ae2faf8 commit 2ef97c8
Show file tree
Hide file tree
Showing 174 changed files with 90,960 additions and 84,863 deletions.
2 changes: 1 addition & 1 deletion WEB-INF/classes/com/cohort/array/Attributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ public String toNcoJsonString(String indent) {
// if (tName.equals("_FillValue")) String2.pressEnterToContinue(">> ncoJson _FillValue=" +
// String2.annotatedString((new StringArray(pa)).toString()) + " maxIsMV=" +
// pa.getMaxIsMV());
String s = (new StringArray(pa)).toNewlineString();
String s = new StringArray(pa).toNewlineString();
sb.append(String2.toJson(s.substring(0, s.length() - 1))); // remove trailing \n
} else {
String js = pa.toJsonCsvString();
Expand Down
4 changes: 2 additions & 2 deletions WEB-INF/classes/com/cohort/array/DoubleArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public void addNInts(final int n, final int value) {
*/
@Override
public void addNLongs(final int n, final long value) {
addN(n, value); // ! assumes value=Integer.MAX_VALUE isn't maxIsMV
addN(n, (double) value); // ! assumes value=Integer.MAX_VALUE isn't maxIsMV
}

/**
Expand Down Expand Up @@ -733,7 +733,7 @@ public long getLong(final int index) {
*/
@Override
public void setLong(final int index, final long i) {
set(index, i);
set(index, (double) i);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions WEB-INF/classes/com/cohort/array/FloatArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public void addNInts(final int n, final int value) {
*/
@Override
public void addNLongs(final int n, final long value) {
addN(n, value); // ! assumes value=Integer.MAX_VALUE isn't maxIsMV
addN(n, (float) value); // ! assumes value=Integer.MAX_VALUE isn't maxIsMV
}

/**
Expand Down Expand Up @@ -730,7 +730,7 @@ public long getLong(final int index) {
*/
@Override
public void setLong(final int index, final long i) {
set(index, i);
set(index, (float) i);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions WEB-INF/classes/com/cohort/array/LongArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ public void set(final int index, final long value) {
*/
@Override
public int getInt(final int index) {
return Math2.roundToInt(get(index));
return Math2.roundToInt((double) get(index));
}

// getRawInt(index) uses default getInt(index) since missingValue is bigger than int.
Expand Down Expand Up @@ -946,8 +946,8 @@ public void setString(final int index, final String s) {
if (s == null
|| s.indexOf("223372036854775807")
< 0) // without leading 9 to allow for 9.2233...e18 etc //not perfect, but gets common
// cases
maxIsMV = true;
// cases
maxIsMV = true;
}
set(index, tl);
}
Expand Down
18 changes: 9 additions & 9 deletions WEB-INF/classes/com/cohort/array/PrimitiveArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -2537,8 +2537,8 @@ public PrimitiveArray simplify(String colName) {

if (!String2.isSomething2(
s)) // this catches a large number of string and numeric missing value stand-ins, but
// not NaN
continue;
// not NaN
continue;

if (s.toLowerCase().equals("nan")) { // signifies a numeric missing value
// non-specific, skip this row
Expand Down Expand Up @@ -2611,7 +2611,7 @@ public PrimitiveArray simplify(String colName) {
|| d
> Long
.MAX_VALUE) { // good (checks range) but imperfect: Long.MAX_VALUE is imprecise
// as a double
// as a double
// String2.log(">> simplify -> LONG because d=" + d);
type = PAType.FLOAT; // not ULONG
if (this instanceof FloatArray) // not ULongArray
Expand Down Expand Up @@ -3036,8 +3036,8 @@ public static void append(List table1, List table2) {
// append table2 to the end of table1
for (int col = 0; col < table1.size(); col++) {
// if needed, make a new wider PrimitiveArray in table1
PrimitiveArray pa1 = (PrimitiveArray) (table1.get(col));
PrimitiveArray pa2 = (PrimitiveArray) (table2.get(col));
PrimitiveArray pa1 = (PrimitiveArray) table1.get(col);
PrimitiveArray pa2 = (PrimitiveArray) table2.get(col);

PAType needPAType = pa1.needPAType(pa2.elementType());
if (pa1.elementType() != needPAType) {
Expand Down Expand Up @@ -3640,7 +3640,7 @@ public static boolean testValueOpValue(float value1, String op, float value2) {
if (op.equals("<")) return value1 < value2;
if (op.equals(">")) return value1 > value2;
if (op.equals("!="))
return Float.isNaN(value1) && Float.isNaN(value2) ? false : value1 != value2;
return (Float.isNaN(value1) && Float.isNaN(value2)) ? false : value1 != value2;
// Regex test has to be handled via String testValueOpValue
// if (op.equals(PrimitiveArray.REGEX_OP))
throw new SimpleException("Query error: " + "Unknown operator=\"" + op + "\".");
Expand Down Expand Up @@ -3672,7 +3672,7 @@ public static boolean testValueOpValue(double value1, String op, double value2)
if (op.equals("<")) return value1 < value2;
if (op.equals(">")) return value1 > value2;
if (op.equals("!="))
return Double.isNaN(value1) && Double.isNaN(value2) ? false : value1 != value2;
return (Double.isNaN(value1) && Double.isNaN(value2)) ? false : value1 != value2;
// Regex test has to be handled via String testValueOpValue
// if (op.equals(PrimitiveArray.REGEX_OP))
throw new SimpleException("Query error: " + "Unknown operator=\"" + op + "\".");
Expand Down Expand Up @@ -3706,7 +3706,7 @@ public static boolean testValueOpValueExtra(double value1, String op, double val
if (op.equals("<")) return value1 < value2;
if (op.equals(">")) return value1 > value2;
if (op.equals("!="))
return Double.isNaN(value1) && Double.isNaN(value2) ? false : value1 != value2;
return (Double.isNaN(value1) && Double.isNaN(value2)) ? false : value1 != value2;
// Regex test has to be handled via String testValueOpValue
// if (op.equals(PrimitiveArray.REGEX_OP))
throw new SimpleException("Query error: " + "Unknown operator=\"" + op + "\".");
Expand Down Expand Up @@ -3737,7 +3737,7 @@ public static boolean testValueOpValueExact(double value1, String op, double val
if (op.equals("<")) return value1 < value2;
if (op.equals(">")) return value1 > value2;
if (op.equals("!="))
return Double.isNaN(value1) && Double.isNaN(value2) ? false : value1 != value2;
return (Double.isNaN(value1) && Double.isNaN(value2)) ? false : value1 != value2;
// Regex test has to be handled via String testValueOpValue
// if (op.equals(PrimitiveArray.REGEX_OP))
throw new SimpleException("Query error: " + "Unknown operator=\"" + op + "\".");
Expand Down
18 changes: 8 additions & 10 deletions WEB-INF/classes/com/cohort/array/StringArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ public static String rafReadString(
final RandomAccessFile raf, final long start, final int index, final int nBytesPer)
throws Exception {

raf.seek(start + nBytesPer * index);
raf.seek(start + nBytesPer * ((long) index));
final byte bar[] = new byte[nBytesPer];
raf.readFully(bar);
int po = 0;
Expand Down Expand Up @@ -2180,7 +2180,7 @@ else if (ch == 'u'
&& po <= n - 4
&& // \\uxxxx
String2.isHexString(searchFor.substring(po, po + 4))) {
word.append((char) (Integer.parseInt(searchFor.substring(po, po + 4), 16)));
word.append((char) Integer.parseInt(searchFor.substring(po, po + 4), 16));
po += 4;
}
// else if (ch == '') word.append('');
Expand Down Expand Up @@ -2431,10 +2431,9 @@ public static StringArray simpleFromJsonArray(final String csv) {
public String isAscending() {
if (size == 0) return "";
String s = get(0);
if (s
== null) // other classes test isMissingValue. StringArray's behavior is intentionally a
// little different.
return MessageFormat.format(ArrayNotAscending, getClass().getSimpleName(), "[0]=null");
if (s == null) // other classes test isMissingValue. StringArray's behavior is intentionally a
// little different.
return MessageFormat.format(ArrayNotAscending, getClass().getSimpleName(), "[0]=null");
for (int i = 1; i < size; i++) {
final String oldS = s;
s = get(i);
Expand Down Expand Up @@ -2469,10 +2468,9 @@ public String isAscending() {
public String isDescending() {
if (size == 0) return "";
String s = get(0);
if (s
== null) // other classes test isMissingValue. StringArray's behavior is intentionally a
// little different.
return MessageFormat.format(ArrayNotDescending, getClass().getSimpleName(), "[0]=null");
if (s == null) // other classes test isMissingValue. StringArray's behavior is intentionally a
// little different.
return MessageFormat.format(ArrayNotDescending, getClass().getSimpleName(), "[0]=null");
for (int i = 1; i < size; i++) {
final String oldS = s;
s = get(i);
Expand Down
4 changes: 2 additions & 2 deletions WEB-INF/classes/com/cohort/array/ULongArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ULongArray extends PrimitiveArray {

/** This is the Long.MAX_VALUE+1 stored as a BigInteger. */
public static final BigInteger LONG_MAX_VALUE1 =
(new BigInteger("" + Long.MAX_VALUE)).add(BigInteger.ONE);
new BigInteger("" + Long.MAX_VALUE).add(BigInteger.ONE);

/** This is the maximum value, stored as a double. */
public static final double MAX_VALUE_AS_DOUBLE = MAX_VALUE.doubleValue();
Expand Down Expand Up @@ -1474,7 +1474,7 @@ public PrimitiveArray makeIndices(final IntArray indices) {
boolean alreadySorted = true;
for (int i = 1; i < size; i++) {
BigInteger currentValue = unpackIgnoreMaxIsMV(array[i]);
if (currentValue != lastValue) {
if (!currentValue.equals(lastValue)) {
if (currentValue.compareTo(lastValue) < 0) alreadySorted = false;
lastValue = currentValue;
hashMap.put(lastValue, dummy);
Expand Down
Loading

0 comments on commit 2ef97c8

Please sign in to comment.