diff --git a/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java b/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java index 92af95a1c3..3ef23c3300 100644 --- a/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java +++ b/cameraserver/src/main/java/edu/wpi/first/cameraserver/CameraServer.java @@ -9,7 +9,7 @@ package edu.wpi.first.cameraserver; import java.util.ArrayList; import java.util.Arrays; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; @@ -302,10 +302,10 @@ public final class CameraServer { "PMD.NPathComplexity"}) private CameraServer() { m_defaultUsbDevice = new AtomicInteger(); - m_sources = new Hashtable<>(); - m_sinks = new Hashtable<>(); - m_fixedSources = new Hashtable<>(); - m_tables = new Hashtable<>(); + m_sources = new HashMap<>(); + m_sinks = new HashMap<>(); + m_fixedSources = new HashMap<>(); + m_tables = new HashMap<>(); m_publishTable = NetworkTableInstance.getDefault().getTable(kPublishName); m_nextPort = kBasePort; m_addresses = new String[0]; @@ -616,7 +616,9 @@ public final class CameraServer { // create a dummy CvSource CvSource source = new CvSource(name, VideoMode.PixelFormat.kMJPEG, 160, 120, 30); MjpegServer server = startAutomaticCapture(source); - m_fixedSources.put(server.getHandle(), source.getHandle()); + synchronized (this) { + m_fixedSources.put(server.getHandle(), source.getHandle()); + } return server; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java index ebc2a1934b..b25d9073cb 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Preferences.java @@ -7,7 +7,7 @@ package edu.wpi.first.wpilibj; -import java.util.Vector; +import java.util.Collection; import edu.wpi.first.hal.FRCNetComm.tResourceType; import edu.wpi.first.hal.HAL; @@ -72,12 +72,11 @@ public final class Preferences { } /** - * Gets the vector of keys. - * @return a vector of the keys + * Gets the preferences keys. + * @return a collection of the keys */ - @SuppressWarnings({"PMD.LooseCoupling", "PMD.UseArrayListInsteadOfVector"}) - public Vector getKeys() { - return new Vector<>(m_table.getKeys()); + public Collection getKeys() { + return m_table.getKeys(); } /** diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java index 653f96f7f1..d1b110ff03 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/smartdashboard/SendableChooser.java @@ -10,6 +10,7 @@ package edu.wpi.first.wpilibj.smartdashboard; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReentrantLock; @@ -55,8 +56,7 @@ public class SendableChooser extends SendableBase { /** * A map linking strings to the objects the represent. */ - @SuppressWarnings("PMD.LooseCoupling") - private final LinkedHashMap m_map = new LinkedHashMap<>(); + private final Map m_map = new LinkedHashMap<>(); private String m_defaultChoice = ""; private final int m_instance; private static final AtomicInteger s_instances = new AtomicInteger(); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java deleted file mode 100644 index f17d073d70..0000000000 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/util/SortedVector.java +++ /dev/null @@ -1,81 +0,0 @@ -/*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 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. */ -/*----------------------------------------------------------------------------*/ - -package edu.wpi.first.wpilibj.util; - -import java.util.Vector; - -/** - * A vector that is sorted. - */ -public class SortedVector extends Vector { - /** - * Interface used to determine the order to place sorted objects. - */ - public interface Comparator { - /** - * Compare the given two objects. - * - *

Should return -1, 0, or 1 if the first object is less than, equal to, or greater than the - * second, respectively. - * - * @param object1 First object to compare - * @param object2 Second object to compare - * @return -1, 0, or 1. - */ - int compare(Object object1, Object object2); - } - - private final Comparator m_comparator; - - /** - * Create a new sorted vector and use the given comparator to determine order. - * - * @param comparator The comparator to use to determine what order to place the elements in this - * vector. - */ - public SortedVector(Comparator comparator) { - m_comparator = comparator; - } - - /** - * Adds an element in the Vector, sorted from greatest to least. - * - * @param element The element to add to the Vector - */ - @Override - public synchronized void addElement(E element) { - int highBound = size(); - int lowBound = 0; - while (highBound - lowBound > 0) { - int index = (highBound + lowBound) / 2; - int result = m_comparator.compare(element, elementAt(index)); - if (result < 0) { - lowBound = index + 1; - } else if (result > 0) { - highBound = index; - } else { - lowBound = index; - highBound = index; - } - } - insertElementAt(element, lowBound); - } - - /** - * Sort the vector. - */ - @SuppressWarnings("unchecked") - public synchronized void sort() { - Object[] array = new Object[size()]; - copyInto(array); - removeAllElements(); - for (Object o : array) { - addElement((E) o); - } - } -} diff --git a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuite.java b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuite.java index b8af56d8ce..29c115c30a 100644 --- a/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuite.java +++ b/wpilibjIntegrationTests/src/main/java/edu/wpi/first/wpilibj/test/AbstractTestSuite.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */ +/* Copyright (c) 2008-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,8 +8,8 @@ package edu.wpi.first.wpilibj.test; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.List; -import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -37,7 +37,7 @@ public abstract class AbstractTestSuite { */ protected List> getAnnotatedTestClasses() { SuiteClasses annotation = getClass().getAnnotation(SuiteClasses.class); - List> classes = new Vector>(); + List> classes = new ArrayList<>(); if (annotation == null) { throw new RuntimeException(String.format("class '%s' must have a SuiteClasses annotation", getClass().getName())); @@ -77,7 +77,7 @@ public abstract class AbstractTestSuite { } protected List getMethodMatching(final String regex) { - List classMethodPairs = new Vector(); + List classMethodPairs = new ArrayList<>(); // Get all of the test classes for (Class c : getAllContainedBaseTests()) { for (Method m : c.getMethods()) { @@ -136,7 +136,7 @@ public abstract class AbstractTestSuite { * @return The list of base test classes. */ public List> getAllContainedBaseTests() { - List> runningBaseTests = new Vector>(); + List> runningBaseTests = new ArrayList<>(); return getAllContainedBaseTests(runningBaseTests); } @@ -167,7 +167,7 @@ public abstract class AbstractTestSuite { * @return The list of classes matching the regex pattern */ public List> getAllClassMatching(final String regex) { - final List> matchingClasses = new Vector>(); + final List> matchingClasses = new ArrayList<>(); return getAllClassMatching(regex, matchingClasses); } @@ -226,7 +226,7 @@ public abstract class AbstractTestSuite { * @return the list of suite and/or test classes matching the regex. */ protected List> getSuiteOrTestMatchingRegex(final String regex) { - final List> matchingClasses = new Vector>(); + final List> matchingClasses = new ArrayList<>(); return getSuiteOrTestMatchingRegex(regex, matchingClasses); } @@ -248,7 +248,7 @@ public abstract class AbstractTestSuite { * @throws RuntimeException If the @SuiteClasses annotation is missing. */ public List getAllClassName() { - List classNames = new Vector(); + List classNames = new ArrayList<>(); for (Class c : getAnnotatedTestClasses()) { classNames.add(c.getName()); }