8205456: Unification of iterations over arrays
authorserb
Fri, 22 Jun 2018 19:19:43 -0700
changeset 50832 e069b9e49ca7
parent 50831 59c6972e39fa
child 50833 97852c0a7a91
8205456: Unification of iterations over arrays Reviewed-by: prr
src/java.desktop/share/classes/javax/sound/midi/InvalidMidiDataException.java
src/java.desktop/share/classes/javax/sound/midi/MetaMessage.java
src/java.desktop/share/classes/javax/sound/midi/ShortMessage.java
src/java.desktop/share/classes/javax/sound/midi/SysexMessage.java
src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java
src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileWriter.java
src/java.desktop/share/classes/javax/sound/sampled/AudioFormat.java
src/java.desktop/share/classes/javax/sound/sampled/CompoundControl.java
src/java.desktop/share/classes/javax/sound/sampled/EnumControl.java
src/java.desktop/share/classes/javax/sound/sampled/LineEvent.java
src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileWriter.java
src/java.desktop/share/classes/javax/sound/sampled/spi/FormatConversionProvider.java
src/java.desktop/share/classes/javax/sound/sampled/spi/MixerProvider.java
--- a/src/java.desktop/share/classes/javax/sound/midi/InvalidMidiDataException.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/midi/InvalidMidiDataException.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 @@
      * error detail message.
      */
     public InvalidMidiDataException() {
-
         super();
     }
 
@@ -59,8 +58,7 @@
      *
      * @param  message the string to display as an error detail message
      */
-    public InvalidMidiDataException(String message) {
-
+    public InvalidMidiDataException(final String message) {
         super(message);
     }
 }
--- a/src/java.desktop/share/classes/javax/sound/midi/MetaMessage.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/midi/MetaMessage.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 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
--- a/src/java.desktop/share/classes/javax/sound/midi/ShortMessage.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/midi/ShortMessage.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 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);
     }
 
     /**
--- a/src/java.desktop/share/classes/javax/sound/midi/SysexMessage.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/midi/SysexMessage.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 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);
     }
 }
--- a/src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 @@
      * @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);
     }
 
     /**
--- a/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileWriter.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileWriter.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 @@
 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 @@
      * @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 @@
      *         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);
     }
 
     /**
--- a/src/java.desktop/share/classes/javax/sound/sampled/AudioFormat.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/sampled/AudioFormat.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 @@
      * @see Encoding#ALAW
      */
     public Encoding getEncoding() {
-
         return encoding;
     }
 
@@ -288,7 +287,6 @@
      * @see AudioSystem#NOT_SPECIFIED
      */
     public float getSampleRate() {
-
         return sampleRate;
     }
 
@@ -309,7 +307,6 @@
      * @see AudioSystem#NOT_SPECIFIED
      */
     public int getSampleSizeInBits() {
-
         return sampleSizeInBits;
     }
 
@@ -326,7 +323,6 @@
      * @see AudioSystem#NOT_SPECIFIED
      */
     public int getChannels() {
-
         return channels;
     }
 
@@ -345,7 +341,6 @@
      * @see AudioSystem#NOT_SPECIFIED
      */
     public int getFrameSize() {
-
         return frameSize;
     }
 
@@ -365,7 +360,6 @@
      * @see AudioSystem#NOT_SPECIFIED
      */
     public float getFrameRate() {
-
         return frameRate;
     }
 
@@ -378,7 +372,6 @@
      *         {@code false} if little-endian
      */
     public boolean isBigEndian() {
-
         return bigEndian;
     }
 
--- a/src/java.desktop/share/classes/javax/sound/sampled/CompoundControl.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/sampled/CompoundControl.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 @@
      * @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();
     }
 
     /**
--- a/src/java.desktop/share/classes/javax/sound/sampled/EnumControl.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/sampled/EnumControl.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 @@
      * @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 @@
          * {@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.
--- a/src/java.desktop/share/classes/javax/sound/sampled/LineEvent.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/sampled/LineEvent.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 @@
      * @return the line responsible for this event
      */
     public final Line getLine() {
-
         return (Line)getSource();
     }
 
@@ -111,7 +110,6 @@
      *         {@link Type#START}, or {@link Type#STOP})
      */
     public final Type getType() {
-
         return type;
     }
 
@@ -137,7 +135,6 @@
      * which is a reasonable definition....
      */
     public final long getFramePosition() {
-
         return position;
     }
 
--- a/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileWriter.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileWriter.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 @@
 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 @@
      *         {@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 @@
      * @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);
     }
 
     /**
--- a/src/java.desktop/share/classes/javax/sound/sampled/spi/FormatConversionProvider.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/sampled/spi/FormatConversionProvider.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 @@
      * @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 @@
      * @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 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 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);
     }
 
--- a/src/java.desktop/share/classes/javax/sound/sampled/spi/MixerProvider.java	Fri Jun 22 13:21:23 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/sampled/spi/MixerProvider.java	Fri Jun 22 19:19:43 2018 -0700
@@ -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 @@
      * @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);
     }
 
     /**