Skip to content
Permalink
Browse files
8271603: Unnecessary Vector usage in java.desktop
Reviewed-by: prr, serb
  • Loading branch information
turbanoff authored and mrserb committed Sep 8, 2021
1 parent ea4907a commit 1513dc7afc33386106439ccb9b7b16956b3c534a
Showing 34 changed files with 240 additions and 252 deletions.
@@ -57,6 +57,7 @@
import java.io.File;
import java.net.URI;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;
@@ -1300,23 +1301,23 @@ void addItem(final File directory) {

// create File instances of each directory leading up to the top
File f = directory.getAbsoluteFile();
final Vector<File> path = new Vector<File>(10);
final ArrayList<File> path = new ArrayList<File>(10);
while (f.getParent() != null) {
path.addElement(f);
path.add(f);
f = getFileChooser().getFileSystemView().createFileObject(f.getParent());
};

// Add root file (the desktop) to the model
final File[] roots = getFileChooser().getFileSystemView().getRoots();
for (final File element : roots) {
path.addElement(element);
path.add(element);
}
fPathCount = path.size();

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

setSelectedItem(fDirectories.elementAt(0));
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
@@ -31,6 +31,7 @@
import java.awt.image.SampleModel;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
@@ -270,10 +271,10 @@ public String[] getPropertyNames(String prefix) {

prefix = prefix.toLowerCase();

Vector<String> names = new Vector<String>();
ArrayList<String> names = new ArrayList<String>();
for (int i = 0; i < propertyNames.length; i++) {
if (propertyNames[i].startsWith(prefix)) {
names.addElement(propertyNames[i]);
names.add(propertyNames[i]);
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 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
@@ -212,7 +212,7 @@ public String getFileName() {
directoryList : fileList;
Object[] files = list.getSelectedValues();
int len = files.length;
Vector<String> result = new Vector<String>(len + 1);
ArrayList<String> result = new ArrayList<String>(len + 1);

// we return all selected file names
for (int i = 0; i < len; i++) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, 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
@@ -25,6 +25,7 @@

package com.sun.media.sound;

import java.util.ArrayList;
import java.util.Vector;

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

int i;
Vector<Line.Info> vec = new Vector<>();
ArrayList<Line.Info> vec = new ArrayList<>();

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

if (info.matches(sourceLineInfo[i])) {
vec.addElement(sourceLineInfo[i]);
vec.add(sourceLineInfo[i]);
}
}

Line.Info[] returnedArray = new Line.Info[vec.size()];
for (i = 0; i < returnedArray.length; i++) {
returnedArray[i] = vec.elementAt(i);
returnedArray[i] = vec.get(i);
}

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

int i;
Vector<Line.Info> vec = new Vector<>();
ArrayList<Line.Info> vec = new ArrayList<>();

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

if (info.matches(targetLineInfo[i])) {
vec.addElement(targetLineInfo[i]);
vec.add(targetLineInfo[i]);
}
}

Line.Info[] returnedArray = new Line.Info[vec.size()];
for (i = 0; i < returnedArray.length; i++) {
returnedArray[i] = vec.elementAt(i);
returnedArray[i] = vec.get(i);
}

return returnedArray;
@@ -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
@@ -26,8 +26,8 @@
package com.sun.media.sound;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Vector;

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


Vector<AudioFormat> formats = new Vector<>();
ArrayList<AudioFormat> formats = new ArrayList<>();
AudioFormat format;

if (inputFormat.getSampleSizeInBits() == 16
@@ -216,7 +216,7 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
inputFormat.getChannels(),
inputFormat.getChannels(),
inputFormat.getSampleRate(), false);
formats.addElement(format);
formats.add(format);
}
if (inputFormat.getSampleSizeInBits() == 8
&& AudioFormat.Encoding.ALAW.equals(inputFormat.getEncoding())) {
@@ -225,18 +225,18 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
inputFormat.getChannels(),
inputFormat.getChannels() * 2,
inputFormat.getSampleRate(), false);
formats.addElement(format);
formats.add(format);
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
inputFormat.getSampleRate(), 16,
inputFormat.getChannels(),
inputFormat.getChannels() * 2,
inputFormat.getSampleRate(), true);
formats.addElement(format);
formats.add(format);
}

AudioFormat[] formatArray = new AudioFormat[formats.size()];
for (int i = 0; i < formatArray.length; i++) {
formatArray[i] = formats.elementAt(i);
formatArray[i] = formats.get(i);
}
return formatArray;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, 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
@@ -26,8 +26,8 @@
package com.sun.media.sound;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Vector;

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

AudioFormat[] formats = getOutputFormats( sourceFormat );
Vector<AudioFormat> newFormats = new Vector<>();
ArrayList<AudioFormat> newFormats = new ArrayList<>();
for(int i=0; i<formats.length; i++ ) {
if( formats[i].getEncoding().equals( targetEncoding ) ) {
newFormats.addElement( formats[i] );
newFormats.add( formats[i] );
}
}

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

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

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

Vector<AudioFormat> formats = new Vector<>();
ArrayList<AudioFormat> formats = new ArrayList<>();
AudioFormat format;

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

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

} else if ( sampleSize==16 ) {
@@ -210,23 +210,23 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
true );
formats.addElement(format);
formats.add(format);
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
inputFormat.getSampleRate(),
inputFormat.getSampleSizeInBits(),
inputFormat.getChannels(),
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
false );
formats.addElement(format);
formats.add(format);
format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
inputFormat.getSampleRate(),
inputFormat.getSampleSizeInBits(),
inputFormat.getChannels(),
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
false );
formats.addElement(format);
formats.add(format);
}

if ( AudioFormat.Encoding.PCM_UNSIGNED.equals(inputFormat.getEncoding()) && isBigEndian ) {
@@ -238,23 +238,23 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
true );
formats.addElement(format);
formats.add(format);
format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
inputFormat.getSampleRate(),
inputFormat.getSampleSizeInBits(),
inputFormat.getChannels(),
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
false );
formats.addElement(format);
formats.add(format);
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
inputFormat.getSampleRate(),
inputFormat.getSampleSizeInBits(),
inputFormat.getChannels(),
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
false );
formats.addElement(format);
formats.add(format);
}

if ( AudioFormat.Encoding.PCM_SIGNED.equals(inputFormat.getEncoding()) && !isBigEndian ) {
@@ -266,23 +266,23 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
false );
formats.addElement(format);
formats.add(format);
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
inputFormat.getSampleRate(),
inputFormat.getSampleSizeInBits(),
inputFormat.getChannels(),
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
true );
formats.addElement(format);
formats.add(format);
format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
inputFormat.getSampleRate(),
inputFormat.getSampleSizeInBits(),
inputFormat.getChannels(),
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
true );
formats.addElement(format);
formats.add(format);
}

if ( AudioFormat.Encoding.PCM_UNSIGNED.equals(inputFormat.getEncoding()) && !isBigEndian ) {
@@ -294,35 +294,30 @@ private AudioFormat[] getOutputFormats(AudioFormat inputFormat) {
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
false );
formats.addElement(format);
formats.add(format);
format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
inputFormat.getSampleRate(),
inputFormat.getSampleSizeInBits(),
inputFormat.getChannels(),
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
true );
formats.addElement(format);
formats.add(format);
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
inputFormat.getSampleRate(),
inputFormat.getSampleSizeInBits(),
inputFormat.getChannels(),
inputFormat.getFrameSize(),
inputFormat.getFrameRate(),
true );
formats.addElement(format);
formats.add(format);
}
}
AudioFormat[] formatArray;
AudioFormat[] formatArray = new AudioFormat[formats.size()];

synchronized(formats) {

formatArray = new AudioFormat[formats.size()];

for (int i = 0; i < formatArray.length; i++) {
for (int i = 0; i < formatArray.length; i++) {

formatArray[i] = formats.elementAt(i);
}
formatArray[i] = formats.get(i);
}

return formatArray;

1 comment on commit 1513dc7

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 1513dc7 Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.