Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: use bounded wildcards for private, and static methods #5927

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private List<java.util.regex.MatchResult> processMatches(
}

private static int matchStrings(int matchNumber, Perl5Matcher matcher,
Pattern pattern, List<MatchResult> matches, int found,
Pattern pattern, List<? super MatchResult> matches, int found,
String inputString) {
PatternMatcherInput input = new PatternMatcherInput(inputString);
while (matchNumber <=0 || found != matchNumber) {
Expand All @@ -329,7 +329,7 @@ private static int matchStrings(int matchNumber, Perl5Matcher matcher,
}

private static int matchStrings(int matchNumber, java.util.regex.Pattern pattern,
List<java.util.regex.MatchResult> matches, int found,
List<? super java.util.regex.MatchResult> matches, int found,
String inputString) {
Matcher matcher = pattern.matcher(inputString);
while (matchNumber <=0 || found != matchNumber) {
Expand Down Expand Up @@ -513,7 +513,7 @@ private void initTemplate() {
* the entry number in the list
* @return MatchResult
*/
private static MatchResult getCorrectMatch(List<MatchResult> matches, int entry) {
private static MatchResult getCorrectMatch(List<? extends MatchResult> matches, int entry) {
int matchSize = matches.size();

if (matchSize <= 0 || entry > matchSize){
Expand All @@ -528,7 +528,7 @@ private static MatchResult getCorrectMatch(List<MatchResult> matches, int entry)
return matches.get(entry - 1);
}

private static java.util.regex.MatchResult getCorrectMatchJavaRegex(List<java.util.regex.MatchResult> matches, int entry) {
private static java.util.regex.MatchResult getCorrectMatchJavaRegex(List<? extends java.util.regex.MatchResult> matches, int entry) {
int matchSize = matches.size();

if (matchSize <= 0 || entry > matchSize){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void setFragment(boolean selected) {
* @throws SaxonApiException
* @throws FactoryConfigurationError
*/
private void getValuesForXPath(String query, List<String> matchStrings, int matchNumber, String responseData)
private void getValuesForXPath(String query, List<? super String> matchStrings, int matchNumber, String responseData)
throws SaxonApiException, FactoryConfigurationError {
XPathUtil.putValuesForXPathInListUsingSaxon(responseData, query, matchStrings, getFragment(), matchNumber, getNamespaces());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private Document parseResponse(String unicodeData)
*
* @throws TransformerException
*/
private void getValuesForXPath(Document d,String query, List<String> matchStrings, int matchNumber)
private void getValuesForXPath(Document d,String query, List<? super String> matchStrings, int matchNumber)
throws TransformerException {
XPathUtil.putValuesForXPathInList(d, query, matchStrings, getFragment(), matchNumber);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void expandAll(TreePath parent) {
}

@SuppressWarnings("JdkObsolete")
private static void applyToChildren(TreePath parent, Consumer<TreePath> method) {
private static void applyToChildren(TreePath parent, Consumer<? super TreePath> method) {
TreeNode node = (TreeNode) parent.getLastPathComponent();
Enumeration<?> e = node.children();
while (e.hasMoreElements()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private Object getSelectedObject() {

private static TreePath checkExpandedOrSelected(List<TreeNode> path,
Object item, Object oldSelectedObject,
Set<Object> oldExpandedObjects, Set<TreePath> newExpandedPaths,
Set<Object> oldExpandedObjects, Set<? super TreePath> newExpandedPaths,
TreePath defaultPath) {
TreePath result = defaultPath;
if (oldSelectedObject == item) {
Expand All @@ -250,7 +250,7 @@ private static TreePath checkExpandedOrSelected(List<TreeNode> path,

private static TreePath checkExpandedOrSelected(List<TreeNode> path,
Object item, Object oldSelectedObject,
Set<Object> oldExpandedObjects, Set<TreePath> newExpandedPaths,
Set<Object> oldExpandedObjects, Set<? super TreePath> newExpandedPaths,
TreePath defaultPath, DefaultMutableTreeNode extensionNode) {
TreePath result = defaultPath;
if (oldSelectedObject == item) {
Expand Down Expand Up @@ -279,7 +279,7 @@ private static Set<Object> extractExpandedObjects(final Enumeration<TreePath> ex

private TreePath addSubResults(DefaultMutableTreeNode currNode,
SampleResult res, List<TreeNode> path, Object selectedObject,
Set<Object> oldExpandedObjects, Set<TreePath> newExpandedPaths) {
Set<Object> oldExpandedObjects, Set<? super TreePath> newExpandedPaths) {
SampleResult[] subResults = res.getSubResults();

int leafIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PickleGraphiteMetricsSender extends AbstractGraphiteMetricsSender {
private List<MetricTuple> metrics = new ArrayList<>();

private SocketConnectionInfos socketConnectionInfos;
private GenericKeyedObjectPool<SocketConnectionInfos, SocketOutputStream> socketOutputStreamPool;
private GenericKeyedObjectPool<? super SocketConnectionInfos, SocketOutputStream> socketOutputStreamPool;
private String prefix;

PickleGraphiteMetricsSender() {
Expand All @@ -79,7 +79,7 @@ public void setup(String graphiteHost, int graphitePort, String prefix) {

/** Setup used for testing, or if explicit customisation is required. */
public void setup(SocketConnectionInfos socketConnectionInfos,
GenericKeyedObjectPool<SocketConnectionInfos, SocketOutputStream> socketOutputStreamPool,
GenericKeyedObjectPool<? super SocketConnectionInfos, SocketOutputStream> socketOutputStreamPool,
String prefix) {
this.socketConnectionInfos = socketConnectionInfos;
this.socketOutputStreamPool = socketOutputStreamPool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TextGraphiteMetricsSender extends AbstractGraphiteMetricsSender {
private List<MetricTuple> metrics = new ArrayList<>();

private SocketConnectionInfos socketConnectionInfos;
private GenericKeyedObjectPool<SocketConnectionInfos, SocketOutputStream> socketOutputStreamPool;
private GenericKeyedObjectPool<? super SocketConnectionInfos, SocketOutputStream> socketOutputStreamPool;
private String prefix;

TextGraphiteMetricsSender() {
Expand All @@ -63,7 +63,7 @@ public void setup(String graphiteHost, int graphitePort, String prefix) {

/** Setup used for testing, or if explicit customisation is required. */
public void setup(SocketConnectionInfos socketConnectionInfos,
GenericKeyedObjectPool<SocketConnectionInfos, SocketOutputStream> socketOutputStreamPool,
GenericKeyedObjectPool<? super SocketConnectionInfos, SocketOutputStream> socketOutputStreamPool,
String prefix) {
this.socketConnectionInfos = socketConnectionInfos;
this.socketOutputStreamPool = socketOutputStreamPool;
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/main/java/org/apache/jmeter/JMeter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ public ListenToTest(RunMode runMode, boolean remoteStop, ReportGenerator reportG
this.reportGenerator = reportGenerator;
}

public void setStartedRemoteEngines(List<JMeterEngine> engines) {
public void setStartedRemoteEngines(List<? extends JMeterEngine> engines) {
if (runMode != RunMode.REMOTE) {
throw new IllegalArgumentException("This method should only be called in RunMode.REMOTE");
}
Expand Down Expand Up @@ -1355,7 +1355,7 @@ public static boolean isNonGUI(){
return "true".equals(System.getProperty(JMeter.JMETER_NON_GUI)); //$NON-NLS-1$
}

private static void startUdpDdaemon(final List<JMeterEngine> engines) {
private static void startUdpDdaemon(final List<? extends JMeterEngine> engines) {
int port = JMeterUtils.getPropDefault("jmeterengine.nongui.port", UDP_PORT_DEFAULT); // $NON-NLS-1$
int maxPort = JMeterUtils.getPropDefault("jmeterengine.nongui.maxport", 4455); // $NON-NLS-1$
if (port > 1000){
Expand All @@ -1375,7 +1375,7 @@ public void run() {
}
}

private static void waitForSignals(final List<JMeterEngine> engines, DatagramSocket socket) {
private static void waitForSignals(final List<? extends JMeterEngine> engines, DatagramSocket socket) {
byte[] buf = new byte[80];
System.out.println("Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port "+socket.getLocalPort());//NOSONAR
DatagramPacket request = new DatagramPacket(buf, buf.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class ArgumentsPanel extends AbstractConfigGui implements ActionListener
/** Disable buttons :Detail, Add, Add from Clipboard, Delete, Up and Down*/
private final boolean disableButtons;

private final Function<String[], Argument> argCreator;
private final Function<String[], ? extends Argument> argCreator;

/** Command for adding a row to the table. */
private static final String ADD = "add"; // $NON-NLS-1$
Expand Down Expand Up @@ -250,7 +250,7 @@ public ArgumentsPanel(String label, Color bkg, boolean enableUpDown, boolean sta
* @param argCreator function to create {@link Argument}s from Strings taken from clipboard
*/
public ArgumentsPanel(String label, Color bkg, boolean enableUpDown, boolean standalone, ObjectTableModel model,
boolean disableButtons, Function<String[], Argument> argCreator) {
boolean disableButtons, Function<String[], ? extends Argument> argCreator) {
tableLabel = new JLabel(label);
this.enableUpDown = enableUpDown;
this.disableButtons = disableButtons;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private static void removeThreadGroups(List<?> elements) {
}
}

private void notifyTestListenersOfStart(SearchByClass<TestStateListener> testListeners) {
private void notifyTestListenersOfStart(SearchByClass<? extends TestStateListener> testListeners) {
for (TestStateListener tl : testListeners.getSearchResults()) {
if (tl instanceof TestBean) {
TestBeanHelper.prepare((TestElement) tl);
Expand All @@ -250,7 +250,7 @@ private void notifyTestListenersOfStart(SearchByClass<TestStateListener> testLis
}
}

private void notifyTestListenersOfEnd(SearchByClass<TestStateListener> testListeners) {
private void notifyTestListenersOfEnd(SearchByClass<? extends TestStateListener> testListeners) {
log.info("Notifying test listeners of end of test");
for (TestStateListener tl : testListeners.getSearchResults()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void replaceValues(TestElement el) throws InvalidVariableException {
setProperties(el, newProps);
}

private static void setProperties(TestElement el, Collection<JMeterProperty> newProps) {
private static void setProperties(TestElement el, Collection<? extends JMeterProperty> newProps) {
el.clear();
for (JMeterProperty jmp : newProps) {
el.setProperty(jmp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public final class GlobalUndoableEdit extends AbstractUndoableEdit {
private static final long serialVersionUID = -4964577622742131354L;
private final UndoHistoryItem item;
private final UndoHistoryItem previous;
private final Consumer<UndoHistoryItem> loader;
private final Consumer<? super UndoHistoryItem> loader;

public GlobalUndoableEdit(UndoHistoryItem item, UndoHistoryItem previous, Consumer<UndoHistoryItem> loader) {
public GlobalUndoableEdit(UndoHistoryItem item, UndoHistoryItem previous, Consumer<? super UndoHistoryItem> loader) {
this.item = item;
this.previous = previous;
this.loader = loader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void removePreActionListener(Class<?> action, ActionListener listener) {
* @param listener {@link ActionListener}
* @param actionListeners {@link Set} of {@link ActionListener}
*/
private static void removeActionListener(Class<?> action, ActionListener listener, Map<String, Set<ActionListener>> actionListeners) {
private static void removeActionListener(Class<?> action, ActionListener listener, Map<? super String, Set<ActionListener>> actionListeners) {
if (action != null) {
Set<ActionListener> set = actionListeners.get(action.getName());
if (set != null) {
Expand Down Expand Up @@ -251,7 +251,7 @@ public void addPostActionListener(Class<?> action, ActionListener listener) {
* @param listener {@link ActionListener}
* @param actionListeners {@link Set}
*/
private static void addActionListener(Class<?> action, ActionListener listener, Map<String, Set<ActionListener>> actionListeners) {
private static void addActionListener(Class<?> action, ActionListener listener, Map<? super String, Set<ActionListener>> actionListeners) {
if (action != null) {
Set<ActionListener> set = actionListeners.get(action.getName());
if (set == null) {
Expand Down Expand Up @@ -297,7 +297,7 @@ void postActionPerformed(Class<? extends Command> action, ActionEvent e) {
* @param e {@link ActionEvent}
* @param actionListeners {@link Set}
*/
private static void actionPerformed(Class<? extends Command> action, ActionEvent e, Map<String, Set<ActionListener>> actionListeners) {
private static void actionPerformed(Class<? extends Command> action, ActionEvent e, Map<String, ? extends Set<ActionListener>> actionListeners) {
if (action != null) {
Set<ActionListener> listenerSet = actionListeners.get(action.getName());
if (listenerSet != null && !listenerSet.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private static void removeRecentFile(int index) {
* @param fileLoadRecentFiles List of JMenuItem
* @return true if at least on JMenuItem is visible
*/
public static boolean hasVisibleMenuItem(List<JComponent> fileLoadRecentFiles) {
public static boolean hasVisibleMenuItem(List<? extends JComponent> fileLoadRecentFiles) {
return fileLoadRecentFiles.stream()
.anyMatch(JComponent::isVisible);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void run() {
* @param processArgs arguments to be given to ProcessBuilder
* @param mainCommand original command line split at spaces
*/
private static void processRemainingArgs(List<String> processArgs, String[] mainCommand) {
private static void processRemainingArgs(List<? super String> processArgs, String[] mainCommand) {
boolean paramValue = false;
StringBuilder partialParamValue = new StringBuilder();
for (int i = 1; i < mainCommand.length; i++) {
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/main/java/org/apache/jmeter/gui/action/Save.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private static List<File> createBackupFile(File fileToBackup) {
* @param backupFiles
* {@link List} of {@link File}
*/
private static int getHighestVersionNumber(Pattern backupPattern, List<File> backupFiles) {
private static int getHighestVersionNumber(Pattern backupPattern, List<? extends File> backupFiles) {
return backupFiles.stream().map(backupFile -> backupPattern.matcher(backupFile.getName()))
.filter(matcher -> matcher.find() && matcher.groupCount() > 0)
.mapToInt(matcher -> Integer.parseInt(matcher.group(1))).max().orElse(0);
Expand All @@ -414,7 +414,7 @@ private static int getHighestVersionNumber(Pattern backupPattern, List<File> bac
* @return list of files to be deleted based upon properties described
* {@link #createBackupFile(File)}
*/
private static List<File> backupFilesToDelete(List<File> backupFiles) {
private static List<File> backupFilesToDelete(List<? extends File> backupFiles) {
List<File> filesToDelete = new ArrayList<>();
if (BACKUP_MAX_HOURS > 0) {
filesToDelete.addAll(expiredBackupFiles(backupFiles));
Expand All @@ -434,7 +434,7 @@ private static List<File> backupFilesToDelete(List<File> backupFiles) {
* @param backupFiles {@link List} of {@link File} to filter
* @return {@link List} of {@link File} that are expired
*/
private static List<File> expiredBackupFiles(List<File> backupFiles) {
private static List<File> expiredBackupFiles(List<? extends File> backupFiles) {
if (BACKUP_MAX_HOURS > 0) {
final long expiryMillis = System.currentTimeMillis() - (1L * BACKUP_MAX_HOURS * MS_PER_HOUR);
return backupFiles.stream().filter(file -> file.lastModified() < expiryMillis).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private Pair<Integer, Set<JMeterTreeNode>> searchInTree(GuiPackage guiPackage, S
* @param expand true if we want to expand
* @param nodes Set of {@link JMeterTreeNode} to mark
*/
private static void markConcernedNodes(boolean expand, Set<JMeterTreeNode> nodes) {
private static void markConcernedNodes(boolean expand, Set<? extends JMeterTreeNode> nodes) {
GuiPackage guiInstance = GuiPackage.getInstance();
JTree jTree = guiInstance.getMainFrame().getTree();
for (JMeterTreeNode jMeterTreeNode : nodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public Map<String, Template> parseTemplateFile(File file) throws IOException, SA
* @param templates Map of {@link Template} referenced by name
* @param templateNode {@link Node} the xml template node
*/
static void parseTemplateNode(Map<String, Template> templates, Node templateNode) {
static void parseTemplateNode(Map<? super String, ? super Template> templates, Node templateNode) {
if (templateNode.getNodeType() == Node.ELEMENT_NODE) {
Template template = new Template();
Element element = (Element) templateNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void removeNodeFromParent(JMeterTreeNode node) {
}

@SuppressWarnings("JdkObsolete")
private static void traverseAndFind(Class<?> type, JMeterTreeNode node, List<JMeterTreeNode> nodeList) {
private static void traverseAndFind(Class<?> type, JMeterTreeNode node, List<? super JMeterTreeNode> nodeList) {
if (type.isInstance(node.getUserObject())) {
nodeList.add(node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ private void makeSearchMenu() {
* @param menuCreators
* @param location
*/
private static void addPluginsMenuItems(JMenu menu, Collection<MenuCreator> menuCreators, MENU_LOCATION location) {
private static void addPluginsMenuItems(JMenu menu, Collection<? extends MenuCreator> menuCreators, MENU_LOCATION location) {
for (MenuCreator menuCreator : menuCreators) {
JMenuItem[] menuItems = menuCreator.getMenuItemsAtLocation(location);
if (menuItems.length != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ private static JMeterGUIComponent getGUIComponent(
return item;
}

private static void sortMenus(Collection<List<MenuInfo>> menus) {
private static void sortMenus(Collection<? extends List<MenuInfo>> menus) {
for (List<MenuInfo> menu : menus) {
menu.sort(Comparator.comparing(MenuInfo::getLabel));
menu.sort(Comparator.comparingInt(MenuInfo::getSortOrder));
}
}

private static void separateItemsWithExplicitOrder(Collection<List<MenuInfo>> menus) {
private static void separateItemsWithExplicitOrder(Collection<? extends List<MenuInfo>> menus) {
for (List<MenuInfo> menu : menus) {
Optional<MenuInfo> firstDefaultSortItem = menu.stream()
.filter(info -> info.getSortOrder() == MenuInfo.SORT_ORDER_DEFAULT)
Expand Down Expand Up @@ -468,7 +468,7 @@ public static JMenu makeMenu(String category, String actionCommand) {
* @return the menu
*/
private static JMenu makeMenu(
Collection<MenuInfo> menuInfo, String actionCommand, String menuName) {
Collection<? extends MenuInfo> menuInfo, String actionCommand, String menuName) {

JMenu menu = new JMenu(menuName);
menuInfo.stream()
Expand Down