8205456: Unification of iterations over arrays

Reviewed-by: prr
This commit is contained in:
Sergey Bylokhov 2018-06-22 19:19:43 -07:00
parent 075d860ee6
commit 9eeb3ed886
13 changed files with 46 additions and 110 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -49,7 +49,6 @@ public class InvalidMidiDataException extends Exception {
* error detail message. * error detail message.
*/ */
public InvalidMidiDataException() { public InvalidMidiDataException() {
super(); super();
} }
@ -59,8 +58,7 @@ public class InvalidMidiDataException extends Exception {
* *
* @param message the string to display as an error detail message * @param message the string to display as an error detail message
*/ */
public InvalidMidiDataException(String message) { public InvalidMidiDataException(final String message) {
super(message); super(message);
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -199,9 +199,7 @@ public class MetaMessage extends MidiMessage {
public Object clone() { public Object clone() {
byte[] newData = new byte[length]; byte[] newData = new byte[length];
System.arraycopy(data, 0, newData, 0, newData.length); System.arraycopy(data, 0, newData, 0, newData.length);
return new MetaMessage(newData);
MetaMessage event = new MetaMessage(newData);
return event;
} }
// HELPER METHODS // HELPER METHODS

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -432,9 +432,7 @@ public class ShortMessage extends MidiMessage {
public Object clone() { public Object clone() {
byte[] newData = new byte[length]; byte[] newData = new byte[length];
System.arraycopy(data, 0, newData, 0, newData.length); System.arraycopy(data, 0, newData, 0, newData.length);
return new ShortMessage(newData);
ShortMessage msg = new ShortMessage(newData);
return msg;
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -240,7 +240,6 @@ public class SysexMessage extends MidiMessage {
public Object clone() { public Object clone() {
byte[] newData = new byte[length]; byte[] newData = new byte[length];
System.arraycopy(data, 0, newData, 0, newData.length); System.arraycopy(data, 0, newData, 0, newData.length);
SysexMessage event = new SysexMessage(newData); return new SysexMessage(newData);
return event;
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,6 @@
package javax.sound.midi.spi; package javax.sound.midi.spi;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects;
import javax.sound.midi.MidiDevice; import javax.sound.midi.MidiDevice;
@ -50,8 +49,7 @@ public abstract class MidiDeviceProvider {
* @throws NullPointerException if {@code info} is {@code null} * @throws NullPointerException if {@code info} is {@code null}
*/ */
public boolean isDeviceSupported(final MidiDevice.Info info) { public boolean isDeviceSupported(final MidiDevice.Info info) {
Objects.requireNonNull(info); return Arrays.stream(getDeviceInfo()).anyMatch(info::equals);
return Arrays.asList(getDeviceInfo()).contains(info);
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,6 +28,7 @@ package javax.sound.midi.spi;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Arrays;
import javax.sound.midi.Sequence; import javax.sound.midi.Sequence;
@ -69,15 +70,9 @@ public abstract class MidiFileWriter {
* @return {@code true} if the file type is supported, otherwise * @return {@code true} if the file type is supported, otherwise
* {@code false} * {@code false}
*/ */
public boolean isFileTypeSupported(int fileType) { public boolean isFileTypeSupported(final int fileType) {
return Arrays.stream(getMidiFileTypes())
int types[] = getMidiFileTypes(); .anyMatch(type -> fileType == type);
for(int i=0; i<types.length; i++) {
if( fileType == types[i] ) {
return true;
}
}
return false;
} }
/** /**
@ -90,15 +85,10 @@ public abstract class MidiFileWriter {
* otherwise {@code false} * otherwise {@code false}
* @throws NullPointerException if {@code sequence} is {@code null} * @throws NullPointerException if {@code sequence} is {@code null}
*/ */
public boolean isFileTypeSupported(int fileType, Sequence sequence) { public boolean isFileTypeSupported(final int fileType,
final Sequence sequence) {
int types[] = getMidiFileTypes( sequence ); return Arrays.stream(getMidiFileTypes(sequence))
for(int i=0; i<types.length; i++) { .anyMatch(type -> fileType == type);
if( fileType == types[i] ) {
return true;
}
}
return false;
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -267,7 +267,6 @@ public class AudioFormat {
* @see Encoding#ALAW * @see Encoding#ALAW
*/ */
public Encoding getEncoding() { public Encoding getEncoding() {
return encoding; return encoding;
} }
@ -288,7 +287,6 @@ public class AudioFormat {
* @see AudioSystem#NOT_SPECIFIED * @see AudioSystem#NOT_SPECIFIED
*/ */
public float getSampleRate() { public float getSampleRate() {
return sampleRate; return sampleRate;
} }
@ -309,7 +307,6 @@ public class AudioFormat {
* @see AudioSystem#NOT_SPECIFIED * @see AudioSystem#NOT_SPECIFIED
*/ */
public int getSampleSizeInBits() { public int getSampleSizeInBits() {
return sampleSizeInBits; return sampleSizeInBits;
} }
@ -326,7 +323,6 @@ public class AudioFormat {
* @see AudioSystem#NOT_SPECIFIED * @see AudioSystem#NOT_SPECIFIED
*/ */
public int getChannels() { public int getChannels() {
return channels; return channels;
} }
@ -345,7 +341,6 @@ public class AudioFormat {
* @see AudioSystem#NOT_SPECIFIED * @see AudioSystem#NOT_SPECIFIED
*/ */
public int getFrameSize() { public int getFrameSize() {
return frameSize; return frameSize;
} }
@ -365,7 +360,6 @@ public class AudioFormat {
* @see AudioSystem#NOT_SPECIFIED * @see AudioSystem#NOT_SPECIFIED
*/ */
public float getFrameRate() { public float getFrameRate() {
return frameRate; return frameRate;
} }
@ -378,7 +372,6 @@ public class AudioFormat {
* {@code false} if little-endian * {@code false} if little-endian
*/ */
public boolean isBigEndian() { public boolean isBigEndian() {
return bigEndian; return bigEndian;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -57,13 +57,7 @@ public abstract class CompoundControl extends Control {
* @return the set of member controls * @return the set of member controls
*/ */
public Control[] getMemberControls() { public Control[] getMemberControls() {
Control[] localArray = new Control[controls.length]; return controls.clone();
for (int i = 0; i < controls.length; i++) {
localArray[i] = controls[i];
}
return localArray;
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -107,14 +107,7 @@ public abstract class EnumControl extends Control {
* @return the set of possible values * @return the set of possible values
*/ */
public Object[] getValues() { public Object[] getValues() {
return values.clone();
Object[] localArray = new Object[values.length];
for (int i = 0; i < values.length; i++) {
localArray[i] = values[i];
}
return localArray;
} }
/** /**
@ -164,7 +157,7 @@ public abstract class EnumControl extends Control {
* {@link EnumControl#getValues} on an enumerated control of type * {@link EnumControl#getValues} on an enumerated control of type
* {@code REVERB}.) * {@code REVERB}.)
*/ */
public static final Type REVERB = new Type("Reverb"); public static final Type REVERB = new Type("Reverb");
/** /**
* Constructs a new enumerated control type. * Constructs a new enumerated control type.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -100,7 +100,6 @@ public class LineEvent extends EventObject {
* @return the line responsible for this event * @return the line responsible for this event
*/ */
public final Line getLine() { public final Line getLine() {
return (Line)getSource(); return (Line)getSource();
} }
@ -111,7 +110,6 @@ public class LineEvent extends EventObject {
* {@link Type#START}, or {@link Type#STOP}) * {@link Type#START}, or {@link Type#STOP})
*/ */
public final Type getType() { public final Type getType() {
return type; return type;
} }
@ -137,7 +135,6 @@ public class LineEvent extends EventObject {
* which is a reasonable definition.... * which is a reasonable definition....
*/ */
public final long getFramePosition() { public final long getFramePosition() {
return position; return position;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,7 @@ package javax.sound.sampled.spi;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Objects; import java.util.Arrays;
import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioSystem;
@ -63,17 +63,8 @@ public abstract class AudioFileWriter {
* {@code false} * {@code false}
* @throws NullPointerException if {@code fileType} is {@code null} * @throws NullPointerException if {@code fileType} is {@code null}
*/ */
public boolean isFileTypeSupported(Type fileType) { public boolean isFileTypeSupported(final Type fileType) {
Objects.requireNonNull(fileType); return Arrays.stream(getAudioFileTypes()).anyMatch(fileType::equals);
Type types[] = getAudioFileTypes();
for(int i=0; i<types.length; i++) {
if( fileType.equals( types[i] ) ) {
return true;
}
}
return false;
} }
/** /**
@ -99,16 +90,10 @@ public abstract class AudioFileWriter {
* @throws NullPointerException if {@code fileType} or {@code stream} are * @throws NullPointerException if {@code fileType} or {@code stream} are
* {@code null} * {@code null}
*/ */
public boolean isFileTypeSupported(Type fileType, AudioInputStream stream) { public boolean isFileTypeSupported(final Type fileType,
Objects.requireNonNull(fileType); final AudioInputStream stream) {
Type types[] = getAudioFileTypes( stream ); return Arrays.stream(getAudioFileTypes(stream))
.anyMatch(fileType::equals);
for(int i=0; i<types.length; i++) {
if( fileType.equals( types[i] ) ) {
return true;
}
}
return false;
} }
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
package javax.sound.sampled.spi; package javax.sound.sampled.spi;
import java.util.stream.Stream; import java.util.Arrays;
import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioInputStream;
@ -82,7 +82,8 @@ public abstract class FormatConversionProvider {
* @throws NullPointerException if {@code sourceEncoding} is {@code null} * @throws NullPointerException if {@code sourceEncoding} is {@code null}
*/ */
public boolean isSourceEncodingSupported(final Encoding sourceEncoding) { public boolean isSourceEncodingSupported(final Encoding sourceEncoding) {
return Stream.of(getSourceEncodings()).anyMatch(sourceEncoding::equals); return Arrays.stream(getSourceEncodings())
.anyMatch(sourceEncoding::equals);
} }
/** /**
@ -96,7 +97,8 @@ public abstract class FormatConversionProvider {
* @throws NullPointerException if {@code targetEncoding} is {@code null} * @throws NullPointerException if {@code targetEncoding} is {@code null}
*/ */
public boolean isTargetEncodingSupported(final Encoding targetEncoding) { public boolean isTargetEncodingSupported(final Encoding targetEncoding) {
return Stream.of(getTargetEncodings()).anyMatch(targetEncoding::equals); return Arrays.stream(getTargetEncodings())
.anyMatch(targetEncoding::equals);
} }
/** /**
@ -123,7 +125,7 @@ public abstract class FormatConversionProvider {
*/ */
public boolean isConversionSupported(final Encoding targetEncoding, public boolean isConversionSupported(final Encoding targetEncoding,
final AudioFormat sourceFormat) { final AudioFormat sourceFormat) {
return Stream.of(getTargetEncodings(sourceFormat)) return Arrays.stream(getTargetEncodings(sourceFormat))
.anyMatch(targetEncoding::equals); .anyMatch(targetEncoding::equals);
} }
@ -155,7 +157,7 @@ public abstract class FormatConversionProvider {
public boolean isConversionSupported(final AudioFormat targetFormat, public boolean isConversionSupported(final AudioFormat targetFormat,
final AudioFormat sourceFormat) { final AudioFormat sourceFormat) {
final Encoding targetEncoding = targetFormat.getEncoding(); final Encoding targetEncoding = targetFormat.getEncoding();
return Stream.of(getTargetFormats(targetEncoding, sourceFormat)) return Arrays.stream(getTargetFormats(targetEncoding, sourceFormat))
.anyMatch(targetFormat::matches); .anyMatch(targetFormat::matches);
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
package javax.sound.sampled.spi; package javax.sound.sampled.spi;
import java.util.Objects; import java.util.Arrays;
import javax.sound.sampled.Mixer; import javax.sound.sampled.Mixer;
@ -54,17 +54,8 @@ public abstract class MixerProvider {
* @throws NullPointerException if {@code info} is {@code null} * @throws NullPointerException if {@code info} is {@code null}
* @see #getMixerInfo() * @see #getMixerInfo()
*/ */
public boolean isMixerSupported(Mixer.Info info) { public boolean isMixerSupported(final Mixer.Info info) {
Objects.requireNonNull(info); return Arrays.stream(getMixerInfo()).anyMatch(info::equals);
Mixer.Info infos[] = getMixerInfo();
for(int i=0; i<infos.length; i++){
if( info.equals( infos[i] ) ) {
return true;
}
}
return false;
} }
/** /**