Replaced ternary operators with if statements (#346)

Instances of the ternary operator were replaced with if statements to make the code base more consistent.
This commit is contained in:
Tyler Veness
2017-11-08 23:44:03 -08:00
committed by Peter Johnson
parent c8e44256ef
commit 7efab4c43a
7 changed files with 58 additions and 39 deletions

View File

@@ -211,18 +211,20 @@ public class DriverStation implements RobotState.Interface {
} else {
locString = "";
}
boolean haveLoc = false;
String traceString = "";
for (int i = stackTraceFirst; i < stackTrace.length; i++) {
String loc = stackTrace[i].toString();
traceString += "\tat " + loc + "\n";
// get first user function
if (!haveLoc && !loc.startsWith("edu.wpi.first")) {
locString = loc;
haveLoc = true;
if (printTrace) {
boolean haveLoc = false;
for (int i = stackTraceFirst; i < stackTrace.length; i++) {
String loc = stackTrace[i].toString();
traceString += "\tat " + loc + "\n";
// get first user function
if (!haveLoc && !loc.startsWith("edu.wpi.first")) {
locString = loc;
haveLoc = true;
}
}
}
HAL.sendError(isError, code, false, error, locString, printTrace ? traceString : "", false);
HAL.sendError(isError, code, false, error, locString, traceString, true);
}
/**

View File

@@ -8,7 +8,6 @@
package edu.wpi.first.wpilibj.command;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import edu.wpi.first.networktables.EntryListenerFlags;
import edu.wpi.first.networktables.NetworkTable;
@@ -43,47 +42,56 @@ import edu.wpi.first.wpilibj.Timer;
* @see IllegalUseOfCommandException
*/
public abstract class Command implements NamedSendable {
/**
* The name of this command.
*/
private String m_name;
/**
* The time since this command was initialized.
*/
private double m_startTime = -1;
/**
* The time (in seconds) before this command "times out" (or -1 if no timeout).
*/
private double m_timeout = -1;
/**
* Whether or not this command has been initialized.
*/
private boolean m_initialized = false;
/**
* The requirements (or null if no requirements).
* The required subsystems.
*/
private Set m_requirements;
private final Set m_requirements = new Set();
/**
* Whether or not it is running.
*/
private boolean m_running = false;
/**
* Whether or not it is interruptible.
*/
private boolean m_interruptible = true;
/**
* Whether or not it has been canceled.
*/
private boolean m_canceled = false;
/**
* Whether or not it has been locked.
*/
private boolean m_locked = false;
/**
* Whether this command should run when the robot is disabled.
*/
private boolean m_runWhenDisabled = false;
/**
* The {@link CommandGroup} this is in.
*/
@@ -191,9 +199,6 @@ public abstract class Command implements NamedSendable {
protected synchronized void requires(Subsystem subsystem) {
validate("Can not add new requirement to command");
if (subsystem != null) {
if (m_requirements == null) {
m_requirements = new Set();
}
m_requirements.add(subsystem);
} else {
throw new IllegalArgumentException("Subsystem must not be null.");
@@ -347,7 +352,7 @@ public abstract class Command implements NamedSendable {
* Subsystems}) of this command
*/
synchronized Enumeration getRequirements() {
return m_requirements == null ? emptyEnumeration : m_requirements.getElements();
return m_requirements.getElements();
}
/**
@@ -393,7 +398,7 @@ public abstract class Command implements NamedSendable {
* in {@link CommandGroup}.
*/
protected void clearRequirements() {
m_requirements = new Set();
m_requirements.clear();
}
/**
@@ -501,7 +506,7 @@ public abstract class Command implements NamedSendable {
* @return whether or not the subsystem is required, or false if given null
*/
public synchronized boolean doesRequire(Subsystem system) {
return m_requirements != null && m_requirements.contains(system);
return m_requirements.contains(system);
}
/**
@@ -535,20 +540,6 @@ public abstract class Command implements NamedSendable {
return m_runWhenDisabled;
}
/**
* An empty enumeration given whenever there are no requirements.
*/
private static Enumeration emptyEnumeration = new Enumeration() {
public boolean hasMoreElements() {
return false;
}
public Object nextElement() {
throw new NoSuchElementException();
}
};
/**
* The string representation for a {@link Command} is by default its name.
*

View File

@@ -42,7 +42,10 @@ public class Scheduler implements NamedSendable {
* @return the {@link Scheduler}
*/
public static synchronized Scheduler getInstance() {
return instance == null ? instance = new Scheduler() : instance;
if (instance == null) {
instance = new Scheduler();
}
return instance;
}
/**

View File

@@ -34,6 +34,10 @@ class Set {
}
}
public void clear() {
m_set.clear();
}
public boolean contains(Object o) {
return m_set.contains(o);
}