Java cleanups (#1776)

* Remove extra ';'s
* Remove unnecessary conversions to String
* Use StandardCharsets object
* Replace infinite while with check for interrupted thread
* Remove redundant local vars
* Remove redundant throws clause
* Remove redundant primitive wrapping
* Fix malformed Nested class test
* Remove unnecessary unboxing
* Remove unnecessary explicit type argument
* Replace lambdas with method references
* Replace statement lambdas with expression lambdas
* Replace null check with method call
* Replace number comparison with method call
* Fix broken javadoc comments
* Replace Arrays.asList with singletonLists
* Remove excessive lambda usage
* Remove redundant string operation
* Remove redundant type casts
* Remove unnecessary returns
* Remove redundant suppressions
* Fix unresolved file reference
* static analysis fixes
This commit is contained in:
Austin Shalit
2019-08-01 01:19:48 -04:00
committed by Peter Johnson
parent 39561751fc
commit df12fc2a86
43 changed files with 129 additions and 180 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -218,7 +218,7 @@ public final class NetworkTable {
final int prefixLen = m_path.length() + 1;
final NetworkTable parent = this;
return m_inst.addEntryListener(m_pathWithSep, new Consumer<EntryNotification>() {
return m_inst.addEntryListener(m_pathWithSep, new Consumer<>() {
final Set<String> m_notifiedTables = new HashSet<>();
@Override
@@ -358,7 +358,7 @@ public final class NetworkTable {
*
* @param key the key
* @param defaultValue the default value to set if key doesn't exist.
* @returns False if the table key exists with a different type
* @return False if the table key exists with a different type
*/
boolean setDefaultValue(String key, NetworkTableValue defaultValue) {
return getEntry(key).setDefaultValue(defaultValue);

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -280,7 +280,7 @@ public final class NetworkTableEntry {
switch (((NetworkTableValue) defaultValue).getType()) {
case kBoolean:
return NetworkTablesJNI.setDefaultBoolean(m_handle, time,
((Boolean) otherValue).booleanValue());
(Boolean) otherValue);
case kDouble:
return NetworkTablesJNI.setDefaultDouble(m_handle, time,
((Number) otherValue).doubleValue());
@@ -438,7 +438,7 @@ public final class NetworkTableEntry {
Object otherValue = ((NetworkTableValue) value).getValue();
switch (((NetworkTableValue) value).getType()) {
case kBoolean:
return NetworkTablesJNI.setBoolean(m_handle, time, ((Boolean) otherValue).booleanValue(),
return NetworkTablesJNI.setBoolean(m_handle, time, (Boolean) otherValue,
false);
case kDouble:
return NetworkTablesJNI.setDouble(m_handle, time, ((Number) otherValue).doubleValue(),
@@ -612,7 +612,7 @@ public final class NetworkTableEntry {
Object otherValue = ((NetworkTableValue) value).getValue();
switch (((NetworkTableValue) value).getType()) {
case kBoolean:
NetworkTablesJNI.setBoolean(m_handle, time, ((Boolean) otherValue).booleanValue(), true);
NetworkTablesJNI.setBoolean(m_handle, time, (Boolean) otherValue, true);
return;
case kDouble:
NetworkTablesJNI.setDouble(m_handle, time, ((Number) otherValue).doubleValue(), true);

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -153,7 +153,7 @@ public final class NetworkTableValue {
if (m_type != NetworkTableType.kBoolean) {
throw new ClassCastException("cannot convert " + m_type + " to boolean");
}
return ((Boolean) m_value).booleanValue();
return (Boolean) m_value;
}
/**

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -8,6 +8,7 @@
package edu.wpi.first.networktables;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
@@ -65,8 +66,8 @@ class NetworkTableTest {
private static Stream<Arguments> getHierarchyArguments() {
return Stream.of(
Arguments.of(Arrays.asList("/"), ""),
Arguments.of(Arrays.asList("/"), "/"),
Arguments.of(Collections.singletonList("/"), ""),
Arguments.of(Collections.singletonList("/"), "/"),
Arguments.of(Arrays.asList("/", "/foo", "/foo/bar", "/foo/bar/baz"), "/foo/bar/baz"),
Arguments.of(Arrays.asList("/", "/foo", "/foo/bar", "/foo/bar/"), "/foo/bar/")
);