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

8271603: Unnecessary Vector usage in java.desktop #4680

@@ -31,8 +31,9 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serial;
import java.util.Enumeration;
import java.util.ArrayList;
import java.util.EventListener;
import java.util.Iterator;
import java.util.Vector;

import javax.accessibility.Accessible;
@@ -324,14 +325,14 @@ public void insert(MenuItem menuitem, int index) {
}

int nitems = getItemCount();
Vector<MenuItem> tempItems = new Vector<>();
ArrayList<MenuItem> tempItems = new ArrayList<>();

/* Remove the item at index, nitems-index times
storing them in a temporary vector in the
order they appear on the menu.
*/
for (int i = index ; i < nitems; i++) {
tempItems.addElement(getItem(index));
tempItems.add(getItem(index));
remove(index);
}

@@ -341,7 +342,7 @@ public void insert(MenuItem menuitem, int index) {
already in the correct order in the temp vector.
*/
for (int i = 0; i < tempItems.size() ; i++) {
add(tempItems.elementAt(i));
add(tempItems.get(i));
}
}
}
@@ -390,14 +391,14 @@ public void insertSeparator(int index) {
}

int nitems = getItemCount();
Vector<MenuItem> tempItems = new Vector<>();
ArrayList<MenuItem> tempItems = new ArrayList<>();

/* Remove the item at index, nitems-index times
storing them in a temporary vector in the
order they appear on the menu.
*/
for (int i = index ; i < nitems; i++) {
tempItems.addElement(getItem(index));
tempItems.add(getItem(index));
remove(index);
}

@@ -407,7 +408,7 @@ public void insertSeparator(int index) {
already in the correct order in the temp vector.
*/
for (int i = 0; i < tempItems.size() ; i++) {
add(tempItems.elementAt(i));
add(tempItems.get(i));
}
}
}
@@ -486,24 +487,24 @@ MenuItem getShortcutMenuItem(MenuShortcut s) {
return null;
}

synchronized Enumeration<MenuShortcut> shortcuts() {
turbanoff marked this conversation as resolved.
Show resolved Hide resolved
Vector<MenuShortcut> shortcuts = new Vector<>();
synchronized Iterator<MenuShortcut> shortcuts() {
ArrayList<MenuShortcut> shortcuts = new ArrayList<>();
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
MenuItem mi = getItem(i);
if (mi instanceof Menu) {
Enumeration<MenuShortcut> e = ((Menu)mi).shortcuts();
while (e.hasMoreElements()) {
shortcuts.addElement(e.nextElement());
Iterator<MenuShortcut> e = ((Menu)mi).shortcuts();
while (e.hasNext()) {
shortcuts.add(e.next());
}
} else {
MenuShortcut ms = mi.getShortcut();
if (ms != null) {
shortcuts.addElement(ms);
shortcuts.add(ms);
}
}
}
return shortcuts.elements();
return shortcuts.iterator();
}

void deleteShortcut(MenuShortcut s) {
@@ -33,6 +33,7 @@
import java.io.Serial;
import java.util.Enumeration;
import java.util.EventListener;
import java.util.Iterator;
import java.util.Vector;

import javax.accessibility.Accessible;
@@ -342,9 +343,9 @@ public synchronized Enumeration<MenuShortcut> shortcuts() {
Vector<MenuShortcut> shortcuts = new Vector<>();
int nmenus = getMenuCount();
for (int i = 0 ; i < nmenus ; i++) {
Enumeration<MenuShortcut> e = getMenu(i).shortcuts();
while (e.hasMoreElements()) {
shortcuts.addElement(e.nextElement());
Iterator<MenuShortcut> e = getMenu(i).shortcuts();
while (e.hasNext()) {
shortcuts.addElement(e.next());
turbanoff marked this conversation as resolved.
Show resolved Hide resolved
}
}
return shortcuts.elements();
@@ -1749,7 +1749,7 @@ boolean isModalExcluded(Dialog.ModalExclusionType exclusionType) {
}

void updateChildrenBlocking() {
Vector<Window> childHierarchy = new Vector<Window>();
ArrayList<Window> childHierarchy = new ArrayList<>();
Window[] ownedWindows = getOwnedWindows();
for (int i = 0; i < ownedWindows.length; i++) {
childHierarchy.add(ownedWindows[i]);
@@ -29,11 +29,11 @@
import java.io.Serializable;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.Vector;

/**
* Class {@code MimeType} encapsulates a Multipurpose Internet Mail Extensions
@@ -571,10 +571,9 @@ private void parse(String s) {
throw new NullPointerException();
}
LexicalAnalyzer theLexer = new LexicalAnalyzer (s);
int theLexemeType;
Vector<String> thePieces = new Vector<>();
boolean mediaTypeIsText = false;
boolean parameterNameIsCharset = false;
ArrayList<String> thePieces = new ArrayList<>();
boolean mediaTypeIsText;
boolean parameterNameIsCharset;
turbanoff marked this conversation as resolved.
Show resolved Hide resolved

// Parse media type.
if (theLexer.getLexemeType() == TOKEN_LEXEME) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -225,11 +225,10 @@ public static Mixer getMixer(final Mixer.Info info) {
*/
public static Line.Info[] getSourceLineInfo(Line.Info info) {

Vector<Line.Info> vector = new Vector<>();
ArrayList<Line.Info> list = new ArrayList<>();
Line.Info[] currentInfoArray;

Mixer mixer;
Line.Info fullInfo = null;
Mixer.Info[] infoArray = getMixerInfo();

for (int i = 0; i < infoArray.length; i++) {
@@ -238,17 +237,11 @@ public static Line.Info[] getSourceLineInfo(Line.Info info) {

currentInfoArray = mixer.getSourceLineInfo(info);
for (int j = 0; j < currentInfoArray.length; j++) {
vector.addElement(currentInfoArray[j]);
list.add(currentInfoArray[j]);
}
}

Line.Info[] returnedArray = new Line.Info[vector.size()];

for (int i = 0; i < returnedArray.length; i++) {
returnedArray[i] = vector.get(i);
}

return returnedArray;
return list.toArray(new Line.Info[0]);
turbanoff marked this conversation as resolved.
Show resolved Hide resolved
}

/**
@@ -264,11 +257,10 @@ public static Line.Info[] getSourceLineInfo(Line.Info info) {
*/
public static Line.Info[] getTargetLineInfo(Line.Info info) {

Vector<Line.Info> vector = new Vector<>();
ArrayList<Line.Info> list = new ArrayList<>();
Line.Info[] currentInfoArray;

Mixer mixer;
Line.Info fullInfo = null;
Mixer.Info[] infoArray = getMixerInfo();

for (int i = 0; i < infoArray.length; i++) {
@@ -277,17 +269,11 @@ public static Line.Info[] getTargetLineInfo(Line.Info info) {

currentInfoArray = mixer.getTargetLineInfo(info);
for (int j = 0; j < currentInfoArray.length; j++) {
vector.addElement(currentInfoArray[j]);
list.add(currentInfoArray[j]);
}
}

Line.Info[] returnedArray = new Line.Info[vector.size()];

for (int i = 0; i < returnedArray.length; i++) {
returnedArray[i] = vector.get(i);
}

return returnedArray;
return list.toArray(new Line.Info[0]);
}

/**
@@ -674,22 +660,22 @@ public static AudioFormat.Encoding[] getTargetEncodings(AudioFormat.Encoding sou
Objects.requireNonNull(sourceEncoding);

List<FormatConversionProvider> codecs = getFormatConversionProviders();
Vector<AudioFormat.Encoding> encodings = new Vector<>();
ArrayList<AudioFormat.Encoding> encodings = new ArrayList<>();

AudioFormat.Encoding[] encs = null;
AudioFormat.Encoding[] encs;

// gather from all the codecs
for(int i=0; i<codecs.size(); i++ ) {
FormatConversionProvider codec = codecs.get(i);
if( codec.isSourceEncodingSupported( sourceEncoding ) ) {
encs = codec.getTargetEncodings();
for (int j = 0; j < encs.length; j++) {
encodings.addElement( encs[j] );
encodings.add( encs[j] );
}
}
}
if (!encodings.contains(sourceEncoding)) {
encodings.addElement(sourceEncoding);
encodings.add(sourceEncoding);
}

return encodings.toArray(new AudioFormat.Encoding[encodings.size()]);