Skip to content

Commit 1513dc7

Browse files
turbanoffmrserb
authored andcommitted
8271603: Unnecessary Vector usage in java.desktop
Reviewed-by: prr, serb
1 parent ea4907a commit 1513dc7

34 files changed

Lines changed: 240 additions & 252 deletions

src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.io.File;
5858
import java.net.URI;
5959
import java.text.DateFormat;
60+
import java.util.ArrayList;
6061
import java.util.Date;
6162
import java.util.Locale;
6263
import java.util.Objects;
@@ -1300,23 +1301,23 @@ void addItem(final File directory) {
13001301

13011302
// create File instances of each directory leading up to the top
13021303
File f = directory.getAbsoluteFile();
1303-
final Vector<File> path = new Vector<File>(10);
1304+
final ArrayList<File> path = new ArrayList<File>(10);
13041305
while (f.getParent() != null) {
1305-
path.addElement(f);
1306+
path.add(f);
13061307
f = getFileChooser().getFileSystemView().createFileObject(f.getParent());
13071308
};
13081309

13091310
// Add root file (the desktop) to the model
13101311
final File[] roots = getFileChooser().getFileSystemView().getRoots();
13111312
for (final File element : roots) {
1312-
path.addElement(element);
1313+
path.add(element);
13131314
}
13141315
fPathCount = path.size();
13151316

13161317
// insert all the path fDirectories leading up to the
13171318
// selected directory in reverse order (current directory at top)
13181319
for (int i = 0; i < path.size(); i++) {
1319-
fDirectories.addElement(path.elementAt(i));
1320+
fDirectories.addElement(path.get(i));
13201321
}
13211322

13221323
setSelectedItem(fDirectories.elementAt(0));

src/java.desktop/share/classes/com/sun/imageio/plugins/common/SimpleRenderedImage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,6 +31,7 @@
3131
import java.awt.image.SampleModel;
3232
import java.awt.image.Raster;
3333
import java.awt.image.WritableRaster;
34+
import java.util.ArrayList;
3435
import java.util.Enumeration;
3536
import java.util.Hashtable;
3637
import java.util.Iterator;
@@ -270,10 +271,10 @@ public String[] getPropertyNames(String prefix) {
270271

271272
prefix = prefix.toLowerCase();
272273

273-
Vector<String> names = new Vector<String>();
274+
ArrayList<String> names = new ArrayList<String>();
274275
for (int i = 0; i < propertyNames.length; i++) {
275276
if (propertyNames[i].startsWith(prefix)) {
276-
names.addElement(propertyNames[i]);
277+
names.add(propertyNames[i]);
277278
}
278279
}
279280

src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -212,7 +212,7 @@ public String getFileName() {
212212
directoryList : fileList;
213213
Object[] files = list.getSelectedValues();
214214
int len = files.length;
215-
Vector<String> result = new Vector<String>(len + 1);
215+
ArrayList<String> result = new ArrayList<String>(len + 1);
216216

217217
// we return all selected file names
218218
for (int i = 0; i < len; i++) {

src/java.desktop/share/classes/com/sun/media/sound/AbstractMixer.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525

2626
package com.sun.media.sound;
2727

28+
import java.util.ArrayList;
2829
import java.util.Vector;
2930

3031
import javax.sound.sampled.Control;
@@ -138,18 +139,18 @@ public final Line.Info[] getTargetLineInfo() {
138139
public final Line.Info[] getSourceLineInfo(Line.Info info) {
139140

140141
int i;
141-
Vector<Line.Info> vec = new Vector<>();
142+
ArrayList<Line.Info> vec = new ArrayList<>();
142143

143144
for (i = 0; i < sourceLineInfo.length; i++) {
144145

145146
if (info.matches(sourceLineInfo[i])) {
146-
vec.addElement(sourceLineInfo[i]);
147+
vec.add(sourceLineInfo[i]);
147148
}
148149
}
149150

150151
Line.Info[] returnedArray = new Line.Info[vec.size()];
151152
for (i = 0; i < returnedArray.length; i++) {
152-
returnedArray[i] = vec.elementAt(i);
153+
returnedArray[i] = vec.get(i);
153154
}
154155

155156
return returnedArray;
@@ -159,18 +160,18 @@ public final Line.Info[] getSourceLineInfo(Line.Info info) {
159160
public final Line.Info[] getTargetLineInfo(Line.Info info) {
160161

161162
int i;
162-
Vector<Line.Info> vec = new Vector<>();
163+
ArrayList<Line.Info> vec = new ArrayList<>();
163164

164165
for (i = 0; i < targetLineInfo.length; i++) {
165166

166167
if (info.matches(targetLineInfo[i])) {
167-
vec.addElement(targetLineInfo[i]);
168+
vec.add(targetLineInfo[i]);
168169
}
169170
}
170171

171172
Line.Info[] returnedArray = new Line.Info[vec.size()];
172173
for (i = 0; i < returnedArray.length; i++) {
173-
returnedArray[i] = vec.elementAt(i);
174+
returnedArray[i] = vec.get(i);
174175
}
175176

176177
return returnedArray;

src/java.desktop/share/classes/com/sun/media/sound/AlawCodec.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,8 @@
2626
package com.sun.media.sound;
2727

2828
import java.io.IOException;
29+
import java.util.ArrayList;
2930
import java.util.Objects;
30-
import java.util.Vector;
3131

3232
import javax.sound.sampled.AudioFormat;
3333
import javax.sound.sampled.AudioFormat.Encoding;
@@ -206,7 +206,7 @@ private AudioInputStream getConvertedStream(AudioFormat outputFormat, AudioInput
206206
private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
207207

208208

209-
Vector<AudioFormat> formats = new Vector<>();
209+
ArrayList<AudioFormat> formats = new ArrayList<>();
210210
AudioFormat format;
211211

212212
if (inputFormat.getSampleSizeInBits() == 16
@@ -216,7 +216,7 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
216216
inputFormat.getChannels(),
217217
inputFormat.getChannels(),
218218
inputFormat.getSampleRate(), false);
219-
formats.addElement(format);
219+
formats.add(format);
220220
}
221221
if (inputFormat.getSampleSizeInBits() == 8
222222
&& AudioFormat.Encoding.ALAW.equals(inputFormat.getEncoding())) {
@@ -225,18 +225,18 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
225225
inputFormat.getChannels(),
226226
inputFormat.getChannels() * 2,
227227
inputFormat.getSampleRate(), false);
228-
formats.addElement(format);
228+
formats.add(format);
229229
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
230230
inputFormat.getSampleRate(), 16,
231231
inputFormat.getChannels(),
232232
inputFormat.getChannels() * 2,
233233
inputFormat.getSampleRate(), true);
234-
formats.addElement(format);
234+
formats.add(format);
235235
}
236236

237237
AudioFormat[] formatArray = new AudioFormat[formats.size()];
238238
for (int i = 0; i < formatArray.length; i++) {
239-
formatArray[i] = formats.elementAt(i);
239+
formatArray[i] = formats.get(i);
240240
}
241241
return formatArray;
242242
}

src/java.desktop/share/classes/com/sun/media/sound/PCMtoPCMCodec.java

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,8 @@
2626
package com.sun.media.sound;
2727

2828
import java.io.IOException;
29+
import java.util.ArrayList;
2930
import java.util.Objects;
30-
import java.util.Vector;
3131

3232
import javax.sound.sampled.AudioFormat;
3333
import javax.sound.sampled.AudioFormat.Encoding;
@@ -87,17 +87,17 @@ public AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, Audio
8787
// filter out targetEncoding from the old getOutputFormats( sourceFormat ) method
8888

8989
AudioFormat[] formats = getOutputFormats( sourceFormat );
90-
Vector<AudioFormat> newFormats = new Vector<>();
90+
ArrayList<AudioFormat> newFormats = new ArrayList<>();
9191
for(int i=0; i<formats.length; i++ ) {
9292
if( formats[i].getEncoding().equals( targetEncoding ) ) {
93-
newFormats.addElement( formats[i] );
93+
newFormats.add( formats[i] );
9494
}
9595
}
9696

9797
AudioFormat[] formatArray = new AudioFormat[newFormats.size()];
9898

9999
for (int i = 0; i < formatArray.length; i++) {
100-
formatArray[i] = newFormats.elementAt(i);
100+
formatArray[i] = newFormats.get(i);
101101
}
102102

103103
return formatArray;
@@ -167,7 +167,7 @@ private AudioInputStream getConvertedStream(AudioFormat outputFormat, AudioInput
167167
*/
168168
private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
169169

170-
Vector<AudioFormat> formats = new Vector<>();
170+
ArrayList<AudioFormat> formats = new ArrayList<>();
171171
AudioFormat format;
172172

173173
int sampleSize = inputFormat.getSampleSizeInBits();
@@ -184,7 +184,7 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
184184
inputFormat.getFrameSize(),
185185
inputFormat.getFrameRate(),
186186
false );
187-
formats.addElement(format);
187+
formats.add(format);
188188
}
189189

190190
if ( AudioFormat.Encoding.PCM_UNSIGNED.equals(inputFormat.getEncoding()) ) {
@@ -196,7 +196,7 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
196196
inputFormat.getFrameSize(),
197197
inputFormat.getFrameRate(),
198198
false );
199-
formats.addElement(format);
199+
formats.add(format);
200200
}
201201

202202
} else if ( sampleSize==16 ) {
@@ -210,23 +210,23 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
210210
inputFormat.getFrameSize(),
211211
inputFormat.getFrameRate(),
212212
true );
213-
formats.addElement(format);
213+
formats.add(format);
214214
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
215215
inputFormat.getSampleRate(),
216216
inputFormat.getSampleSizeInBits(),
217217
inputFormat.getChannels(),
218218
inputFormat.getFrameSize(),
219219
inputFormat.getFrameRate(),
220220
false );
221-
formats.addElement(format);
221+
formats.add(format);
222222
format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
223223
inputFormat.getSampleRate(),
224224
inputFormat.getSampleSizeInBits(),
225225
inputFormat.getChannels(),
226226
inputFormat.getFrameSize(),
227227
inputFormat.getFrameRate(),
228228
false );
229-
formats.addElement(format);
229+
formats.add(format);
230230
}
231231

232232
if ( AudioFormat.Encoding.PCM_UNSIGNED.equals(inputFormat.getEncoding()) && isBigEndian ) {
@@ -238,23 +238,23 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
238238
inputFormat.getFrameSize(),
239239
inputFormat.getFrameRate(),
240240
true );
241-
formats.addElement(format);
241+
formats.add(format);
242242
format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
243243
inputFormat.getSampleRate(),
244244
inputFormat.getSampleSizeInBits(),
245245
inputFormat.getChannels(),
246246
inputFormat.getFrameSize(),
247247
inputFormat.getFrameRate(),
248248
false );
249-
formats.addElement(format);
249+
formats.add(format);
250250
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
251251
inputFormat.getSampleRate(),
252252
inputFormat.getSampleSizeInBits(),
253253
inputFormat.getChannels(),
254254
inputFormat.getFrameSize(),
255255
inputFormat.getFrameRate(),
256256
false );
257-
formats.addElement(format);
257+
formats.add(format);
258258
}
259259

260260
if ( AudioFormat.Encoding.PCM_SIGNED.equals(inputFormat.getEncoding()) && !isBigEndian ) {
@@ -266,23 +266,23 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
266266
inputFormat.getFrameSize(),
267267
inputFormat.getFrameRate(),
268268
false );
269-
formats.addElement(format);
269+
formats.add(format);
270270
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
271271
inputFormat.getSampleRate(),
272272
inputFormat.getSampleSizeInBits(),
273273
inputFormat.getChannels(),
274274
inputFormat.getFrameSize(),
275275
inputFormat.getFrameRate(),
276276
true );
277-
formats.addElement(format);
277+
formats.add(format);
278278
format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
279279
inputFormat.getSampleRate(),
280280
inputFormat.getSampleSizeInBits(),
281281
inputFormat.getChannels(),
282282
inputFormat.getFrameSize(),
283283
inputFormat.getFrameRate(),
284284
true );
285-
formats.addElement(format);
285+
formats.add(format);
286286
}
287287

288288
if ( AudioFormat.Encoding.PCM_UNSIGNED.equals(inputFormat.getEncoding()) && !isBigEndian ) {
@@ -294,35 +294,30 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
294294
inputFormat.getFrameSize(),
295295
inputFormat.getFrameRate(),
296296
false );
297-
formats.addElement(format);
297+
formats.add(format);
298298
format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
299299
inputFormat.getSampleRate(),
300300
inputFormat.getSampleSizeInBits(),
301301
inputFormat.getChannels(),
302302
inputFormat.getFrameSize(),
303303
inputFormat.getFrameRate(),
304304
true );
305-
formats.addElement(format);
305+
formats.add(format);
306306
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
307307
inputFormat.getSampleRate(),
308308
inputFormat.getSampleSizeInBits(),
309309
inputFormat.getChannels(),
310310
inputFormat.getFrameSize(),
311311
inputFormat.getFrameRate(),
312312
true );
313-
formats.addElement(format);
313+
formats.add(format);
314314
}
315315
}
316-
AudioFormat[] formatArray;
316+
AudioFormat[] formatArray = new AudioFormat[formats.size()];
317317

318-
synchronized(formats) {
319-
320-
formatArray = new AudioFormat[formats.size()];
321-
322-
for (int i = 0; i < formatArray.length; i++) {
318+
for (int i = 0; i < formatArray.length; i++) {
323319

324-
formatArray[i] = formats.elementAt(i);
325-
}
320+
formatArray[i] = formats.get(i);
326321
}
327322

328323
return formatArray;

0 commit comments

Comments
 (0)