Enable PMD rule UnnecessaryBoxing and fix violations

This commit is contained in:
Manuel Fuhr 2024-04-03 14:50:05 +02:00
parent dd896347a2
commit c73a8cebb8
6 changed files with 30 additions and 34 deletions

View file

@ -246,7 +246,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
public int getLookupKey(String name) {
int res = -1;
try {
res = lookupNumbers.get(name).intValue();
res = lookupNumbers.get(name);
} catch (Exception e) {
}
return res;
@ -438,7 +438,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
// first count
for (String name : lookupNumbers.keySet()) {
int cnt = 0;
int inum = lookupNumbers.get(name).intValue();
int inum = lookupNumbers.get(name);
int[] histo = lookupHistograms.get(inum);
// if ( histo.length == 500 ) continue;
for (int i = 2; i < histo.length; i++) {
@ -451,7 +451,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
String key = counts.lastEntry().getKey();
String name = counts.get(key);
counts.remove(key);
int inum = lookupNumbers.get(name).intValue();
int inum = lookupNumbers.get(name);
BExpressionLookupValue[] values = lookupValues.get(inum);
int[] histo = lookupHistograms.get(inum);
if (values.length == 1000) continue;
@ -508,7 +508,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
public String variableName(int idx) {
for (Map.Entry<String, Integer> e : variableNumbers.entrySet()) {
if (e.getValue().intValue() == idx) {
if (e.getValue() == idx) {
return e.getKey();
}
}
@ -545,9 +545,8 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
}
// look for that value
int inum = num.intValue();
BExpressionLookupValue[] values = lookupValues.get(inum);
int[] histo = lookupHistograms.get(inum);
BExpressionLookupValue[] values = lookupValues.get(num);
int[] histo = lookupHistograms.get(num);
int i = 0;
boolean bFoundAsterix = false;
for (; i < values.length; i++) {
@ -559,7 +558,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
if (lookupData2 != null) {
// do not create unknown value for external data array,
// record as 'unknown' instead
lookupData2[inum] = 1; // 1 == unknown
lookupData2[num] = 1; // 1 == unknown
if (bFoundAsterix) {
// found value for lookup *
//System.out.println( "add unknown " + name + " " + value );
@ -653,11 +652,11 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
// found negative maxdraft values
// no negative values
// values are float with 2 decimals
lookupData2[inum] = 1000 + (int) (Math.abs(Float.parseFloat(value)) * 100f);
lookupData2[num] = 1000 + (int) (Math.abs(Float.parseFloat(value)) * 100f);
} catch (Exception e) {
// ignore errors
System.err.println("error for " + name + " " + org + " trans " + value + " " + e.getMessage());
lookupData2[inum] = 0;
lookupData2[num] = 0;
}
}
return newValue;
@ -678,15 +677,15 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
histo = nhisto;
newValue = new BExpressionLookupValue(value);
values[i] = newValue;
lookupHistograms.set(inum, histo);
lookupValues.set(inum, values);
lookupHistograms.set(num, histo);
lookupValues.set(num, values);
}
histo[i]++;
// finally remember the actual data
if (lookupData2 != null) lookupData2[inum] = i;
else lookupData[inum] = i;
if (lookupData2 != null) lookupData2[num] = i;
else lookupData[num] = i;
return newValue;
}
@ -701,11 +700,10 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
}
// look for that value
int inum = num.intValue();
int nvalues = lookupValues.get(inum).length;
int nvalues = lookupValues.get(num).length;
if (valueIndex < 0 || valueIndex >= nvalues)
throw new IllegalArgumentException("value index out of range for name " + name + ": " + valueIndex);
lookupData[inum] = valueIndex;
lookupData[num] = valueIndex;
}
@ -722,9 +720,8 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
}
// look for that value
int inum = num.intValue();
int nvalues = lookupValues.get(inum).length;
int oldValueIndex = lookupData[inum];
int nvalues = lookupValues.get(num).length;
int oldValueIndex = lookupData[num];
if (oldValueIndex > 1 && oldValueIndex < valueIndex) {
return;
}
@ -733,12 +730,12 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
}
if (valueIndex < 0)
throw new IllegalArgumentException("value index out of range for name " + name + ": " + valueIndex);
lookupData[inum] = valueIndex;
lookupData[num] = valueIndex;
}
public boolean getBooleanLookupValue(String name) {
Integer num = lookupNumbers.get(name);
return num != null && lookupData[num.intValue()] == 2;
return num != null && lookupData[num] == 2;
}
public int getOutputVariableIndex(String name, boolean mustExist) {
@ -850,7 +847,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
public void setVariableValue(String name, float value, boolean create) {
Integer num = variableNumbers.get(name);
if (num != null) {
variableData[num.intValue()] = value;
variableData[num] = value;
} else if (create) {
num = getVariableIdx(name, create);
float[] readOnlyData = variableData;
@ -859,13 +856,13 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
for (int i = 0; i < minWriteIdx; i++) {
variableData[i] = readOnlyData[i];
}
variableData[num.intValue()] = value;
variableData[num] = value;
}
}
public float getVariableValue(String name, float defaultValue) {
Integer num = variableNumbers.get(name);
return num == null ? defaultValue : getVariableValue(num.intValue());
return num == null ? defaultValue : getVariableValue(num);
}
float getVariableValue(int variableIdx) {
@ -883,7 +880,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
return -1;
}
}
return num.intValue();
return num;
}
int getMinWriteIdx() {
@ -901,7 +898,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
public int getLookupNameIdx(String name) {
Integer num = lookupNumbers.get(name);
return num == null ? -1 : num.intValue();
return num == null ? -1 : num;
}
public final void markLookupIdxUsed(int idx) {