mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Replace outdated Java collections (#508)
This commit is contained in:
committed by
Peter Johnson
parent
8993ce5bf1
commit
4b2b21d247
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user