jdk/src/share/classes/java/util/Arrays.java
changeset 16929 c984ae5655cb
parent 14925 72729557c226
child 17195 e897ad52979e
equal deleted inserted replaced
16928:2fa9b0fd9dd6 16929:c984ae5655cb
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
  3515         }
  3515         }
  3516 
  3516 
  3517         @Override
  3517         @Override
  3518         public boolean contains(Object o) {
  3518         public boolean contains(Object o) {
  3519             return indexOf(o) != -1;
  3519             return indexOf(o) != -1;
       
  3520         }
       
  3521 
       
  3522         @Override
       
  3523         public Spliterator<E> spliterator() {
       
  3524             return Spliterators.spliterator(a, Spliterator.ORDERED);
  3520         }
  3525         }
  3521     }
  3526     }
  3522 
  3527 
  3523     /**
  3528     /**
  3524      * Returns a hash code based on the contents of the specified array.
  3529      * Returns a hash code based on the contents of the specified array.
  4298             buf.append(", ");
  4303             buf.append(", ");
  4299         }
  4304         }
  4300         buf.append(']');
  4305         buf.append(']');
  4301         dejaVu.remove(a);
  4306         dejaVu.remove(a);
  4302     }
  4307     }
       
  4308 
       
  4309     /**
       
  4310      * Creates a {@link Spliterator} covering all of the specified array.
       
  4311      *
       
  4312      * <p>The spliterator reports {@link Spliterator#SIZED},
       
  4313      * {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
       
  4314      * {@link Spliterator#IMMUTABLE}.
       
  4315      *
       
  4316      * @param <T> Type of elements
       
  4317      * @param array The array, assumed to be unmodified during use
       
  4318      * @return A spliterator from the array
       
  4319      * @throws NullPointerException if the specified array is {@code null}
       
  4320      * @since 1.8
       
  4321      */
       
  4322     public static <T> Spliterator<T> spliterator(T[] array) {
       
  4323         return Spliterators.spliterator(array,
       
  4324                                         Spliterator.ORDERED | Spliterator.IMMUTABLE);
       
  4325     }
       
  4326 
       
  4327     /**
       
  4328      * Creates a {@link Spliterator} covering the specified range of the
       
  4329      * specified array.
       
  4330      *
       
  4331      * <p>The spliterator reports {@link Spliterator#SIZED},
       
  4332      * {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
       
  4333      * {@link Spliterator#IMMUTABLE}.
       
  4334      *
       
  4335      * @param <T> Type of elements
       
  4336      * @param array The array, assumed to be unmodified during use
       
  4337      * @param fromIndex The least index (inclusive) to cover
       
  4338      * @param toIndex One past the greatest index to cover
       
  4339      * @return A spliterator from the array
       
  4340      * @throws NullPointerException if the specified array is {@code null}
       
  4341      * @throws ArrayIndexOutOfBoundsException if {@code fromIndex} is negative,
       
  4342      *         {@code toIndex} is less than {@code fromIndex}, or
       
  4343      *         {@code toIndex} is greater than the array size
       
  4344      * @since 1.8
       
  4345      */
       
  4346     public static <T> Spliterator<T> spliterator(T[] array, int fromIndex, int toIndex) {
       
  4347         return Spliterators.spliterator(array, fromIndex, toIndex,
       
  4348                                         Spliterator.ORDERED | Spliterator.IMMUTABLE);
       
  4349     }
       
  4350 
       
  4351     /**
       
  4352      * Creates a {@link Spliterator.OfInt} covering all of the specified array.
       
  4353      *
       
  4354      * <p>The spliterator reports {@link Spliterator#SIZED},
       
  4355      * {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
       
  4356      * {@link Spliterator#IMMUTABLE}.
       
  4357      *
       
  4358      * @param array The array, assumed to be unmodified during use
       
  4359      * @return A spliterator from the array
       
  4360      * @throws NullPointerException if the specified array is {@code null}
       
  4361      * @since 1.8
       
  4362      */
       
  4363     public static Spliterator.OfInt spliterator(int[] array) {
       
  4364         return Spliterators.spliterator(array,
       
  4365                                         Spliterator.ORDERED | Spliterator.IMMUTABLE);
       
  4366     }
       
  4367 
       
  4368     /**
       
  4369      * Creates a {@link Spliterator.OfInt} covering the specified range of the
       
  4370      * specified array.
       
  4371      *
       
  4372      * <p>The spliterator reports {@link Spliterator#SIZED},
       
  4373      * {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
       
  4374      * {@link Spliterator#IMMUTABLE}.
       
  4375      *
       
  4376      * @param array The array, assumed to be unmodified during use
       
  4377      * @param fromIndex The least index (inclusive) to cover
       
  4378      * @param toIndex One past the greatest index to cover
       
  4379      * @return A spliterator from the array
       
  4380      * @throws NullPointerException if the specified array is {@code null}
       
  4381      * @throws ArrayIndexOutOfBoundsException if {@code fromIndex} is negative,
       
  4382      *         {@code toIndex} is less than {@code fromIndex}, or
       
  4383      *         {@code toIndex} is greater than the array size
       
  4384      * @since 1.8
       
  4385      */
       
  4386     public static Spliterator.OfInt spliterator(int[] array, int fromIndex, int toIndex) {
       
  4387         return Spliterators.spliterator(array, fromIndex, toIndex,
       
  4388                                         Spliterator.ORDERED | Spliterator.IMMUTABLE);
       
  4389     }
       
  4390 
       
  4391     /**
       
  4392      * Creates a {@link Spliterator.OfLong} covering all of the specified array.
       
  4393      *
       
  4394      * <p>The spliterator reports {@link Spliterator#SIZED},
       
  4395      * {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
       
  4396      * {@link Spliterator#IMMUTABLE}.
       
  4397      *
       
  4398      * @param array The array, assumed to be unmodified during use
       
  4399      * @return A spliterator from the array
       
  4400      * @throws NullPointerException if the specified array is {@code null}
       
  4401      * @since 1.8
       
  4402      */
       
  4403     public static Spliterator.OfLong spliterator(long[] array) {
       
  4404         return Spliterators.spliterator(array,
       
  4405                                         Spliterator.ORDERED | Spliterator.IMMUTABLE);
       
  4406     }
       
  4407 
       
  4408     /**
       
  4409      * Creates a {@link Spliterator.OfLong} covering the specified range of the
       
  4410      * specified array.
       
  4411      *
       
  4412      * <p>The spliterator reports {@link Spliterator#SIZED},
       
  4413      * {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
       
  4414      * {@link Spliterator#IMMUTABLE}.
       
  4415      *
       
  4416      * @param array The array, assumed to be unmodified during use
       
  4417      * @param fromIndex The least index (inclusive) to cover
       
  4418      * @param toIndex One past the greatest index to cover
       
  4419      * @return A spliterator from the array
       
  4420      * @throws NullPointerException if the specified array is {@code null}
       
  4421      * @throws ArrayIndexOutOfBoundsException if {@code fromIndex} is negative,
       
  4422      *         {@code toIndex} is less than {@code fromIndex}, or
       
  4423      *         {@code toIndex} is greater than the array size
       
  4424      * @since 1.8
       
  4425      */
       
  4426     public static Spliterator.OfLong spliterator(long[] array, int fromIndex, int toIndex) {
       
  4427         return Spliterators.spliterator(array, fromIndex, toIndex,
       
  4428                                         Spliterator.ORDERED | Spliterator.IMMUTABLE);
       
  4429     }
       
  4430 
       
  4431     /**
       
  4432      * Creates a {@link Spliterator.OfDouble} covering all of the specified
       
  4433      * array.
       
  4434      *
       
  4435      * <p>The spliterator reports {@link Spliterator#SIZED},
       
  4436      * {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
       
  4437      * {@link Spliterator#IMMUTABLE}.
       
  4438      *
       
  4439      * @param array The array, assumed to be unmodified during use
       
  4440      * @return A spliterator from the array
       
  4441      * @throws NullPointerException if the specified array is {@code null}
       
  4442      * @since 1.8
       
  4443      */
       
  4444     public static Spliterator.OfDouble spliterator(double[] array) {
       
  4445         return Spliterators.spliterator(array,
       
  4446                                         Spliterator.ORDERED | Spliterator.IMMUTABLE);
       
  4447     }
       
  4448 
       
  4449     /**
       
  4450      * Creates a {@link Spliterator.OfDouble} covering the specified range of
       
  4451      * the specified array.
       
  4452      *
       
  4453      * <p>The spliterator reports {@link Spliterator#SIZED},
       
  4454      * {@link Spliterator#SUBSIZED}, {@link Spliterator#ORDERED}, and
       
  4455      * {@link Spliterator#IMMUTABLE}.
       
  4456      *
       
  4457      * @param array The array, assumed to be unmodified during use
       
  4458      * @param fromIndex The least index (inclusive) to cover
       
  4459      * @param toIndex One past the greatest index to cover
       
  4460      * @return A spliterator from the array
       
  4461      * @throws NullPointerException if the specified array is {@code null}
       
  4462      * @throws ArrayIndexOutOfBoundsException if {@code fromIndex} is negative,
       
  4463      *         {@code toIndex} is less than {@code fromIndex}, or
       
  4464      *         {@code toIndex} is greater than the array size
       
  4465      * @since 1.8
       
  4466      */
       
  4467     public static Spliterator.OfDouble spliterator(double[] array, int fromIndex, int toIndex) {
       
  4468         return Spliterators.spliterator(array, fromIndex, toIndex,
       
  4469                                         Spliterator.ORDERED | Spliterator.IMMUTABLE);
       
  4470     }
  4303 }
  4471 }