Skip to content

Commit

Permalink
Run "Code cleanup..."
Browse files Browse the repository at this point in the history
  • Loading branch information
cpesch committed Sep 6, 2023
1 parent 68a9c0b commit 05e1741
Show file tree
Hide file tree
Showing 367 changed files with 1,007 additions and 1,062 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected void second(int second) {
}
if (!profile.exists()) {
List<TravelMode> availableTravelModes = getAvailableTravelModes();
if (availableTravelModes.size() == 0) {
if (availableTravelModes.isEmpty()) {
log.warning(format("Cannot route between %s and %s: no travel modes found in %s", from, to, getProfilesDirectory()));
return new RoutingResult(asList(from, to), new DistanceAndTime(calculateBearing(from.getLongitude(), from.getLatitude(), to.getLongitude(), to.getLatitude()).getDistance(), null), Invalid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static org.junit.Assert.assertEquals;

public class BRouterTest {
private BRouter router = new BRouter(null);
private final BRouter router = new BRouter(null);

@Test
public void testLongitude() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public void componentHidden(ComponentEvent e) {

List<NavigationPosition> render = new ArrayList<>(positionReducer.reduceSelectedPositions(copiedPositions, copiedSelectedPositionIndices));
render.addAll(selectedPositions);
NavigationPosition centerPosition = render.size() > 0 ? new BoundingBox(render).getCenter() : null;
NavigationPosition centerPosition = !render.isEmpty() ? new BoundingBox(render).getCenter() : null;
selectPositions(render, recenter ? centerPosition : null);
log.info("Selected positions updated for " + render.size() + " positions, reason: " +
selectionUpdateReason + ", recentering: " + recenter + " to: " + centerPosition);
Expand Down Expand Up @@ -491,13 +491,11 @@ protected void initializeCallbackListener() {

try {
final Socket socket = callbackListenerServerSocket.accept();
executor.execute(new Runnable() {
public void run() {
try {
processStream(socket);
} catch (IOException e) {
log.severe(format("Cannot process stream from callback listener socket: %s, %s ", e, printStackTrace(e)));
}
executor.execute(() -> {
try {
processStream(socket);
} catch (IOException e) {
log.severe(format("Cannot process stream from callback listener socket: %s, %s ", e, printStackTrace(e)));
}
});
} catch (SocketTimeoutException e) {
Expand Down Expand Up @@ -581,42 +579,40 @@ public void receivedCallback(int port) {
}
};

executor.execute(new Runnable() {
public void run() {
addMapViewListener(callbackWaiter);
try {
executeScript("checkCallbackListenerPort();");

long start = currentTimeMillis();
while (true) {
synchronized (receivedCallback) {
if (receivedCallback[0]) {
long end = currentTimeMillis();
log.info("Received callback from browser after " + (end - start) + " milliseconds");
break;
}
}
executor.execute(() -> {
addMapViewListener(callbackWaiter);
try {
executeScript("checkCallbackListenerPort();");

if (start + 5000 < currentTimeMillis())
long start = currentTimeMillis();
while (true) {
synchronized (receivedCallback) {
if (receivedCallback[0]) {
long end = currentTimeMillis();
log.info("Received callback from browser after " + (end - start) + " milliseconds");
break;

try {
sleep(50);
} catch (InterruptedException e) {
// intentionally left empty
}
}

synchronized (receivedCallback) {
if (!receivedCallback[0]) {
setCallbackListenerPort(-1);
initializeCallbackPoller();
log.warning("Switched from callback to polling the browser");
}
if (start + 5000 < currentTimeMillis())
break;

try {
sleep(50);
} catch (InterruptedException e) {
// intentionally left empty
}
}

synchronized (receivedCallback) {
if (!receivedCallback[0]) {
setCallbackListenerPort(-1);
initializeCallbackPoller();
log.warning("Switched from callback to polling the browser");
}
} finally {
removeMapViewListener(callbackWaiter);
}
} finally {
removeMapViewListener(callbackWaiter);
}
});
}
Expand All @@ -643,7 +639,7 @@ private String registerMaps(List<TileServer> tileServers) {

String apiKey = APIKeyRegistry.getInstance().getAPIKey("thunderforest", "map");
for (TileServer tileServer : tileServers) {
if (!tileServer.isActive() || tileServer.getHosts().size() == 0)
if (!tileServer.isActive() || tileServer.getHosts().isEmpty())
continue;

String copyright = tileServer.getCopyright().toLowerCase();
Expand Down Expand Up @@ -861,7 +857,7 @@ public void setSelectedPositions(List<NavigationPosition> selectedPositions) {
synchronized (notificationMutex) {
this.selectedPositions = selectedPositions;
this.selectedPositionIndices = new int[0];
haveToRecenterMap = selectedPositions.size() > 0;
haveToRecenterMap = !selectedPositions.isEmpty();
haveToRepaintSelection = true;
selectionUpdateReason = "selected " + selectedPositions.size() + " positions without model";
notificationMutex.notifyAll();
Expand Down Expand Up @@ -1153,7 +1149,7 @@ private void addMarkersToMap(List<NavigationPosition> positions) {
private void setCenterOfMap(List<NavigationPosition> positions, boolean recenter) {
StringBuilder buffer = new StringBuilder();

boolean fitBoundsToPositions = positions.size() > 0 && recenter;
boolean fitBoundsToPositions = !positions.isEmpty() && recenter;
if (fitBoundsToPositions) {
BoundingBox boundingBox = new BoundingBox(positions);
buffer.append("fitBounds(new google.maps.LatLng(").append(asCoordinates(boundingBox.getSouthWest())).append("),").
Expand All @@ -1164,7 +1160,7 @@ private void setCenterOfMap(List<NavigationPosition> positions, boolean recenter
if (haveToInitializeMapOnFirstStart) {
NavigationPosition center;
// if there are positions right at the start center on them else take the last known center and zoom
if (positions.size() > 0) {
if (!positions.isEmpty()) {
center = new BoundingBox(positions).getCenter();
} else {
int zoom = getZoom();
Expand Down Expand Up @@ -1754,7 +1750,7 @@ private void insertPosition(int row, Double longitude, Double latitude) {
}

private int getAddRow() {
NavigationPosition position = lastSelectedPositions.size() > 0 ? lastSelectedPositions.get(lastSelectedPositions.size() - 1) : null;
NavigationPosition position = !lastSelectedPositions.isEmpty() ? lastSelectedPositions.get(lastSelectedPositions.size() - 1) : null;
// quite crude logic to be as robust as possible on failures
if (position == null && positionsModel.getRowCount() > 0)
position = positionsModel.getPosition(positionsModel.getRowCount() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static org.junit.Assert.assertEquals;

public class PositionReducerTest {
private PositionReducer reducer = new PositionReducer(new PositionReducer.Callback() {
private final PositionReducer reducer = new PositionReducer(new PositionReducer.Callback() {
public int getZoom() {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public class ActionManager {
private static final Preferences preferences = Preferences.userNodeForPackage(ActionManager.class);
private static final String RUN_COUNT_PREFERENCE = "runCount";

private Map<String, Action> actionMap = new HashMap<>();
private Map<String, ProxyAction> proxyActionMap = new HashMap<>();
private final Map<String, Action> actionMap = new HashMap<>();
private final Map<String, ProxyAction> proxyActionMap = new HashMap<>();
private String localName;

public String getLocalName() {
Expand Down Expand Up @@ -143,12 +143,12 @@ public void logUsage() {
if (runs > 0)
builder.append(format("%n%s, runs: %d", actionName, runs));
}
log.info("Action usage:" + builder.toString());
log.info("Action usage:" + builder);
}

private static class ProxyAction implements Action, PropertyChangeListener {
private Action delegate;
private SwingPropertyChangeSupport changeSupport = new SwingPropertyChangeSupport(this);
private final SwingPropertyChangeSupport changeSupport = new SwingPropertyChangeSupport(this);

private ProxyAction() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void perform(List<List<Integer>> ranges) {
if (operation.isInterrupted())
return;
}
if (range.size() == 0)
if (range.isEmpty())
continue;
int firstValue = range.get(0);
int lastValue = range.get(range.size() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static List<List<Integer>> asContinuousMonotonicallyIncreasingRanges(int[
List<List<Integer>> result = new ArrayList<>();
List<Integer> range = new ArrayList<>();
for (int index : indices) {
if ((range.size() == 0 || index == range.get(range.size() - 1) + 1) && range.size() < maximumRangeLength) {
if ((range.isEmpty() || index == range.get(range.size() - 1) + 1) && range.size() < maximumRangeLength) {
range.add(index);
} else {
result.add(range);
Expand All @@ -69,7 +69,7 @@ public static List<List<Integer>> asContinuousMonotonicallyDecreasingRanges(int[
List<List<Integer>> result = new ArrayList<>();
List<Integer> range = new ArrayList<>();
for (int index : indices) {
if (range.size() == 0 || index == range.get(range.size() - 1) - 1) {
if (range.isEmpty() || index == range.get(range.size() - 1) - 1) {
range.add(index);
} else {
result.add(range);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static JMenu createMenu(String name) {
JMenu menu = new JMenu(getString(name + "-menu"));
menu.setName(name);
String mnemonic = getOptionalString(name + "-menu-mnemonic");
if (mnemonic != null && mnemonic.length() > 0)
if (mnemonic != null && !mnemonic.isEmpty())
menu.setMnemonic(mnemonic.charAt(0));
return menu;
}
Expand Down Expand Up @@ -89,7 +89,7 @@ private static void setMnemonic(AbstractButton item, char mnemonic) {

public static void setMnemonic(AbstractButton button, String key) {
String mnemonic = getOptionalString(key);
if (mnemonic != null && mnemonic.length() > 0)
if (mnemonic != null && !mnemonic.isEmpty())
setMnemonic(button, mnemonic.charAt(0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
public class NotificationManager {
private static final int DISPLAY_TIMEOUT = 2 * 1000;

private JWindow window;
private JLabel label = new JLabel();
private final JWindow window;
private final JLabel label = new JLabel();

private static final Object notificationMutex = new Object();
private boolean running = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public class Bearing {
/**
* the azimuth, degrees, 0 = north, clockwise positive
*/
private double azimuth;
private final double azimuth;

/**
* the back azimuth, degrees, 0 = north, clockwise positive
*/
private double backazimuth;
private final double backazimuth;

/**
* separation in meters
*/
private double distance;
private final double distance;

/**
* Earth radius in meters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import slash.common.type.CompactCalendar;

import java.util.List;
import java.util.Objects;

import static java.lang.Math.abs;
import static slash.common.type.CompactCalendar.fromMillis;
Expand Down Expand Up @@ -135,8 +136,8 @@ public boolean equals(Object o) {

BoundingBox that = (BoundingBox) o;

return !(northEast != null ? !northEast.equals(that.northEast) : that.northEast != null) &&
!(southWest != null ? !southWest.equals(that.southWest) : that.southWest != null);
return !(!Objects.equals(northEast, that.northEast)) &&
!(!Objects.equals(southWest, that.southWest));
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum Orientation {
West("W"),
East("E");

private String value;
private final String value;

Orientation(String value) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import slash.common.type.CompactCalendar;

import java.util.Objects;

/**
* A navigation position that supports just longitude, latitude, elevation, description and time.
*
Expand Down Expand Up @@ -142,12 +144,12 @@ public boolean equals(Object o) {

SimpleNavigationPosition that = (SimpleNavigationPosition) o;

return !(description != null ? !description.equals(that.description) : that.description != null) &&
!(speed != null ? !speed.equals(that.speed) : that.speed != null) &&
!(elevation != null ? !elevation.equals(that.elevation) : that.elevation != null) &&
!(latitude != null ? !latitude.equals(that.latitude) : that.latitude != null) &&
!(longitude != null ? !longitude.equals(that.longitude) : that.longitude != null) &&
!(time != null ? !time.equals(that.time) : that.time != null);
return !(!Objects.equals(description, that.description)) &&
!(!Objects.equals(speed, that.speed)) &&
!(!Objects.equals(elevation, that.elevation)) &&
!(!Objects.equals(latitude, that.latitude)) &&
!(!Objects.equals(longitude, that.longitude)) &&
!(!Objects.equals(time, that.time));
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
* @author Christian Pesch
*/
public class ValueAndOrientation {
private double value;
private Orientation orientation;
private final double value;
private final Orientation orientation;

public ValueAndOrientation(double value, Orientation orientation) {
this.value = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void logUsage() {

String apiKey = getAPIKey(serviceName, "usage");
if (apiKey != null)
log.info(serviceName + " API key: " + apiKey + " usage:" + builder.toString());
log.info(serviceName + " API key: " + apiKey + " usage:" + builder);
}

} catch (BackingStoreException e) {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/slash/common/helpers/JAXBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class JAXBHelper {
private static final String HEADER_LINE = "\n<!-- Generated by Christian Peschs RouteConverter. See https://www.routeconverter.com -->\n";
private static final String JAXB_IMPL_HEADER = "com.sun.xml.internal.bind.xmlHeaders";

private static Map<List<Class<?>>, JAXBContext> classesToContext = new HashMap<>();
private static final Map<List<Class<?>>, JAXBContext> classesToContext = new HashMap<>();
private static boolean cacheContexts;

public static void setCacheContexts(boolean cacheContexts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static ExecutorService createSingleThreadExecutor(String namePrefix) {
}

private static class NamedThreadFactory implements ThreadFactory {
private String namePrefix;
private final String namePrefix;
private int number = 1;

private NamedThreadFactory(String namePrefix) {
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/slash/common/helpers/TimeZoneAndId.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
* @author Christian Pesch
*/
public class TimeZoneAndId {
private String id;
private TimeZone timeZone;
private final String id;
private final TimeZone timeZone;

public TimeZoneAndId(String id, TimeZone timeZone) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/

public class NotClosingUnderlyingInputStream extends InputStream {
private InputStream delegate;
private final InputStream delegate;

public NotClosingUnderlyingInputStream(InputStream delegate) {
this.delegate = delegate;
Expand Down
Loading

0 comments on commit 05e1741

Please sign in to comment.