mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Use generics
This commit is contained in:
committed by
Peter Johnson
parent
5d3af62c0e
commit
617ff52f18
@@ -36,14 +36,14 @@ public class CommandGroup extends Command {
|
||||
/**
|
||||
* The commands in this group (stored in entries).
|
||||
*/
|
||||
private final Vector m_commands = new Vector();
|
||||
private final Vector<Entry> m_commands = new Vector<>();
|
||||
/*
|
||||
* Intentionally package private
|
||||
*/
|
||||
/**
|
||||
* The active children in this group (stored in entries).
|
||||
*/
|
||||
final Vector m_children = new Vector();
|
||||
final Vector<Entry> m_children = new Vector<>();
|
||||
/**
|
||||
* The current command, -1 signifies that none have been run.
|
||||
*/
|
||||
@@ -239,7 +239,7 @@ public class CommandGroup extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
entry = (Entry) m_commands.elementAt(m_currentCommandIndex);
|
||||
entry = m_commands.elementAt(m_currentCommandIndex);
|
||||
cmd = null;
|
||||
|
||||
switch (entry.m_state) {
|
||||
@@ -268,7 +268,7 @@ public class CommandGroup extends Command {
|
||||
|
||||
// Run Children
|
||||
for (int i = 0; i < m_children.size(); i++) {
|
||||
entry = (Entry) m_children.elementAt(i);
|
||||
entry = m_children.elementAt(i);
|
||||
Command child = entry.m_command;
|
||||
if (entry.isTimedOut()) {
|
||||
child._cancel();
|
||||
@@ -285,7 +285,7 @@ public class CommandGroup extends Command {
|
||||
// Theoretically, we don't have to check this, but we do if teams override
|
||||
// the isFinished method
|
||||
if (m_currentCommandIndex != -1 && m_currentCommandIndex < m_commands.size()) {
|
||||
Command cmd = ((Entry) m_commands.elementAt(m_currentCommandIndex)).m_command;
|
||||
Command cmd = m_commands.elementAt(m_currentCommandIndex).m_command;
|
||||
cmd._cancel();
|
||||
cmd.removed();
|
||||
}
|
||||
@@ -346,14 +346,14 @@ public class CommandGroup extends Command {
|
||||
}
|
||||
|
||||
if (m_currentCommandIndex != -1 && m_currentCommandIndex < m_commands.size()) {
|
||||
Command cmd = ((Entry) m_commands.elementAt(m_currentCommandIndex)).m_command;
|
||||
Command cmd = m_commands.elementAt(m_currentCommandIndex).m_command;
|
||||
if (!cmd.isInterruptible()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_children.size(); i++) {
|
||||
if (!((Entry) m_children.elementAt(i)).m_command.isInterruptible()) {
|
||||
if (!m_children.elementAt(i).m_command.isInterruptible()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -363,7 +363,7 @@ public class CommandGroup extends Command {
|
||||
|
||||
private void cancelConflicts(Command command) {
|
||||
for (int i = 0; i < m_children.size(); i++) {
|
||||
Command child = ((Entry) m_children.elementAt(i)).m_command;
|
||||
Command child = m_children.elementAt(i).m_command;
|
||||
|
||||
Enumeration requirements = command.getRequirements();
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Scheduler implements NamedSendable {
|
||||
/**
|
||||
* A hashtable of active {@link Command Commands} to their {@link LinkedListElement}.
|
||||
*/
|
||||
private Hashtable m_commandTable = new Hashtable();
|
||||
private Hashtable<Command, LinkedListElement> m_commandTable = new Hashtable<>();
|
||||
/**
|
||||
* The {@link Set} of all {@link Subsystem Subsystems}.
|
||||
*/
|
||||
@@ -71,13 +71,13 @@ public class Scheduler implements NamedSendable {
|
||||
/**
|
||||
* A list of all {@link Command Commands} which need to be added.
|
||||
*/
|
||||
private Vector m_additions = new Vector();
|
||||
private Vector<Command> m_additions = new Vector<>();
|
||||
private ITable m_table;
|
||||
/**
|
||||
* A list of all {@link edu.wpi.first.wpilibj.buttons.Trigger.ButtonScheduler Buttons}. It is
|
||||
* created lazily.
|
||||
*/
|
||||
private Vector m_buttons;
|
||||
private Vector<ButtonScheduler> m_buttons;
|
||||
private boolean m_runningCommandsChanged;
|
||||
|
||||
/**
|
||||
@@ -111,7 +111,7 @@ public class Scheduler implements NamedSendable {
|
||||
*/
|
||||
public void addButton(ButtonScheduler button) {
|
||||
if (m_buttons == null) {
|
||||
m_buttons = new Vector();
|
||||
m_buttons = new Vector<>();
|
||||
}
|
||||
m_buttons.addElement(button);
|
||||
}
|
||||
@@ -195,7 +195,7 @@ public class Scheduler implements NamedSendable {
|
||||
// Get button input (going backwards preserves button priority)
|
||||
if (m_buttons != null) {
|
||||
for (int i = m_buttons.size() - 1; i >= 0; i--) {
|
||||
((ButtonScheduler) m_buttons.elementAt(i)).execute();
|
||||
m_buttons.elementAt(i).execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public class Scheduler implements NamedSendable {
|
||||
|
||||
// Add the new things
|
||||
for (int i = 0; i < m_additions.size(); i++) {
|
||||
_add((Command) m_additions.elementAt(i));
|
||||
_add(m_additions.elementAt(i));
|
||||
}
|
||||
m_additions.removeAllElements();
|
||||
|
||||
@@ -257,7 +257,7 @@ public class Scheduler implements NamedSendable {
|
||||
if (command == null || !m_commandTable.containsKey(command)) {
|
||||
return;
|
||||
}
|
||||
LinkedListElement element = (LinkedListElement) m_commandTable.get(command);
|
||||
LinkedListElement element = m_commandTable.get(command);
|
||||
m_commandTable.remove(command);
|
||||
|
||||
if (element.equals(m_lastCommand)) {
|
||||
|
||||
@@ -22,9 +22,9 @@ import edu.wpi.first.wpilibj.tables.ITable;
|
||||
*/
|
||||
public class LiveWindow {
|
||||
|
||||
private static Vector sensors = new Vector();
|
||||
private static Vector<LiveWindowSendable> sensors = new Vector<>();
|
||||
// private static Vector actuators = new Vector();
|
||||
private static Hashtable components = new Hashtable();
|
||||
private static Hashtable<LiveWindowSendable, LiveWindowComponent> components = new Hashtable<>();
|
||||
private static ITable livewindowTable;
|
||||
private static ITable statusTable;
|
||||
private static boolean liveWindowEnabled = false;
|
||||
@@ -42,7 +42,7 @@ public class LiveWindow {
|
||||
statusTable = livewindowTable.getSubTable("~STATUS~");
|
||||
for (Enumeration e = components.keys(); e.hasMoreElements(); ) {
|
||||
LiveWindowSendable component = (LiveWindowSendable) e.nextElement();
|
||||
LiveWindowComponent liveWindowComponent = (LiveWindowComponent) components.get(component);
|
||||
LiveWindowComponent liveWindowComponent = components.get(component);
|
||||
String subsystem = liveWindowComponent.getSubsystem();
|
||||
String name = liveWindowComponent.getName();
|
||||
System.out.println("Initializing table for '" + subsystem + "' '" + name + "'");
|
||||
@@ -170,7 +170,7 @@ public class LiveWindow {
|
||||
private static void updateValues() {
|
||||
// TODO: gross - needs to be sped up
|
||||
for (int i = 0; i < sensors.size(); i++) {
|
||||
LiveWindowSendable lws = (LiveWindowSendable) sensors.elementAt(i);
|
||||
LiveWindowSendable lws = sensors.elementAt(i);
|
||||
lws.updateTable();
|
||||
}
|
||||
// TODO: Add actuators?
|
||||
|
||||
@@ -15,7 +15,6 @@ import edu.wpi.first.wpilibj.HLUsageReporting;
|
||||
import edu.wpi.first.wpilibj.NamedSendable;
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTableKeyNotDefined;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
|
||||
/**
|
||||
@@ -34,7 +33,7 @@ public class SmartDashboard {
|
||||
* A table linking tables in the SmartDashboard to the {@link Sendable} objects they
|
||||
* came from.
|
||||
*/
|
||||
private static final Hashtable tablesToData = new Hashtable();
|
||||
private static final Hashtable<ITable, Sendable> tablesToData = new Hashtable<>();
|
||||
|
||||
static {
|
||||
HLUsageReporting.reportSmartDashboard();
|
||||
@@ -52,7 +51,7 @@ public class SmartDashboard {
|
||||
ITable dataTable = table.getSubTable(key);
|
||||
dataTable.putString("~TYPE~", data.getSmartDashboardType());
|
||||
data.initTable(dataTable);
|
||||
tablesToData.put(data, key);
|
||||
tablesToData.put(dataTable, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,16 +74,15 @@ public class SmartDashboard {
|
||||
*
|
||||
* @param key the key
|
||||
* @return the value
|
||||
* @throws NetworkTableKeyNotDefined if there is no value mapped to by the key
|
||||
* @throws IllegalArgumentException if the key is null
|
||||
*/
|
||||
public static Sendable getData(String key) {
|
||||
ITable subtable = table.getSubTable(key);
|
||||
Object data = tablesToData.get(subtable);
|
||||
Sendable data = tablesToData.get(subtable);
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("SmartDashboard data does not exist: " + key);
|
||||
} else {
|
||||
return (Sendable) data;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Vector;
|
||||
/**
|
||||
* A vector that is sorted.
|
||||
*/
|
||||
public class SortedVector extends Vector {
|
||||
public class SortedVector<E> extends Vector<E> {
|
||||
|
||||
/**
|
||||
* Interface used to determine the order to place sorted objects.
|
||||
@@ -49,7 +49,7 @@ public class SortedVector extends Vector {
|
||||
*
|
||||
* @param element The element to add to the Vector
|
||||
*/
|
||||
public void addElement(Object element) {
|
||||
public void addElement(E element) {
|
||||
int highBound = size();
|
||||
int lowBound = 0;
|
||||
while (highBound - lowBound > 0) {
|
||||
@@ -70,12 +70,13 @@ public class SortedVector extends Vector {
|
||||
/**
|
||||
* Sort the vector.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void sort() {
|
||||
Object[] array = new Object[size()];
|
||||
copyInto(array);
|
||||
removeAllElements();
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
addElement(array[i]);
|
||||
addElement((E) array[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user