mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
Replace outdated Java collections (#508)
This commit is contained in:
committed by
Peter Johnson
parent
8993ce5bf1
commit
4b2b21d247
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<String> getKeys() {
|
||||
return new Vector<>(m_table.getKeys());
|
||||
public Collection<String> getKeys() {
|
||||
return m_table.getKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<V> extends SendableBase {
|
||||
/**
|
||||
* A map linking strings to the objects the represent.
|
||||
*/
|
||||
@SuppressWarnings("PMD.LooseCoupling")
|
||||
private final LinkedHashMap<String, V> m_map = new LinkedHashMap<>();
|
||||
private final Map<String, V> m_map = new LinkedHashMap<>();
|
||||
private String m_defaultChoice = "";
|
||||
private final int m_instance;
|
||||
private static final AtomicInteger s_instances = new AtomicInteger();
|
||||
|
||||
@@ -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<E> extends Vector<E> {
|
||||
/**
|
||||
* Interface used to determine the order to place sorted objects.
|
||||
*/
|
||||
public interface Comparator {
|
||||
/**
|
||||
* Compare the given two objects.
|
||||
*
|
||||
* <p>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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Class<?>> getAnnotatedTestClasses() {
|
||||
SuiteClasses annotation = getClass().getAnnotation(SuiteClasses.class);
|
||||
List<Class<?>> classes = new Vector<Class<?>>();
|
||||
List<Class<?>> 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<ClassMethodPair> getMethodMatching(final String regex) {
|
||||
List<ClassMethodPair> classMethodPairs = new Vector<ClassMethodPair>();
|
||||
List<ClassMethodPair> 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<Class<?>> getAllContainedBaseTests() {
|
||||
List<Class<?>> runningBaseTests = new Vector<Class<?>>();
|
||||
List<Class<?>> 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<Class<?>> getAllClassMatching(final String regex) {
|
||||
final List<Class<?>> matchingClasses = new Vector<Class<?>>();
|
||||
final List<Class<?>> 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<Class<?>> getSuiteOrTestMatchingRegex(final String regex) {
|
||||
final List<Class<?>> matchingClasses = new Vector<Class<?>>();
|
||||
final List<Class<?>> matchingClasses = new ArrayList<>();
|
||||
return getSuiteOrTestMatchingRegex(regex, matchingClasses);
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ public abstract class AbstractTestSuite {
|
||||
* @throws RuntimeException If the <code>@SuiteClasses</code> annotation is missing.
|
||||
*/
|
||||
public List<String> getAllClassName() {
|
||||
List<String> classNames = new Vector<String>();
|
||||
List<String> classNames = new ArrayList<>();
|
||||
for (Class<?> c : getAnnotatedTestClasses()) {
|
||||
classNames.add(c.getName());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user