Skip to content

Commit

Permalink
Cleanup by findbugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengtmartensson committed Dec 26, 2023
1 parent f4b1449 commit b863686
Show file tree
Hide file tree
Showing 32 changed files with 46 additions and 58 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/harctoolbox/analyze/AbstractDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ Protocol parse(int number, boolean signalMode) throws DecodeException {
}
}
BitspecIrstream bitspecIrstream = new BitspecIrstream(bitSpec, irStream);
Protocol protocol = new Protocol(params.getGeneralSpec(timebase), bitspecIrstream, nameEngine, null, null, getClass());
return protocol;
return new Protocol(params.getGeneralSpec(timebase), bitspecIrstream, nameEngine, null, null, getClass());
}

protected Flash newFlash(int flash) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/harctoolbox/cmdline/CmdLineProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ protected void setupLoggers() throws UsageException, IOException {
topLevelLogger.setLevel(commandBasicOptions.logLevel);
}

@SuppressWarnings("NoopMethodInAbstractClass")
public void extraSetup() {
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/harctoolbox/cmdline/CommandAnalyze.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private void analyze(Analyzer analyzer, List<String> names, IrSignal inputSignal
parameterWidths.add(width);
}
} else {
parameterNamedWidths.stream().map((param) -> Integer.parseInt(param)).forEachOrdered((width) -> {
parameterNamedWidths.stream().map((param) -> Integer.valueOf(param)).forEachOrdered((width) -> {
parameterWidths.add(width);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/harctoolbox/cmdline/CommandList.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void list(PrintStream out, CommandCommonOptions commandLineArgs, IrpDatab

if (preferOvers || all) {
out.println("preferovers tree:");
if (commandLineArgs.quiet && ! this.name && protocol.preferredOvers().size() > 0)
if (commandLineArgs.quiet && ! this.name && !protocol.preferredOvers().isEmpty())
out.println(irpDatabase.getName(protocolName) + ":");
protocol.dumpPreferOvers(out, irpDatabase);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/harctoolbox/cmdline/FrequencyParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public class FrequencyParser implements IStringConverter<Double> {
public Double convert(String value) {
return value.toLowerCase(Locale.US).endsWith("k")
? IrCoreUtils.khz2Hz(Double.parseDouble(value.substring(0, value.length() - 1)))
: Double.parseDouble(value);
: Double.valueOf(value);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/harctoolbox/ircore/AbstractIrParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected static String fixIrRemoteSilliness(String str) {
}

protected static IrSignal mkIrSignal(List<IrSequence> list, Double frequency) throws OddSequenceLengthException {
return (list.size() > 0 && list.size() <= 3)
return (!list.isEmpty() && list.size() <= 3)
? new IrSignal(list.get(0), list.size() > 1 ? list.get(1) : null, list.size() > 2 ? list.get(2) : null, frequency, null)
: null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public IrSignal toIrSignal(Double fallbackFrequency, Double dummyGap) throws Odd
int pos = s.indexOf('H', 6);
if (pos != -1) {
try {
readFrequency = Double.parseDouble(s.substring(5, pos));
readFrequency = Double.valueOf(s.substring(5, pos));
} catch (NumberFormatException ex) {
// leaving as null
}
Expand All @@ -52,7 +52,7 @@ public IrSignal toIrSignal(Double fallbackFrequency, Double dummyGap) throws Odd
pos = s.indexOf('[', 6);
if (pos != -1) {
try {
readFrequency = Double.parseDouble(s.substring(5, pos));
readFrequency = Double.valueOf(s.substring(5, pos));
} catch (NumberFormatException ex) {
// leaving as null
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/harctoolbox/ircore/IrCoreUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -644,8 +644,7 @@ public static boolean approximatelyEquals(int x, int y, int absoluteTolerance, d
if (absoluteOk)
return true;
int max = Math.max(Math.abs(x), Math.abs(y));
boolean relativeOk = max > 0 && absDiff / (double) max <= relativeTolerance;
return relativeOk;
return max > 0 && absDiff / (double) max <= relativeTolerance;
}

public static long maskTo(long data, int width) {
Expand Down Expand Up @@ -718,7 +717,7 @@ public static void main(String[] args) {
double relTolerance = hasOption ? Double.parseDouble(args[1]) : 0.0;
ArrayList<Integer> data = new ArrayList<>(args.length);
for (int i = hasOption ? 2 : 0; i < args.length; i++)
data.add(Integer.parseInt(args[i]));
data.add(Integer.valueOf(args[i]));

int gcd = approximateGreatestCommonDivider(data, relTolerance);
System.out.println(gcd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ public List<IrSequence> chop(double amount) {
@Override
@SuppressWarnings("CloneDeclaresCloneNotSupported")
public ModulatedIrSequence clone() {
ModulatedIrSequence result = (ModulatedIrSequence) super.clone();
return result;
return (ModulatedIrSequence) super.clone();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public ModulatedIrSequence toModulatedIrSequence(Double fallbackFrequency, Doubl
String s = getSource().replace(",", " ").trim();
if (s.startsWith("f=")) {
int pos = s.indexOf(' ', 3);
frequency = Double.parseDouble(s.substring(2, pos));
frequency = Double.valueOf(s.substring(2, pos));
s = s.substring(pos + 1).trim();
} else if (s.startsWith("Freq=")) {
int pos = s.indexOf('H', 6);
frequency = Double.parseDouble(s.substring(5, pos));
frequency = Double.valueOf(s.substring(5, pos));
s = s.substring(pos + 2).trim();
}
IrSequence irSequence = new IrSequence(s, dummyGap);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/harctoolbox/irp/BitFieldExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ public String toIrpString(int radix) {

@Override
public Map<String, Object> propertiesMap(boolean eval, GeneralSpec generalSpec, NameEngine nameEngine) {
Map<String, Object> map = bitField.propertiesMap(true, generalSpec, nameEngine);
//map.put("scalar", true);
return map;
return bitField.propertiesMap(true, generalSpec, nameEngine);
}

@Override
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/harctoolbox/irp/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,12 @@ public DecoderParameters(boolean strict, Double frequencyTolerance, Double absol
}

public DecoderParameters select(boolean newStrict, Double frequencyTolerance, Double absoluteTolerance, Double relativeTolerance, Double minimumLeadout) {
DecoderParameters copy = new DecoderParameters(strict || newStrict, allDecodes, removeDefaultedParameters, recursive,
return new DecoderParameters(strict || newStrict, allDecodes, removeDefaultedParameters, recursive,
selectValue(frequencyTolerance, this.frequencyTolerance, override),
selectValue(absoluteTolerance, this.absoluteTolerance, override),
selectValue(relativeTolerance, this.relativeTolerance, override),
selectValue(minimumLeadout, this.minimumLeadout, override),
override, ignoreLeadingGarbage);

return copy;
}

private Double selectValue(Double databaseValue, Double userValue, boolean override) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/harctoolbox/irp/Duration.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ public static Duration newDuration(ParserDriver parserDriver) {

public static Duration newDuration(IrpParser.DurationContext d) {
ParseTree child = d.getChild(0);
Duration instance = (child instanceof IrpParser.FlashContext)
return (child instanceof IrpParser.FlashContext)
? new Flash((IrpParser.FlashContext) child)
: child instanceof IrpParser.GapContext
? new Gap((IrpParser.GapContext) child)
: new Extent((IrpParser.ExtentContext) child);
//instance.parseTree = (ParserRuleContext) child;
return instance;
}

public static Duration newDuration(IrpParser.ExtentContext e) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/harctoolbox/irp/EvaluatedIrStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ IrSequence toIrSequence() throws NameUnassignedException, IrpInvalidArgumentExce
elapsed += Math.abs(time);
}
}
IrSequence result = mkIrSequence(times);
return result;
return mkIrSequence(times);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/harctoolbox/irp/IrStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ public BareIrStream extractPass(Pass pass, PassExtractorState state) {
/**
* Extracts a the intro, repeat- or ending sequence as BareIrStream.
* The real top level function; main test object.
* @param pass
* @return
*/
public BareIrStream extractPass(Pass pass) {
return extractPass(pass, new PassExtractorState(Pass.intro));
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/harctoolbox/irp/IrpObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,16 @@ public Map<String, Object> propertiesMap(int noProperites) {
return IrpUtils.propertiesMap(noProperites, this);
}

@SuppressWarnings("NoopMethodInAbstractClass")
public void updateStateWhenEntering(IrSignal.Pass pass, IrStream.PassExtractorState state) {
}

@SuppressWarnings("NoopMethodInAbstractClass")
public void updateStateWhenExiting(IrSignal.Pass pass, IrStream.PassExtractorState state) {
}

// Default implementation, often overridden
@SuppressWarnings("NoopMethodInAbstractClass")
public void createParameterSpecs(ParameterSpecs parameterSpecs) throws InvalidNameException {
}
}
2 changes: 0 additions & 2 deletions src/main/java/org/harctoolbox/irp/IrpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
package org.harctoolbox.irp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/harctoolbox/irp/NamedProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ public NamedProtocol(String name, String irp, DocumentFragment htmlDocumentation
super(irp);
this.name = name;
this.htmlDocumentation = htmlDocumentation;
this.frequencyTolerance = frequencyTolerance != null ? Double.parseDouble(frequencyTolerance) : null;
this.frequencyLower = frequencyLower != null ? Double.parseDouble(frequencyLower) : null;
this.frequencyUpper = frequencyUpper != null ? Double.parseDouble(frequencyUpper) : null;
this.absoluteTolerance = absoluteTolerance != null ? Double.parseDouble(absoluteTolerance) : null;
this.relativeTolerance = relativeTolerance != null ? Double.parseDouble(relativeTolerance) : null;
this.minimumLeadout = minimumLeadout != null ? Double.parseDouble(minimumLeadout) : null;
this.frequencyTolerance = frequencyTolerance != null ? Double.valueOf(frequencyTolerance) : null;
this.frequencyLower = frequencyLower != null ? Double.valueOf(frequencyLower) : null;
this.frequencyUpper = frequencyUpper != null ? Double.valueOf(frequencyUpper) : null;
this.absoluteTolerance = absoluteTolerance != null ? Double.valueOf(absoluteTolerance) : null;
this.relativeTolerance = relativeTolerance != null ? Double.valueOf(relativeTolerance) : null;
this.minimumLeadout = minimumLeadout != null ? Double.valueOf(minimumLeadout) : null;
this.decodable = decodable == null || Boolean.parseBoolean(decodable);
this.rejectRepeatless = rejectRepeatless != null && Boolean.parseBoolean(rejectRepeatless);
this.preferOver = PreferOver.parse(preferOver);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/harctoolbox/irp/Number.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static java.lang.Number parse(String str) {

public static java.lang.Number parse(String str, int radix) {
try {
return Long.parseLong(str, radix);
return Long.valueOf(str, radix);
} catch (NumberFormatException ex) {
return str.equals("UINT8_MAX") ? UINT8_MAX
: str.equals("UINT16_MAX") ? UINT16_MAX
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/harctoolbox/irp/ParameterSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ private long randomSimple(Random rng) {
private long randomHairy(Random rng) {
long x = rng.nextLong() & IrCoreUtils.ones(Long.SIZE - 1); // between 0 and Long.MAX_VALUE
double frac = ((double) x) / Long.MAX_VALUE; // between 0 and 1
long out = (long) ((getMax() - getMin()) * frac + getMin());
return out;
return (long) ((getMax() - getMin()) * frac + getMin());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/harctoolbox/irp/PrimaryItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static PrimaryItem newPrimaryItem(long n) {

public static PrimaryItem newPrimaryItem(String name) throws InvalidNameException {
try {
return new Number(Long.parseLong(name));
return new Number(Long.valueOf(name));
} catch (NumberFormatException ex) {
return name.trim().startsWith("(") ? Expression.newExpression(name) : new Name(name);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/harctoolbox/irp/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ public Protocol substituteConstantVariables() {
Map<String, Long> constantVariables = definitions.getNumericLiterals();
NameEngine newDefs = definitions.remove(constantVariables.keySet());
BitspecIrstream newBitspecIrstream = bitspecIrstream.substituteConstantVariables(constantVariables);
Protocol newProtocol = new Protocol(this.generalSpec, newBitspecIrstream, newDefs, parameterSpecs);
return newProtocol;
return new Protocol(this.generalSpec, newBitspecIrstream, newDefs, parameterSpecs);
}

private void checkSanity() throws UnsupportedRepeatException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private Element commandsToElement(boolean fat) {
remote.appendChild(commandSet);
if (analyzer != null) {
if (analyzer.isSignalMode())
commandSet.appendChild(commandToElement(protocols.get(0), (names != null && names.size() > 0) ? names.get(0) : null,
commandSet.appendChild(commandToElement(protocols.get(0), (names != null && !names.isEmpty()) ? names.get(0) : null,
analyzer.cleanedIrSequence(0), analyzer.cleanedIrSequence(1), analyzer.cleanedIrSequence(2), fat));
else
for (int i = 0; i < protocols.size(); i++)
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/harctoolbox/irp/STCodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public String fileName(String protocolName) {
if (itemCodeGenerator == null)
throw new ThisCannotHappenException("Template \"FileName\" not found."); // FIXME
itemCodeGenerator.setAttribute("protocolName", protocolName);
String fileName = itemCodeGenerator.render();
return fileName;
return itemCodeGenerator.render();
}
}
11 changes: 4 additions & 7 deletions src/main/java/org/harctoolbox/lirc/LircConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ static long parseLircNumber(String s) {

static long parseUnsignedLongHex(String s) {
if (s.length() == 16) {
long value = new BigInteger(s, 16).longValue();
return value;
return new BigInteger(s, 16).longValue();
}
return Long.parseLong(s, 16);
}
Expand Down Expand Up @@ -217,9 +216,8 @@ private LircRemote remote(String source) throws IOException, ParseException, Eof
List<LircCommand> codes = codes();
gobble("end", "remote");

LircRemote irRemote = new LircRemote(parameters.name, parameters.flags,
return new LircRemote(parameters.name, parameters.flags,
parameters.unaryParameters, parameters.binaryParameters, codes, raw, parameters.driver, source);
return irRemote;
}

private void readLine() throws IOException, EofException {
Expand Down Expand Up @@ -382,8 +380,7 @@ private LircCommand rawCode() throws IOException, EofException, ParseException {
String cmdName = words[1];
consumeLine();
List<Long> codes = integerList();
LircCommand irNCode = new LircCommand(cmdName, codes);
return irNCode;
return new LircCommand(cmdName, codes);
}

private List<Long> integerList() throws IOException, EofException {
Expand All @@ -392,7 +389,7 @@ private List<Long> integerList() throws IOException, EofException {
readLine();
try {
for (String w : words)
numbers.add(Long.parseLong(w));
numbers.add(Long.valueOf(w));
} catch (NumberFormatException ex) {
return numbers;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/harctoolbox/xml/XmlTransmogrifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ private static NodeList evaluateXpath(Node node, String xpath, MyResolver resolv
if (resolver != null)
xpather.setNamespaceContext(resolver);
XPathExpression xpathExpression = xpather.compile(xpath);
NodeList nodeList = (NodeList) xpathExpression.evaluate(node, XPathConstants.NODESET);
return nodeList;
return (NodeList) xpathExpression.evaluate(node, XPathConstants.NODESET);
}

@SuppressWarnings({"UseOfSystemOutOrSystemErr", "CallToPrintStackTrace"})
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/harctoolbox/xml/XmlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ public static ByteArrayInputStream renderDOM(Document document, Document xslt, S
ByteArrayOutputStream out = new ByteArrayOutputStream(65536);
XmlUtils.printDOM(out, document, encoding, xslt, new HashMap<>(0), false);
byte[] data = out.toByteArray();
ByteArrayInputStream inStream = new ByteArrayInputStream(data);
return inStream;
return new ByteArrayInputStream(data);
}

public static InputStreamReader mkReaderXml(String docu, String xslt, String encoding) throws SAXException, UnsupportedEncodingException, TransformerException, IOException {
Expand Down Expand Up @@ -578,8 +577,7 @@ private static class MyLSResourceResolver implements LSResourceResolver {
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
try {
MyInput input = new MyInput(type, namespaceURI, publicId, systemId, baseURI);
return input;
return new MyInput(type, namespaceURI, publicId, systemId, baseURI);
} catch (IOException | URISyntaxException ex) {
throw new ThisCannotHappenException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ private static Protocol parse(int[] data) throws OddSequenceLengthException, Dec
widths.add(8);
Analyzer.AnalyzerParams paramsRc6 = new Analyzer.AnalyzerParams(36000d, null, BitDirection.msb, true, widths, false);
AbstractBiphaseDecoder decoder = new BiphaseWithDoubleToggleDecoder(analyzer, paramsRc6);
Protocol result = decoder.parse()[0];
return result;
return decoder.parse()[0];
}

private static void testStuff(int[] data, String expected) throws IrpException, OddSequenceLengthException, DecodeException, InvalidArgumentException {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/harctoolbox/irp/BareIrStreamNGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

@SuppressWarnings("UseOfSystemOutOrSystemErr")
public class BareIrStreamNGTest {

public BareIrStreamNGTest() {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/harctoolbox/irp/IrpDatabaseNGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public void testRender() throws Exception {

/**
* Test of expandAlias method, of class IrpDatabase.
* @throws java.lang.Exception
*/
@Test
public void testExpandAlias() throws Exception {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/harctoolbox/irp/ProtocolNGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ public void testSort() {

/**
* Test of line comment of class Protocol.
* @throws java.lang.Exception
*/
public void testLineComment() throws Exception {
System.out.println("lineComment");
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/harctoolbox/xml/XmlUtilsNGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void tearDownMethod() throws Exception {
* Test of openXmlFile method, of class XmlUtils.
*/
@Test
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public void testOpenXmlFile_File() {
System.out.println("openXmlFile");
File file = new File("[.girr");
Expand Down

0 comments on commit b863686

Please sign in to comment.