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.
*
* 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.
*/
public InvalidMidiDataException() {
super();
}
@ -59,8 +58,7 @@ public class InvalidMidiDataException extends Exception {
*
* @param message the string to display as an error detail message
*/
public InvalidMidiDataException(String message) {
public InvalidMidiDataException(final String 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.
*
* 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() {
byte[] newData = new byte[length];
System.arraycopy(data, 0, newData, 0, newData.length);
MetaMessage event = new MetaMessage(newData);
return event;
return new MetaMessage(newData);
}
// 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.
*
* 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() {
byte[] newData = new byte[length];
System.arraycopy(data, 0, newData, 0, newData.length);
ShortMessage msg = new ShortMessage(newData);
return msg;
return new ShortMessage(newData);
}
/**

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.
*
* 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() {
byte[] newData = new byte[length];
System.arraycopy(data, 0, newData, 0, newData.length);
SysexMessage event = new SysexMessage(newData);
return event;
return new SysexMessage(newData);
}
}

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.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,6 @@
package javax.sound.midi.spi;
import java.util.Arrays;
import java.util.Objects;
import javax.sound.midi.MidiDevice;
@ -50,8 +49,7 @@ public abstract class MidiDeviceProvider {
* @throws NullPointerException if {@code info} is {@code null}
*/
public boolean isDeviceSupported(final MidiDevice.Info info) {
Objects.requireNonNull(info);
return Arrays.asList(getDeviceInfo()).contains(info);
return Arrays.stream(getDeviceInfo()).anyMatch(info::equals);
}
/**

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.
*
* 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.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import javax.sound.midi.Sequence;
@ -69,15 +70,9 @@ public abstract class MidiFileWriter {
* @return {@code true} if the file type is supported, otherwise
* {@code false}
*/
public boolean isFileTypeSupported(int fileType) {
int types[] = getMidiFileTypes();
for(int i=0; i<types.length; i++) {
if( fileType == types[i] ) {
return true;
}
}
return false;
public boolean isFileTypeSupported(final int fileType) {
return Arrays.stream(getMidiFileTypes())
.anyMatch(type -> fileType == type);
}
/**
@ -90,15 +85,10 @@ public abstract class MidiFileWriter {
* otherwise {@code false}
* @throws NullPointerException if {@code sequence} is {@code null}
*/
public boolean isFileTypeSupported(int fileType, Sequence sequence) {
int types[] = getMidiFileTypes( sequence );
for(int i=0; i<types.length; i++) {
if( fileType == types[i] ) {
return true;
}
}
return false;
public boolean isFileTypeSupported(final int fileType,
final Sequence sequence) {
return Arrays.stream(getMidiFileTypes(sequence))
.anyMatch(type -> fileType == 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -267,7 +267,6 @@ public class AudioFormat {
* @see Encoding#ALAW
*/
public Encoding getEncoding() {
return encoding;
}
@ -288,7 +287,6 @@ public class AudioFormat {
* @see AudioSystem#NOT_SPECIFIED
*/
public float getSampleRate() {
return sampleRate;
}
@ -309,7 +307,6 @@ public class AudioFormat {
* @see AudioSystem#NOT_SPECIFIED
*/
public int getSampleSizeInBits() {
return sampleSizeInBits;
}
@ -326,7 +323,6 @@ public class AudioFormat {
* @see AudioSystem#NOT_SPECIFIED
*/
public int getChannels() {
return channels;
}
@ -345,7 +341,6 @@ public class AudioFormat {
* @see AudioSystem#NOT_SPECIFIED
*/
public int getFrameSize() {
return frameSize;
}
@ -365,7 +360,6 @@ public class AudioFormat {
* @see AudioSystem#NOT_SPECIFIED
*/
public float getFrameRate() {
return frameRate;
}
@ -378,7 +372,6 @@ public class AudioFormat {
* {@code false} if little-endian
*/
public boolean isBigEndian() {
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.
*
* 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
*/
public Control[] getMemberControls() {
Control[] localArray = new Control[controls.length];
for (int i = 0; i < controls.length; i++) {
localArray[i] = controls[i];
}
return localArray;
return controls.clone();
}
/**

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.
*
* 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
*/
public Object[] getValues() {
Object[] localArray = new Object[values.length];
for (int i = 0; i < values.length; i++) {
localArray[i] = values[i];
}
return localArray;
return values.clone();
}
/**
@ -164,7 +157,7 @@ public abstract class EnumControl extends Control {
* {@link EnumControl#getValues} on an enumerated control of type
* {@code REVERB}.)
*/
public static final Type REVERB = new Type("Reverb");
public static final Type REVERB = new Type("Reverb");
/**
* 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.
*
* 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
*/
public final Line getLine() {
return (Line)getSource();
}
@ -111,7 +110,6 @@ public class LineEvent extends EventObject {
* {@link Type#START}, or {@link Type#STOP})
*/
public final Type getType() {
return type;
}
@ -137,7 +135,6 @@ public class LineEvent extends EventObject {
* which is a reasonable definition....
*/
public final long getFramePosition() {
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.
*
* 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.IOException;
import java.io.OutputStream;
import java.util.Objects;
import java.util.Arrays;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
@ -63,17 +63,8 @@ public abstract class AudioFileWriter {
* {@code false}
* @throws NullPointerException if {@code fileType} is {@code null}
*/
public boolean isFileTypeSupported(Type fileType) {
Objects.requireNonNull(fileType);
Type types[] = getAudioFileTypes();
for(int i=0; i<types.length; i++) {
if( fileType.equals( types[i] ) ) {
return true;
}
}
return false;
public boolean isFileTypeSupported(final Type fileType) {
return Arrays.stream(getAudioFileTypes()).anyMatch(fileType::equals);
}
/**
@ -99,16 +90,10 @@ public abstract class AudioFileWriter {
* @throws NullPointerException if {@code fileType} or {@code stream} are
* {@code null}
*/
public boolean isFileTypeSupported(Type fileType, AudioInputStream stream) {
Objects.requireNonNull(fileType);
Type types[] = getAudioFileTypes( stream );
for(int i=0; i<types.length; i++) {
if( fileType.equals( types[i] ) ) {
return true;
}
}
return false;
public boolean isFileTypeSupported(final Type fileType,
final AudioInputStream stream) {
return Arrays.stream(getAudioFileTypes(stream))
.anyMatch(fileType::equals);
}
/**

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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
package javax.sound.sampled.spi;
import java.util.stream.Stream;
import java.util.Arrays;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
@ -82,7 +82,8 @@ public abstract class FormatConversionProvider {
* @throws NullPointerException if {@code sourceEncoding} is {@code null}
*/
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}
*/
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,
final AudioFormat sourceFormat) {
return Stream.of(getTargetEncodings(sourceFormat))
return Arrays.stream(getTargetEncodings(sourceFormat))
.anyMatch(targetEncoding::equals);
}
@ -155,7 +157,7 @@ public abstract class FormatConversionProvider {
public boolean isConversionSupported(final AudioFormat targetFormat,
final AudioFormat sourceFormat) {
final Encoding targetEncoding = targetFormat.getEncoding();
return Stream.of(getTargetFormats(targetEncoding, sourceFormat))
return Arrays.stream(getTargetFormats(targetEncoding, sourceFormat))
.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.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,7 @@
package javax.sound.sampled.spi;
import java.util.Objects;
import java.util.Arrays;
import javax.sound.sampled.Mixer;
@ -54,17 +54,8 @@ public abstract class MixerProvider {
* @throws NullPointerException if {@code info} is {@code null}
* @see #getMixerInfo()
*/
public boolean isMixerSupported(Mixer.Info info) {
Objects.requireNonNull(info);
Mixer.Info infos[] = getMixerInfo();
for(int i=0; i<infos.length; i++){
if( info.equals( infos[i] ) ) {
return true;
}
}
return false;
public boolean isMixerSupported(final Mixer.Info info) {
return Arrays.stream(getMixerInfo()).anyMatch(info::equals);
}
/**