diff --git a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/NoSuchElementExceptionTest.java b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/NoSuchElementExceptionTest.java
index 7727f3f6c3..161dada795 100644
--- a/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/NoSuchElementExceptionTest.java
+++ b/jre_emul/android/platform/libcore/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/NoSuchElementExceptionTest.java
@@ -1,18 +1,18 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.harmony.tests.java.util;
@@ -46,7 +46,7 @@ public void test_ConstructorLjava_lang_String() {
// Test for method java.util.NoSuchElementException(java.lang.String)
assertNotNull(new NoSuchElementException("String"));
- assertNotNull(new NoSuchElementException(null));
+ assertNotNull(new NoSuchElementException((String)null));
try {
Vector v = new Vector();
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractCollection.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractCollection.java
index 6ea9224820..bfefdb338e 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractCollection.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractCollection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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,30 +26,30 @@
package java.util;
/**
- * This class provides a skeletal implementation of the Collection
+ * This class provides a skeletal implementation of the {@code Collection}
* interface, to minimize the effort required to implement this interface.
*
* To implement an unmodifiable collection, the programmer needs only to
- * extend this class and provide implementations for the iterator and
- * size methods. (The iterator returned by the iterator
- * method must implement hasNext and next .)
+ * extend this class and provide implementations for the {@code iterator} and
+ * {@code size} methods. (The iterator returned by the {@code iterator}
+ * method must implement {@code hasNext} and {@code next}.)
*
* To implement a modifiable collection, the programmer must additionally
- * override this class's add method (which otherwise throws an
- * UnsupportedOperationException ), and the iterator returned by the
- * iterator method must additionally implement its remove
+ * override this class's {@code add} method (which otherwise throws an
+ * {@code UnsupportedOperationException}), and the iterator returned by the
+ * {@code iterator} method must additionally implement its {@code remove}
* method.
*
* The programmer should generally provide a void (no argument) and
- * Collection constructor, as per the recommendation in the
- * Collection interface specification.
+ * {@code Collection} constructor, as per the recommendation in the
+ * {@code Collection} interface specification.
*
* The documentation for each non-abstract method in this class describes its
* implementation in detail. Each of these methods may be overridden if
* the collection being implemented admits a more efficient implementation.
*
* This class is a member of the
- *
+ *
* Java Collections Framework .
*
* @author Josh Bloch
@@ -80,7 +80,8 @@ protected AbstractCollection() {
/**
* {@inheritDoc}
*
- *
This implementation returns size() == 0 .
+ * @implSpec
+ * This implementation returns {@code size() == 0}.
*/
public boolean isEmpty() {
return size() == 0;
@@ -89,7 +90,8 @@ public boolean isEmpty() {
/**
* {@inheritDoc}
*
- *
This implementation iterates over the elements in the collection,
+ * @implSpec
+ * This implementation iterates over the elements in the collection,
* checking each element in turn for equality with the specified element.
*
* @throws ClassCastException {@inheritDoc}
@@ -112,7 +114,8 @@ public boolean contains(Object o) {
/**
* {@inheritDoc}
*
- *
This implementation returns an array containing all the elements
+ * @implSpec
+ * This implementation returns an array containing all the elements
* returned by this collection's iterator, in the same order, stored in
* consecutive elements of the array, starting with index {@code 0}.
* The length of the returned array is equal to the number of elements
@@ -139,7 +142,8 @@ public native Object[] toArray() /*-[
/**
* {@inheritDoc}
*
- *
This implementation returns an array containing all the elements
+ * @implSpec
+ * This implementation returns an array containing all the elements
* returned by this collection's iterator in the same order, stored in
* consecutive elements of the array, starting with index {@code 0}.
* If the number of elements returned by the iterator is too large to
@@ -226,8 +230,9 @@ private static int hugeCapacity(int minCapacity) {
/**
* {@inheritDoc}
*
- *
This implementation always throws an
- * UnsupportedOperationException .
+ * @implSpec
+ * This implementation always throws an
+ * {@code UnsupportedOperationException}.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
@@ -242,13 +247,14 @@ public boolean add(E e) {
/**
* {@inheritDoc}
*
- *
This implementation iterates over the collection looking for the
+ * @implSpec
+ * This implementation iterates over the collection looking for the
* specified element. If it finds the element, it removes the element
* from the collection using the iterator's remove method.
*
*
Note that this implementation throws an
- * UnsupportedOperationException if the iterator returned by this
- * collection's iterator method does not implement the remove
+ * {@code UnsupportedOperationException} if the iterator returned by this
+ * collection's iterator method does not implement the {@code remove}
* method and this collection contains the specified object.
*
* @throws UnsupportedOperationException {@inheritDoc}
@@ -281,10 +287,11 @@ public boolean remove(Object o) {
/**
* {@inheritDoc}
*
- *
This implementation iterates over the specified collection,
+ * @implSpec
+ * This implementation iterates over the specified collection,
* checking each element returned by the iterator in turn to see
* if it's contained in this collection. If all elements are so
- * contained true is returned, otherwise false .
+ * contained {@code true} is returned, otherwise {@code false}.
*
* @throws ClassCastException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
@@ -300,11 +307,12 @@ public boolean containsAll(Collection> c) {
/**
* {@inheritDoc}
*
- *
This implementation iterates over the specified collection, and adds
+ * @implSpec
+ * This implementation iterates over the specified collection, and adds
* each object returned by the iterator to this collection, in turn.
*
*
Note that this implementation will throw an
- * UnsupportedOperationException unless add is
+ * {@code UnsupportedOperationException} unless {@code add} is
* overridden (assuming the specified collection is non-empty).
*
* @throws UnsupportedOperationException {@inheritDoc}
@@ -326,14 +334,15 @@ public boolean addAll(Collection extends E> c) {
/**
* {@inheritDoc}
*
- *
This implementation iterates over this collection, checking each
+ * @implSpec
+ * This implementation iterates over this collection, checking each
* element returned by the iterator in turn to see if it's contained
* in the specified collection. If it's so contained, it's removed from
- * this collection with the iterator's remove method.
+ * this collection with the iterator's {@code remove} method.
*
*
Note that this implementation will throw an
- * UnsupportedOperationException if the iterator returned by the
- * iterator method does not implement the remove method
+ * {@code UnsupportedOperationException} if the iterator returned by the
+ * {@code iterator} method does not implement the {@code remove} method
* and this collection contains one or more elements in common with the
* specified collection.
*
@@ -360,14 +369,15 @@ public boolean removeAll(Collection> c) {
/**
* {@inheritDoc}
*
- *
This implementation iterates over this collection, checking each
+ * @implSpec
+ * This implementation iterates over this collection, checking each
* element returned by the iterator in turn to see if it's contained
* in the specified collection. If it's not so contained, it's removed
- * from this collection with the iterator's remove method.
+ * from this collection with the iterator's {@code remove} method.
*
*
Note that this implementation will throw an
- * UnsupportedOperationException if the iterator returned by the
- * iterator method does not implement the remove method
+ * {@code UnsupportedOperationException} if the iterator returned by the
+ * {@code iterator} method does not implement the {@code remove} method
* and this collection contains one or more elements not present in the
* specified collection.
*
@@ -394,15 +404,16 @@ public boolean retainAll(Collection> c) {
/**
* {@inheritDoc}
*
- *
This implementation iterates over this collection, removing each
- * element using the Iterator.remove operation. Most
+ * @implSpec
+ * This implementation iterates over this collection, removing each
+ * element using the {@code Iterator.remove} operation. Most
* implementations will probably choose to override this method for
* efficiency.
*
*
Note that this implementation will throw an
- * UnsupportedOperationException if the iterator returned by this
- * collection's iterator method does not implement the
- * remove method and this collection is non-empty.
+ * {@code UnsupportedOperationException} if the iterator returned by this
+ * collection's {@code iterator} method does not implement the
+ * {@code remove} method and this collection is non-empty.
*
* @throws UnsupportedOperationException {@inheritDoc}
*/
@@ -421,8 +432,8 @@ public void clear() {
* Returns a string representation of this collection. The string
* representation consists of a list of the collection's elements in the
* order they are returned by its iterator, enclosed in square brackets
- * ("[]" ). Adjacent elements are separated by the characters
- * ", " (comma and space). Elements are converted to strings as
+ * ({@code "[]"}). Adjacent elements are separated by the characters
+ * {@code ", "} (comma and space). Elements are converted to strings as
* by {@link String#valueOf(Object)}.
*
* @return a string representation of this collection
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractList.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractList.java
index 951dc9a493..11925b3162 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractList.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractList.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -62,7 +62,7 @@
* collection being implemented admits a more efficient implementation.
*
*
This class is a member of the
- *
+ *
* Java Collections Framework .
*
* @author Josh Bloch
@@ -374,7 +374,7 @@ public E next() {
return next;
} catch (IndexOutOfBoundsException e) {
checkForComodification();
- throw new NoSuchElementException();
+ throw new NoSuchElementException(e);
}
}
@@ -418,7 +418,7 @@ public E previous() {
return previous;
} catch (IndexOutOfBoundsException e) {
checkForComodification();
- throw new NoSuchElementException();
+ throw new NoSuchElementException(e);
}
}
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractMap.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractMap.java
index e275726505..3f4ab5448a 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractMap.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractMap.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -34,24 +34,24 @@
]-*/
/**
- * This class provides a skeletal implementation of the Map
+ * This class provides a skeletal implementation of the {@code Map}
* interface, to minimize the effort required to implement this interface.
*
*
To implement an unmodifiable map, the programmer needs only to extend this
- * class and provide an implementation for the entrySet method, which
+ * class and provide an implementation for the {@code entrySet} method, which
* returns a set-view of the map's mappings. Typically, the returned set
- * will, in turn, be implemented atop AbstractSet . This set should
- * not support the add or remove methods, and its iterator
- * should not support the remove method.
+ * will, in turn, be implemented atop {@code AbstractSet}. This set should
+ * not support the {@code add} or {@code remove} methods, and its iterator
+ * should not support the {@code remove} method.
*
*
To implement a modifiable map, the programmer must additionally override
- * this class's put method (which otherwise throws an
- * UnsupportedOperationException ), and the iterator returned by
- * entrySet().iterator() must additionally implement its
- * remove method.
+ * this class's {@code put} method (which otherwise throws an
+ * {@code UnsupportedOperationException}), and the iterator returned by
+ * {@code entrySet().iterator()} must additionally implement its
+ * {@code remove} method.
*
*
The programmer should generally provide a void (no argument) and map
- * constructor, as per the recommendation in the Map interface
+ * constructor, as per the recommendation in the {@code Map} interface
* specification.
*
*
The documentation for each non-abstract method in this class describes its
@@ -59,7 +59,7 @@
* map being implemented admits a more efficient implementation.
*
*
This class is a member of the
- *
+ *
* Java Collections Framework .
*
* @param the type of keys maintained by this map
@@ -86,7 +86,7 @@ protected AbstractMap() {
* {@inheritDoc}
*
* @implSpec
- * This implementation returns entrySet().size() .
+ * This implementation returns {@code entrySet().size()}.
*/
public int size() {
return entrySet().size();
@@ -96,7 +96,7 @@ public int size() {
* {@inheritDoc}
*
* @implSpec
- * This implementation returns size() == 0 .
+ * This implementation returns {@code size() == 0}.
*/
public boolean isEmpty() {
return size() == 0;
@@ -106,10 +106,10 @@ public boolean isEmpty() {
* {@inheritDoc}
*
* @implSpec
- * This implementation iterates over entrySet() searching
+ * This implementation iterates over {@code entrySet()} searching
* for an entry with the specified value. If such an entry is found,
- * true is returned. If the iteration terminates without
- * finding such an entry, false is returned. Note that this
+ * {@code true} is returned. If the iteration terminates without
+ * finding such an entry, {@code false} is returned. Note that this
* implementation requires linear time in the size of the map.
*
* @throws ClassCastException {@inheritDoc}
@@ -137,10 +137,10 @@ public boolean containsValue(Object value) {
* {@inheritDoc}
*
* @implSpec
- * This implementation iterates over entrySet() searching
+ * This implementation iterates over {@code entrySet()} searching
* for an entry with the specified key. If such an entry is found,
- * true is returned. If the iteration terminates without
- * finding such an entry, false is returned. Note that this
+ * {@code true} is returned. If the iteration terminates without
+ * finding such an entry, {@code false} is returned. Note that this
* implementation requires linear time in the size of the map; many
* implementations will override this method.
*
@@ -169,10 +169,10 @@ public boolean containsKey(Object key) {
* {@inheritDoc}
*
* @implSpec
- * This implementation iterates over entrySet() searching
+ * This implementation iterates over {@code entrySet()} searching
* for an entry with the specified key. If such an entry is found,
* the entry's value is returned. If the iteration terminates without
- * finding such an entry, null is returned. Note that this
+ * finding such an entry, {@code null} is returned. Note that this
* implementation requires linear time in the size of the map; many
* implementations will override this method.
*
@@ -205,7 +205,7 @@ public V get(Object key) {
*
* @implSpec
* This implementation always throws an
- * UnsupportedOperationException .
+ * {@code UnsupportedOperationException}.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
@@ -220,18 +220,18 @@ public V put(K key, V value) {
* {@inheritDoc}
*
* @implSpec
- * This implementation iterates over entrySet() searching for an
+ * This implementation iterates over {@code entrySet()} searching for an
* entry with the specified key. If such an entry is found, its value is
- * obtained with its getValue operation, the entry is removed
+ * obtained with its {@code getValue} operation, the entry is removed
* from the collection (and the backing map) with the iterator's
- * remove operation, and the saved value is returned. If the
- * iteration terminates without finding such an entry, null is
+ * {@code remove} operation, and the saved value is returned. If the
+ * iteration terminates without finding such an entry, {@code null} is
* returned. Note that this implementation requires linear time in the
* size of the map; many implementations will override this method.
*
* Note that this implementation throws an
- * UnsupportedOperationException if the entrySet
- * iterator does not support the remove method and this map
+ * {@code UnsupportedOperationException} if the {@code entrySet}
+ * iterator does not support the {@code remove} method and this map
* contains a mapping for the specified key.
*
* @throws UnsupportedOperationException {@inheritDoc}
@@ -271,12 +271,12 @@ public V remove(Object key) {
*
* @implSpec
* This implementation iterates over the specified map's
- * entrySet() collection, and calls this map's put
+ * {@code entrySet()} collection, and calls this map's {@code put}
* operation once for each entry returned by the iteration.
*
*
Note that this implementation throws an
- * UnsupportedOperationException if this map does not support
- * the put operation and the specified map is nonempty.
+ * {@code UnsupportedOperationException} if this map does not support
+ * the {@code put} operation and the specified map is nonempty.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
@@ -292,11 +292,11 @@ public void putAll(Map extends K, ? extends V> m) {
* {@inheritDoc}
*
* @implSpec
- * This implementation calls entrySet().clear() .
+ * This implementation calls {@code entrySet().clear()}.
*
*
Note that this implementation throws an
- * UnsupportedOperationException if the entrySet
- * does not support the clear operation.
+ * {@code UnsupportedOperationException} if the {@code entrySet}
+ * does not support the {@code clear} operation.
*
* @throws UnsupportedOperationException {@inheritDoc}
*/
@@ -331,8 +331,8 @@ public void clear() {
* }
*}
*/
- transient volatile Set keySet = null;
- transient volatile Collection values = null;
+ transient Set keySet;
+ transient Collection values;
/**
* {@inheritDoc}
@@ -340,10 +340,10 @@ public void clear() {
* @implSpec
* This implementation returns a set that subclasses {@link AbstractSet}.
* The subclass's iterator method returns a "wrapper object" over this
- * map's entrySet() iterator. The size method
- * delegates to this map's size method and the
- * contains method delegates to this map's
- * containsKey method.
+ * map's {@code entrySet()} iterator. The {@code size} method
+ * delegates to this map's {@code size} method and the
+ * {@code contains} method delegates to this map's
+ * {@code containsKey} method.
*
* The set is created the first time this method is called,
* and returned in response to all subsequent calls. No synchronization
@@ -401,10 +401,10 @@ public boolean contains(Object k) {
* @implSpec
* This implementation returns a collection that subclasses {@link
* AbstractCollection}. The subclass's iterator method returns a
- * "wrapper object" over this map's entrySet() iterator.
- * The size method delegates to this map's size
- * method and the contains method delegates to this map's
- * containsValue method.
+ * "wrapper object" over this map's {@code entrySet()} iterator.
+ * The {@code size} method delegates to this map's {@code size}
+ * method and the {@code contains} method delegates to this map's
+ * {@code containsValue} method.
*
*
The collection is created the first time this method is called, and
* returned in response to all subsequent calls. No synchronization is
@@ -463,25 +463,25 @@ public boolean contains(Object v) {
/**
* Compares the specified object with this map for equality. Returns
- * true if the given object is also a map and the two maps
- * represent the same mappings. More formally, two maps m1 and
- * m2 represent the same mappings if
- * m1.entrySet().equals(m2.entrySet()) . This ensures that the
- * equals method works properly across different implementations
- * of the Map interface.
+ * {@code true} if the given object is also a map and the two maps
+ * represent the same mappings. More formally, two maps {@code m1} and
+ * {@code m2} represent the same mappings if
+ * {@code m1.entrySet().equals(m2.entrySet())}. This ensures that the
+ * {@code equals} method works properly across different implementations
+ * of the {@code Map} interface.
*
* @implSpec
* This implementation first checks if the specified object is this map;
- * if so it returns true . Then, it checks if the specified
+ * if so it returns {@code true}. Then, it checks if the specified
* object is a map whose size is identical to the size of this map; if
- * not, it returns false . If so, it iterates over this map's
- * entrySet collection, and checks that the specified map
+ * not, it returns {@code false}. If so, it iterates over this map's
+ * {@code entrySet} collection, and checks that the specified map
* contains each mapping that this map contains. If the specified map
- * fails to contain such a mapping, false is returned. If the
- * iteration completes, true is returned.
+ * fails to contain such a mapping, {@code false} is returned. If the
+ * iteration completes, {@code true} is returned.
*
* @param o object to be compared for equality with this map
- * @return true if the specified object is equal to this map
+ * @return {@code true} if the specified object is equal to this map
*/
public boolean equals(Object o) {
if (o == this)
@@ -494,13 +494,11 @@ public boolean equals(Object o) {
return false;
try {
- Iterator> i = entrySet().iterator();
- while (i.hasNext()) {
- Entry e = i.next();
+ for (Entry e : entrySet()) {
K key = e.getKey();
V value = e.getValue();
if (value == null) {
- if (!(m.get(key)==null && m.containsKey(key)))
+ if (!(m.get(key) == null && m.containsKey(key)))
return false;
} else {
if (!value.equals(m.get(key)))
@@ -519,13 +517,13 @@ public boolean equals(Object o) {
/**
* Returns the hash code value for this map. The hash code of a map is
* defined to be the sum of the hash codes of each entry in the map's
- * entrySet() view. This ensures that m1.equals(m2)
- * implies that m1.hashCode()==m2.hashCode() for any two maps
- * m1 and m2 , as required by the general contract of
+ * {@code entrySet()} view. This ensures that {@code m1.equals(m2)}
+ * implies that {@code m1.hashCode()==m2.hashCode()} for any two maps
+ * {@code m1} and {@code m2}, as required by the general contract of
* {@link Object#hashCode}.
*
* @implSpec
- * This implementation iterates over entrySet() , calling
+ * This implementation iterates over {@code entrySet()}, calling
* {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
* set, and adding up the results.
*
@@ -536,19 +534,18 @@ public boolean equals(Object o) {
*/
public int hashCode() {
int h = 0;
- Iterator> i = entrySet().iterator();
- while (i.hasNext())
- h += i.next().hashCode();
+ for (Entry entry : entrySet())
+ h += entry.hashCode();
return h;
}
/**
* Returns a string representation of this map. The string representation
* consists of a list of key-value mappings in the order returned by the
- * map's entrySet view's iterator, enclosed in braces
- * ("{}" ). Adjacent mappings are separated by the characters
- * ", " (comma and space). Each key-value mapping is rendered as
- * the key followed by an equals sign ("=" ) followed by the
+ * map's {@code entrySet} view's iterator, enclosed in braces
+ * ({@code "{}"}). Adjacent mappings are separated by the characters
+ * {@code ", "} (comma and space). Each key-value mapping is rendered as
+ * the key followed by an equals sign ({@code "="}) followed by the
* associated value. Keys and values are converted to strings as by
* {@link String#valueOf(Object)}.
*
@@ -575,7 +572,7 @@ public String toString() {
}
/**
- * Returns a shallow copy of this AbstractMap instance: the keys
+ * Returns a shallow copy of this {@code AbstractMap} instance: the keys
* and values themselves are not cloned.
*
* @return a shallow copy of this map
@@ -607,11 +604,11 @@ private static boolean eq(Object o1, Object o2) {
/**
* An Entry maintaining a key and a value. The value may be
- * changed using the setValue method. This class
+ * changed using the {@code setValue} method. This class
* facilitates the process of building custom map
* implementations. For example, it may be convenient to return
- * arrays of SimpleEntry instances in method
- * Map.entrySet().toArray .
+ * arrays of {@code SimpleEntry} instances in method
+ * {@code Map.entrySet().toArray}.
*
* @since 1.6
*/
@@ -726,7 +723,7 @@ public int hashCode() {
/**
* Returns a String representation of this map entry. This
* implementation returns the string representation of this
- * entry's key followed by the equals character ("= ")
+ * entry's key followed by the equals character ("{@code =}")
* followed by the string representation of this entry's value.
*
* @return a String representation of this map entry
@@ -739,7 +736,7 @@ public String toString() {
/**
* An Entry maintaining an immutable key and value. This class
- * does not support method setValue . This class may be
+ * does not support method {@code setValue}. This class may be
* convenient in methods that return thread-safe snapshots of
* key-value mappings.
*
@@ -797,7 +794,7 @@ public V getValue() {
/**
* Replaces the value corresponding to this entry with the specified
* value (optional operation). This implementation simply throws
- * UnsupportedOperationException , as this class implements
+ * {@code UnsupportedOperationException}, as this class implements
* an immutable map entry.
*
* @param value new value to be stored in this entry
@@ -857,7 +854,7 @@ public int hashCode() {
/**
* Returns a String representation of this map entry. This
* implementation returns the string representation of this
- * entry's key followed by the equals character ("= ")
+ * entry's key followed by the equals character ("{@code =}")
* followed by the string representation of this entry's value.
*
* @return a String representation of this map entry
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractSequentialList.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractSequentialList.java
index 36a91dabaa..91ce740141 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractSequentialList.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractSequentialList.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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,35 +26,35 @@
package java.util;
/**
- * This class provides a skeletal implementation of the List
+ * This class provides a skeletal implementation of the {@code List}
* interface to minimize the effort required to implement this interface
* backed by a "sequential access" data store (such as a linked list). For
- * random access data (such as an array), AbstractList should be used
+ * random access data (such as an array), {@code AbstractList} should be used
* in preference to this class.
*
- * This class is the opposite of the AbstractList class in the sense
- * that it implements the "random access" methods (get(int index) ,
- * set(int index, E element) , add(int index, E element) and
- * remove(int index) ) on top of the list's list iterator, instead of
+ * This class is the opposite of the {@code AbstractList} class in the sense
+ * that it implements the "random access" methods ({@code get(int index)},
+ * {@code set(int index, E element)}, {@code add(int index, E element)} and
+ * {@code remove(int index)}) on top of the list's list iterator, instead of
* the other way around.
*
* To implement a list the programmer needs only to extend this class and
- * provide implementations for the listIterator and size
+ * provide implementations for the {@code listIterator} and {@code size}
* methods. For an unmodifiable list, the programmer need only implement the
- * list iterator's hasNext , next , hasPrevious ,
- * previous and index methods.
+ * list iterator's {@code hasNext}, {@code next}, {@code hasPrevious},
+ * {@code previous} and {@code index} methods.
*
* For a modifiable list the programmer should additionally implement the list
- * iterator's set method. For a variable-size list the programmer
- * should additionally implement the list iterator's remove and
- * add methods.
+ * iterator's {@code set} method. For a variable-size list the programmer
+ * should additionally implement the list iterator's {@code remove} and
+ * {@code add} methods.
*
* The programmer should generally provide a void (no argument) and collection
- * constructor, as per the recommendation in the Collection interface
+ * constructor, as per the recommendation in the {@code Collection} interface
* specification.
*
* This class is a member of the
- *
+ *
* Java Collections Framework .
*
* @author Josh Bloch
@@ -78,8 +78,8 @@ protected AbstractSequentialList() {
* Returns the element at the specified position in this list.
*
*
This implementation first gets a list iterator pointing to the
- * indexed element (with listIterator(index) ). Then, it gets
- * the element using ListIterator.next and returns it.
+ * indexed element (with {@code listIterator(index)}). Then, it gets
+ * the element using {@code ListIterator.next} and returns it.
*
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
@@ -96,13 +96,13 @@ public E get(int index) {
* specified element (optional operation).
*
*
This implementation first gets a list iterator pointing to the
- * indexed element (with listIterator(index) ). Then, it gets
- * the current element using ListIterator.next and replaces it
- * with ListIterator.set .
+ * indexed element (with {@code listIterator(index)}). Then, it gets
+ * the current element using {@code ListIterator.next} and replaces it
+ * with {@code ListIterator.set}.
*
*
Note that this implementation will throw an
- * UnsupportedOperationException if the list iterator does not
- * implement the set operation.
+ * {@code UnsupportedOperationException} if the list iterator does not
+ * implement the {@code set} operation.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
@@ -128,12 +128,12 @@ public E set(int index, E element) {
* indices).
*
*
This implementation first gets a list iterator pointing to the
- * indexed element (with listIterator(index) ). Then, it
- * inserts the specified element with ListIterator.add .
+ * indexed element (with {@code listIterator(index)}). Then, it
+ * inserts the specified element with {@code ListIterator.add}.
*
*
Note that this implementation will throw an
- * UnsupportedOperationException if the list iterator does not
- * implement the add operation.
+ * {@code UnsupportedOperationException} if the list iterator does not
+ * implement the {@code add} operation.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
@@ -156,12 +156,12 @@ public void add(int index, E element) {
* list.
*
*
This implementation first gets a list iterator pointing to the
- * indexed element (with listIterator(index) ). Then, it removes
- * the element with ListIterator.remove .
+ * indexed element (with {@code listIterator(index)}). Then, it removes
+ * the element with {@code ListIterator.remove}.
*
*
Note that this implementation will throw an
- * UnsupportedOperationException if the list iterator does not
- * implement the remove operation.
+ * {@code UnsupportedOperationException} if the list iterator does not
+ * implement the {@code remove} operation.
*
* @throws UnsupportedOperationException {@inheritDoc}
* @throws IndexOutOfBoundsException {@inheritDoc}
@@ -193,14 +193,14 @@ public E remove(int index) {
*
*
This implementation gets an iterator over the specified collection and
* a list iterator over this list pointing to the indexed element (with
- * listIterator(index) ). Then, it iterates over the specified
+ * {@code listIterator(index)}). Then, it iterates over the specified
* collection, inserting the elements obtained from the iterator into this
- * list, one at a time, using ListIterator.add followed by
- * ListIterator.next (to skip over the added element).
+ * list, one at a time, using {@code ListIterator.add} followed by
+ * {@code ListIterator.next} (to skip over the added element).
*
*
Note that this implementation will throw an
- * UnsupportedOperationException if the list iterator returned by
- * the listIterator method does not implement the add
+ * {@code UnsupportedOperationException} if the list iterator returned by
+ * the {@code listIterator} method does not implement the {@code add}
* operation.
*
* @throws UnsupportedOperationException {@inheritDoc}
@@ -213,9 +213,8 @@ public boolean addAll(int index, Collection extends E> c) {
try {
boolean modified = false;
ListIterator e1 = listIterator(index);
- Iterator extends E> e2 = c.iterator();
- while (e2.hasNext()) {
- e1.add(e2.next());
+ for (E e : c) {
+ e1.add(e);
modified = true;
}
return modified;
@@ -244,7 +243,7 @@ public Iterator iterator() {
* sequence).
*
* @param index index of first element to be returned from the list
- * iterator (by a call to the next method)
+ * iterator (by a call to the {@code next} method)
* @return a list iterator over the elements in this list (in proper
* sequence)
* @throws IndexOutOfBoundsException {@inheritDoc}
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractSet.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractSet.java
index b3fe0dc0bf..80d4c5e91d 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractSet.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/AbstractSet.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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,23 +26,23 @@
package java.util;
/**
- * This class provides a skeletal implementation of the Set
+ * This class provides a skeletal implementation of the {@code Set}
* interface to minimize the effort required to implement this
* interface.
*
* The process of implementing a set by extending this class is identical
* to that of implementing a Collection by extending AbstractCollection,
* except that all of the methods and constructors in subclasses of this
- * class must obey the additional constraints imposed by the Set
+ * class must obey the additional constraints imposed by the {@code Set}
* interface (for instance, the add method must not permit addition of
* multiple instances of an object to a set).
*
* Note that this class does not override any of the implementations from
- * the AbstractCollection class. It merely adds implementations
- * for equals and hashCode .
+ * the {@code AbstractCollection} class. It merely adds implementations
+ * for {@code equals} and {@code hashCode}.
*
* This class is a member of the
- *
+ *
* Java Collections Framework .
*
* @param the type of elements maintained by this set
@@ -67,20 +67,20 @@ protected AbstractSet() {
/**
* Compares the specified object with this set for equality. Returns
- * true if the given object is also a set, the two sets have
+ * {@code true} if the given object is also a set, the two sets have
* the same size, and every member of the given set is contained in
- * this set. This ensures that the equals method works
- * properly across different implementations of the Set
+ * this set. This ensures that the {@code equals} method works
+ * properly across different implementations of the {@code Set}
* interface.
*
* This implementation first checks if the specified object is this
- * set; if so it returns true . Then, it checks if the
+ * set; if so it returns {@code true}. Then, it checks if the
* specified object is a set whose size is identical to the size of
* this set; if not, it returns false. If so, it returns
- * containsAll((Collection) o) .
+ * {@code containsAll((Collection) o)}.
*
* @param o object to be compared for equality with this set
- * @return true if the specified object is equal to this set
+ * @return {@code true} if the specified object is equal to this set
*/
public boolean equals(Object o) {
if (o == this)
@@ -93,9 +93,7 @@ public boolean equals(Object o) {
return false;
try {
return containsAll(c);
- } catch (ClassCastException unused) {
- return false;
- } catch (NullPointerException unused) {
+ } catch (ClassCastException | NullPointerException unused) {
return false;
}
}
@@ -103,14 +101,14 @@ public boolean equals(Object o) {
/**
* Returns the hash code value for this set. The hash code of a set is
* defined to be the sum of the hash codes of the elements in the set,
- * where the hash code of a null element is defined to be zero.
- * This ensures that s1.equals(s2) implies that
- * s1.hashCode()==s2.hashCode() for any two sets s1
- * and s2 , as required by the general contract of
+ * where the hash code of a {@code null} element is defined to be zero.
+ * This ensures that {@code s1.equals(s2)} implies that
+ * {@code s1.hashCode()==s2.hashCode()} for any two sets {@code s1}
+ * and {@code s2}, as required by the general contract of
* {@link Object#hashCode}.
*
*
This implementation iterates over the set, calling the
- * hashCode method on each element in the set, and adding up
+ * {@code hashCode} method on each element in the set, and adding up
* the results.
*
* @return the hash code value for this set
@@ -136,24 +134,24 @@ public int hashCode() {
* the two sets.
*
*
This implementation determines which is the smaller of this set
- * and the specified collection, by invoking the size
+ * and the specified collection, by invoking the {@code size}
* method on each. If this set has fewer elements, then the
* implementation iterates over this set, checking each element
* returned by the iterator in turn to see if it is contained in
* the specified collection. If it is so contained, it is removed
- * from this set with the iterator's remove method. If
+ * from this set with the iterator's {@code remove} method. If
* the specified collection has fewer elements, then the
* implementation iterates over the specified collection, removing
* from this set each element returned by the iterator, using this
- * set's remove method.
+ * set's {@code remove} method.
*
*
Note that this implementation will throw an
- * UnsupportedOperationException if the iterator returned by the
- * iterator method does not implement the remove method.
+ * {@code UnsupportedOperationException} if the iterator returned by the
+ * {@code iterator} method does not implement the {@code remove} method.
*
* @param c collection containing elements to be removed from this set
- * @return true if this set changed as a result of the call
- * @throws UnsupportedOperationException if the removeAll operation
+ * @return {@code true} if this set changed as a result of the call
+ * @throws UnsupportedOperationException if the {@code removeAll} operation
* is not supported by this set
* @throws ClassCastException if the class of an element of this set
* is incompatible with the specified collection
@@ -170,8 +168,8 @@ public boolean removeAll(Collection> c) {
boolean modified = false;
if (size() > c.size()) {
- for (Iterator> i = c.iterator(); i.hasNext(); )
- modified |= remove(i.next());
+ for (Object e : c)
+ modified |= remove(e);
} else {
for (Iterator> i = iterator(); i.hasNext(); ) {
if (c.contains(i.next())) {
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/ArrayList.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/ArrayList.java
index 273dfef3c2..d67000e617 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/ArrayList.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/ArrayList.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 The Android Open Source Project
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -31,33 +31,33 @@
import java.util.function.UnaryOperator;
/**
- * Resizable-array implementation of the List interface. Implements
+ * Resizable-array implementation of the {@code List} interface. Implements
* all optional list operations, and permits all elements, including
- * null . In addition to implementing the List interface,
+ * {@code null}. In addition to implementing the {@code List} interface,
* this class provides methods to manipulate the size of the array that is
* used internally to store the list. (This class is roughly equivalent to
- * Vector , except that it is unsynchronized.)
+ * {@code Vector}, except that it is unsynchronized.)
*
- *
The size , isEmpty , get , set ,
- * iterator , and listIterator operations run in constant
- * time. The add operation runs in amortized constant time ,
+ *
The {@code size}, {@code isEmpty}, {@code get}, {@code set},
+ * {@code iterator}, and {@code listIterator} operations run in constant
+ * time. The {@code add} operation runs in amortized constant time ,
* that is, adding n elements requires O(n) time. All of the other operations
* run in linear time (roughly speaking). The constant factor is low compared
- * to that for the LinkedList implementation.
+ * to that for the {@code LinkedList} implementation.
*
- *
Each ArrayList instance has a capacity . The capacity is
+ *
Each {@code ArrayList} instance has a capacity . The capacity is
* the size of the array used to store the elements in the list. It is always
* at least as large as the list size. As elements are added to an ArrayList,
* its capacity grows automatically. The details of the growth policy are not
* specified beyond the fact that adding an element has constant amortized
* time cost.
*
- *
An application can increase the capacity of an ArrayList instance
- * before adding a large number of elements using the ensureCapacity
+ *
An application can increase the capacity of an {@code ArrayList} instance
+ * before adding a large number of elements using the {@code ensureCapacity}
* operation. This may reduce the amount of incremental reallocation.
*
*
Note that this implementation is not synchronized.
- * If multiple threads access an ArrayList instance concurrently,
+ * If multiple threads access an {@code ArrayList} instance concurrently,
* and at least one of the threads modifies the list structurally, it
* must be synchronized externally. (A structural modification is
* any operation that adds or deletes one or more elements, or explicitly
@@ -71,9 +71,9 @@
* unsynchronized access to the list:
* List list = Collections.synchronizedList(new ArrayList(...));
*
- *
+ *
* The iterators returned by this class's {@link #iterator() iterator} and
- * {@link #listIterator(int) listIterator} methods are fail-fast :
+ * {@link #listIterator(int) listIterator} methods are fail-fast :
* if the list is structurally modified at any time after the iterator is
* created, in any way except through the iterator's own
* {@link ListIterator#remove() remove} or
@@ -92,9 +92,11 @@
* should be used only to detect bugs.
*
*
This class is a member of the
- *
+ *
* Java Collections Framework .
*
+ * @param the type of elements in this list
+ *
* @author Josh Bloch
* @author Neal Gafter
* @see Collection
@@ -103,18 +105,10 @@
* @see Vector
* @since 1.2
*/
-// Android-changed: Inlined methods; CME in iterators; throw AIOOBE when toIndex < fromIndex.
+// Android-changed: CME in iterators;
/*
- * - AOSP commit 3be987f0f18648b3c532c8b89d09505e18594241
- * Inline for improved performance:
- * - checkForComodification
- * - elementData()
- * - rangeCheck()
- * - rangeCheckForAdd()
* - AOSP commit b10b2a3ab693cfd6156d06ffe4e00ce69b9c9194
* Fix ConcurrentModificationException in ArrayList iterators.
- * - AOSP commit a68b1a5ba82ef8cc19aafdce7d9c7f9631943f84
- * Throw AIOOBE when toIndex < fromIndex.
*/
public class ArrayList extends AbstractList
implements List, RandomAccess, Cloneable, java.io.Serializable
@@ -188,21 +182,23 @@ public ArrayList() {
* @throws NullPointerException if the specified collection is null
*/
public ArrayList(Collection extends E> c) {
- elementData = c.toArray();
- if ((size = elementData.length) != 0) {
- // c.toArray might (incorrectly) not return Object[] (see 6260652)
- if (elementData.getClass() != Object[].class)
- elementData = Arrays.copyOf(elementData, size, Object[].class);
+ Object[] a = c.toArray();
+ if ((size = a.length) != 0) {
+ if (c.getClass() == ArrayList.class) {
+ elementData = a;
+ } else {
+ elementData = Arrays.copyOf(a, size, Object[].class);
+ }
} else {
// replace with empty array.
- this.elementData = EMPTY_ELEMENTDATA;
+ elementData = EMPTY_ELEMENTDATA;
}
}
/**
- * Trims the capacity of this ArrayList instance to be the
+ * Trims the capacity of this {@code ArrayList} instance to be the
* list's current size. An application can use this operation to minimize
- * the storage of an ArrayList instance.
+ * the storage of an {@code ArrayList} instance.
*/
public void trimToSize() {
modCount++;
@@ -214,43 +210,23 @@ public void trimToSize() {
}
/**
- * Increases the capacity of this ArrayList instance, if
+ * Increases the capacity of this {@code ArrayList} instance, if
* necessary, to ensure that it can hold at least the number of elements
* specified by the minimum capacity argument.
*
- * @param minCapacity the desired minimum capacity
+ * @param minCapacity the desired minimum capacity
*/
public void ensureCapacity(int minCapacity) {
- int minExpand = (elementData != DEFAULTCAPACITY_EMPTY_ELEMENTDATA)
- // any size if not default element table
- ? 0
- // larger than default for default empty table. It's already
- // supposed to be at default size.
- : DEFAULT_CAPACITY;
-
- if (minCapacity > minExpand) {
- ensureExplicitCapacity(minCapacity);
- }
- }
-
- private void ensureCapacityInternal(int minCapacity) {
- if (elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA) {
- minCapacity = Math.max(DEFAULT_CAPACITY, minCapacity);
- }
-
- ensureExplicitCapacity(minCapacity);
- }
-
- private void ensureExplicitCapacity(int minCapacity) {
- modCount++;
-
- // overflow-conscious code
- if (minCapacity - elementData.length > 0)
+ if (minCapacity > elementData.length
+ && !(elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA
+ && minCapacity <= DEFAULT_CAPACITY)) {
+ modCount++;
grow(minCapacity);
+ }
}
/**
- * The maximum size of array to allocate.
+ * The maximum size of array to allocate (unless necessary).
* Some VMs reserve some header words in an array.
* Attempts to allocate larger arrays may result in
* OutOfMemoryError: Requested array size exceeds VM limit
@@ -262,25 +238,48 @@ private void ensureExplicitCapacity(int minCapacity) {
* number of elements specified by the minimum capacity argument.
*
* @param minCapacity the desired minimum capacity
+ * @throws OutOfMemoryError if minCapacity is less than zero
*/
- private void grow(int minCapacity) {
+ private Object[] grow(int minCapacity) {
+ return elementData = Arrays.copyOf(elementData,
+ newCapacity(minCapacity));
+ }
+
+ private Object[] grow() {
+ return grow(size + 1);
+ }
+
+ /**
+ * Returns a capacity at least as large as the given minimum capacity.
+ * Returns the current capacity increased by 50% if that suffices.
+ * Will not return a capacity greater than MAX_ARRAY_SIZE unless
+ * the given minimum capacity is greater than MAX_ARRAY_SIZE.
+ *
+ * @param minCapacity the desired minimum capacity
+ * @throws OutOfMemoryError if minCapacity is less than zero
+ */
+ private int newCapacity(int minCapacity) {
// overflow-conscious code
int oldCapacity = elementData.length;
int newCapacity = oldCapacity + (oldCapacity >> 1);
- if (newCapacity - minCapacity < 0)
- newCapacity = minCapacity;
- if (newCapacity - MAX_ARRAY_SIZE > 0)
- newCapacity = hugeCapacity(minCapacity);
- // minCapacity is usually close to size, so this is a win:
- elementData = Arrays.copyOf(elementData, newCapacity);
+ if (newCapacity - minCapacity <= 0) {
+ if (elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA)
+ return Math.max(DEFAULT_CAPACITY, minCapacity);
+ if (minCapacity < 0) // overflow
+ throw new OutOfMemoryError();
+ return minCapacity;
+ }
+ return (newCapacity - MAX_ARRAY_SIZE <= 0)
+ ? newCapacity
+ : hugeCapacity(minCapacity);
}
private static int hugeCapacity(int minCapacity) {
if (minCapacity < 0) // overflow
throw new OutOfMemoryError();
- return (minCapacity > MAX_ARRAY_SIZE) ?
- Integer.MAX_VALUE :
- MAX_ARRAY_SIZE;
+ return (minCapacity > MAX_ARRAY_SIZE)
+ ? Integer.MAX_VALUE
+ : MAX_ARRAY_SIZE;
}
/**
@@ -293,22 +292,22 @@ public int size() {
}
/**
- * Returns true if this list contains no elements.
+ * Returns {@code true} if this list contains no elements.
*
- * @return true if this list contains no elements
+ * @return {@code true} if this list contains no elements
*/
public boolean isEmpty() {
return size == 0;
}
/**
- * Returns true if this list contains the specified element.
- * More formally, returns true if and only if this list contains
- * at least one element e such that
- * (o==null ? e==null : o.equals(e)) .
+ * Returns {@code true} if this list contains the specified element.
+ * More formally, returns {@code true} if and only if this list contains
+ * at least one element {@code e} such that
+ * {@code Objects.equals(o, e)}.
*
* @param o element whose presence in this list is to be tested
- * @return true if this list contains the specified element
+ * @return {@code true} if this list contains the specified element
*/
public boolean contains(Object o) {
return indexOf(o) >= 0;
@@ -317,19 +316,28 @@ public boolean contains(Object o) {
/**
* Returns the index of the first occurrence of the specified element
* in this list, or -1 if this list does not contain the element.
- * More formally, returns the lowest index i such that
- * (o==null ? get(i)==null : o.equals(get(i))) ,
+ * More formally, returns the lowest index {@code i} such that
+ * {@code Objects.equals(o, get(i))},
* or -1 if there is no such index.
*/
public int indexOf(Object o) {
+ return indexOfRange(o, 0, size);
+ }
+
+ int indexOfRange(Object o, int start, int end) {
+ Object[] es = elementData;
if (o == null) {
- for (int i = 0; i < size; i++)
- if (elementData[i]==null)
+ for (int i = start; i < end; i++) {
+ if (es[i] == null) {
return i;
+ }
+ }
} else {
- for (int i = 0; i < size; i++)
- if (o.equals(elementData[i]))
+ for (int i = start; i < end; i++) {
+ if (o.equals(es[i])) {
return i;
+ }
+ }
}
return -1;
}
@@ -337,28 +345,37 @@ public int indexOf(Object o) {
/**
* Returns the index of the last occurrence of the specified element
* in this list, or -1 if this list does not contain the element.
- * More formally, returns the highest index i such that
- * (o==null ? get(i)==null : o.equals(get(i))) ,
+ * More formally, returns the highest index {@code i} such that
+ * {@code Objects.equals(o, get(i))},
* or -1 if there is no such index.
*/
public int lastIndexOf(Object o) {
+ return lastIndexOfRange(o, 0, size);
+ }
+
+ int lastIndexOfRange(Object o, int start, int end) {
+ Object[] es = elementData;
if (o == null) {
- for (int i = size-1; i >= 0; i--)
- if (elementData[i]==null)
+ for (int i = end - 1; i >= start; i--) {
+ if (es[i] == null) {
return i;
+ }
+ }
} else {
- for (int i = size-1; i >= 0; i--)
- if (o.equals(elementData[i]))
+ for (int i = end - 1; i >= start; i--) {
+ if (o.equals(es[i])) {
return i;
+ }
+ }
}
return -1;
}
/**
- * Returns a shallow copy of this ArrayList instance. (The
+ * Returns a shallow copy of this {@code ArrayList} instance. (The
* elements themselves are not copied.)
*
- * @return a clone of this ArrayList instance
+ * @return a clone of this {@code ArrayList} instance
*/
public Object clone() {
try {
@@ -401,7 +418,7 @@ public Object[] toArray() {
* If the list fits in the specified array with room to spare
* (i.e., the array has more elements than the list), the element in
* the array immediately following the end of the collection is set to
- * null . (This is useful in determining the length of the
+ * {@code null}. (This is useful in determining the length of the
* list only if the caller knows that the list does not contain
* any null elements.)
*
@@ -425,6 +442,18 @@ public T[] toArray(T[] a) {
return a;
}
+ // Positional Access Operations
+
+ @SuppressWarnings("unchecked")
+ E elementData(int index) {
+ return (E) elementData[index];
+ }
+
+ @SuppressWarnings("unchecked")
+ static E elementAt(Object[] es, int index) {
+ return (E) es[index];
+ }
+
/**
* Returns the element at the specified position in this list.
*
@@ -433,10 +462,8 @@ public T[] toArray(T[] a) {
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
public E get(int index) {
- if (index >= size)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
-
- return (E) elementData[index];
+ Objects.checkIndex(index, size);
+ return elementData(index);
}
/**
@@ -449,23 +476,33 @@ public E get(int index) {
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
public E set(int index, E element) {
- if (index >= size)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
-
- E oldValue = (E) elementData[index];
+ Objects.checkIndex(index, size);
+ E oldValue = elementData(index);
elementData[index] = element;
return oldValue;
}
+ /**
+ * This helper method split out from add(E) to keep method
+ * bytecode size under 35 (the -XX:MaxInlineSize default value),
+ * which helps when add(E) is called in a C1-compiled loop.
+ */
+ private void add(E e, Object[] elementData, int s) {
+ if (s == elementData.length)
+ elementData = grow();
+ elementData[s] = e;
+ size = s + 1;
+ }
+
/**
* Appends the specified element to the end of this list.
*
* @param e element to be appended to this list
- * @return true (as specified by {@link Collection#add})
+ * @return {@code true} (as specified by {@link Collection#add})
*/
public boolean add(E e) {
- ensureCapacityInternal(size + 1); // Increments modCount!!
- elementData[size++] = e;
+ modCount++;
+ add(e, elementData, size);
return true;
}
@@ -479,14 +516,17 @@ public boolean add(E e) {
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
public void add(int index, E element) {
- if (index > size || index < 0)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
-
- ensureCapacityInternal(size + 1); // Increments modCount!!
- System.arraycopy(elementData, index, elementData, index + 1,
- size - index);
+ rangeCheckForAdd(index);
+ modCount++;
+ final int s;
+ Object[] elementData;
+ if ((s = size) == (elementData = this.elementData).length)
+ elementData = grow();
+ System.arraycopy(elementData, index,
+ elementData, index + 1,
+ s - index);
elementData[index] = element;
- size++;
+ size = s + 1;
}
/**
@@ -499,62 +539,145 @@ public void add(int index, E element) {
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
public E remove(int index) {
- if (index >= size)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
+ Objects.checkIndex(index, size);
+ final Object[] es = elementData;
- modCount++;
- E oldValue = (E) elementData[index];
-
- int numMoved = size - index - 1;
- if (numMoved > 0)
- System.arraycopy(elementData, index+1, elementData, index,
- numMoved);
- elementData[--size] = null; // clear to let GC do its work
+ @SuppressWarnings("unchecked") E oldValue = (E) es[index];
+ fastRemove(es, index);
return oldValue;
}
+ /**
+ * {@inheritDoc}
+ */
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ }
+
+ if (!(o instanceof List)) {
+ return false;
+ }
+
+ final int expectedModCount = modCount;
+ // ArrayList can be subclassed and given arbitrary behavior, but we can
+ // still deal with the common case where o is ArrayList precisely
+ boolean equal = (o.getClass() == ArrayList.class)
+ ? equalsArrayList((ArrayList>) o)
+ : equalsRange((List>) o, 0, size);
+
+ checkForComodification(expectedModCount);
+ return equal;
+ }
+
+ boolean equalsRange(List> other, int from, int to) {
+ final Object[] es = elementData;
+ if (to > es.length) {
+ throw new ConcurrentModificationException();
+ }
+ var oit = other.iterator();
+ for (; from < to; from++) {
+ if (!oit.hasNext() || !Objects.equals(es[from], oit.next())) {
+ return false;
+ }
+ }
+ return !oit.hasNext();
+ }
+
+ private boolean equalsArrayList(ArrayList> other) {
+ final int otherModCount = other.modCount;
+ final int s = size;
+ boolean equal;
+ if (equal = (s == other.size)) {
+ final Object[] otherEs = other.elementData;
+ final Object[] es = elementData;
+ if (s > es.length || s > otherEs.length) {
+ throw new ConcurrentModificationException();
+ }
+ for (int i = 0; i < s; i++) {
+ if (!Objects.equals(es[i], otherEs[i])) {
+ equal = false;
+ break;
+ }
+ }
+ }
+ other.checkForComodification(otherModCount);
+ return equal;
+ }
+
+ private void checkForComodification(final int expectedModCount) {
+ if (modCount != expectedModCount) {
+ throw new ConcurrentModificationException();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int hashCode() {
+ int expectedModCount = modCount;
+ int hash = hashCodeRange(0, size);
+ checkForComodification(expectedModCount);
+ return hash;
+ }
+
+ int hashCodeRange(int from, int to) {
+ final Object[] es = elementData;
+ if (to > es.length) {
+ throw new ConcurrentModificationException();
+ }
+ int hashCode = 1;
+ for (int i = from; i < to; i++) {
+ Object e = es[i];
+ hashCode = 31 * hashCode + (e == null ? 0 : e.hashCode());
+ }
+ return hashCode;
+ }
+
/**
* Removes the first occurrence of the specified element from this list,
* if it is present. If the list does not contain the element, it is
* unchanged. More formally, removes the element with the lowest index
- * i such that
- * (o==null ? get(i)==null : o.equals(get(i)))
- * (if such an element exists). Returns true if this list
+ * {@code i} such that
+ * {@code Objects.equals(o, get(i))}
+ * (if such an element exists). Returns {@code true} if this list
* contained the specified element (or equivalently, if this list
* changed as a result of the call).
*
* @param o element to be removed from this list, if present
- * @return true if this list contained the specified element
+ * @return {@code true} if this list contained the specified element
*/
public boolean remove(Object o) {
- if (o == null) {
- for (int index = 0; index < size; index++)
- if (elementData[index] == null) {
- fastRemove(index);
- return true;
- }
- } else {
- for (int index = 0; index < size; index++)
- if (o.equals(elementData[index])) {
- fastRemove(index);
- return true;
- }
+ final Object[] es = elementData;
+ final int size = this.size;
+ int i = 0;
+ found: {
+ if (o == null) {
+ for (; i < size; i++)
+ if (es[i] == null)
+ break found;
+ } else {
+ for (; i < size; i++)
+ if (o.equals(es[i]))
+ break found;
+ }
+ return false;
}
- return false;
+ fastRemove(es, i);
+ return true;
}
- /*
+ /**
* Private remove method that skips bounds checking and does not
* return the value removed.
*/
- private void fastRemove(int index) {
+ private void fastRemove(Object[] es, int i) {
modCount++;
- int numMoved = size - index - 1;
- if (numMoved > 0)
- System.arraycopy(elementData, index+1, elementData, index,
- numMoved);
- elementData[--size] = null; // clear to let GC do its work
+ final int newSize;
+ if ((newSize = size - 1) > i)
+ System.arraycopy(es, i + 1, es, i, newSize - i);
+ es[size = newSize] = null;
}
/**
@@ -563,12 +686,9 @@ private void fastRemove(int index) {
*/
public void clear() {
modCount++;
-
- // clear to let GC do its work
- for (int i = 0; i < size; i++)
- elementData[i] = null;
-
- size = 0;
+ final Object[] es = elementData;
+ for (int to = size, i = size = 0; i < to; i++)
+ es[i] = null;
}
/**
@@ -581,16 +701,22 @@ public void clear() {
* list is nonempty.)
*
* @param c collection containing elements to be added to this list
- * @return true if this list changed as a result of the call
+ * @return {@code true} if this list changed as a result of the call
* @throws NullPointerException if the specified collection is null
*/
public boolean addAll(Collection extends E> c) {
Object[] a = c.toArray();
+ modCount++;
int numNew = a.length;
- ensureCapacityInternal(size + numNew); // Increments modCount
- System.arraycopy(a, 0, elementData, size, numNew);
- size += numNew;
- return numNew != 0;
+ if (numNew == 0)
+ return false;
+ Object[] elementData;
+ final int s;
+ if (numNew > (elementData = this.elementData).length - (s = size))
+ elementData = grow(s + numNew);
+ System.arraycopy(a, 0, elementData, s, numNew);
+ size = s + numNew;
+ return true;
}
/**
@@ -604,26 +730,31 @@ public boolean addAll(Collection extends E> c) {
* @param index index at which to insert the first element from the
* specified collection
* @param c collection containing elements to be added to this list
- * @return true if this list changed as a result of the call
+ * @return {@code true} if this list changed as a result of the call
* @throws IndexOutOfBoundsException {@inheritDoc}
* @throws NullPointerException if the specified collection is null
*/
public boolean addAll(int index, Collection extends E> c) {
- if (index > size || index < 0)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
+ rangeCheckForAdd(index);
Object[] a = c.toArray();
+ modCount++;
int numNew = a.length;
- ensureCapacityInternal(size + numNew); // Increments modCount
+ if (numNew == 0)
+ return false;
+ Object[] elementData;
+ final int s;
+ if (numNew > (elementData = this.elementData).length - (s = size))
+ elementData = grow(s + numNew);
- int numMoved = size - index;
+ int numMoved = s - index;
if (numMoved > 0)
- System.arraycopy(elementData, index, elementData, index + numNew,
+ System.arraycopy(elementData, index,
+ elementData, index + numNew,
numMoved);
-
System.arraycopy(a, 0, elementData, index, numNew);
- size += numNew;
- return numNew != 0;
+ size = s + numNew;
+ return true;
}
/**
@@ -636,29 +767,31 @@ public boolean addAll(int index, Collection extends E> c) {
* @throws IndexOutOfBoundsException if {@code fromIndex} or
* {@code toIndex} is out of range
* ({@code fromIndex < 0 ||
- * fromIndex >= size() ||
* toIndex > size() ||
* toIndex < fromIndex})
*/
protected void removeRange(int fromIndex, int toIndex) {
- // Android-changed: Throw an IOOBE if toIndex < fromIndex as documented.
- // All the other cases (negative indices, or indices greater than the size
- // will be thrown by System#arrayCopy.
- if (toIndex < fromIndex) {
- throw new IndexOutOfBoundsException("toIndex < fromIndex");
+ if (fromIndex > toIndex) {
+ throw new IndexOutOfBoundsException(
+ outOfBoundsMsg(fromIndex, toIndex));
}
-
modCount++;
- int numMoved = size - toIndex;
- System.arraycopy(elementData, toIndex, elementData, fromIndex,
- numMoved);
+ shiftTailOverGap(elementData, fromIndex, toIndex);
+ }
- // clear to let GC do its work
- int newSize = size - (toIndex-fromIndex);
- for (int i = newSize; i < size; i++) {
- elementData[i] = null;
- }
- size = newSize;
+ /** Erases the gap from lo to hi, by sliding down following elements. */
+ private void shiftTailOverGap(Object[] es, int lo, int hi) {
+ System.arraycopy(es, hi, es, lo, size - hi);
+ for (int to = size, i = (size -= hi - lo); i < to; i++)
+ es[i] = null;
+ }
+
+ /**
+ * A version of rangeCheck used by add and addAll.
+ */
+ private void rangeCheckForAdd(int index) {
+ if (index > size || index < 0)
+ throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
}
/**
@@ -670,6 +803,13 @@ private String outOfBoundsMsg(int index) {
return "Index: "+index+", Size: "+size;
}
+ /**
+ * A version used in checking (fromIndex > toIndex) condition
+ */
+ private static String outOfBoundsMsg(int fromIndex, int toIndex) {
+ return "From Index: " + fromIndex + " > To Index: " + toIndex;
+ }
+
/**
* Removes from this list all of its elements that are contained in the
* specified collection.
@@ -686,8 +826,7 @@ private String outOfBoundsMsg(int index) {
* @see Collection#contains(Object)
*/
public boolean removeAll(Collection> c) {
- Objects.requireNonNull(c);
- return batchRemove(c, false);
+ return batchRemove(c, false, 0, size);
}
/**
@@ -707,54 +846,56 @@ public boolean removeAll(Collection> c) {
* @see Collection#contains(Object)
*/
public boolean retainAll(Collection> c) {
- Objects.requireNonNull(c);
- return batchRemove(c, true);
+ return batchRemove(c, true, 0, size);
}
- private boolean batchRemove(Collection> c, boolean complement) {
- final Object[] elementData = this.elementData;
- int r = 0, w = 0;
- boolean modified = false;
+ boolean batchRemove(Collection> c, boolean complement,
+ final int from, final int end) {
+ Objects.requireNonNull(c);
+ final Object[] es = elementData;
+ int r;
+ // Optimize for initial run of survivors
+ for (r = from;; r++) {
+ if (r == end)
+ return false;
+ if (c.contains(es[r]) != complement)
+ break;
+ }
+ int w = r++;
try {
- for (; r < size; r++)
- if (c.contains(elementData[r]) == complement)
- elementData[w++] = elementData[r];
- } finally {
+ for (Object e; r < end; r++)
+ if (c.contains(e = es[r]) == complement)
+ es[w++] = e;
+ } catch (Throwable ex) {
// Preserve behavioral compatibility with AbstractCollection,
// even if c.contains() throws.
- if (r != size) {
- System.arraycopy(elementData, r,
- elementData, w,
- size - r);
- w += size - r;
- }
- if (w != size) {
- // clear to let GC do its work
- for (int i = w; i < size; i++)
- elementData[i] = null;
- modCount += size - w;
- size = w;
- modified = true;
- }
+ System.arraycopy(es, r, es, w, end - r);
+ w += end - r;
+ throw ex;
+ } finally {
+ modCount += end - w;
+ shiftTailOverGap(es, w, end);
}
- return modified;
+ return true;
}
/**
- * Save the state of the ArrayList instance to a stream (that
- * is, serialize it).
+ * Saves the state of the {@code ArrayList} instance to a stream
+ * (that is, serializes it).
*
- * @serialData The length of the array backing the ArrayList
+ * @param s the stream
+ * @throws java.io.IOException if an I/O error occurs
+ * @serialData The length of the array backing the {@code ArrayList}
* instance is emitted (int), followed by all of its elements
- * (each an Object ) in the proper order.
+ * (each an {@code Object}) in the proper order.
*/
private void writeObject(java.io.ObjectOutputStream s)
- throws java.io.IOException{
+ throws java.io.IOException {
// Write out element count, and any hidden stuff
int expectedModCount = modCount;
s.defaultWriteObject();
- // Write out size as capacity for behavioural compatibility with clone()
+ // Write out size as capacity for behavioral compatibility with clone()
s.writeInt(size);
// Write out all elements in the proper order.
@@ -768,12 +909,15 @@ private void writeObject(java.io.ObjectOutputStream s)
}
/**
- * Reconstitute the ArrayList instance from a stream (that is,
- * deserialize it).
+ * Reconstitutes the {@code ArrayList} instance from a stream (that is,
+ * deserializes it).
+ * @param s the stream
+ * @throws ClassNotFoundException if the class of a serialized object
+ * could not be found
+ * @throws java.io.IOException if an I/O error occurs
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
- elementData = EMPTY_ELEMENTDATA;
// Read in size, and any hidden stuff
s.defaultReadObject();
@@ -782,14 +926,21 @@ private void readObject(java.io.ObjectInputStream s)
s.readInt(); // ignored
if (size > 0) {
- // be like clone(), allocate array based upon size not capacity
- ensureCapacityInternal(size);
+ // like clone(), allocate array based upon size not capacity
+ // TODO(b/287571490): Reimplement code with dependencies outside of the core JRE subset
+ // sun.misc.SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, size);
+ Object[] elements = new Object[size];
- Object[] a = elementData;
// Read in all elements in the proper order.
- for (int i=0; i listIterator(int index) {
- if (index < 0 || index > size)
- throw new IndexOutOfBoundsException("Index: "+index);
+ rangeCheckForAdd(index);
return new ListItr(index);
}
@@ -850,14 +1000,16 @@ private class Itr implements Iterator {
int lastRet = -1; // index of last element returned; -1 if no such
int expectedModCount = modCount;
+ // prevent creating a synthetic constructor
+ Itr() {}
+
public boolean hasNext() {
return cursor < limit;
}
@SuppressWarnings("unchecked")
public E next() {
- if (modCount != expectedModCount)
- throw new ConcurrentModificationException();
+ checkForComodification();
int i = cursor;
if (i >= limit)
throw new NoSuchElementException();
@@ -871,8 +1023,7 @@ public E next() {
public void remove() {
if (lastRet < 0)
throw new IllegalStateException();
- if (modCount != expectedModCount)
- throw new ConcurrentModificationException();
+ checkForComodification();
try {
ArrayList.this.remove(lastRet);
@@ -886,25 +1037,24 @@ public void remove() {
}
@Override
- @SuppressWarnings("unchecked")
- public void forEachRemaining(Consumer super E> consumer) {
- Objects.requireNonNull(consumer);
+ public void forEachRemaining(Consumer super E> action) {
+ Objects.requireNonNull(action);
final int size = ArrayList.this.size;
int i = cursor;
- if (i >= size) {
- return;
- }
- final Object[] elementData = ArrayList.this.elementData;
- if (i >= elementData.length) {
- throw new ConcurrentModificationException();
- }
- while (i != size && modCount == expectedModCount) {
- consumer.accept((E) elementData[i++]);
+ if (i < size) {
+ final Object[] es = elementData;
+ if (i >= es.length)
+ throw new ConcurrentModificationException();
+ for (; i < size && modCount == expectedModCount; i++)
+ action.accept(elementAt(es, i));
+ // update once at end to reduce heap write traffic
+ cursor = i;
+ lastRet = i - 1;
+ checkForComodification();
}
- // update once at end of iteration to reduce heap write traffic
- cursor = i;
- lastRet = i - 1;
+ }
+ final void checkForComodification() {
if (modCount != expectedModCount)
throw new ConcurrentModificationException();
}
@@ -933,8 +1083,7 @@ public int previousIndex() {
@SuppressWarnings("unchecked")
public E previous() {
- if (modCount != expectedModCount)
- throw new ConcurrentModificationException();
+ checkForComodification();
int i = cursor - 1;
if (i < 0)
throw new NoSuchElementException();
@@ -948,8 +1097,7 @@ public E previous() {
public void set(E e) {
if (lastRet < 0)
throw new IllegalStateException();
- if (modCount != expectedModCount)
- throw new ConcurrentModificationException();
+ checkForComodification();
try {
ArrayList.this.set(lastRet, e);
@@ -959,8 +1107,7 @@ public void set(E e) {
}
public void add(E e) {
- if (modCount != expectedModCount)
- throw new ConcurrentModificationException();
+ checkForComodification();
try {
int i = cursor;
@@ -1006,86 +1153,75 @@ public void add(E e) {
*/
public List subList(int fromIndex, int toIndex) {
subListRangeCheck(fromIndex, toIndex, size);
- return new SubList(this, 0, fromIndex, toIndex);
+ return new SubList<>(this, fromIndex, toIndex);
}
- static void subListRangeCheck(int fromIndex, int toIndex, int size) {
- if (fromIndex < 0)
- throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
- if (toIndex > size)
- throw new IndexOutOfBoundsException("toIndex = " + toIndex);
- if (fromIndex > toIndex)
- throw new IllegalArgumentException("fromIndex(" + fromIndex +
- ") > toIndex(" + toIndex + ")");
- }
-
- private class SubList extends AbstractList implements RandomAccess {
- private final AbstractList parent;
- private final int parentOffset;
+ private static class SubList extends AbstractList implements RandomAccess {
+ private final ArrayList root;
+ private final SubList parent;
private final int offset;
- int size;
+ private int size;
+
+ /**
+ * Constructs a sublist of an arbitrary ArrayList.
+ */
+ public SubList(ArrayList root, int fromIndex, int toIndex) {
+ this.root = root;
+ this.parent = null;
+ this.offset = fromIndex;
+ this.size = toIndex - fromIndex;
+ this.modCount = root.modCount;
+ }
- SubList(AbstractList parent,
- int offset, int fromIndex, int toIndex) {
+ /**
+ * Constructs a sublist of another SubList.
+ */
+ private SubList(SubList parent, int fromIndex, int toIndex) {
+ this.root = parent.root;
this.parent = parent;
- this.parentOffset = fromIndex;
- this.offset = offset + fromIndex;
+ this.offset = parent.offset + fromIndex;
this.size = toIndex - fromIndex;
- this.modCount = ArrayList.this.modCount;
+ this.modCount = parent.modCount;
}
- public E set(int index, E e) {
- if (index < 0 || index >= this.size)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
- if (ArrayList.this.modCount != this.modCount)
- throw new ConcurrentModificationException();
- E oldValue = (E) ArrayList.this.elementData[offset + index];
- ArrayList.this.elementData[offset + index] = e;
+ public E set(int index, E element) {
+ Objects.checkIndex(index, size);
+ checkForComodification();
+ E oldValue = root.elementData(offset + index);
+ root.elementData[offset + index] = element;
return oldValue;
}
public E get(int index) {
- if (index < 0 || index >= this.size)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
- if (ArrayList.this.modCount != this.modCount)
- throw new ConcurrentModificationException();
- return (E) ArrayList.this.elementData[offset + index];
+ Objects.checkIndex(index, size);
+ checkForComodification();
+ return root.elementData(offset + index);
}
public int size() {
- if (ArrayList.this.modCount != this.modCount)
- throw new ConcurrentModificationException();
- return this.size;
+ checkForComodification();
+ return size;
}
- public void add(int index, E e) {
- if (index < 0 || index > this.size)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
- if (ArrayList.this.modCount != this.modCount)
- throw new ConcurrentModificationException();
- parent.add(parentOffset + index, e);
- this.modCount = parent.modCount;
- this.size++;
+ public void add(int index, E element) {
+ rangeCheckForAdd(index);
+ checkForComodification();
+ root.add(offset + index, element);
+ updateSizeAndModCount(1);
}
public E remove(int index) {
- if (index < 0 || index >= this.size)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
- if (ArrayList.this.modCount != this.modCount)
- throw new ConcurrentModificationException();
- E result = parent.remove(parentOffset + index);
- this.modCount = parent.modCount;
- this.size--;
+ Objects.checkIndex(index, size);
+ checkForComodification();
+ E result = root.remove(offset + index);
+ updateSizeAndModCount(-1);
return result;
}
protected void removeRange(int fromIndex, int toIndex) {
- if (ArrayList.this.modCount != this.modCount)
- throw new ConcurrentModificationException();
- parent.removeRange(parentOffset + fromIndex,
- parentOffset + toIndex);
- this.modCount = parent.modCount;
- this.size -= toIndex - fromIndex;
+ checkForComodification();
+ root.removeRange(offset + fromIndex, offset + toIndex);
+ updateSizeAndModCount(fromIndex - toIndex);
}
public boolean addAll(Collection extends E> c) {
@@ -1093,35 +1229,112 @@ public boolean addAll(Collection extends E> c) {
}
public boolean addAll(int index, Collection extends E> c) {
- if (index < 0 || index > this.size)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
+ rangeCheckForAdd(index);
int cSize = c.size();
if (cSize==0)
return false;
-
- if (ArrayList.this.modCount != this.modCount)
- throw new ConcurrentModificationException();
- parent.addAll(parentOffset + index, c);
- this.modCount = parent.modCount;
- this.size += cSize;
+ checkForComodification();
+ root.addAll(offset + index, c);
+ updateSizeAndModCount(cSize);
return true;
}
+ public void replaceAll(UnaryOperator operator) {
+ root.replaceAllRange(operator, offset, offset + size);
+ }
+
+ public boolean removeAll(Collection> c) {
+ return batchRemove(c, false);
+ }
+
+ public boolean retainAll(Collection> c) {
+ return batchRemove(c, true);
+ }
+
+ private boolean batchRemove(Collection> c, boolean complement) {
+ checkForComodification();
+ int oldSize = root.size;
+ boolean modified =
+ root.batchRemove(c, complement, offset, offset + size);
+ if (modified)
+ updateSizeAndModCount(root.size - oldSize);
+ return modified;
+ }
+
+ public boolean removeIf(Predicate super E> filter) {
+ checkForComodification();
+ int oldSize = root.size;
+ boolean modified = root.removeIf(filter, offset, offset + size);
+ if (modified)
+ updateSizeAndModCount(root.size - oldSize);
+ return modified;
+ }
+
+ public Object[] toArray() {
+ checkForComodification();
+ return Arrays.copyOfRange(root.elementData, offset, offset + size);
+ }
+
+ @SuppressWarnings("unchecked")
+ public T[] toArray(T[] a) {
+ checkForComodification();
+ if (a.length < size)
+ return (T[]) Arrays.copyOfRange(
+ root.elementData, offset, offset + size, a.getClass());
+ System.arraycopy(root.elementData, offset, a, 0, size);
+ if (a.length > size)
+ a[size] = null;
+ return a;
+ }
+
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ }
+
+ if (!(o instanceof List)) {
+ return false;
+ }
+
+ boolean equal = root.equalsRange((List>)o, offset, offset + size);
+ checkForComodification();
+ return equal;
+ }
+
+ public int hashCode() {
+ int hash = root.hashCodeRange(offset, offset + size);
+ checkForComodification();
+ return hash;
+ }
+
+ public int indexOf(Object o) {
+ int index = root.indexOfRange(o, offset, offset + size);
+ checkForComodification();
+ return index >= 0 ? index - offset : -1;
+ }
+
+ public int lastIndexOf(Object o) {
+ int index = root.lastIndexOfRange(o, offset, offset + size);
+ checkForComodification();
+ return index >= 0 ? index - offset : -1;
+ }
+
+ public boolean contains(Object o) {
+ return indexOf(o) >= 0;
+ }
+
public Iterator iterator() {
return listIterator();
}
- public ListIterator listIterator(final int index) {
- if (ArrayList.this.modCount != this.modCount)
- throw new ConcurrentModificationException();
- if (index < 0 || index > this.size)
- throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
- final int offset = this.offset;
+ public ListIterator listIterator(int index) {
+ checkForComodification();
+ rangeCheckForAdd(index);
return new ListIterator() {
int cursor = index;
int lastRet = -1;
- int expectedModCount = ArrayList.this.modCount;
+ int expectedModCount = SubList.this.modCount;
public boolean hasNext() {
return cursor != SubList.this.size;
@@ -1129,12 +1342,11 @@ public boolean hasNext() {
@SuppressWarnings("unchecked")
public E next() {
- if (expectedModCount != ArrayList.this.modCount)
- throw new ConcurrentModificationException();
+ checkForComodification();
int i = cursor;
if (i >= SubList.this.size)
throw new NoSuchElementException();
- Object[] elementData = ArrayList.this.elementData;
+ Object[] elementData = root.elementData;
if (offset + i >= elementData.length)
throw new ConcurrentModificationException();
cursor = i + 1;
@@ -1147,37 +1359,32 @@ public boolean hasPrevious() {
@SuppressWarnings("unchecked")
public E previous() {
- if (expectedModCount != ArrayList.this.modCount)
- throw new ConcurrentModificationException();
+ checkForComodification();
int i = cursor - 1;
if (i < 0)
throw new NoSuchElementException();
- Object[] elementData = ArrayList.this.elementData;
+ Object[] elementData = root.elementData;
if (offset + i >= elementData.length)
throw new ConcurrentModificationException();
cursor = i;
return (E) elementData[offset + (lastRet = i)];
}
- @SuppressWarnings("unchecked")
- public void forEachRemaining(Consumer super E> consumer) {
- Objects.requireNonNull(consumer);
+ public void forEachRemaining(Consumer super E> action) {
+ Objects.requireNonNull(action);
final int size = SubList.this.size;
int i = cursor;
- if (i >= size) {
- return;
- }
- final Object[] elementData = ArrayList.this.elementData;
- if (offset + i >= elementData.length) {
- throw new ConcurrentModificationException();
+ if (i < size) {
+ final Object[] es = root.elementData;
+ if (offset + i >= es.length)
+ throw new ConcurrentModificationException();
+ for (; i < size && root.modCount == expectedModCount; i++)
+ action.accept(elementAt(es, offset + i));
+ // update once at end to reduce heap write traffic
+ cursor = i;
+ lastRet = i - 1;
+ checkForComodification();
}
- while (i != size && modCount == expectedModCount) {
- consumer.accept((E) elementData[offset + (i++)]);
- }
- // update once at end of iteration to reduce heap write traffic
- lastRet = cursor = i;
- if (expectedModCount != ArrayList.this.modCount)
- throw new ConcurrentModificationException();
}
public int nextIndex() {
@@ -1191,14 +1398,13 @@ public int previousIndex() {
public void remove() {
if (lastRet < 0)
throw new IllegalStateException();
- if (expectedModCount != ArrayList.this.modCount)
- throw new ConcurrentModificationException();
+ checkForComodification();
try {
SubList.this.remove(lastRet);
cursor = lastRet;
lastRet = -1;
- expectedModCount = ArrayList.this.modCount;
+ expectedModCount = SubList.this.modCount;
} catch (IndexOutOfBoundsException ex) {
throw new ConcurrentModificationException();
}
@@ -1207,66 +1413,151 @@ public void remove() {
public void set(E e) {
if (lastRet < 0)
throw new IllegalStateException();
- if (expectedModCount != ArrayList.this.modCount)
- throw new ConcurrentModificationException();
+ checkForComodification();
try {
- ArrayList.this.set(offset + lastRet, e);
+ root.set(offset + lastRet, e);
} catch (IndexOutOfBoundsException ex) {
throw new ConcurrentModificationException();
}
}
public void add(E e) {
- if (expectedModCount != ArrayList.this.modCount)
- throw new ConcurrentModificationException();
+ checkForComodification();
try {
int i = cursor;
SubList.this.add(i, e);
cursor = i + 1;
lastRet = -1;
- expectedModCount = ArrayList.this.modCount;
+ expectedModCount = SubList.this.modCount;
} catch (IndexOutOfBoundsException ex) {
throw new ConcurrentModificationException();
}
}
+
+ final void checkForComodification() {
+ if (root.modCount != expectedModCount)
+ throw new ConcurrentModificationException();
+ }
};
}
public List subList(int fromIndex, int toIndex) {
subListRangeCheck(fromIndex, toIndex, size);
- return new SubList(this, offset, fromIndex, toIndex);
+ return new SubList<>(this, fromIndex, toIndex);
+ }
+
+ private void rangeCheckForAdd(int index) {
+ if (index < 0 || index > this.size)
+ throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
}
private String outOfBoundsMsg(int index) {
return "Index: "+index+", Size: "+this.size;
}
- public Spliterator spliterator() {
- if (modCount != ArrayList.this.modCount)
+ private void checkForComodification() {
+ if (root.modCount != modCount)
throw new ConcurrentModificationException();
- return new ArrayListSpliterator(ArrayList.this, offset,
- offset + this.size, this.modCount);
+ }
+
+ private void updateSizeAndModCount(int sizeChange) {
+ SubList slist = this;
+ do {
+ slist.size += sizeChange;
+ slist.modCount = root.modCount;
+ slist = slist.parent;
+ } while (slist != null);
+ }
+
+ public Spliterator spliterator() {
+ checkForComodification();
+
+ // ArrayListSpliterator not used here due to late-binding
+ return new Spliterator() {
+ private int index = offset; // current index, modified on advance/split
+ private int fence = -1; // -1 until used; then one past last index
+ private int expectedModCount; // initialized when fence set
+
+ private int getFence() { // initialize fence to size on first use
+ int hi; // (a specialized variant appears in method forEach)
+ if ((hi = fence) < 0) {
+ expectedModCount = modCount;
+ hi = fence = offset + size;
+ }
+ return hi;
+ }
+
+ public ArrayList.ArrayListSpliterator trySplit() {
+ int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
+ // ArrayListSpliterator can be used here as the source is already bound
+ return (lo >= mid) ? null : // divide range in half unless too small
+ root.new ArrayListSpliterator(lo, index = mid, expectedModCount);
+ }
+
+ public boolean tryAdvance(Consumer super E> action) {
+ Objects.requireNonNull(action);
+ int hi = getFence(), i = index;
+ if (i < hi) {
+ index = i + 1;
+ @SuppressWarnings("unchecked") E e = (E)root.elementData[i];
+ action.accept(e);
+ if (root.modCount != expectedModCount)
+ throw new ConcurrentModificationException();
+ return true;
+ }
+ return false;
+ }
+
+ public void forEachRemaining(Consumer super E> action) {
+ Objects.requireNonNull(action);
+ int i, hi, mc; // hoist accesses and checks from loop
+ ArrayList lst = root;
+ Object[] a;
+ if ((a = lst.elementData) != null) {
+ if ((hi = fence) < 0) {
+ mc = modCount;
+ hi = offset + size;
+ }
+ else
+ mc = expectedModCount;
+ if ((i = index) >= 0 && (index = hi) <= a.length) {
+ for (; i < hi; ++i) {
+ @SuppressWarnings("unchecked") E e = (E) a[i];
+ action.accept(e);
+ }
+ if (lst.modCount == mc)
+ return;
+ }
+ }
+ throw new ConcurrentModificationException();
+ }
+
+ public long estimateSize() {
+ return getFence() - index;
+ }
+
+ public int characteristics() {
+ return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED;
+ }
+ };
}
}
+ /**
+ * @throws NullPointerException {@inheritDoc}
+ */
@Override
public void forEach(Consumer super E> action) {
Objects.requireNonNull(action);
final int expectedModCount = modCount;
- @SuppressWarnings("unchecked")
- final E[] elementData = (E[]) this.elementData;
+ final Object[] es = elementData;
final int size = this.size;
- for (int i=0; modCount == expectedModCount && i < size; i++) {
- action.accept(elementData[i]);
- }
- // Android-note:
- // Iterator will not throw a CME if we add something while iterating over the *last* element
- // forEach will throw a CME in this case.
- if (modCount != expectedModCount) {
+ for (int i = 0; modCount == expectedModCount && i < size; i++)
+ action.accept(elementAt(es, i));
+ if (modCount != expectedModCount)
throw new ConcurrentModificationException();
- }
}
/**
@@ -1284,11 +1575,11 @@ public void forEach(Consumer super E> action) {
*/
@Override
public Spliterator spliterator() {
- return new ArrayListSpliterator<>(this, 0, -1, 0);
+ return new ArrayListSpliterator(0, -1, 0);
}
/** Index-based split-by-two, lazily initialized Spliterator */
- static final class ArrayListSpliterator implements Spliterator {
+ final class ArrayListSpliterator implements Spliterator {
/*
* If ArrayLists were immutable, or structurally immutable (no
@@ -1322,15 +1613,12 @@ static final class ArrayListSpliterator implements Spliterator {
* these streamlinings.
*/
- private final ArrayList list;
private int index; // current index, modified on advance/split
private int fence; // -1 until used; then one past last index
private int expectedModCount; // initialized when fence set
- /** Create new spliterator covering the given range */
- ArrayListSpliterator(ArrayList list, int origin, int fence,
- int expectedModCount) {
- this.list = list; // OK if null unless traversed
+ /** Creates new spliterator covering the given range. */
+ ArrayListSpliterator(int origin, int fence, int expectedModCount) {
this.index = origin;
this.fence = fence;
this.expectedModCount = expectedModCount;
@@ -1338,23 +1626,17 @@ static final class ArrayListSpliterator implements Spliterator {
private int getFence() { // initialize fence to size on first use
int hi; // (a specialized variant appears in method forEach)
- ArrayList lst;
if ((hi = fence) < 0) {
- if ((lst = list) == null)
- hi = fence = 0;
- else {
- expectedModCount = lst.modCount;
- hi = fence = lst.size;
- }
+ expectedModCount = modCount;
+ hi = fence = size;
}
return hi;
}
- public ArrayListSpliterator trySplit() {
+ public ArrayListSpliterator trySplit() {
int hi = getFence(), lo = index, mid = (lo + hi) >>> 1;
return (lo >= mid) ? null : // divide range in half unless too small
- new ArrayListSpliterator(list, lo, index = mid,
- expectedModCount);
+ new ArrayListSpliterator(lo, index = mid, expectedModCount);
}
public boolean tryAdvance(Consumer super E> action) {
@@ -1363,9 +1645,9 @@ public boolean tryAdvance(Consumer super E> action) {
int hi = getFence(), i = index;
if (i < hi) {
index = i + 1;
- @SuppressWarnings("unchecked") E e = (E)list.elementData[i];
+ @SuppressWarnings("unchecked") E e = (E)elementData[i];
action.accept(e);
- if (list.modCount != expectedModCount)
+ if (modCount != expectedModCount)
throw new ConcurrentModificationException();
return true;
}
@@ -1374,13 +1656,13 @@ public boolean tryAdvance(Consumer super E> action) {
public void forEachRemaining(Consumer super E> action) {
int i, hi, mc; // hoist accesses and checks from loop
- ArrayList lst; Object[] a;
+ Object[] a;
if (action == null)
throw new NullPointerException();
- if ((lst = list) != null && (a = lst.elementData) != null) {
+ if ((a = elementData) != null) {
if ((hi = fence) < 0) {
- mc = lst.modCount;
- hi = lst.size;
+ mc = modCount;
+ hi = size;
}
else
mc = expectedModCount;
@@ -1389,7 +1671,7 @@ public void forEachRemaining(Consumer super E> action) {
@SuppressWarnings("unchecked") E e = (E) a[i];
action.accept(e);
}
- if (lst.modCount == mc)
+ if (modCount == mc)
return;
}
}
@@ -1397,7 +1679,7 @@ public void forEachRemaining(Consumer super E> action) {
}
public long estimateSize() {
- return (long) (getFence() - index);
+ return getFence() - index;
}
public int characteristics() {
@@ -1405,62 +1687,77 @@ public int characteristics() {
}
}
+ // A tiny bit set implementation
+
+ private static long[] nBits(int n) {
+ return new long[((n - 1) >> 6) + 1];
+ }
+ private static void setBit(long[] bits, int i) {
+ bits[i >> 6] |= 1L << i;
+ }
+ private static boolean isClear(long[] bits, int i) {
+ return (bits[i >> 6] & (1L << i)) == 0;
+ }
+
+ /**
+ * @throws NullPointerException {@inheritDoc}
+ */
@Override
public boolean removeIf(Predicate super E> filter) {
- Objects.requireNonNull(filter);
- // figure out which elements are to be removed
- // any exception thrown from the filter predicate at this stage
- // will leave the collection unmodified
- int removeCount = 0;
- final BitSet removeSet = new BitSet(size);
- final int expectedModCount = modCount;
- final int size = this.size;
- for (int i=0; modCount == expectedModCount && i < size; i++) {
- @SuppressWarnings("unchecked")
- final E element = (E) elementData[i];
- if (filter.test(element)) {
- removeSet.set(i);
- removeCount++;
- }
- }
- if (modCount != expectedModCount) {
- throw new ConcurrentModificationException();
- }
+ return removeIf(filter, 0, size);
+ }
- // shift surviving elements left over the spaces left by removed elements
- final boolean anyToRemove = removeCount > 0;
- if (anyToRemove) {
- final int newSize = size - removeCount;
- for (int i=0, j=0; (i < size) && (j < newSize); i++, j++) {
- i = removeSet.nextClearBit(i);
- elementData[j] = elementData[i];
- }
- for (int k=newSize; k < size; k++) {
- elementData[k] = null; // Let gc do its work
- }
- this.size = newSize;
- if (modCount != expectedModCount) {
+ /**
+ * Removes all elements satisfying the given predicate, from index
+ * i (inclusive) to index end (exclusive).
+ */
+ boolean removeIf(Predicate super E> filter, int i, final int end) {
+ Objects.requireNonNull(filter);
+ int expectedModCount = modCount;
+ final Object[] es = elementData;
+ // Optimize for initial run of survivors
+ for (; i < end && !filter.test(elementAt(es, i)); i++)
+ ;
+ // Tolerate predicates that reentrantly access the collection for
+ // read (but writers still get CME), so traverse once to find
+ // elements to delete, a second pass to physically expunge.
+ if (i < end) {
+ final int beg = i;
+ final long[] deathRow = nBits(end - beg);
+ deathRow[0] = 1L; // set bit 0
+ for (i = beg + 1; i < end; i++)
+ if (filter.test(elementAt(es, i)))
+ setBit(deathRow, i - beg);
+ if (modCount != expectedModCount)
throw new ConcurrentModificationException();
- }
modCount++;
+ int w = beg;
+ for (i = beg; i < end; i++)
+ if (isClear(deathRow, i - beg))
+ es[w++] = es[i];
+ shiftTailOverGap(es, w, end);
+ return true;
+ } else {
+ if (modCount != expectedModCount)
+ throw new ConcurrentModificationException();
+ return false;
}
-
- return anyToRemove;
}
@Override
- @SuppressWarnings("unchecked")
public void replaceAll(UnaryOperator operator) {
+ replaceAllRange(operator, 0, size);
+ modCount++;
+ }
+
+ private void replaceAllRange(UnaryOperator operator, int i, int end) {
Objects.requireNonNull(operator);
final int expectedModCount = modCount;
- final int size = this.size;
- for (int i=0; modCount == expectedModCount && i < size; i++) {
- elementData[i] = operator.apply((E) elementData[i]);
- }
- if (modCount != expectedModCount) {
+ final Object[] es = elementData;
+ for (; modCount == expectedModCount && i < end; i++)
+ es[i] = operator.apply(elementAt(es, i));
+ if (modCount != expectedModCount)
throw new ConcurrentModificationException();
- }
- modCount++;
}
@Override
@@ -1468,12 +1765,16 @@ public void replaceAll(UnaryOperator operator) {
public void sort(Comparator super E> c) {
final int expectedModCount = modCount;
Arrays.sort((E[]) elementData, 0, size, c);
- if (modCount != expectedModCount) {
+ if (modCount != expectedModCount)
throw new ConcurrentModificationException();
- }
modCount++;
}
+ void checkInvariants() {
+ // assert size >= 0;
+ // assert size == elementData.length || elementData[size] == null;
+ }
+
/*-[
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
objects:(__unsafe_unretained id *)stackbuf
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Arrays.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Arrays.java
index 8cd8aaf1e1..19770da14b 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Arrays.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Arrays.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 The Android Open Source Project
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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,6 +26,12 @@
package java.util;
+/* J2ObjC removed
+import jdk.internal.util.ArraysSupport;
+import jdk.internal.vm.annotation.IntrinsicCandidate;
+*/
+
+import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.concurrent.ForkJoinPool;
import java.util.function.BinaryOperator;
@@ -53,7 +59,7 @@
* if the specified array reference is null, except where noted.
*
* The documentation for the methods contained in this class includes
- * briefs description of the implementations . Such descriptions should
+ * brief descriptions of the implementations . Such descriptions should
* be regarded as implementation notes , rather than parts of the
* specification . Implementors should feel free to substitute other
* algorithms, so long as the specification itself is adhered to. (For
@@ -61,7 +67,7 @@
* a MergeSort, but it does have to be stable .)
*
*
This class is a member of the
- *
+ *
* Java Collections Framework .
*
* @author Josh Bloch
@@ -71,62 +77,12 @@
*/
public class Arrays {
- /**
- * The minimum array length below which a parallel sorting
- * algorithm will not further partition the sorting task. Using
- * smaller sizes typically results in memory contention across
- * tasks that makes parallel speedups unlikely.
- * @hide
- */
- // Android-changed: Make MIN_ARRAY_SORT_GRAN public and @hide (used by harmony ArraysTest).
- public static final int MIN_ARRAY_SORT_GRAN = 1 << 13;
-
// Suppresses default constructor, ensuring non-instantiability.
private Arrays() {}
- /**
- * A comparator that implements the natural ordering of a group of
- * mutually comparable elements. May be used when a supplied
- * comparator is null. To simplify code-sharing within underlying
- * implementations, the compare method only declares type Object
- * for its second argument.
- *
- * Arrays class implementor's note: It is an empirical matter
- * whether ComparableTimSort offers any performance benefit over
- * TimSort used with this comparator. If not, you are better off
- * deleting or bypassing ComparableTimSort. There is currently no
- * empirical case for separating them for parallel sorting, so all
- * public Object parallelSort methods use the same comparator
- * based implementation.
- */
- static final class NaturalOrder implements Comparator {
- @SuppressWarnings("unchecked")
- public int compare(Object first, Object second) {
- return ((Comparable)first).compareTo(second);
- }
- static final NaturalOrder INSTANCE = new NaturalOrder();
- }
-
- /**
- * Checks that {@code fromIndex} and {@code toIndex} are in
- * the range and throws an exception if they aren't.
- */
- private static void rangeCheck(int arrayLength, int fromIndex, int toIndex) {
- if (fromIndex > toIndex) {
- throw new IllegalArgumentException(
- "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
- }
- if (fromIndex < 0) {
- throw new ArrayIndexOutOfBoundsException(fromIndex);
- }
- if (toIndex > arrayLength) {
- throw new ArrayIndexOutOfBoundsException(toIndex);
- }
- }
-
/*
* Sorting methods. Note that all public "sort" methods take the
- * same form: Performing argument checks if necessary, and then
+ * same form: performing argument checks if necessary, and then
* expanding arguments into those required for the internal
* implementation methods residing in other package-private
* classes (except for legacyMergeSort, included in this class).
@@ -135,10 +91,9 @@ private static void rangeCheck(int arrayLength, int fromIndex, int toIndex) {
/**
* Sorts the specified array into ascending numerical order.
*
- * Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -153,10 +108,9 @@ public static void sort(int[] a) {
* the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
* the range to be sorted is empty.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -175,10 +129,9 @@ public static void sort(int[] a, int fromIndex, int toIndex) {
/**
* Sorts the specified array into ascending numerical order.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -193,10 +146,9 @@ public static void sort(long[] a) {
* the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
* the range to be sorted is empty.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -215,10 +167,9 @@ public static void sort(long[] a, int fromIndex, int toIndex) {
/**
* Sorts the specified array into ascending numerical order.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -233,10 +184,9 @@ public static void sort(short[] a) {
* the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
* the range to be sorted is empty.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -255,10 +205,9 @@ public static void sort(short[] a, int fromIndex, int toIndex) {
/**
* Sorts the specified array into ascending numerical order.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -273,10 +222,9 @@ public static void sort(char[] a) {
* the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
* the range to be sorted is empty.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -295,10 +243,9 @@ public static void sort(char[] a, int fromIndex, int toIndex) {
/**
* Sorts the specified array into ascending numerical order.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -313,10 +260,9 @@ public static void sort(byte[] a) {
* the index {@code toIndex}, exclusive. If {@code fromIndex == toIndex},
* the range to be sorted is empty.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -343,10 +289,9 @@ public static void sort(byte[] a, int fromIndex, int toIndex) {
* {@code 0.0f} and {@code Float.NaN} is considered greater than any
* other value and all {@code Float.NaN} values are considered equal.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -369,10 +314,9 @@ public static void sort(float[] a) {
* {@code 0.0f} and {@code Float.NaN} is considered greater than any
* other value and all {@code Float.NaN} values are considered equal.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -399,10 +343,9 @@ public static void sort(float[] a, int fromIndex, int toIndex) {
* {@code 0.0d} and {@code Double.NaN} is considered greater than any
* other value and all {@code Double.NaN} values are considered equal.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -425,10 +368,9 @@ public static void sort(double[] a) {
* {@code 0.0d} and {@code Double.NaN} is considered greater than any
* other value and all {@code Double.NaN} values are considered equal.
*
- *
Implementation note: The sorting algorithm is a Dual-Pivot Quicksort
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort
* by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm
- * offers O(n log(n)) performance on many data sets that cause other
- * quicksorts to degrade to quadratic performance, and is typically
+ * offers O(n log(n)) performance on all data sets, and is typically
* faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
@@ -447,16 +389,10 @@ public static void sort(double[] a, int fromIndex, int toIndex) {
/**
* Sorts the specified array into ascending numerical order.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(byte[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(byte[]) Arrays.sort} method. The algorithm requires a
- * working space no greater than the size of the original array. The
- * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
- * execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
*
@@ -480,16 +416,10 @@ public static void parallelSort(byte[] a) {
* inclusive, to the index {@code toIndex}, exclusive. If
* {@code fromIndex == toIndex}, the range to be sorted is empty.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(byte[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(byte[]) Arrays.sort} method. The algorithm requires a working
- * space no greater than the size of the specified range of the original
- * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
- * used to execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
* @param fromIndex the index of the first element, inclusive, to be sorted
@@ -517,16 +447,10 @@ public static void parallelSort(byte[] a, int fromIndex, int toIndex) {
/**
* Sorts the specified array into ascending numerical order.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(char[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(char[]) Arrays.sort} method. The algorithm requires a
- * working space no greater than the size of the original array. The
- * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
- * execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
*
@@ -550,16 +474,10 @@ public static void parallelSort(char[] a) {
* inclusive, to the index {@code toIndex}, exclusive. If
* {@code fromIndex == toIndex}, the range to be sorted is empty.
*
- @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(char[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(char[]) Arrays.sort} method. The algorithm requires a working
- * space no greater than the size of the specified range of the original
- * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
- * used to execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
* @param fromIndex the index of the first element, inclusive, to be sorted
@@ -587,16 +505,10 @@ public static void parallelSort(char[] a, int fromIndex, int toIndex) {
/**
* Sorts the specified array into ascending numerical order.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(short[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(short[]) Arrays.sort} method. The algorithm requires a
- * working space no greater than the size of the original array. The
- * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
- * execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
*
@@ -620,16 +532,10 @@ public static void parallelSort(short[] a) {
* inclusive, to the index {@code toIndex}, exclusive. If
* {@code fromIndex == toIndex}, the range to be sorted is empty.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(short[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(short[]) Arrays.sort} method. The algorithm requires a working
- * space no greater than the size of the specified range of the original
- * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
- * used to execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
* @param fromIndex the index of the first element, inclusive, to be sorted
@@ -657,16 +563,10 @@ public static void parallelSort(short[] a, int fromIndex, int toIndex) {
/**
* Sorts the specified array into ascending numerical order.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(int[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(int[]) Arrays.sort} method. The algorithm requires a
- * working space no greater than the size of the original array. The
- * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
- * execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
*
@@ -690,16 +590,10 @@ public static void parallelSort(int[] a) {
* inclusive, to the index {@code toIndex}, exclusive. If
* {@code fromIndex == toIndex}, the range to be sorted is empty.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(int[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(int[]) Arrays.sort} method. The algorithm requires a working
- * space no greater than the size of the specified range of the original
- * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
- * used to execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
* @param fromIndex the index of the first element, inclusive, to be sorted
@@ -727,16 +621,10 @@ public static void parallelSort(int[] a, int fromIndex, int toIndex) {
/**
* Sorts the specified array into ascending numerical order.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(long[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(long[]) Arrays.sort} method. The algorithm requires a
- * working space no greater than the size of the original array. The
- * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
- * execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
*
@@ -760,16 +648,10 @@ public static void parallelSort(long[] a) {
* inclusive, to the index {@code toIndex}, exclusive. If
* {@code fromIndex == toIndex}, the range to be sorted is empty.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(long[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(long[]) Arrays.sort} method. The algorithm requires a working
- * space no greater than the size of the specified range of the original
- * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
- * used to execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
* @param fromIndex the index of the first element, inclusive, to be sorted
@@ -805,16 +687,10 @@ public static void parallelSort(long[] a, int fromIndex, int toIndex) {
* {@code 0.0f} and {@code Float.NaN} is considered greater than any
* other value and all {@code Float.NaN} values are considered equal.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(float[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(float[]) Arrays.sort} method. The algorithm requires a
- * working space no greater than the size of the original array. The
- * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
- * execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
*
@@ -846,16 +722,10 @@ public static void parallelSort(float[] a) {
* {@code 0.0f} and {@code Float.NaN} is considered greater than any
* other value and all {@code Float.NaN} values are considered equal.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(float[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(float[]) Arrays.sort} method. The algorithm requires a working
- * space no greater than the size of the specified range of the original
- * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
- * used to execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
* @param fromIndex the index of the first element, inclusive, to be sorted
@@ -891,16 +761,10 @@ public static void parallelSort(float[] a, int fromIndex, int toIndex) {
* {@code 0.0d} and {@code Double.NaN} is considered greater than any
* other value and all {@code Double.NaN} values are considered equal.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(double[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(double[]) Arrays.sort} method. The algorithm requires a
- * working space no greater than the size of the original array. The
- * {@link ForkJoinPool#commonPool() ForkJoin common pool} is used to
- * execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
*
@@ -932,16 +796,10 @@ public static void parallelSort(double[] a) {
* {@code 0.0d} and {@code Double.NaN} is considered greater than any
* other value and all {@code Double.NaN} values are considered equal.
*
- * @implNote The sorting algorithm is a parallel sort-merge that breaks the
- * array into sub-arrays that are themselves sorted and then merged. When
- * the sub-array length reaches a minimum granularity, the sub-array is
- * sorted using the appropriate {@link Arrays#sort(double[]) Arrays.sort}
- * method. If the length of the specified array is less than the minimum
- * granularity, then it is sorted using the appropriate {@link
- * Arrays#sort(double[]) Arrays.sort} method. The algorithm requires a working
- * space no greater than the size of the specified range of the original
- * array. The {@link ForkJoinPool#commonPool() ForkJoin common pool} is
- * used to execute any parallel tasks.
+ * @implNote The sorting algorithm is a Dual-Pivot Quicksort by
+ * Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm
+ * offers O(n log(n)) performance on all data sets, and is typically
+ * faster than traditional (one-pivot) Quicksort implementations.
*
* @param a the array to be sorted
* @param fromIndex the index of the first element, inclusive, to be sorted
@@ -966,6 +824,58 @@ public static void parallelSort(double[] a, int fromIndex, int toIndex) {
MIN_ARRAY_SORT_GRAN : g).invoke();
}
+ /**
+ * Checks that {@code fromIndex} and {@code toIndex} are in
+ * the range and throws an exception if they aren't.
+ */
+ static void rangeCheck(int arrayLength, int fromIndex, int toIndex) {
+ if (fromIndex > toIndex) {
+ throw new IllegalArgumentException(
+ "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
+ }
+ if (fromIndex < 0) {
+ throw new ArrayIndexOutOfBoundsException(fromIndex);
+ }
+ if (toIndex > arrayLength) {
+ throw new ArrayIndexOutOfBoundsException(toIndex);
+ }
+ }
+
+ /**
+ * A comparator that implements the natural ordering of a group of
+ * mutually comparable elements. May be used when a supplied
+ * comparator is null. To simplify code-sharing within underlying
+ * implementations, the compare method only declares type Object
+ * for its second argument.
+ *
+ * Arrays class implementor's note: It is an empirical matter
+ * whether ComparableTimSort offers any performance benefit over
+ * TimSort used with this comparator. If not, you are better off
+ * deleting or bypassing ComparableTimSort. There is currently no
+ * empirical case for separating them for parallel sorting, so all
+ * public Object parallelSort methods use the same comparator
+ * based implementation.
+ */
+ static final class NaturalOrder implements Comparator {
+ @SuppressWarnings("unchecked")
+ public int compare(Object first, Object second) {
+ return ((Comparable)first).compareTo(second);
+ }
+ static final NaturalOrder INSTANCE = new NaturalOrder();
+ }
+
+ /**
+ * The minimum array length below which a parallel sorting
+ * algorithm will not further partition the sorting task. Using
+ * smaller sizes typically results in memory contention across
+ * tasks that makes parallel speedups unlikely.
+ *
+ * @hide
+ */
+ // Android-changed: Make MIN_ARRAY_SORT_GRAN public and @hide (used by harmony
+ // ArraysTest).
+ public static final int MIN_ARRAY_SORT_GRAN = 1 << 13;
+
/**
* Sorts the specified array of objects into ascending order, according
* to the {@linkplain Comparable natural ordering} of its elements.
@@ -1007,7 +917,7 @@ public static > void parallelSort(T[] a) {
(p = ForkJoinPool.getCommonPoolParallelism()) == 1)
TimSort.sort(a, 0, n, NaturalOrder.INSTANCE, null, 0, 0);
else
- new ArraysParallelSortHelpers.FJObject.Sorter
+ new ArraysParallelSortHelpers.FJObject.Sorter<>
(null, a,
(T[])Array.newInstance(a.getClass().getComponentType(), n),
0, n, 0, ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
@@ -1066,7 +976,7 @@ void parallelSort(T[] a, int fromIndex, int toIndex) {
(p = ForkJoinPool.getCommonPoolParallelism()) == 1)
TimSort.sort(a, fromIndex, toIndex, NaturalOrder.INSTANCE, null, 0, 0);
else
- new ArraysParallelSortHelpers.FJObject.Sorter
+ new ArraysParallelSortHelpers.FJObject.Sorter<>
(null, a,
(T[])Array.newInstance(a.getClass().getComponentType(), n),
fromIndex, n, 0, ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
@@ -1115,7 +1025,7 @@ public static void parallelSort(T[] a, Comparator super T> cmp) {
(p = ForkJoinPool.getCommonPoolParallelism()) == 1)
TimSort.sort(a, 0, n, cmp, null, 0, 0);
else
- new ArraysParallelSortHelpers.FJObject.Sorter
+ new ArraysParallelSortHelpers.FJObject.Sorter<>
(null, a,
(T[])Array.newInstance(a.getClass().getComponentType(), n),
0, n, 0, ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
@@ -1176,7 +1086,7 @@ public static void parallelSort(T[] a, int fromIndex, int toIndex,
(p = ForkJoinPool.getCommonPoolParallelism()) == 1)
TimSort.sort(a, fromIndex, toIndex, cmp, null, 0, 0);
else
- new ArraysParallelSortHelpers.FJObject.Sorter
+ new ArraysParallelSortHelpers.FJObject.Sorter<>
(null, a,
(T[])Array.newInstance(a.getClass().getComponentType(), n),
fromIndex, n, 0, ((g = n / (p << 2)) <= MIN_ARRAY_SORT_GRAN) ?
@@ -1187,7 +1097,23 @@ public static void parallelSort(T[] a, int fromIndex, int toIndex,
* Sorting of complex type arrays.
*/
- // Android-removed: LegacyMergeSort class (unused on Android).
+ // BEGIN Android-removed: LegacyMergeSort class (unused on Android).
+ /*
+ /**
+ * Old merge sort implementation can be selected (for
+ * compatibility with broken comparators) using a system property.
+ * Cannot be a static boolean in the enclosing class due to
+ * circular dependencies. To be removed in a future release.
+ *
+ static final class LegacyMergeSort {
+ @SuppressWarnings("removal")
+ private static final boolean userRequested =
+ java.security.AccessController.doPrivileged(
+ new sun.security.action.GetBooleanAction(
+ "java.util.Arrays.useLegacyMergeSort")).booleanValue();
+ }
+ */
+ // END Android-removed: LegacyMergeSort class (unused on Android).
/**
* Sorts the specified array of objects into ascending order, according
@@ -1213,7 +1139,7 @@ public static void parallelSort(T[] a, int fromIndex, int toIndex,
*
* The implementation takes equal advantage of ascending and
* descending order in its input array, and can take advantage of
- * ascending and descending order in different parts of the the same
+ * ascending and descending order in different parts of the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
*
@@ -1232,14 +1158,25 @@ public static void parallelSort(T[] a, int fromIndex, int toIndex,
* {@link Comparable} contract
*/
public static void sort(Object[] a) {
- // Android-removed: LegacyMergeSort support.
- // if (LegacyMergeSort.userRequested)
- // legacyMergeSort(a);
- // else
+ // BEGIN Android-removed: LegacyMergeSort support.
+ /*
+ if (LegacyMergeSort.userRequested)
+ legacyMergeSort(a);
+ else
+ */
+ // END Android-removed: LegacyMergeSort support.
ComparableTimSort.sort(a, 0, a.length, null, 0, 0);
}
- // Android-removed: legacyMergeSort() (unused on Android).
+ // BEGIN Android-removed: legacyMergeSort() (unused on Android).
+ /*
+ /** To be removed in a future release.
+ private static void legacyMergeSort(Object[] a) {
+ Object[] aux = a.clone();
+ mergeSort(aux, a, 0, a.length, 0);
+ }
+ */
+ // END Android-removed: legacyMergeSort() (unused on Android).
/**
* Sorts the specified range of the specified array of objects into
@@ -1269,7 +1206,7 @@ public static void sort(Object[] a) {
*
* The implementation takes equal advantage of ascending and
* descending order in its input array, and can take advantage of
- * ascending and descending order in different parts of the the same
+ * ascending and descending order in different parts of the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
*
@@ -1295,14 +1232,27 @@ public static void sort(Object[] a) {
*/
public static void sort(Object[] a, int fromIndex, int toIndex) {
rangeCheck(a.length, fromIndex, toIndex);
- // Android-removed: LegacyMergeSort support.
- // if (LegacyMergeSort.userRequested)
- // legacyMergeSort(a, fromIndex, toIndex);
- // else
+ // BEGIN Android-removed: LegacyMergeSort support.
+ /*
+ if (LegacyMergeSort.userRequested)
+ legacyMergeSort(a, fromIndex, toIndex);
+ else
+ */
+ // END Android-removed: LegacyMergeSort support.
ComparableTimSort.sort(a, fromIndex, toIndex, null, 0, 0);
}
- // Android-removed: legacyMergeSort() (unused on Android).
+ // BEGIN Android-removed: legacyMergeSort() (unused on Android).
+ /*
+ /** To be removed in a future release. *
+ private static void legacyMergeSort(Object[] a,
+ int fromIndex, int toIndex) {
+ Object[] aux = copyOfRange(a, fromIndex, toIndex);
+ mergeSort(aux, a, fromIndex, toIndex, -fromIndex);
+ }
+ */
+ // END Android-removed: legacyMergeSort() (unused on Android).
+
/**
* Tuning parameter: list size at or below which insertion sort will be
@@ -1392,7 +1342,7 @@ private static void swap(Object[] x, int a, int b) {
*
*
The implementation takes equal advantage of ascending and
* descending order in its input array, and can take advantage of
- * ascending and descending order in different parts of the the same
+ * ascending and descending order in different parts of the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
*
@@ -1417,15 +1367,28 @@ public static void sort(T[] a, Comparator super T> c) {
if (c == null) {
sort(a);
} else {
- // Android-removed: LegacyMergeSort support.
- // if (LegacyMergeSort.userRequested)
- // legacyMergeSort(a, c);
- // else
+ // BEGIN Android-removed: LegacyMergeSort support.
+ /*
+ if (LegacyMergeSort.userRequested)
+ legacyMergeSort(a, c);
+ else
+ */
+ // END Android-removed: LegacyMergeSort support.
TimSort.sort(a, 0, a.length, c, null, 0, 0);
}
}
- // Android-removed: legacyMergeSort() (unused on Android).
+ // BEGIN Android-removed: legacyMergeSort() (unused on Android).
+ /** To be removed in a future release. *
+ private static void legacyMergeSort(T[] a, Comparator super T> c) {
+ T[] aux = a.clone();
+ if (c==null)
+ mergeSort(aux, a, 0, a.length, 0);
+ else
+ mergeSort(aux, a, 0, a.length, 0, c);
+ }
+ */
+ // END Android-removed: legacyMergeSort() (unused on Android).
/**
* Sorts the specified range of the specified array of objects according
@@ -1452,7 +1415,7 @@ public static void sort(T[] a, Comparator super T> c) {
*
* The implementation takes equal advantage of ascending and
* descending order in its input array, and can take advantage of
- * ascending and descending order in different parts of the the same
+ * ascending and descending order in different parts of the same
* input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array.
*
@@ -1485,16 +1448,78 @@ public static void sort(T[] a, int fromIndex, int toIndex,
sort(a, fromIndex, toIndex);
} else {
rangeCheck(a.length, fromIndex, toIndex);
- // Android-removed: LegacyMergeSort support.
- // if (LegacyMergeSort.userRequested)
- // legacyMergeSort(a, fromIndex, toIndex, c);
- // else
+ // BEGIN Android-removed: LegacyMergeSort support.
+ /*
+ if (LegacyMergeSort.userRequested)
+ legacyMergeSort(a, fromIndex, toIndex, c);
+ else
+ */
+ // END Android-removed: LegacyMergeSort support.
TimSort.sort(a, fromIndex, toIndex, c, null, 0, 0);
}
}
- // Android-removed: legacyMergeSort() (unused on Android).
- // Android-removed: mergeSort() (unused on Android).
+ // BEGIN Android-removed: legacyMergeSort() and mergeSort() (unused on Android).
+ /*
+ /** To be removed in a future release. *
+ private static void legacyMergeSort(T[] a, int fromIndex, int toIndex,
+ Comparator super T> c) {
+ T[] aux = copyOfRange(a, fromIndex, toIndex);
+ if (c==null)
+ mergeSort(aux, a, fromIndex, toIndex, -fromIndex);
+ else
+ mergeSort(aux, a, fromIndex, toIndex, -fromIndex, c);
+ }
+
+ /**
+ * Src is the source array that starts at index 0
+ * Dest is the (possibly larger) array destination with a possible offset
+ * low is the index in dest to start sorting
+ * high is the end index in dest to end sorting
+ * off is the offset into src corresponding to low in dest
+ * To be removed in a future release.
+ *
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private static void mergeSort(Object[] src,
+ Object[] dest,
+ int low, int high, int off,
+ Comparator c) {
+ int length = high - low;
+
+ // Insertion sort on smallest arrays
+ if (length < INSERTIONSORT_THRESHOLD) {
+ for (int i=low; ilow && c.compare(dest[j-1], dest[j])>0; j--)
+ swap(dest, j, j-1);
+ return;
+ }
+
+ // Recursively sort halves of dest into src
+ int destLow = low;
+ int destHigh = high;
+ low += off;
+ high += off;
+ int mid = (low + high) >>> 1;
+ mergeSort(dest, src, low, mid, -off, c);
+ mergeSort(dest, src, mid, high, -off, c);
+
+ // If list is already sorted, just copy from src to dest. This is an
+ // optimization that results in faster sorts for nearly ordered lists.
+ if (c.compare(src[mid-1], src[mid]) <= 0) {
+ System.arraycopy(src, low, dest, destLow, length);
+ return;
+ }
+
+ // Merge sorted halves (now in src) into dest
+ for(int i = destLow, p = low, q = mid; i < destHigh; i++) {
+ if (q >= high || p < mid && c.compare(src[p], src[q]) <= 0)
+ dest[i] = src[p++];
+ else
+ dest[i] = src[q++];
+ }
+ }
+ */
+ // END Android-removed: legacyMergeSort() and mergeSort() (unused on Android).
// Parallel prefix
@@ -1696,10 +1721,10 @@ public static void parallelPrefix(int[] array, int fromIndex,
* @param a the array to be searched
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
- * element greater than the key, or a.length if all
+ * element greater than the key, or {@code a.length} if all
* elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -1726,11 +1751,11 @@ public static int binarySearch(long[] a, long key) {
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array
* within the specified range;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
* element in the range greater than the key,
- * or toIndex if all
+ * or {@code toIndex} if all
* elements in the range are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -1777,10 +1802,10 @@ else if (midVal > key)
* @param a the array to be searched
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
- * element greater than the key, or a.length if all
+ * element greater than the key, or {@code a.length} if all
* elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -1807,11 +1832,11 @@ public static int binarySearch(int[] a, int key) {
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array
* within the specified range;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
* element in the range greater than the key,
- * or toIndex if all
+ * or {@code toIndex} if all
* elements in the range are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -1858,10 +1883,10 @@ else if (midVal > key)
* @param a the array to be searched
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
- * element greater than the key, or a.length if all
+ * element greater than the key, or {@code a.length} if all
* elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -1888,11 +1913,11 @@ public static int binarySearch(short[] a, short key) {
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array
* within the specified range;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
* element in the range greater than the key,
- * or toIndex if all
+ * or {@code toIndex} if all
* elements in the range are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -1939,10 +1964,10 @@ else if (midVal > key)
* @param a the array to be searched
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
- * element greater than the key, or a.length if all
+ * element greater than the key, or {@code a.length} if all
* elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -1969,11 +1994,11 @@ public static int binarySearch(char[] a, char key) {
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array
* within the specified range;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
* element in the range greater than the key,
- * or toIndex if all
+ * or {@code toIndex} if all
* elements in the range are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2020,10 +2045,10 @@ else if (midVal > key)
* @param a the array to be searched
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
- * element greater than the key, or a.length if all
+ * element greater than the key, or {@code a.length} if all
* elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2050,11 +2075,11 @@ public static int binarySearch(byte[] a, byte key) {
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array
* within the specified range;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
* element in the range greater than the key,
- * or toIndex if all
+ * or {@code toIndex} if all
* elements in the range are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2102,10 +2127,10 @@ else if (midVal > key)
* @param a the array to be searched
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
- * element greater than the key, or a.length if all
+ * element greater than the key, or {@code a.length} if all
* elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2133,11 +2158,11 @@ public static int binarySearch(double[] a, double key) {
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array
* within the specified range;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
* element in the range greater than the key,
- * or toIndex if all
+ * or {@code toIndex} if all
* elements in the range are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2193,10 +2218,10 @@ else if (midBits < keyBits) // (-0.0, 0.0) or (!NaN, NaN)
* @param a the array to be searched
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
- * element greater than the key, or a.length if all
+ * element greater than the key, or {@code a.length} if all
* elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2224,11 +2249,11 @@ public static int binarySearch(float[] a, float key) {
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array
* within the specified range;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
* element in the range greater than the key,
- * or toIndex if all
+ * or {@code toIndex} if all
* elements in the range are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2290,10 +2315,10 @@ else if (midBits < keyBits) // (-0.0, 0.0) or (!NaN, NaN)
* @param a the array to be searched
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
- * element greater than the key, or a.length if all
+ * element greater than the key, or {@code a.length} if all
* elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2328,11 +2353,11 @@ public static int binarySearch(Object[] a, Object key) {
* @param key the value to be searched for
* @return index of the search key, if it is contained in the array
* within the specified range;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
* element in the range greater than the key,
- * or toIndex if all
+ * or {@code toIndex} if all
* elements in the range are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2388,13 +2413,13 @@ else if (cmp > 0)
* @param a the array to be searched
* @param key the value to be searched for
* @param c the comparator by which the array is ordered. A
- * null value indicates that the elements'
+ * {@code null} value indicates that the elements'
* {@linkplain Comparable natural ordering} should be used.
* @return index of the search key, if it is contained in the array;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
- * element greater than the key, or a.length if all
+ * element greater than the key, or {@code a.length} if all
* elements in the array are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2427,15 +2452,15 @@ public static int binarySearch(T[] a, T key, Comparator super T> c) {
* @param toIndex the index of the last element (exclusive) to be searched
* @param key the value to be searched for
* @param c the comparator by which the array is ordered. A
- * null value indicates that the elements'
+ * {@code null} value indicates that the elements'
* {@linkplain Comparable natural ordering} should be used.
* @return index of the search key, if it is contained in the array
* within the specified range;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the array: the index of the first
* element in the range greater than the key,
- * or toIndex if all
+ * or {@code toIndex} if all
* elements in the range are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -2481,16 +2506,16 @@ else if (cmp > 0)
// Equality Testing
/**
- * Returns true if the two specified arrays of longs are
+ * Returns {@code true} if the two specified arrays of longs are
* equal to one another. Two arrays are considered equal if both
* arrays contain the same number of elements, and all corresponding pairs
* of elements in the two arrays are equal. In other words, two arrays
* are equal if they contain the same elements in the same order. Also,
- * two array references are considered equal if both are null .
+ * two array references are considered equal if both are {@code null}.
*
* @param a one array to be tested for equality
* @param a2 the other array to be tested for equality
- * @return true if the two arrays are equal
+ * @return {@code true} if the two arrays are equal
*/
public static boolean equals(long[] a, long[] a2) {
if (a==a2)
@@ -2510,16 +2535,16 @@ public static boolean equals(long[] a, long[] a2) {
}
/**
- * Returns true if the two specified arrays of ints are
+ * Returns {@code true} if the two specified arrays of ints are
* equal to one another. Two arrays are considered equal if both
* arrays contain the same number of elements, and all corresponding pairs
* of elements in the two arrays are equal. In other words, two arrays
* are equal if they contain the same elements in the same order. Also,
- * two array references are considered equal if both are null .
+ * two array references are considered equal if both are {@code null}.
*
* @param a one array to be tested for equality
* @param a2 the other array to be tested for equality
- * @return true if the two arrays are equal
+ * @return {@code true} if the two arrays are equal
*/
public static boolean equals(int[] a, int[] a2) {
if (a==a2)
@@ -2539,16 +2564,16 @@ public static boolean equals(int[] a, int[] a2) {
}
/**
- * Returns true if the two specified arrays of shorts are
+ * Returns {@code true} if the two specified arrays of shorts are
* equal to one another. Two arrays are considered equal if both
* arrays contain the same number of elements, and all corresponding pairs
* of elements in the two arrays are equal. In other words, two arrays
* are equal if they contain the same elements in the same order. Also,
- * two array references are considered equal if both are null .
+ * two array references are considered equal if both are {@code null}.
*
* @param a one array to be tested for equality
* @param a2 the other array to be tested for equality
- * @return true if the two arrays are equal
+ * @return {@code true} if the two arrays are equal
*/
public static boolean equals(short[] a, short a2[]) {
if (a==a2)
@@ -2568,17 +2593,20 @@ public static boolean equals(short[] a, short a2[]) {
}
/**
- * Returns true if the two specified arrays of chars are
+ * Returns {@code true} if the two specified arrays of chars are
* equal to one another. Two arrays are considered equal if both
* arrays contain the same number of elements, and all corresponding pairs
* of elements in the two arrays are equal. In other words, two arrays
* are equal if they contain the same elements in the same order. Also,
- * two array references are considered equal if both are null .
+ * two array references are considered equal if both are {@code null}.
*
* @param a one array to be tested for equality
* @param a2 the other array to be tested for equality
- * @return true if the two arrays are equal
+ * @return {@code true} if the two arrays are equal
*/
+ /* J2ObjC removed
+ @IntrinsicCandidate
+ */
public static boolean equals(char[] a, char[] a2) {
if (a==a2)
return true;
@@ -2597,17 +2625,20 @@ public static boolean equals(char[] a, char[] a2) {
}
/**
- * Returns true if the two specified arrays of bytes are
+ * Returns {@code true} if the two specified arrays of bytes are
* equal to one another. Two arrays are considered equal if both
* arrays contain the same number of elements, and all corresponding pairs
* of elements in the two arrays are equal. In other words, two arrays
* are equal if they contain the same elements in the same order. Also,
- * two array references are considered equal if both are null .
+ * two array references are considered equal if both are {@code null}.
*
* @param a one array to be tested for equality
* @param a2 the other array to be tested for equality
- * @return true if the two arrays are equal
+ * @return {@code true} if the two arrays are equal
*/
+ /* J2ObjC removed
+ @IntrinsicCandidate
+ */
public static boolean equals(byte[] a, byte[] a2) {
if (a==a2)
return true;
@@ -2626,16 +2657,16 @@ public static boolean equals(byte[] a, byte[] a2) {
}
/**
- * Returns true if the two specified arrays of booleans are
+ * Returns {@code true} if the two specified arrays of booleans are
* equal to one another. Two arrays are considered equal if both
* arrays contain the same number of elements, and all corresponding pairs
* of elements in the two arrays are equal. In other words, two arrays
* are equal if they contain the same elements in the same order. Also,
- * two array references are considered equal if both are null .
+ * two array references are considered equal if both are {@code null}.
*
* @param a one array to be tested for equality
* @param a2 the other array to be tested for equality
- * @return true if the two arrays are equal
+ * @return {@code true} if the two arrays are equal
*/
public static boolean equals(boolean[] a, boolean[] a2) {
if (a==a2)
@@ -2655,21 +2686,21 @@ public static boolean equals(boolean[] a, boolean[] a2) {
}
/**
- * Returns true if the two specified arrays of doubles are
+ * Returns {@code true} if the two specified arrays of doubles are
* equal to one another. Two arrays are considered equal if both
* arrays contain the same number of elements, and all corresponding pairs
* of elements in the two arrays are equal. In other words, two arrays
* are equal if they contain the same elements in the same order. Also,
- * two array references are considered equal if both are null .
+ * two array references are considered equal if both are {@code null}.
*
- * Two doubles d1 and d2 are considered equal if:
- *
new Double(d1).equals(new Double(d2))
- * (Unlike the == operator, this method considers
- * NaN equals to itself, and 0.0d unequal to -0.0d.)
+ * Two doubles {@code d1} and {@code d2} are considered equal if:
+ * {@code new Double(d1).equals(new Double(d2))}
+ * (Unlike the {@code ==} operator, this method considers
+ * {@code NaN} equal to itself, and 0.0d unequal to -0.0d.)
*
* @param a one array to be tested for equality
* @param a2 the other array to be tested for equality
- * @return true if the two arrays are equal
+ * @return {@code true} if the two arrays are equal
* @see Double#equals(Object)
*/
public static boolean equals(double[] a, double[] a2) {
@@ -2690,21 +2721,21 @@ public static boolean equals(double[] a, double[] a2) {
}
/**
- * Returns true if the two specified arrays of floats are
+ * Returns {@code true} if the two specified arrays of floats are
* equal to one another. Two arrays are considered equal if both
* arrays contain the same number of elements, and all corresponding pairs
* of elements in the two arrays are equal. In other words, two arrays
* are equal if they contain the same elements in the same order. Also,
- * two array references are considered equal if both are null .
+ * two array references are considered equal if both are {@code null}.
*
- * Two floats f1 and f2 are considered equal if:
- *
new Float(f1).equals(new Float(f2))
- * (Unlike the == operator, this method considers
- * NaN equals to itself, and 0.0f unequal to -0.0f.)
+ * Two floats {@code f1} and {@code f2} are considered equal if:
+ * {@code new Float(f1).equals(new Float(f2))}
+ * (Unlike the {@code ==} operator, this method considers
+ * {@code NaN} equal to itself, and 0.0f unequal to -0.0f.)
*
* @param a one array to be tested for equality
* @param a2 the other array to be tested for equality
- * @return true if the two arrays are equal
+ * @return {@code true} if the two arrays are equal
* @see Float#equals(Object)
*/
public static boolean equals(float[] a, float[] a2) {
@@ -2725,18 +2756,19 @@ public static boolean equals(float[] a, float[] a2) {
}
/**
- * Returns true if the two specified arrays of Objects are
+ * Returns {@code true} if the two specified arrays of Objects are
* equal to one another. The two arrays are considered equal if
* both arrays contain the same number of elements, and all corresponding
- * pairs of elements in the two arrays are equal. Two objects e1
- * and e2 are considered equal if (e1==null ? e2==null
- * : e1.equals(e2)) . In other words, the two arrays are equal if
+ * pairs of elements in the two arrays are equal. Two objects {@code e1}
+ * and {@code e2} are considered equal if
+ * {@code Objects.equals(e1, e2)}.
+ * In other words, the two arrays are equal if
* they contain the same elements in the same order. Also, two array
- * references are considered equal if both are null .
+ * references are considered equal if both are {@code null}.
*
* @param a one array to be tested for equality
* @param a2 the other array to be tested for equality
- * @return true if the two arrays are equal
+ * @return {@code true} if the two arrays are equal
*/
public static boolean equals(Object[] a, Object[] a2) {
if (a==a2)
@@ -2749,9 +2781,157 @@ public static boolean equals(Object[] a, Object[] a2) {
return false;
for (int i=0; iequal to one another.
+ *
+ * Two arrays are considered equal if the number of elements covered by
+ * each range is the same, and all corresponding pairs of elements over the
+ * specified ranges in the two arrays are equal. In other words, two arrays
+ * are equal if they contain, over the specified ranges, the same elements
+ * in the same order.
+ *
+ *
Two objects {@code e1} and {@code e2} are considered equal if
+ * {@code Objects.equals(e1, e2)}.
+ *
+ * @param a the first array to be tested for equality
+ * @param aFromIndex the index (inclusive) of the first element in the
+ * first array to be tested
+ * @param aToIndex the index (exclusive) of the last element in the
+ * first array to be tested
+ * @param b the second array to be tested for equality
+ * @param bFromIndex the index (inclusive) of the first element in the
+ * second array to be tested
+ * @param bToIndex the index (exclusive) of the last element in the
+ * second array to be tested
+ * @return {@code true} if the two arrays, over the specified ranges, are
+ * equal
+ * @throws IllegalArgumentException
+ * if {@code aFromIndex > aToIndex} or
+ * if {@code bFromIndex > bToIndex}
+ * @throws ArrayIndexOutOfBoundsException
+ * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ * if {@code bFromIndex < 0 or bToIndex > b.length}
+ * @throws NullPointerException
+ * if either array is {@code null}
+ * @since 9
+ */
+ public static boolean equals(Object[] a, int aFromIndex, int aToIndex,
+ Object[] b, int bFromIndex, int bToIndex) {
+ rangeCheck(a.length, aFromIndex, aToIndex);
+ rangeCheck(b.length, bFromIndex, bToIndex);
+
+ int aLength = aToIndex - aFromIndex;
+ int bLength = bToIndex - bFromIndex;
+ if (aLength != bLength)
+ return false;
+
+ for (int i = 0; i < aLength; i++) {
+ if (!Objects.equals(a[aFromIndex++], b[bFromIndex++]))
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns {@code true} if the two specified arrays of Objects are
+ * equal to one another.
+ *
+ *
Two arrays are considered equal if both arrays contain the same number
+ * of elements, and all corresponding pairs of elements in the two arrays
+ * are equal. In other words, the two arrays are equal if they contain the
+ * same elements in the same order. Also, two array references are
+ * considered equal if both are {@code null}.
+ *
+ *
Two objects {@code e1} and {@code e2} are considered equal if,
+ * given the specified comparator, {@code cmp.compare(e1, e2) == 0}.
+ *
+ * @param a one array to be tested for equality
+ * @param a2 the other array to be tested for equality
+ * @param cmp the comparator to compare array elements
+ * @param the type of array elements
+ * @return {@code true} if the two arrays are equal
+ * @throws NullPointerException if the comparator is {@code null}
+ * @since 9
+ */
+ public static boolean equals(T[] a, T[] a2, Comparator super T> cmp) {
+ Objects.requireNonNull(cmp);
+ if (a==a2)
+ return true;
+ if (a==null || a2==null)
+ return false;
+
+ int length = a.length;
+ if (a2.length != length)
+ return false;
+
+ for (int i=0; iequal to one another.
+ *
+ * Two arrays are considered equal if the number of elements covered by
+ * each range is the same, and all corresponding pairs of elements over the
+ * specified ranges in the two arrays are equal. In other words, two arrays
+ * are equal if they contain, over the specified ranges, the same elements
+ * in the same order.
+ *
+ *
Two objects {@code e1} and {@code e2} are considered equal if,
+ * given the specified comparator, {@code cmp.compare(e1, e2) == 0}.
+ *
+ * @param a the first array to be tested for equality
+ * @param aFromIndex the index (inclusive) of the first element in the
+ * first array to be tested
+ * @param aToIndex the index (exclusive) of the last element in the
+ * first array to be tested
+ * @param b the second array to be tested for equality
+ * @param bFromIndex the index (inclusive) of the first element in the
+ * second array to be tested
+ * @param bToIndex the index (exclusive) of the last element in the
+ * second array to be tested
+ * @param cmp the comparator to compare array elements
+ * @param the type of array elements
+ * @return {@code true} if the two arrays, over the specified ranges, are
+ * equal
+ * @throws IllegalArgumentException
+ * if {@code aFromIndex > aToIndex} or
+ * if {@code bFromIndex > bToIndex}
+ * @throws ArrayIndexOutOfBoundsException
+ * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ * if {@code bFromIndex < 0 or bToIndex > b.length}
+ * @throws NullPointerException
+ * if either array or the comparator is {@code null}
+ * @since 9
+ */
+ public static boolean equals(T[] a, int aFromIndex, int aToIndex,
+ T[] b, int bFromIndex, int bToIndex,
+ Comparator super T> cmp) {
+ Objects.requireNonNull(cmp);
+ rangeCheck(a.length, aFromIndex, aToIndex);
+ rangeCheck(b.length, bFromIndex, bToIndex);
+
+ int aLength = aToIndex - aFromIndex;
+ int bLength = bToIndex - bFromIndex;
+ if (aLength != bLength)
+ return false;
+
+ for (int i = 0; i < aLength; i++) {
+ if (cmp.compare(a[aFromIndex++], b[bFromIndex++]) != 0)
return false;
}
@@ -2775,8 +2955,8 @@ public static void fill(long[] a, long val) {
/**
* Assigns the specified long value to each element of the specified
* range of the specified array of longs. The range to be filled
- * extends from index fromIndex , inclusive, to index
- * toIndex , exclusive. (If fromIndex==toIndex , the
+ * extends from index {@code fromIndex}, inclusive, to index
+ * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be filled is empty.)
*
* @param a the array to be filled
@@ -2785,9 +2965,9 @@ public static void fill(long[] a, long val) {
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param val the value to be stored in all elements of the array
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 or
- * toIndex > a.length
+ * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+ * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
+ * {@code toIndex > a.length}
*/
public static void fill(long[] a, int fromIndex, int toIndex, long val) {
rangeCheck(a.length, fromIndex, toIndex);
@@ -2810,8 +2990,8 @@ public static void fill(int[] a, int val) {
/**
* Assigns the specified int value to each element of the specified
* range of the specified array of ints. The range to be filled
- * extends from index fromIndex , inclusive, to index
- * toIndex , exclusive. (If fromIndex==toIndex , the
+ * extends from index {@code fromIndex}, inclusive, to index
+ * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be filled is empty.)
*
* @param a the array to be filled
@@ -2820,9 +3000,9 @@ public static void fill(int[] a, int val) {
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param val the value to be stored in all elements of the array
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 or
- * toIndex > a.length
+ * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+ * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
+ * {@code toIndex > a.length}
*/
public static void fill(int[] a, int fromIndex, int toIndex, int val) {
rangeCheck(a.length, fromIndex, toIndex);
@@ -2845,8 +3025,8 @@ public static void fill(short[] a, short val) {
/**
* Assigns the specified short value to each element of the specified
* range of the specified array of shorts. The range to be filled
- * extends from index fromIndex , inclusive, to index
- * toIndex , exclusive. (If fromIndex==toIndex , the
+ * extends from index {@code fromIndex}, inclusive, to index
+ * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be filled is empty.)
*
* @param a the array to be filled
@@ -2855,9 +3035,9 @@ public static void fill(short[] a, short val) {
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param val the value to be stored in all elements of the array
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 or
- * toIndex > a.length
+ * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+ * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
+ * {@code toIndex > a.length}
*/
public static void fill(short[] a, int fromIndex, int toIndex, short val) {
rangeCheck(a.length, fromIndex, toIndex);
@@ -2880,8 +3060,8 @@ public static void fill(char[] a, char val) {
/**
* Assigns the specified char value to each element of the specified
* range of the specified array of chars. The range to be filled
- * extends from index fromIndex , inclusive, to index
- * toIndex , exclusive. (If fromIndex==toIndex , the
+ * extends from index {@code fromIndex}, inclusive, to index
+ * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be filled is empty.)
*
* @param a the array to be filled
@@ -2890,9 +3070,9 @@ public static void fill(char[] a, char val) {
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param val the value to be stored in all elements of the array
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 or
- * toIndex > a.length
+ * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+ * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
+ * {@code toIndex > a.length}
*/
public static void fill(char[] a, int fromIndex, int toIndex, char val) {
rangeCheck(a.length, fromIndex, toIndex);
@@ -2915,8 +3095,8 @@ public static void fill(byte[] a, byte val) {
/**
* Assigns the specified byte value to each element of the specified
* range of the specified array of bytes. The range to be filled
- * extends from index fromIndex , inclusive, to index
- * toIndex , exclusive. (If fromIndex==toIndex , the
+ * extends from index {@code fromIndex}, inclusive, to index
+ * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be filled is empty.)
*
* @param a the array to be filled
@@ -2925,9 +3105,9 @@ public static void fill(byte[] a, byte val) {
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param val the value to be stored in all elements of the array
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 or
- * toIndex > a.length
+ * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+ * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
+ * {@code toIndex > a.length}
*/
public static void fill(byte[] a, int fromIndex, int toIndex, byte val) {
rangeCheck(a.length, fromIndex, toIndex);
@@ -2950,8 +3130,8 @@ public static void fill(boolean[] a, boolean val) {
/**
* Assigns the specified boolean value to each element of the specified
* range of the specified array of booleans. The range to be filled
- * extends from index fromIndex , inclusive, to index
- * toIndex , exclusive. (If fromIndex==toIndex , the
+ * extends from index {@code fromIndex}, inclusive, to index
+ * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be filled is empty.)
*
* @param a the array to be filled
@@ -2960,9 +3140,9 @@ public static void fill(boolean[] a, boolean val) {
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param val the value to be stored in all elements of the array
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 or
- * toIndex > a.length
+ * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+ * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
+ * {@code toIndex > a.length}
*/
public static void fill(boolean[] a, int fromIndex, int toIndex,
boolean val) {
@@ -2986,8 +3166,8 @@ public static void fill(double[] a, double val) {
/**
* Assigns the specified double value to each element of the specified
* range of the specified array of doubles. The range to be filled
- * extends from index fromIndex , inclusive, to index
- * toIndex , exclusive. (If fromIndex==toIndex , the
+ * extends from index {@code fromIndex}, inclusive, to index
+ * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be filled is empty.)
*
* @param a the array to be filled
@@ -2996,9 +3176,9 @@ public static void fill(double[] a, double val) {
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param val the value to be stored in all elements of the array
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 or
- * toIndex > a.length
+ * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+ * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
+ * {@code toIndex > a.length}
*/
public static void fill(double[] a, int fromIndex, int toIndex,double val){
rangeCheck(a.length, fromIndex, toIndex);
@@ -3021,8 +3201,8 @@ public static void fill(float[] a, float val) {
/**
* Assigns the specified float value to each element of the specified
* range of the specified array of floats. The range to be filled
- * extends from index fromIndex , inclusive, to index
- * toIndex , exclusive. (If fromIndex==toIndex , the
+ * extends from index {@code fromIndex}, inclusive, to index
+ * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be filled is empty.)
*
* @param a the array to be filled
@@ -3031,9 +3211,9 @@ public static void fill(float[] a, float val) {
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param val the value to be stored in all elements of the array
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 or
- * toIndex > a.length
+ * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+ * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
+ * {@code toIndex > a.length}
*/
public static void fill(float[] a, int fromIndex, int toIndex, float val) {
rangeCheck(a.length, fromIndex, toIndex);
@@ -3058,8 +3238,8 @@ public static void fill(Object[] a, Object val) {
/**
* Assigns the specified Object reference to each element of the specified
* range of the specified array of Objects. The range to be filled
- * extends from index fromIndex , inclusive, to index
- * toIndex , exclusive. (If fromIndex==toIndex , the
+ * extends from index {@code fromIndex}, inclusive, to index
+ * {@code toIndex}, exclusive. (If {@code fromIndex==toIndex}, the
* range to be filled is empty.)
*
* @param a the array to be filled
@@ -3068,9 +3248,9 @@ public static void fill(Object[] a, Object val) {
* @param toIndex the index of the last element (exclusive) to be
* filled with the specified value
* @param val the value to be stored in all elements of the array
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0 or
- * toIndex > a.length
+ * @throws IllegalArgumentException if {@code fromIndex > toIndex}
+ * @throws ArrayIndexOutOfBoundsException if {@code fromIndex < 0} or
+ * {@code toIndex > a.length}
* @throws ArrayStoreException if the specified value is not of a
* runtime type that can be stored in the specified array
*/
@@ -3087,7 +3267,7 @@ public static void fill(Object[] a, int fromIndex, int toIndex, Object val) {
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
- * copy but not the original, the copy will contain null .
+ * copy but not the original, the copy will contain {@code null}.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
* The resulting array is of exactly the same class as the original array.
@@ -3097,8 +3277,8 @@ public static void fill(Object[] a, int fromIndex, int toIndex, Object val) {
* @param newLength the length of the copy to be returned
* @return a copy of the original array, truncated or padded with nulls
* to obtain the specified length
- * @throws NegativeArraySizeException if newLength is negative
- * @throws NullPointerException if original is null
+ * @throws NegativeArraySizeException if {@code newLength} is negative
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
@SuppressWarnings("unchecked")
@@ -3111,10 +3291,10 @@ public static T[] copyOf(T[] original, int newLength) {
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
- * copy but not the original, the copy will contain null .
+ * copy but not the original, the copy will contain {@code null}.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
- * The resulting array is of the class newType .
+ * The resulting array is of the class {@code newType}.
*
* @param the class of the objects in the original array
* @param the class of the objects in the returned array
@@ -3123,13 +3303,16 @@ public static T[] copyOf(T[] original, int newLength) {
* @param newType the class of the copy to be returned
* @return a copy of the original array, truncated or padded with nulls
* to obtain the specified length
- * @throws NegativeArraySizeException if newLength is negative
- * @throws NullPointerException if original is null
+ * @throws NegativeArraySizeException if {@code newLength} is negative
+ * @throws NullPointerException if {@code original} is null
* @throws ArrayStoreException if an element copied from
- * original is not of a runtime type that can be stored in
- * an array of class newType
+ * {@code original} is not of a runtime type that can be stored in
+ * an array of class {@code newType}
* @since 1.6
*/
+ /* J2ObjC removed
+ @IntrinsicCandidate
+ */
public static T[] copyOf(U[] original, int newLength, Class extends T[]> newType) {
@SuppressWarnings("unchecked")
T[] copy = ((Object)newType == (Object)Object[].class)
@@ -3145,7 +3328,7 @@ public static T[] copyOf(U[] original, int newLength, Class extends T[]>
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
- * copy but not the original, the copy will contain (byte)0 .
+ * copy but not the original, the copy will contain {@code (byte)0}.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
*
@@ -3153,8 +3336,8 @@ public static T[] copyOf(U[] original, int newLength, Class extends T[]>
* @param newLength the length of the copy to be returned
* @return a copy of the original array, truncated or padded with zeros
* to obtain the specified length
- * @throws NegativeArraySizeException if newLength is negative
- * @throws NullPointerException if original is null
+ * @throws NegativeArraySizeException if {@code newLength} is negative
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static byte[] copyOf(byte[] original, int newLength) {
@@ -3169,7 +3352,7 @@ public static byte[] copyOf(byte[] original, int newLength) {
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
- * copy but not the original, the copy will contain (short)0 .
+ * copy but not the original, the copy will contain {@code (short)0}.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
*
@@ -3177,8 +3360,8 @@ public static byte[] copyOf(byte[] original, int newLength) {
* @param newLength the length of the copy to be returned
* @return a copy of the original array, truncated or padded with zeros
* to obtain the specified length
- * @throws NegativeArraySizeException if newLength is negative
- * @throws NullPointerException if original is null
+ * @throws NegativeArraySizeException if {@code newLength} is negative
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static short[] copyOf(short[] original, int newLength) {
@@ -3193,7 +3376,7 @@ public static short[] copyOf(short[] original, int newLength) {
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
- * copy but not the original, the copy will contain 0 .
+ * copy but not the original, the copy will contain {@code 0}.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
*
@@ -3201,8 +3384,8 @@ public static short[] copyOf(short[] original, int newLength) {
* @param newLength the length of the copy to be returned
* @return a copy of the original array, truncated or padded with zeros
* to obtain the specified length
- * @throws NegativeArraySizeException if newLength is negative
- * @throws NullPointerException if original is null
+ * @throws NegativeArraySizeException if {@code newLength} is negative
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static int[] copyOf(int[] original, int newLength) {
@@ -3217,7 +3400,7 @@ public static int[] copyOf(int[] original, int newLength) {
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
- * copy but not the original, the copy will contain 0L .
+ * copy but not the original, the copy will contain {@code 0L}.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
*
@@ -3225,8 +3408,8 @@ public static int[] copyOf(int[] original, int newLength) {
* @param newLength the length of the copy to be returned
* @return a copy of the original array, truncated or padded with zeros
* to obtain the specified length
- * @throws NegativeArraySizeException if newLength is negative
- * @throws NullPointerException if original is null
+ * @throws NegativeArraySizeException if {@code newLength} is negative
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static long[] copyOf(long[] original, int newLength) {
@@ -3241,7 +3424,7 @@ public static long[] copyOf(long[] original, int newLength) {
* so the copy has the specified length. For all indices that are valid
* in both the original array and the copy, the two arrays will contain
* identical values. For any indices that are valid in the copy but not
- * the original, the copy will contain '\\u000' . Such indices
+ * the original, the copy will contain {@code '\u005cu0000'}. Such indices
* will exist if and only if the specified length is greater than that of
* the original array.
*
@@ -3249,8 +3432,8 @@ public static long[] copyOf(long[] original, int newLength) {
* @param newLength the length of the copy to be returned
* @return a copy of the original array, truncated or padded with null characters
* to obtain the specified length
- * @throws NegativeArraySizeException if newLength is negative
- * @throws NullPointerException if original is null
+ * @throws NegativeArraySizeException if {@code newLength} is negative
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static char[] copyOf(char[] original, int newLength) {
@@ -3265,7 +3448,7 @@ public static char[] copyOf(char[] original, int newLength) {
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
- * copy but not the original, the copy will contain 0f .
+ * copy but not the original, the copy will contain {@code 0f}.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
*
@@ -3273,8 +3456,8 @@ public static char[] copyOf(char[] original, int newLength) {
* @param newLength the length of the copy to be returned
* @return a copy of the original array, truncated or padded with zeros
* to obtain the specified length
- * @throws NegativeArraySizeException if newLength is negative
- * @throws NullPointerException if original is null
+ * @throws NegativeArraySizeException if {@code newLength} is negative
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static float[] copyOf(float[] original, int newLength) {
@@ -3289,7 +3472,7 @@ public static float[] copyOf(float[] original, int newLength) {
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
- * copy but not the original, the copy will contain 0d .
+ * copy but not the original, the copy will contain {@code 0d}.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
*
@@ -3297,8 +3480,8 @@ public static float[] copyOf(float[] original, int newLength) {
* @param newLength the length of the copy to be returned
* @return a copy of the original array, truncated or padded with zeros
* to obtain the specified length
- * @throws NegativeArraySizeException if newLength is negative
- * @throws NullPointerException if original is null
+ * @throws NegativeArraySizeException if {@code newLength} is negative
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static double[] copyOf(double[] original, int newLength) {
@@ -3309,11 +3492,11 @@ public static double[] copyOf(double[] original, int newLength) {
}
/**
- * Copies the specified array, truncating or padding with false (if necessary)
+ * Copies the specified array, truncating or padding with {@code false} (if necessary)
* so the copy has the specified length. For all indices that are
* valid in both the original array and the copy, the two arrays will
* contain identical values. For any indices that are valid in the
- * copy but not the original, the copy will contain false .
+ * copy but not the original, the copy will contain {@code false}.
* Such indices will exist if and only if the specified length
* is greater than that of the original array.
*
@@ -3321,8 +3504,8 @@ public static double[] copyOf(double[] original, int newLength) {
* @param newLength the length of the copy to be returned
* @return a copy of the original array, truncated or padded with false elements
* to obtain the specified length
- * @throws NegativeArraySizeException if newLength is negative
- * @throws NullPointerException if original is null
+ * @throws NegativeArraySizeException if {@code newLength} is negative
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static boolean[] copyOf(boolean[] original, int newLength) {
@@ -3334,17 +3517,17 @@ public static boolean[] copyOf(boolean[] original, int newLength) {
/**
* Copies the specified range of the specified array into a new array.
- * The initial index of the range (from ) must lie between zero
- * and original.length , inclusive. The value at
- * original[from] is placed into the initial element of the copy
- * (unless from == original.length or from == to ).
+ * The initial index of the range ({@code from}) must lie between zero
+ * and {@code original.length}, inclusive. The value at
+ * {@code original[from]} is placed into the initial element of the copy
+ * (unless {@code from == original.length} or {@code from == to}).
* Values from subsequent elements in the original array are placed into
* subsequent elements in the copy. The final index of the range
- * (to ), which must be greater than or equal to from ,
- * may be greater than original.length , in which case
- * null is placed in all elements of the copy whose index is
- * greater than or equal to original.length - from . The length
- * of the returned array will be to - from .
+ * ({@code to}), which must be greater than or equal to {@code from},
+ * may be greater than {@code original.length}, in which case
+ * {@code null} is placed in all elements of the copy whose index is
+ * greater than or equal to {@code original.length - from}. The length
+ * of the returned array will be {@code to - from}.
*
* The resulting array is of exactly the same class as the original array.
*
@@ -3357,8 +3540,8 @@ public static boolean[] copyOf(boolean[] original, int newLength) {
* truncated or padded with nulls to obtain the required length
* @throws ArrayIndexOutOfBoundsException if {@code from < 0}
* or {@code from > original.length}
- * @throws IllegalArgumentException if from > to
- * @throws NullPointerException if original is null
+ * @throws IllegalArgumentException if {@code from > to}
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
@SuppressWarnings("unchecked")
@@ -3368,18 +3551,18 @@ public static T[] copyOfRange(T[] original, int from, int to) {
/**
* Copies the specified range of the specified array into a new array.
- * The initial index of the range (from ) must lie between zero
- * and original.length , inclusive. The value at
- * original[from] is placed into the initial element of the copy
- * (unless from == original.length or from == to ).
+ * The initial index of the range ({@code from}) must lie between zero
+ * and {@code original.length}, inclusive. The value at
+ * {@code original[from]} is placed into the initial element of the copy
+ * (unless {@code from == original.length} or {@code from == to}).
* Values from subsequent elements in the original array are placed into
* subsequent elements in the copy. The final index of the range
- * (to ), which must be greater than or equal to from ,
- * may be greater than original.length , in which case
- * null is placed in all elements of the copy whose index is
- * greater than or equal to original.length - from . The length
- * of the returned array will be to - from .
- * The resulting array is of the class newType .
+ * ({@code to}), which must be greater than or equal to {@code from},
+ * may be greater than {@code original.length}, in which case
+ * {@code null} is placed in all elements of the copy whose index is
+ * greater than or equal to {@code original.length - from}. The length
+ * of the returned array will be {@code to - from}.
+ * The resulting array is of the class {@code newType}.
*
* @param the class of the objects in the original array
* @param the class of the objects in the returned array
@@ -3392,13 +3575,16 @@ public static T[] copyOfRange(T[] original, int from, int to) {
* truncated or padded with nulls to obtain the required length
* @throws ArrayIndexOutOfBoundsException if {@code from < 0}
* or {@code from > original.length}
- * @throws IllegalArgumentException if from > to
- * @throws NullPointerException if original is null
+ * @throws IllegalArgumentException if {@code from > to}
+ * @throws NullPointerException if {@code original} is null
* @throws ArrayStoreException if an element copied from
- * original is not of a runtime type that can be stored in
- * an array of class newType .
+ * {@code original} is not of a runtime type that can be stored in
+ * an array of class {@code newType}.
* @since 1.6
*/
+ /* J2ObjC removed
+ @IntrinsicCandidate
+ */
public static T[] copyOfRange(U[] original, int from, int to, Class extends T[]> newType) {
int newLength = to - from;
if (newLength < 0)
@@ -3414,17 +3600,17 @@ public static T[] copyOfRange(U[] original, int from, int to, Class exte
/**
* Copies the specified range of the specified array into a new array.
- * The initial index of the range (from ) must lie between zero
- * and original.length , inclusive. The value at
- * original[from] is placed into the initial element of the copy
- * (unless from == original.length or from == to ).
+ * The initial index of the range ({@code from}) must lie between zero
+ * and {@code original.length}, inclusive. The value at
+ * {@code original[from]} is placed into the initial element of the copy
+ * (unless {@code from == original.length} or {@code from == to}).
* Values from subsequent elements in the original array are placed into
* subsequent elements in the copy. The final index of the range
- * (to ), which must be greater than or equal to from ,
- * may be greater than original.length , in which case
- * (byte)0 is placed in all elements of the copy whose index is
- * greater than or equal to original.length - from . The length
- * of the returned array will be to - from .
+ * ({@code to}), which must be greater than or equal to {@code from},
+ * may be greater than {@code original.length}, in which case
+ * {@code (byte)0} is placed in all elements of the copy whose index is
+ * greater than or equal to {@code original.length - from}. The length
+ * of the returned array will be {@code to - from}.
*
* @param original the array from which a range is to be copied
* @param from the initial index of the range to be copied, inclusive
@@ -3434,8 +3620,8 @@ public static T[] copyOfRange(U[] original, int from, int to, Class exte
* truncated or padded with zeros to obtain the required length
* @throws ArrayIndexOutOfBoundsException if {@code from < 0}
* or {@code from > original.length}
- * @throws IllegalArgumentException if from > to
- * @throws NullPointerException if original is null
+ * @throws IllegalArgumentException if {@code from > to}
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static byte[] copyOfRange(byte[] original, int from, int to) {
@@ -3450,17 +3636,17 @@ public static byte[] copyOfRange(byte[] original, int from, int to) {
/**
* Copies the specified range of the specified array into a new array.
- * The initial index of the range (from ) must lie between zero
- * and original.length , inclusive. The value at
- * original[from] is placed into the initial element of the copy
- * (unless from == original.length or from == to ).
+ * The initial index of the range ({@code from}) must lie between zero
+ * and {@code original.length}, inclusive. The value at
+ * {@code original[from]} is placed into the initial element of the copy
+ * (unless {@code from == original.length} or {@code from == to}).
* Values from subsequent elements in the original array are placed into
* subsequent elements in the copy. The final index of the range
- * (to ), which must be greater than or equal to from ,
- * may be greater than original.length , in which case
- * (short)0 is placed in all elements of the copy whose index is
- * greater than or equal to original.length - from . The length
- * of the returned array will be to - from .
+ * ({@code to}), which must be greater than or equal to {@code from},
+ * may be greater than {@code original.length}, in which case
+ * {@code (short)0} is placed in all elements of the copy whose index is
+ * greater than or equal to {@code original.length - from}. The length
+ * of the returned array will be {@code to - from}.
*
* @param original the array from which a range is to be copied
* @param from the initial index of the range to be copied, inclusive
@@ -3470,8 +3656,8 @@ public static byte[] copyOfRange(byte[] original, int from, int to) {
* truncated or padded with zeros to obtain the required length
* @throws ArrayIndexOutOfBoundsException if {@code from < 0}
* or {@code from > original.length}
- * @throws IllegalArgumentException if from > to
- * @throws NullPointerException if original is null
+ * @throws IllegalArgumentException if {@code from > to}
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static short[] copyOfRange(short[] original, int from, int to) {
@@ -3486,17 +3672,17 @@ public static short[] copyOfRange(short[] original, int from, int to) {
/**
* Copies the specified range of the specified array into a new array.
- * The initial index of the range (from ) must lie between zero
- * and original.length , inclusive. The value at
- * original[from] is placed into the initial element of the copy
- * (unless from == original.length or from == to ).
+ * The initial index of the range ({@code from}) must lie between zero
+ * and {@code original.length}, inclusive. The value at
+ * {@code original[from]} is placed into the initial element of the copy
+ * (unless {@code from == original.length} or {@code from == to}).
* Values from subsequent elements in the original array are placed into
* subsequent elements in the copy. The final index of the range
- * (to ), which must be greater than or equal to from ,
- * may be greater than original.length , in which case
- * 0 is placed in all elements of the copy whose index is
- * greater than or equal to original.length - from . The length
- * of the returned array will be to - from .
+ * ({@code to}), which must be greater than or equal to {@code from},
+ * may be greater than {@code original.length}, in which case
+ * {@code 0} is placed in all elements of the copy whose index is
+ * greater than or equal to {@code original.length - from}. The length
+ * of the returned array will be {@code to - from}.
*
* @param original the array from which a range is to be copied
* @param from the initial index of the range to be copied, inclusive
@@ -3506,8 +3692,8 @@ public static short[] copyOfRange(short[] original, int from, int to) {
* truncated or padded with zeros to obtain the required length
* @throws ArrayIndexOutOfBoundsException if {@code from < 0}
* or {@code from > original.length}
- * @throws IllegalArgumentException if from > to
- * @throws NullPointerException if original is null
+ * @throws IllegalArgumentException if {@code from > to}
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static int[] copyOfRange(int[] original, int from, int to) {
@@ -3522,17 +3708,17 @@ public static int[] copyOfRange(int[] original, int from, int to) {
/**
* Copies the specified range of the specified array into a new array.
- * The initial index of the range (from ) must lie between zero
- * and original.length , inclusive. The value at
- * original[from] is placed into the initial element of the copy
- * (unless from == original.length or from == to ).
+ * The initial index of the range ({@code from}) must lie between zero
+ * and {@code original.length}, inclusive. The value at
+ * {@code original[from]} is placed into the initial element of the copy
+ * (unless {@code from == original.length} or {@code from == to}).
* Values from subsequent elements in the original array are placed into
* subsequent elements in the copy. The final index of the range
- * (to ), which must be greater than or equal to from ,
- * may be greater than original.length , in which case
- * 0L is placed in all elements of the copy whose index is
- * greater than or equal to original.length - from . The length
- * of the returned array will be to - from .
+ * ({@code to}), which must be greater than or equal to {@code from},
+ * may be greater than {@code original.length}, in which case
+ * {@code 0L} is placed in all elements of the copy whose index is
+ * greater than or equal to {@code original.length - from}. The length
+ * of the returned array will be {@code to - from}.
*
* @param original the array from which a range is to be copied
* @param from the initial index of the range to be copied, inclusive
@@ -3542,8 +3728,8 @@ public static int[] copyOfRange(int[] original, int from, int to) {
* truncated or padded with zeros to obtain the required length
* @throws ArrayIndexOutOfBoundsException if {@code from < 0}
* or {@code from > original.length}
- * @throws IllegalArgumentException if from > to
- * @throws NullPointerException if original is null
+ * @throws IllegalArgumentException if {@code from > to}
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static long[] copyOfRange(long[] original, int from, int to) {
@@ -3558,17 +3744,17 @@ public static long[] copyOfRange(long[] original, int from, int to) {
/**
* Copies the specified range of the specified array into a new array.
- * The initial index of the range (from ) must lie between zero
- * and original.length , inclusive. The value at
- * original[from] is placed into the initial element of the copy
- * (unless from == original.length or from == to ).
+ * The initial index of the range ({@code from}) must lie between zero
+ * and {@code original.length}, inclusive. The value at
+ * {@code original[from]} is placed into the initial element of the copy
+ * (unless {@code from == original.length} or {@code from == to}).
* Values from subsequent elements in the original array are placed into
* subsequent elements in the copy. The final index of the range
- * (to ), which must be greater than or equal to from ,
- * may be greater than original.length , in which case
- * '\\u000' is placed in all elements of the copy whose index is
- * greater than or equal to original.length - from . The length
- * of the returned array will be to - from .
+ * ({@code to}), which must be greater than or equal to {@code from},
+ * may be greater than {@code original.length}, in which case
+ * {@code '\u005cu0000'} is placed in all elements of the copy whose index is
+ * greater than or equal to {@code original.length - from}. The length
+ * of the returned array will be {@code to - from}.
*
* @param original the array from which a range is to be copied
* @param from the initial index of the range to be copied, inclusive
@@ -3578,8 +3764,8 @@ public static long[] copyOfRange(long[] original, int from, int to) {
* truncated or padded with null characters to obtain the required length
* @throws ArrayIndexOutOfBoundsException if {@code from < 0}
* or {@code from > original.length}
- * @throws IllegalArgumentException if from > to
- * @throws NullPointerException if original is null
+ * @throws IllegalArgumentException if {@code from > to}
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static char[] copyOfRange(char[] original, int from, int to) {
@@ -3594,17 +3780,17 @@ public static char[] copyOfRange(char[] original, int from, int to) {
/**
* Copies the specified range of the specified array into a new array.
- * The initial index of the range (from ) must lie between zero
- * and original.length , inclusive. The value at
- * original[from] is placed into the initial element of the copy
- * (unless from == original.length or from == to ).
+ * The initial index of the range ({@code from}) must lie between zero
+ * and {@code original.length}, inclusive. The value at
+ * {@code original[from]} is placed into the initial element of the copy
+ * (unless {@code from == original.length} or {@code from == to}).
* Values from subsequent elements in the original array are placed into
* subsequent elements in the copy. The final index of the range
- * (to ), which must be greater than or equal to from ,
- * may be greater than original.length , in which case
- * 0f is placed in all elements of the copy whose index is
- * greater than or equal to original.length - from . The length
- * of the returned array will be to - from .
+ * ({@code to}), which must be greater than or equal to {@code from},
+ * may be greater than {@code original.length}, in which case
+ * {@code 0f} is placed in all elements of the copy whose index is
+ * greater than or equal to {@code original.length - from}. The length
+ * of the returned array will be {@code to - from}.
*
* @param original the array from which a range is to be copied
* @param from the initial index of the range to be copied, inclusive
@@ -3614,8 +3800,8 @@ public static char[] copyOfRange(char[] original, int from, int to) {
* truncated or padded with zeros to obtain the required length
* @throws ArrayIndexOutOfBoundsException if {@code from < 0}
* or {@code from > original.length}
- * @throws IllegalArgumentException if from > to
- * @throws NullPointerException if original is null
+ * @throws IllegalArgumentException if {@code from > to}
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static float[] copyOfRange(float[] original, int from, int to) {
@@ -3630,17 +3816,17 @@ public static float[] copyOfRange(float[] original, int from, int to) {
/**
* Copies the specified range of the specified array into a new array.
- * The initial index of the range (from ) must lie between zero
- * and original.length , inclusive. The value at
- * original[from] is placed into the initial element of the copy
- * (unless from == original.length or from == to ).
+ * The initial index of the range ({@code from}) must lie between zero
+ * and {@code original.length}, inclusive. The value at
+ * {@code original[from]} is placed into the initial element of the copy
+ * (unless {@code from == original.length} or {@code from == to}).
* Values from subsequent elements in the original array are placed into
* subsequent elements in the copy. The final index of the range
- * (to ), which must be greater than or equal to from ,
- * may be greater than original.length , in which case
- * 0d is placed in all elements of the copy whose index is
- * greater than or equal to original.length - from . The length
- * of the returned array will be to - from .
+ * ({@code to}), which must be greater than or equal to {@code from},
+ * may be greater than {@code original.length}, in which case
+ * {@code 0d} is placed in all elements of the copy whose index is
+ * greater than or equal to {@code original.length - from}. The length
+ * of the returned array will be {@code to - from}.
*
* @param original the array from which a range is to be copied
* @param from the initial index of the range to be copied, inclusive
@@ -3650,8 +3836,8 @@ public static float[] copyOfRange(float[] original, int from, int to) {
* truncated or padded with zeros to obtain the required length
* @throws ArrayIndexOutOfBoundsException if {@code from < 0}
* or {@code from > original.length}
- * @throws IllegalArgumentException if from > to
- * @throws NullPointerException if original is null
+ * @throws IllegalArgumentException if {@code from > to}
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static double[] copyOfRange(double[] original, int from, int to) {
@@ -3666,17 +3852,17 @@ public static double[] copyOfRange(double[] original, int from, int to) {
/**
* Copies the specified range of the specified array into a new array.
- * The initial index of the range (from ) must lie between zero
- * and original.length , inclusive. The value at
- * original[from] is placed into the initial element of the copy
- * (unless from == original.length or from == to ).
+ * The initial index of the range ({@code from}) must lie between zero
+ * and {@code original.length}, inclusive. The value at
+ * {@code original[from]} is placed into the initial element of the copy
+ * (unless {@code from == original.length} or {@code from == to}).
* Values from subsequent elements in the original array are placed into
* subsequent elements in the copy. The final index of the range
- * (to ), which must be greater than or equal to from ,
- * may be greater than original.length , in which case
- * false is placed in all elements of the copy whose index is
- * greater than or equal to original.length - from . The length
- * of the returned array will be to - from .
+ * ({@code to}), which must be greater than or equal to {@code from},
+ * may be greater than {@code original.length}, in which case
+ * {@code false} is placed in all elements of the copy whose index is
+ * greater than or equal to {@code original.length - from}. The length
+ * of the returned array will be {@code to - from}.
*
* @param original the array from which a range is to be copied
* @param from the initial index of the range to be copied, inclusive
@@ -3686,8 +3872,8 @@ public static double[] copyOfRange(double[] original, int from, int to) {
* truncated or padded with false elements to obtain the required length
* @throws ArrayIndexOutOfBoundsException if {@code from < 0}
* or {@code from > original.length}
- * @throws IllegalArgumentException if from > to
- * @throws NullPointerException if original is null
+ * @throws IllegalArgumentException if {@code from > to}
+ * @throws NullPointerException if {@code original} is null
* @since 1.6
*/
public static boolean[] copyOfRange(boolean[] original, int from, int to) {
@@ -3703,21 +3889,41 @@ public static boolean[] copyOfRange(boolean[] original, int from, int to) {
// Misc
/**
- * Returns a fixed-size list backed by the specified array. (Changes to
- * the returned list "write through" to the array.) This method acts
- * as bridge between array-based and collection-based APIs, in
- * combination with {@link Collection#toArray}. The returned list is
- * serializable and implements {@link RandomAccess}.
+ * Returns a fixed-size list backed by the specified array. Changes made to
+ * the array will be visible in the returned list, and changes made to the
+ * list will be visible in the array. The returned list is
+ * {@link Serializable} and implements {@link RandomAccess}.
+ *
+ * The returned list implements the optional {@code Collection} methods, except
+ * those that would change the size of the returned list. Those methods leave
+ * the list unchanged and throw {@link UnsupportedOperationException}.
+ *
+ * @apiNote
+ * This method acts as bridge between array-based and collection-based
+ * APIs, in combination with {@link Collection#toArray}.
+ *
+ *
This method provides a way to wrap an existing array:
+ *
{@code
+ * Integer[] numbers = ...
+ * ...
+ * List values = Arrays.asList(numbers);
+ * }
*
* This method also provides a convenient way to create a fixed-size
* list initialized to contain several elements:
- *
- * List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");
- *
+ * {@code
+ * List stooges = Arrays.asList("Larry", "Moe", "Curly");
+ * }
+ *
+ * The list returned by this method is modifiable.
+ * To create an unmodifiable list, use
+ * {@link Collections#unmodifiableList Collections.unmodifiableList}
+ * or Unmodifiable Lists .
*
* @param the class of the objects in the array
* @param a the array by which the list will be backed
* @return a list view of the specified array
+ * @throws NullPointerException if the specified array is {@code null}
*/
@SafeVarargs
@SuppressWarnings("varargs")
@@ -3731,6 +3937,7 @@ public static List asList(T... a) {
private static class ArrayList extends AbstractList
implements RandomAccess, java.io.Serializable
{
+ @java.io.Serial
private static final long serialVersionUID = -2764017481108945198L;
private final E[] a;
@@ -3745,6 +3952,11 @@ public int size() {
@Override
public Object[] toArray() {
+ // Android-changed: there are applications which expect this method
+ // to return array with component type E, not just Object.
+ // Keeping pre-Java 9 behaviour for compatibility sake.
+ // See b/204397945.
+ // return Arrays.copyOf(a, a.length, Object[].class);
return a.clone();
}
@@ -3790,7 +4002,7 @@ public int indexOf(Object o) {
@Override
public boolean contains(Object o) {
- return indexOf(o) != -1;
+ return indexOf(o) >= 0;
}
@Override
@@ -3819,22 +4031,51 @@ public void replaceAll(UnaryOperator operator) {
public void sort(Comparator super E> c) {
Arrays.sort(a, c);
}
+
+ @Override
+ public Iterator iterator() {
+ return new ArrayItr<>(a);
+ }
+ }
+
+ private static class ArrayItr implements Iterator {
+ private int cursor;
+ private final E[] a;
+
+ ArrayItr(E[] a) {
+ this.a = a;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return cursor < a.length;
+ }
+
+ @Override
+ public E next() {
+ int i = cursor;
+ if (i >= a.length) {
+ throw new NoSuchElementException();
+ }
+ cursor = i + 1;
+ return a[i];
+ }
}
/**
* Returns a hash code based on the contents of the specified array.
- * For any two long arrays a and b
- * such that Arrays.equals(a, b) , it is also the case that
- * Arrays.hashCode(a) == Arrays.hashCode(b) .
+ * For any two {@code long} arrays {@code a} and {@code b}
+ * such that {@code Arrays.equals(a, b)}, it is also the case that
+ * {@code Arrays.hashCode(a) == Arrays.hashCode(b)}.
*
* The value returned by this method is the same value that would be
- * obtained by invoking the {@link List#hashCode() hashCode }
+ * obtained by invoking the {@link List#hashCode() hashCode}
* method on a {@link List} containing a sequence of {@link Long}
- * instances representing the elements of a in the same order.
- * If a is null , this method returns 0.
+ * instances representing the elements of {@code a} in the same order.
+ * If {@code a} is {@code null}, this method returns 0.
*
* @param a the array whose hash value to compute
- * @return a content-based hash code for a
+ * @return a content-based hash code for {@code a}
* @since 1.5
*/
public static int hashCode(long a[]) {
@@ -3852,18 +4093,18 @@ public static int hashCode(long a[]) {
/**
* Returns a hash code based on the contents of the specified array.
- * For any two non-null int arrays a and b
- * such that Arrays.equals(a, b) , it is also the case that
- * Arrays.hashCode(a) == Arrays.hashCode(b) .
+ * For any two non-null {@code int} arrays {@code a} and {@code b}
+ * such that {@code Arrays.equals(a, b)}, it is also the case that
+ * {@code Arrays.hashCode(a) == Arrays.hashCode(b)}.
*
*
The value returned by this method is the same value that would be
- * obtained by invoking the {@link List#hashCode() hashCode }
+ * obtained by invoking the {@link List#hashCode() hashCode}
* method on a {@link List} containing a sequence of {@link Integer}
- * instances representing the elements of a in the same order.
- * If a is null , this method returns 0.
+ * instances representing the elements of {@code a} in the same order.
+ * If {@code a} is {@code null}, this method returns 0.
*
* @param a the array whose hash value to compute
- * @return a content-based hash code for a
+ * @return a content-based hash code for {@code a}
* @since 1.5
*/
public static int hashCode(int a[]) {
@@ -3879,18 +4120,18 @@ public static int hashCode(int a[]) {
/**
* Returns a hash code based on the contents of the specified array.
- * For any two short arrays a and b
- * such that Arrays.equals(a, b) , it is also the case that
- * Arrays.hashCode(a) == Arrays.hashCode(b) .
+ * For any two {@code short} arrays {@code a} and {@code b}
+ * such that {@code Arrays.equals(a, b)}, it is also the case that
+ * {@code Arrays.hashCode(a) == Arrays.hashCode(b)}.
*
*
The value returned by this method is the same value that would be
- * obtained by invoking the {@link List#hashCode() hashCode }
+ * obtained by invoking the {@link List#hashCode() hashCode}
* method on a {@link List} containing a sequence of {@link Short}
- * instances representing the elements of a in the same order.
- * If a is null , this method returns 0.
+ * instances representing the elements of {@code a} in the same order.
+ * If {@code a} is {@code null}, this method returns 0.
*
* @param a the array whose hash value to compute
- * @return a content-based hash code for a
+ * @return a content-based hash code for {@code a}
* @since 1.5
*/
public static int hashCode(short a[]) {
@@ -3906,18 +4147,18 @@ public static int hashCode(short a[]) {
/**
* Returns a hash code based on the contents of the specified array.
- * For any two char arrays a and b
- * such that Arrays.equals(a, b) , it is also the case that
- * Arrays.hashCode(a) == Arrays.hashCode(b) .
+ * For any two {@code char} arrays {@code a} and {@code b}
+ * such that {@code Arrays.equals(a, b)}, it is also the case that
+ * {@code Arrays.hashCode(a) == Arrays.hashCode(b)}.
*
*
The value returned by this method is the same value that would be
- * obtained by invoking the {@link List#hashCode() hashCode }
+ * obtained by invoking the {@link List#hashCode() hashCode}
* method on a {@link List} containing a sequence of {@link Character}
- * instances representing the elements of a in the same order.
- * If a is null , this method returns 0.
+ * instances representing the elements of {@code a} in the same order.
+ * If {@code a} is {@code null}, this method returns 0.
*
* @param a the array whose hash value to compute
- * @return a content-based hash code for a
+ * @return a content-based hash code for {@code a}
* @since 1.5
*/
public static int hashCode(char a[]) {
@@ -3933,18 +4174,18 @@ public static int hashCode(char a[]) {
/**
* Returns a hash code based on the contents of the specified array.
- * For any two byte arrays a and b
- * such that Arrays.equals(a, b) , it is also the case that
- * Arrays.hashCode(a) == Arrays.hashCode(b) .
+ * For any two {@code byte} arrays {@code a} and {@code b}
+ * such that {@code Arrays.equals(a, b)}, it is also the case that
+ * {@code Arrays.hashCode(a) == Arrays.hashCode(b)}.
*
*
The value returned by this method is the same value that would be
- * obtained by invoking the {@link List#hashCode() hashCode }
+ * obtained by invoking the {@link List#hashCode() hashCode}
* method on a {@link List} containing a sequence of {@link Byte}
- * instances representing the elements of a in the same order.
- * If a is null , this method returns 0.
+ * instances representing the elements of {@code a} in the same order.
+ * If {@code a} is {@code null}, this method returns 0.
*
* @param a the array whose hash value to compute
- * @return a content-based hash code for a
+ * @return a content-based hash code for {@code a}
* @since 1.5
*/
public static int hashCode(byte a[]) {
@@ -3960,18 +4201,18 @@ public static int hashCode(byte a[]) {
/**
* Returns a hash code based on the contents of the specified array.
- * For any two boolean arrays a and b
- * such that Arrays.equals(a, b) , it is also the case that
- * Arrays.hashCode(a) == Arrays.hashCode(b) .
+ * For any two {@code boolean} arrays {@code a} and {@code b}
+ * such that {@code Arrays.equals(a, b)}, it is also the case that
+ * {@code Arrays.hashCode(a) == Arrays.hashCode(b)}.
*
*
The value returned by this method is the same value that would be
- * obtained by invoking the {@link List#hashCode() hashCode }
+ * obtained by invoking the {@link List#hashCode() hashCode}
* method on a {@link List} containing a sequence of {@link Boolean}
- * instances representing the elements of a in the same order.
- * If a is null , this method returns 0.
+ * instances representing the elements of {@code a} in the same order.
+ * If {@code a} is {@code null}, this method returns 0.
*
* @param a the array whose hash value to compute
- * @return a content-based hash code for a
+ * @return a content-based hash code for {@code a}
* @since 1.5
*/
public static int hashCode(boolean a[]) {
@@ -3987,18 +4228,18 @@ public static int hashCode(boolean a[]) {
/**
* Returns a hash code based on the contents of the specified array.
- * For any two float arrays a and b
- * such that Arrays.equals(a, b) , it is also the case that
- * Arrays.hashCode(a) == Arrays.hashCode(b) .
+ * For any two {@code float} arrays {@code a} and {@code b}
+ * such that {@code Arrays.equals(a, b)}, it is also the case that
+ * {@code Arrays.hashCode(a) == Arrays.hashCode(b)}.
*
*
The value returned by this method is the same value that would be
- * obtained by invoking the {@link List#hashCode() hashCode }
+ * obtained by invoking the {@link List#hashCode() hashCode}
* method on a {@link List} containing a sequence of {@link Float}
- * instances representing the elements of a in the same order.
- * If a is null , this method returns 0.
+ * instances representing the elements of {@code a} in the same order.
+ * If {@code a} is {@code null}, this method returns 0.
*
* @param a the array whose hash value to compute
- * @return a content-based hash code for a
+ * @return a content-based hash code for {@code a}
* @since 1.5
*/
public static int hashCode(float a[]) {
@@ -4014,18 +4255,18 @@ public static int hashCode(float a[]) {
/**
* Returns a hash code based on the contents of the specified array.
- * For any two double arrays a and b
- * such that Arrays.equals(a, b) , it is also the case that
- * Arrays.hashCode(a) == Arrays.hashCode(b) .
+ * For any two {@code double} arrays {@code a} and {@code b}
+ * such that {@code Arrays.equals(a, b)}, it is also the case that
+ * {@code Arrays.hashCode(a) == Arrays.hashCode(b)}.
*
*
The value returned by this method is the same value that would be
- * obtained by invoking the {@link List#hashCode() hashCode }
+ * obtained by invoking the {@link List#hashCode() hashCode}
* method on a {@link List} containing a sequence of {@link Double}
- * instances representing the elements of a in the same order.
- * If a is null , this method returns 0.
+ * instances representing the elements of {@code a} in the same order.
+ * If {@code a} is {@code null}, this method returns 0.
*
* @param a the array whose hash value to compute
- * @return a content-based hash code for a
+ * @return a content-based hash code for {@code a}
* @since 1.5
*/
public static int hashCode(double a[]) {
@@ -4048,16 +4289,16 @@ public static int hashCode(double a[]) {
* element, either directly or indirectly through one or more levels of
* arrays.
*
- *
For any two arrays a and b such that
- * Arrays.equals(a, b) , it is also the case that
- * Arrays.hashCode(a) == Arrays.hashCode(b) .
+ *
For any two arrays {@code a} and {@code b} such that
+ * {@code Arrays.equals(a, b)}, it is also the case that
+ * {@code Arrays.hashCode(a) == Arrays.hashCode(b)}.
*
*
The value returned by this method is equal to the value that would
- * be returned by Arrays.asList(a).hashCode() , unless a
- * is null , in which case 0 is returned.
+ * be returned by {@code Arrays.asList(a).hashCode()}, unless {@code a}
+ * is {@code null}, in which case {@code 0} is returned.
*
* @param a the array whose content-based hash code to compute
- * @return a content-based hash code for a
+ * @return a content-based hash code for {@code a}
* @see #deepHashCode(Object[])
* @since 1.5
*/
@@ -4082,23 +4323,23 @@ public static int hashCode(Object a[]) {
* one or more levels of arrays. The behavior of such an invocation is
* undefined.
*
- *
For any two arrays a and b such that
- * Arrays.deepEquals(a, b) , it is also the case that
- * Arrays.deepHashCode(a) == Arrays.deepHashCode(b) .
+ *
For any two arrays {@code a} and {@code b} such that
+ * {@code Arrays.deepEquals(a, b)}, it is also the case that
+ * {@code Arrays.deepHashCode(a) == Arrays.deepHashCode(b)}.
*
*
The computation of the value returned by this method is similar to
* that of the value returned by {@link List#hashCode()} on a list
- * containing the same elements as a in the same order, with one
- * difference: If an element e of a is itself an array,
- * its hash code is computed not by calling e.hashCode() , but as
- * by calling the appropriate overloading of Arrays.hashCode(e)
- * if e is an array of a primitive type, or as by calling
- * Arrays.deepHashCode(e) recursively if e is an array
- * of a reference type. If a is null , this method
+ * containing the same elements as {@code a} in the same order, with one
+ * difference: If an element {@code e} of {@code a} is itself an array,
+ * its hash code is computed not by calling {@code e.hashCode()}, but as
+ * by calling the appropriate overloading of {@code Arrays.hashCode(e)}
+ * if {@code e} is an array of a primitive type, or as by calling
+ * {@code Arrays.deepHashCode(e)} recursively if {@code e} is an array
+ * of a reference type. If {@code a} is {@code null}, this method
* returns 0.
*
* @param a the array whose deep-content-based hash code to compute
- * @return a deep-content-based hash code for a
+ * @return a deep-content-based hash code for {@code a}
* @see #hashCode(Object[])
* @since 1.5
*/
@@ -4109,63 +4350,60 @@ public static int deepHashCode(Object a[]) {
int result = 1;
for (Object element : a) {
- int elementHash = 0;
- // BEGIN Android-changed: getComponentType() is faster than instanceof().
- if (element != null) {
- Class> cl = element.getClass().getComponentType();
- if (cl == null)
- elementHash = element.hashCode();
- else if (element instanceof Object[])
- elementHash = deepHashCode((Object[]) element);
- else if (cl == byte.class)
- elementHash = hashCode((byte[]) element);
- else if (cl == short.class)
- elementHash = hashCode((short[]) element);
- else if (cl == int.class)
- elementHash = hashCode((int[]) element);
- else if (cl == long.class)
- elementHash = hashCode((long[]) element);
- else if (cl == char.class)
- elementHash = hashCode((char[]) element);
- else if (cl == float.class)
- elementHash = hashCode((float[]) element);
- else if (cl == double.class)
- elementHash = hashCode((double[]) element);
- else if (cl == boolean.class)
- elementHash = hashCode((boolean[]) element);
- else
- elementHash = element.hashCode();
- }
- // END Android-changed: getComponentType() is faster than instanceof().
+ final int elementHash;
+ final Class> cl;
+ if (element == null)
+ elementHash = 0;
+ else if ((cl = element.getClass().getComponentType()) == null)
+ elementHash = element.hashCode();
+ else if (element instanceof Object[])
+ elementHash = deepHashCode((Object[]) element);
+ else
+ elementHash = primitiveArrayHashCode(element, cl);
+
result = 31 * result + elementHash;
}
return result;
}
+ private static int primitiveArrayHashCode(Object a, Class> cl) {
+ return
+ (cl == byte.class) ? hashCode((byte[]) a) :
+ (cl == int.class) ? hashCode((int[]) a) :
+ (cl == long.class) ? hashCode((long[]) a) :
+ (cl == char.class) ? hashCode((char[]) a) :
+ (cl == short.class) ? hashCode((short[]) a) :
+ (cl == boolean.class) ? hashCode((boolean[]) a) :
+ (cl == double.class) ? hashCode((double[]) a) :
+ // If new primitive types are ever added, this method must be
+ // expanded or we will fail here with ClassCastException.
+ hashCode((float[]) a);
+ }
+
/**
- * Returns true if the two specified arrays are deeply
+ * Returns {@code true} if the two specified arrays are deeply
* equal to one another. Unlike the {@link #equals(Object[],Object[])}
* method, this method is appropriate for use with nested arrays of
* arbitrary depth.
*
*
Two array references are considered deeply equal if both
- * are null , or if they refer to arrays that contain the same
+ * are {@code null}, or if they refer to arrays that contain the same
* number of elements and all corresponding pairs of elements in the two
* arrays are deeply equal.
*
- *
Two possibly null elements e1 and e2 are
+ *
Two possibly {@code null} elements {@code e1} and {@code e2} are
* deeply equal if any of the following conditions hold:
*
- * e1 and e2 are both arrays of object reference
- * types, and Arrays.deepEquals(e1, e2) would return true
- * e1 and e2 are arrays of the same primitive
+ * {@code e1} and {@code e2} are both arrays of object reference
+ * types, and {@code Arrays.deepEquals(e1, e2) would return true}
+ * {@code e1} and {@code e2} are arrays of the same primitive
* type, and the appropriate overloading of
- * Arrays.equals(e1, e2) would return true.
- * e1 == e2
- * e1.equals(e2) would return true.
+ * {@code Arrays.equals(e1, e2)} would return true.
+ * {@code e1 == e2}
+ * {@code e1.equals(e2)} would return true.
*
- * Note that this definition permits null elements at any depth.
+ * Note that this definition permits {@code null} elements at any depth.
*
* If either of the specified arrays contain themselves as elements
* either directly or indirectly through one or more levels of arrays,
@@ -4173,7 +4411,7 @@ else if (cl == boolean.class)
*
* @param a1 one array to be tested for equality
* @param a2 the other array to be tested for equality
- * @return true if the two arrays are equal
+ * @return {@code true} if the two arrays are equal
* @see #equals(Object[],Object[])
* @see Objects#deepEquals(Object, Object)
* @since 1.5
@@ -4234,14 +4472,14 @@ else if (e1 instanceof boolean[] && e2 instanceof boolean[])
/**
* Returns a string representation of the contents of the specified array.
* The string representation consists of a list of the array's elements,
- * enclosed in square brackets ("[]" ). Adjacent elements are
- * separated by the characters ", " (a comma followed by a
+ * enclosed in square brackets ({@code "[]"}). Adjacent elements are
+ * separated by the characters {@code ", "} (a comma followed by a
* space). Elements are converted to strings as by
- * String.valueOf(long) . Returns "null" if a
- * is null .
+ * {@code String.valueOf(long)}. Returns {@code "null"} if {@code a}
+ * is {@code null}.
*
* @param a the array whose string representation to return
- * @return a string representation of a
+ * @return a string representation of {@code a}
* @since 1.5
*/
public static String toString(long[] a) {
@@ -4264,14 +4502,14 @@ public static String toString(long[] a) {
/**
* Returns a string representation of the contents of the specified array.
* The string representation consists of a list of the array's elements,
- * enclosed in square brackets ("[]" ). Adjacent elements are
- * separated by the characters ", " (a comma followed by a
+ * enclosed in square brackets ({@code "[]"}). Adjacent elements are
+ * separated by the characters {@code ", "} (a comma followed by a
* space). Elements are converted to strings as by
- * String.valueOf(int) . Returns "null" if a is
- * null .
+ * {@code String.valueOf(int)}. Returns {@code "null"} if {@code a} is
+ * {@code null}.
*
* @param a the array whose string representation to return
- * @return a string representation of a
+ * @return a string representation of {@code a}
* @since 1.5
*/
public static String toString(int[] a) {
@@ -4294,14 +4532,14 @@ public static String toString(int[] a) {
/**
* Returns a string representation of the contents of the specified array.
* The string representation consists of a list of the array's elements,
- * enclosed in square brackets ("[]" ). Adjacent elements are
- * separated by the characters ", " (a comma followed by a
+ * enclosed in square brackets ({@code "[]"}). Adjacent elements are
+ * separated by the characters {@code ", "} (a comma followed by a
* space). Elements are converted to strings as by
- * String.valueOf(short) . Returns "null" if a
- * is null .
+ * {@code String.valueOf(short)}. Returns {@code "null"} if {@code a}
+ * is {@code null}.
*
* @param a the array whose string representation to return
- * @return a string representation of a
+ * @return a string representation of {@code a}
* @since 1.5
*/
public static String toString(short[] a) {
@@ -4324,14 +4562,14 @@ public static String toString(short[] a) {
/**
* Returns a string representation of the contents of the specified array.
* The string representation consists of a list of the array's elements,
- * enclosed in square brackets ("[]" ). Adjacent elements are
- * separated by the characters ", " (a comma followed by a
+ * enclosed in square brackets ({@code "[]"}). Adjacent elements are
+ * separated by the characters {@code ", "} (a comma followed by a
* space). Elements are converted to strings as by
- * String.valueOf(char) . Returns "null" if a
- * is null .
+ * {@code String.valueOf(char)}. Returns {@code "null"} if {@code a}
+ * is {@code null}.
*
* @param a the array whose string representation to return
- * @return a string representation of a
+ * @return a string representation of {@code a}
* @since 1.5
*/
public static String toString(char[] a) {
@@ -4354,14 +4592,14 @@ public static String toString(char[] a) {
/**
* Returns a string representation of the contents of the specified array.
* The string representation consists of a list of the array's elements,
- * enclosed in square brackets ("[]" ). Adjacent elements
- * are separated by the characters ", " (a comma followed
+ * enclosed in square brackets ({@code "[]"}). Adjacent elements
+ * are separated by the characters {@code ", "} (a comma followed
* by a space). Elements are converted to strings as by
- * String.valueOf(byte) . Returns "null" if
- * a is null .
+ * {@code String.valueOf(byte)}. Returns {@code "null"} if
+ * {@code a} is {@code null}.
*
* @param a the array whose string representation to return
- * @return a string representation of a
+ * @return a string representation of {@code a}
* @since 1.5
*/
public static String toString(byte[] a) {
@@ -4384,14 +4622,14 @@ public static String toString(byte[] a) {
/**
* Returns a string representation of the contents of the specified array.
* The string representation consists of a list of the array's elements,
- * enclosed in square brackets ("[]" ). Adjacent elements are
- * separated by the characters ", " (a comma followed by a
+ * enclosed in square brackets ({@code "[]"}). Adjacent elements are
+ * separated by the characters {@code ", "} (a comma followed by a
* space). Elements are converted to strings as by
- * String.valueOf(boolean) . Returns "null" if
- * a is null .
+ * {@code String.valueOf(boolean)}. Returns {@code "null"} if
+ * {@code a} is {@code null}.
*
* @param a the array whose string representation to return
- * @return a string representation of a
+ * @return a string representation of {@code a}
* @since 1.5
*/
public static String toString(boolean[] a) {
@@ -4414,14 +4652,14 @@ public static String toString(boolean[] a) {
/**
* Returns a string representation of the contents of the specified array.
* The string representation consists of a list of the array's elements,
- * enclosed in square brackets ("[]" ). Adjacent elements are
- * separated by the characters ", " (a comma followed by a
+ * enclosed in square brackets ({@code "[]"}). Adjacent elements are
+ * separated by the characters {@code ", "} (a comma followed by a
* space). Elements are converted to strings as by
- * String.valueOf(float) . Returns "null" if a
- * is null .
+ * {@code String.valueOf(float)}. Returns {@code "null"} if {@code a}
+ * is {@code null}.
*
* @param a the array whose string representation to return
- * @return a string representation of a
+ * @return a string representation of {@code a}
* @since 1.5
*/
public static String toString(float[] a) {
@@ -4445,14 +4683,14 @@ public static String toString(float[] a) {
/**
* Returns a string representation of the contents of the specified array.
* The string representation consists of a list of the array's elements,
- * enclosed in square brackets ("[]" ). Adjacent elements are
- * separated by the characters ", " (a comma followed by a
+ * enclosed in square brackets ({@code "[]"}). Adjacent elements are
+ * separated by the characters {@code ", "} (a comma followed by a
* space). Elements are converted to strings as by
- * String.valueOf(double) . Returns "null" if a
- * is null .
+ * {@code String.valueOf(double)}. Returns {@code "null"} if {@code a}
+ * is {@code null}.
*
* @param a the array whose string representation to return
- * @return a string representation of a
+ * @return a string representation of {@code a}
* @since 1.5
*/
public static String toString(double[] a) {
@@ -4476,15 +4714,15 @@ public static String toString(double[] a) {
* Returns a string representation of the contents of the specified array.
* If the array contains other arrays as elements, they are converted to
* strings by the {@link Object#toString} method inherited from
- * Object , which describes their identities rather than
+ * {@code Object}, which describes their identities rather than
* their contents.
*
*
The value returned by this method is equal to the value that would
- * be returned by Arrays.asList(a).toString() , unless a
- * is null , in which case "null" is returned.
+ * be returned by {@code Arrays.asList(a).toString()}, unless {@code a}
+ * is {@code null}, in which case {@code "null"} is returned.
*
* @param a the array whose string representation to return
- * @return a string representation of a
+ * @return a string representation of {@code a}
* @see #deepToString(Object[])
* @since 1.5
*/
@@ -4513,29 +4751,29 @@ public static String toString(Object[] a) {
* designed for converting multidimensional arrays to strings.
*
*
The string representation consists of a list of the array's
- * elements, enclosed in square brackets ("[]" ). Adjacent
- * elements are separated by the characters ", " (a comma
+ * elements, enclosed in square brackets ({@code "[]"}). Adjacent
+ * elements are separated by the characters {@code ", "} (a comma
* followed by a space). Elements are converted to strings as by
- * String.valueOf(Object) , unless they are themselves
+ * {@code String.valueOf(Object)}, unless they are themselves
* arrays.
*
- *
If an element e is an array of a primitive type, it is
+ *
If an element {@code e} is an array of a primitive type, it is
* converted to a string as by invoking the appropriate overloading of
- * Arrays.toString(e) . If an element e is an array of a
+ * {@code Arrays.toString(e)}. If an element {@code e} is an array of a
* reference type, it is converted to a string as by invoking
* this method recursively.
*
*
To avoid infinite recursion, if the specified array contains itself
* as an element, or contains an indirect reference to itself through one
* or more levels of arrays, the self-reference is converted to the string
- * "[...]" . For example, an array containing only a reference
- * to itself would be rendered as "[[...]]" .
+ * {@code "[...]"}. For example, an array containing only a reference
+ * to itself would be rendered as {@code "[[...]]"}.
*
- *
This method returns "null" if the specified array
- * is null .
+ *
This method returns {@code "null"} if the specified array
+ * is {@code null}.
*
* @param a the array whose string representation to return
- * @return a string representation of a
+ * @return a string representation of {@code a}
* @see #toString(Object[])
* @since 1.5
*/
@@ -4547,7 +4785,7 @@ public static String deepToString(Object[] a) {
if (a.length != 0 && bufLen <= 0)
bufLen = Integer.MAX_VALUE;
StringBuilder buf = new StringBuilder(bufLen);
- deepToString(a, buf, new HashSet());
+ deepToString(a, buf, new HashSet<>());
return buf.toString();
}
@@ -4616,6 +4854,14 @@ else if (eClass == boolean[].class)
* If the generator function throws an exception, it is relayed to
* the caller and the array is left in an indeterminate state.
*
+ * @apiNote
+ * Setting a subrange of an array, using a generator function to compute
+ * each element, can be written as follows:
+ *
{@code
+ * IntStream.range(startInclusive, endExclusive)
+ * .forEach(i -> array[i] = generator.apply(i));
+ * }
+ *
* @param type of elements of the array
* @param array array to be initialized
* @param generator a function accepting an index and producing the desired
@@ -4637,6 +4883,15 @@ public static void setAll(T[] array, IntFunction extends T> generator) {
* is thrown from {@code parallelSetAll} and the array is left in an
* indeterminate state.
*
+ * @apiNote
+ * Setting a subrange of an array, in parallel, using a generator function
+ * to compute each element, can be written as follows:
+ * {@code
+ * IntStream.range(startInclusive, endExclusive)
+ * .parallel()
+ * .forEach(i -> array[i] = generator.apply(i));
+ * }
+ *
* @param type of elements of the array
* @param array array to be initialized
* @param generator a function accepting an index and producing the desired
@@ -4656,6 +4911,14 @@ public static void parallelSetAll(T[] array, IntFunction extends T> genera
* If the generator function throws an exception, it is relayed to
* the caller and the array is left in an indeterminate state.
*
+ * @apiNote
+ * Setting a subrange of an array, using a generator function to compute
+ * each element, can be written as follows:
+ *
{@code
+ * IntStream.range(startInclusive, endExclusive)
+ * .forEach(i -> array[i] = generator.applyAsInt(i));
+ * }
+ *
* @param array array to be initialized
* @param generator a function accepting an index and producing the desired
* value for that position
@@ -4676,6 +4939,15 @@ public static void setAll(int[] array, IntUnaryOperator generator) {
* is thrown from {@code parallelSetAll} and the array is left in an
* indeterminate state.
*
+ * @apiNote
+ * Setting a subrange of an array, in parallel, using a generator function
+ * to compute each element, can be written as follows:
+ * {@code
+ * IntStream.range(startInclusive, endExclusive)
+ * .parallel()
+ * .forEach(i -> array[i] = generator.applyAsInt(i));
+ * }
+ *
* @param array array to be initialized
* @param generator a function accepting an index and producing the desired
* value for that position
@@ -4694,6 +4966,14 @@ public static void parallelSetAll(int[] array, IntUnaryOperator generator) {
* If the generator function throws an exception, it is relayed to
* the caller and the array is left in an indeterminate state.
*
+ * @apiNote
+ * Setting a subrange of an array, using a generator function to compute
+ * each element, can be written as follows:
+ *
{@code
+ * IntStream.range(startInclusive, endExclusive)
+ * .forEach(i -> array[i] = generator.applyAsLong(i));
+ * }
+ *
* @param array array to be initialized
* @param generator a function accepting an index and producing the desired
* value for that position
@@ -4714,6 +4994,15 @@ public static void setAll(long[] array, IntToLongFunction generator) {
* is thrown from {@code parallelSetAll} and the array is left in an
* indeterminate state.
*
+ * @apiNote
+ * Setting a subrange of an array, in parallel, using a generator function
+ * to compute each element, can be written as follows:
+ * {@code
+ * IntStream.range(startInclusive, endExclusive)
+ * .parallel()
+ * .forEach(i -> array[i] = generator.applyAsLong(i));
+ * }
+ *
* @param array array to be initialized
* @param generator a function accepting an index and producing the desired
* value for that position
@@ -4732,6 +5021,14 @@ public static void parallelSetAll(long[] array, IntToLongFunction generator) {
* If the generator function throws an exception, it is relayed to
* the caller and the array is left in an indeterminate state.
*
+ * @apiNote
+ * Setting a subrange of an array, using a generator function to compute
+ * each element, can be written as follows:
+ *
{@code
+ * IntStream.range(startInclusive, endExclusive)
+ * .forEach(i -> array[i] = generator.applyAsDouble(i));
+ * }
+ *
* @param array array to be initialized
* @param generator a function accepting an index and producing the desired
* value for that position
@@ -4752,6 +5049,15 @@ public static void setAll(double[] array, IntToDoubleFunction generator) {
* is thrown from {@code parallelSetAll} and the array is left in an
* indeterminate state.
*
+ * @apiNote
+ * Setting a subrange of an array, in parallel, using a generator function
+ * to compute each element, can be written as follows:
+ * {@code
+ * IntStream.range(startInclusive, endExclusive)
+ * .parallel()
+ * .forEach(i -> array[i] = generator.applyAsDouble(i));
+ * }
+ *
* @param array array to be initialized
* @param generator a function accepting an index and producing the desired
* value for that position
@@ -5043,4 +5349,3186 @@ public static DoubleStream stream(double[] array) {
public static DoubleStream stream(double[] array, int startInclusive, int endExclusive) {
return StreamSupport.doubleStream(spliterator(array, startInclusive, endExclusive), false);
}
+
+
+ // Comparison methods
+
+ // Compare boolean
+
+ // J2ObjC removed
+ // /**
+ // * Compares two {@code boolean} arrays lexicographically.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Boolean#compare(boolean, boolean)}, at an index within the
+ // * respective arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(boolean[], boolean[])} for the definition of a
+ // * common and proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // *
The comparison is consistent with {@link #equals(boolean[], boolean[]) equals},
+ // * more specifically the following holds for arrays {@code a} and {@code b}:
+ // *
{@code
+ // * Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Boolean.compare(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are equal and
+ // * contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compare(boolean[] a, boolean[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Boolean.compare(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code boolean} arrays lexicographically over the specified
+ // * ranges.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Boolean#compare(boolean, boolean)}, at a
+ // * relative index within the respective arrays that is the length of the
+ // * prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(boolean[], int, int, boolean[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // *
The comparison is consistent with
+ // * {@link #equals(boolean[], int, int, boolean[], int, int) equals}, more
+ // * specifically the following holds for arrays {@code a} and {@code b} with
+ // * specified ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively:
+ // *
{@code
+ // * Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
+ // * (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Boolean.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int compare(boolean[] a, int aFromIndex, int aToIndex,
+ // boolean[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Boolean.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // // Compare byte
+
+ // /**
+ // * Compares two {@code byte} arrays lexicographically.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Byte#compare(byte, byte)}, at an index within the respective
+ // * arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(byte[], byte[])} for the definition of a common and
+ // * proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // *
The comparison is consistent with {@link #equals(byte[], byte[]) equals},
+ // * more specifically the following holds for arrays {@code a} and {@code b}:
+ // *
{@code
+ // * Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Byte.compare(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are equal and
+ // * contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compare(byte[] a, byte[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Byte.compare(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code byte} arrays lexicographically over the specified
+ // * ranges.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Byte#compare(byte, byte)}, at a relative index
+ // * within the respective arrays that is the length of the prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(byte[], int, int, byte[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // *
The comparison is consistent with
+ // * {@link #equals(byte[], int, int, byte[], int, int) equals}, more
+ // * specifically the following holds for arrays {@code a} and {@code b} with
+ // * specified ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively:
+ // *
{@code
+ // * Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
+ // * (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Byte.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int compare(byte[] a, int aFromIndex, int aToIndex,
+ // byte[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Byte.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // /**
+ // * Compares two {@code byte} arrays lexicographically, numerically treating
+ // * elements as unsigned.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Byte#compareUnsigned(byte, byte)}, at an index within the
+ // * respective arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(byte[], byte[])} for the definition of a common
+ // * and proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // * @apiNote
+ // *
This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Byte.compareUnsigned(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are
+ // * equal and contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compareUnsigned(byte[] a, byte[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Byte.compareUnsigned(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+
+ // /**
+ // * Compares two {@code byte} arrays lexicographically over the specified
+ // * ranges, numerically treating elements as unsigned.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Byte#compareUnsigned(byte, byte)}, at a
+ // * relative index within the respective arrays that is the length of the
+ // * prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(byte[], int, int, byte[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // * @apiNote
+ // *
This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Byte.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is null
+ // * @since 9
+ // */
+ // public static int compareUnsigned(byte[] a, int aFromIndex, int aToIndex,
+ // byte[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Byte.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // // Compare short
+
+ // /**
+ // * Compares two {@code short} arrays lexicographically.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Short#compare(short, short)}, at an index within the respective
+ // * arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(short[], short[])} for the definition of a common
+ // * and proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // *
The comparison is consistent with {@link #equals(short[], short[]) equals},
+ // * more specifically the following holds for arrays {@code a} and {@code b}:
+ // *
{@code
+ // * Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Short.compare(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are equal and
+ // * contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compare(short[] a, short[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Short.compare(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code short} arrays lexicographically over the specified
+ // * ranges.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Short#compare(short, short)}, at a relative
+ // * index within the respective arrays that is the length of the prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(short[], int, int, short[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // *
The comparison is consistent with
+ // * {@link #equals(short[], int, int, short[], int, int) equals}, more
+ // * specifically the following holds for arrays {@code a} and {@code b} with
+ // * specified ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively:
+ // *
{@code
+ // * Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
+ // * (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Short.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int compare(short[] a, int aFromIndex, int aToIndex,
+ // short[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Short.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // /**
+ // * Compares two {@code short} arrays lexicographically, numerically treating
+ // * elements as unsigned.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Short#compareUnsigned(short, short)}, at an index within the
+ // * respective arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(short[], short[])} for the definition of a common
+ // * and proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // * @apiNote
+ // *
This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Short.compareUnsigned(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are
+ // * equal and contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compareUnsigned(short[] a, short[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Short.compareUnsigned(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code short} arrays lexicographically over the specified
+ // * ranges, numerically treating elements as unsigned.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Short#compareUnsigned(short, short)}, at a
+ // * relative index within the respective arrays that is the length of the
+ // * prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(short[], int, int, short[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // * @apiNote
+ // *
This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Short.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is null
+ // * @since 9
+ // */
+ // public static int compareUnsigned(short[] a, int aFromIndex, int aToIndex,
+ // short[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Short.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // // Compare char
+
+ // /**
+ // * Compares two {@code char} arrays lexicographically.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Character#compare(char, char)}, at an index within the respective
+ // * arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(char[], char[])} for the definition of a common and
+ // * proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // *
The comparison is consistent with {@link #equals(char[], char[]) equals},
+ // * more specifically the following holds for arrays {@code a} and {@code b}:
+ // *
{@code
+ // * Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Character.compare(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are equal and
+ // * contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compare(char[] a, char[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Character.compare(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code char} arrays lexicographically over the specified
+ // * ranges.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Character#compare(char, char)}, at a relative
+ // * index within the respective arrays that is the length of the prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(char[], int, int, char[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // *
The comparison is consistent with
+ // * {@link #equals(char[], int, int, char[], int, int) equals}, more
+ // * specifically the following holds for arrays {@code a} and {@code b} with
+ // * specified ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively:
+ // *
{@code
+ // * Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
+ // * (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Character.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int compare(char[] a, int aFromIndex, int aToIndex,
+ // char[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Character.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // // Compare int
+
+ // /**
+ // * Compares two {@code int} arrays lexicographically.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Integer#compare(int, int)}, at an index within the respective
+ // * arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(int[], int[])} for the definition of a common and
+ // * proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // *
The comparison is consistent with {@link #equals(int[], int[]) equals},
+ // * more specifically the following holds for arrays {@code a} and {@code b}:
+ // *
{@code
+ // * Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Integer.compare(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are equal and
+ // * contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compare(int[] a, int[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Integer.compare(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code int} arrays lexicographically over the specified
+ // * ranges.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Integer#compare(int, int)}, at a relative index
+ // * within the respective arrays that is the length of the prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(int[], int, int, int[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // *
The comparison is consistent with
+ // * {@link #equals(int[], int, int, int[], int, int) equals}, more
+ // * specifically the following holds for arrays {@code a} and {@code b} with
+ // * specified ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively:
+ // *
{@code
+ // * Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
+ // * (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Integer.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int compare(int[] a, int aFromIndex, int aToIndex,
+ // int[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Integer.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // /**
+ // * Compares two {@code int} arrays lexicographically, numerically treating
+ // * elements as unsigned.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Integer#compareUnsigned(int, int)}, at an index within the
+ // * respective arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(int[], int[])} for the definition of a common
+ // * and proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // * @apiNote
+ // *
This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Integer.compareUnsigned(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are
+ // * equal and contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compareUnsigned(int[] a, int[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Integer.compareUnsigned(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code int} arrays lexicographically over the specified
+ // * ranges, numerically treating elements as unsigned.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Integer#compareUnsigned(int, int)}, at a
+ // * relative index within the respective arrays that is the length of the
+ // * prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(int[], int, int, int[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // * @apiNote
+ // *
This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Integer.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is null
+ // * @since 9
+ // */
+ // public static int compareUnsigned(int[] a, int aFromIndex, int aToIndex,
+ // int[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Integer.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // // Compare long
+
+ // /**
+ // * Compares two {@code long} arrays lexicographically.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Long#compare(long, long)}, at an index within the respective
+ // * arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(long[], long[])} for the definition of a common and
+ // * proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // *
The comparison is consistent with {@link #equals(long[], long[]) equals},
+ // * more specifically the following holds for arrays {@code a} and {@code b}:
+ // *
{@code
+ // * Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Long.compare(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are equal and
+ // * contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compare(long[] a, long[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Long.compare(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code long} arrays lexicographically over the specified
+ // * ranges.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Long#compare(long, long)}, at a relative index
+ // * within the respective arrays that is the length of the prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(long[], int, int, long[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // *
The comparison is consistent with
+ // * {@link #equals(long[], int, int, long[], int, int) equals}, more
+ // * specifically the following holds for arrays {@code a} and {@code b} with
+ // * specified ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively:
+ // *
{@code
+ // * Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
+ // * (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Long.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int compare(long[] a, int aFromIndex, int aToIndex,
+ // long[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Long.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // /**
+ // * Compares two {@code long} arrays lexicographically, numerically treating
+ // * elements as unsigned.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Long#compareUnsigned(long, long)}, at an index within the
+ // * respective arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(long[], long[])} for the definition of a common
+ // * and proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // * @apiNote
+ // *
This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Long.compareUnsigned(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are
+ // * equal and contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compareUnsigned(long[] a, long[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Long.compareUnsigned(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code long} arrays lexicographically over the specified
+ // * ranges, numerically treating elements as unsigned.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Long#compareUnsigned(long, long)}, at a
+ // * relative index within the respective arrays that is the length of the
+ // * prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(long[], int, int, long[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // * @apiNote
+ // *
This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Long.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is null
+ // * @since 9
+ // */
+ // public static int compareUnsigned(long[] a, int aFromIndex, int aToIndex,
+ // long[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Long.compareUnsigned(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // // Compare float
+
+ // /**
+ // * Compares two {@code float} arrays lexicographically.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Float#compare(float, float)}, at an index within the respective
+ // * arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(float[], float[])} for the definition of a common
+ // * and proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // *
The comparison is consistent with {@link #equals(float[], float[]) equals},
+ // * more specifically the following holds for arrays {@code a} and {@code b}:
+ // *
{@code
+ // * Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Float.compare(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are equal and
+ // * contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compare(float[] a, float[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Float.compare(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code float} arrays lexicographically over the specified
+ // * ranges.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Float#compare(float, float)}, at a relative
+ // * index within the respective arrays that is the length of the prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(float[], int, int, float[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // *
The comparison is consistent with
+ // * {@link #equals(float[], int, int, float[], int, int) equals}, more
+ // * specifically the following holds for arrays {@code a} and {@code b} with
+ // * specified ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively:
+ // *
{@code
+ // * Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
+ // * (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Float.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int compare(float[] a, int aFromIndex, int aToIndex,
+ // float[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Float.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // // Compare double
+
+ // /**
+ // * Compares two {@code double} arrays lexicographically.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements, as if by
+ // * {@link Double#compare(double, double)}, at an index within the respective
+ // * arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(double[], double[])} for the definition of a common
+ // * and proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // *
The comparison is consistent with {@link #equals(double[], double[]) equals},
+ // * more specifically the following holds for arrays {@code a} and {@code b}:
+ // *
{@code
+ // * Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return Double.compare(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @return the value {@code 0} if the first and second array are equal and
+ // * contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static int compare(double[] a, double[] b) {
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int i = ArraysSupport.mismatch(a, b,
+ // Math.min(a.length, b.length));
+ // if (i >= 0) {
+ // return Double.compare(a[i], b[i]);
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code double} arrays lexicographically over the specified
+ // * ranges.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements, as if by {@link Double#compare(double, double)}, at a relative
+ // * index within the respective arrays that is the length of the prefix.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(double[], int, int, double[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // *
The comparison is consistent with
+ // * {@link #equals(double[], int, int, double[], int, int) equals}, more
+ // * specifically the following holds for arrays {@code a} and {@code b} with
+ // * specified ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively:
+ // *
{@code
+ // * Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
+ // * (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if:
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return Double.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int compare(double[] a, int aFromIndex, int aToIndex,
+ // double[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // Math.min(aLength, bLength));
+ // if (i >= 0) {
+ // return Double.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // // Compare objects
+
+ // /**
+ // * Compares two {@code Object} arrays, within comparable elements,
+ // * lexicographically.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing two elements of type {@code T} at
+ // * an index {@code i} within the respective arrays that is the prefix
+ // * length, as if by:
+ // *
{@code
+ // * Comparator.nullsFirst(Comparator.naturalOrder()).
+ // * compare(a[i], b[i])
+ // * }
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(Object[], Object[])} for the definition of a common
+ // * and proper prefix.)
+ // *
+ // * A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // * A {@code null} array element is considered lexicographically less than a
+ // * non-{@code null} array element. Two {@code null} array elements are
+ // * considered equal.
+ // *
+ // *
The comparison is consistent with {@link #equals(Object[], Object[]) equals},
+ // * more specifically the following holds for arrays {@code a} and {@code b}:
+ // *
{@code
+ // * Arrays.equals(a, b) == (Arrays.compare(a, b) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if (for non-{@code null} array references
+ // * and elements):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return a[i].compareTo(b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @param the type of comparable array elements
+ // * @return the value {@code 0} if the first and second array are equal and
+ // * contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @since 9
+ // */
+ // public static > int compare(T[] a, T[] b) {
+ // if (a == b)
+ // return 0;
+ // // A null array is less than a non-null array
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int length = Math.min(a.length, b.length);
+ // for (int i = 0; i < length; i++) {
+ // T oa = a[i];
+ // T ob = b[i];
+ // if (oa != ob) {
+ // // A null element is less than a non-null element
+ // if (oa == null || ob == null)
+ // return oa == null ? -1 : 1;
+ // int v = oa.compareTo(ob);
+ // if (v != 0) {
+ // return v;
+ // }
+ // }
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code Object} arrays lexicographically over the specified
+ // * ranges.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing two
+ // * elements of type {@code T} at a relative index {@code i} within the
+ // * respective arrays that is the prefix length, as if by:
+ // *
{@code
+ // * Comparator.nullsFirst(Comparator.naturalOrder()).
+ // * compare(a[aFromIndex + i, b[bFromIndex + i])
+ // * }
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(Object[], int, int, Object[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // * The comparison is consistent with
+ // * {@link #equals(Object[], int, int, Object[], int, int) equals}, more
+ // * specifically the following holds for arrays {@code a} and {@code b} with
+ // * specified ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively:
+ // *
{@code
+ // * Arrays.equals(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) ==
+ // * (Arrays.compare(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex) == 0)
+ // * }
+ // *
+ // * @apiNote
+ // * This method behaves as if (for non-{@code null} array elements):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return a[aFromIndex + i].compareTo(b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @param the type of comparable array elements
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static > int compare(
+ // T[] a, int aFromIndex, int aToIndex,
+ // T[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // for (int i = 0; i < length; i++) {
+ // T oa = a[aFromIndex++];
+ // T ob = b[bFromIndex++];
+ // if (oa != ob) {
+ // if (oa == null || ob == null)
+ // return oa == null ? -1 : 1;
+ // int v = oa.compareTo(ob);
+ // if (v != 0) {
+ // return v;
+ // }
+ // }
+ // }
+
+ // return aLength - bLength;
+ // }
+
+ // /**
+ // * Compares two {@code Object} arrays lexicographically using a specified
+ // * comparator.
+ // *
+ // * If the two arrays share a common prefix then the lexicographic
+ // * comparison is the result of comparing with the specified comparator two
+ // * elements at an index within the respective arrays that is the prefix
+ // * length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two array lengths.
+ // * (See {@link #mismatch(Object[], Object[])} for the definition of a common
+ // * and proper prefix.)
+ // *
+ // *
A {@code null} array reference is considered lexicographically less
+ // * than a non-{@code null} array reference. Two {@code null} array
+ // * references are considered equal.
+ // *
+ // * @apiNote
+ // *
This method behaves as if (for non-{@code null} array references):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, b, cmp);
+ // * if (i >= 0 && i < Math.min(a.length, b.length))
+ // * return cmp.compare(a[i], b[i]);
+ // * return a.length - b.length;
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param b the second array to compare
+ // * @param cmp the comparator to compare array elements
+ // * @param the type of array elements
+ // * @return the value {@code 0} if the first and second array are equal and
+ // * contain the same elements in the same order;
+ // * a value less than {@code 0} if the first array is
+ // * lexicographically less than the second array; and
+ // * a value greater than {@code 0} if the first array is
+ // * lexicographically greater than the second array
+ // * @throws NullPointerException if the comparator is {@code null}
+ // * @since 9
+ // */
+ // public static int compare(T[] a, T[] b,
+ // Comparator super T> cmp) {
+ // Objects.requireNonNull(cmp);
+ // if (a == b)
+ // return 0;
+ // if (a == null || b == null)
+ // return a == null ? -1 : 1;
+
+ // int length = Math.min(a.length, b.length);
+ // for (int i = 0; i < length; i++) {
+ // T oa = a[i];
+ // T ob = b[i];
+ // if (oa != ob) {
+ // // Null-value comparison is deferred to the comparator
+ // int v = cmp.compare(oa, ob);
+ // if (v != 0) {
+ // return v;
+ // }
+ // }
+ // }
+
+ // return a.length - b.length;
+ // }
+
+ // /**
+ // * Compares two {@code Object} arrays lexicographically over the specified
+ // * ranges.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the lexicographic comparison is the result of comparing with the
+ // * specified comparator two elements at a relative index within the
+ // * respective arrays that is the prefix length.
+ // * Otherwise, one array is a proper prefix of the other and, lexicographic
+ // * comparison is the result of comparing the two range lengths.
+ // * (See {@link #mismatch(Object[], int, int, Object[], int, int)} for the
+ // * definition of a common and proper prefix.)
+ // *
+ // * @apiNote
+ // *
This method behaves as if (for non-{@code null} array elements):
+ // *
{@code
+ // * int i = Arrays.mismatch(a, aFromIndex, aToIndex,
+ // * b, bFromIndex, bToIndex, cmp);
+ // * if (i >= 0 && i < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * return cmp.compare(a[aFromIndex + i], b[bFromIndex + i]);
+ // * return (aToIndex - aFromIndex) - (bToIndex - bFromIndex);
+ // * }
+ // *
+ // * @param a the first array to compare
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be compared
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be compared
+ // * @param b the second array to compare
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be compared
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be compared
+ // * @param cmp the comparator to compare array elements
+ // * @param the type of array elements
+ // * @return the value {@code 0} if, over the specified ranges, the first and
+ // * second array are equal and contain the same elements in the same
+ // * order;
+ // * a value less than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically less than the second array; and
+ // * a value greater than {@code 0} if, over the specified ranges, the
+ // * first array is lexicographically greater than the second array
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array or the comparator is {@code null}
+ // * @since 9
+ // */
+ // public static int compare(
+ // T[] a, int aFromIndex, int aToIndex,
+ // T[] b, int bFromIndex, int bToIndex,
+ // Comparator super T> cmp) {
+ // Objects.requireNonNull(cmp);
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // for (int i = 0; i < length; i++) {
+ // T oa = a[aFromIndex++];
+ // T ob = b[bFromIndex++];
+ // if (oa != ob) {
+ // // Null-value comparison is deferred to the comparator
+ // int v = cmp.compare(oa, ob);
+ // if (v != 0) {
+ // return v;
+ // }
+ // }
+ // }
+
+ // return aLength - bLength;
+ // }
+
+
+ // // Mismatch methods
+
+ // // Mismatch boolean
+
+ // /**
+ // * Finds and returns the index of the first mismatch between two
+ // * {@code boolean} arrays, otherwise return -1 if no mismatch is found. The
+ // * index will be in the range of 0 (inclusive) up to the length (inclusive)
+ // * of the smaller array.
+ // *
+ // * If the two arrays share a common prefix then the returned index is the
+ // * length of the common prefix and it follows that there is a mismatch
+ // * between the two elements at that index within the respective arrays.
+ // * If one array is a proper prefix of the other then the returned index is
+ // * the length of the smaller array and it follows that the index is only
+ // * valid for the larger array.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b}, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(a.length, b.length) &&
+ // * Arrays.equals(a, 0, pl, b, 0, pl) &&
+ // * a[pl] != b[pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b}, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * a.length != b.length &&
+ // * Arrays.equals(a, 0, Math.min(a.length, b.length),
+ // * b, 0, Math.min(a.length, b.length))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param b the second array to be tested for a mismatch
+ // * @return the index of the first mismatch between the two arrays,
+ // * otherwise {@code -1}.
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(boolean[] a, boolean[] b) {
+ // int length = Math.min(a.length, b.length); // Check null array refs
+ // if (a == b)
+ // return -1;
+
+ // int i = ArraysSupport.mismatch(a, b, length);
+ // return (i < 0 && a.length != b.length) ? length : i;
+ // }
+
+ // /**
+ // * Finds and returns the relative index of the first mismatch between two
+ // * {@code boolean} arrays over the specified ranges, otherwise return -1 if
+ // * no mismatch is found. The index will be in the range of 0 (inclusive) up
+ // * to the length (inclusive) of the smaller range.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the returned relative index is the length of the common prefix and
+ // * it follows that there is a mismatch between the two elements at that
+ // * relative index within the respective arrays.
+ // * If one array is a proper prefix of the other, over the specified ranges,
+ // * then the returned relative index is the length of the smaller range and
+ // * it follows that the relative index is only valid for the array with the
+ // * larger range.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
+ // * a[aFromIndex + pl] != b[bFromIndex + pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be tested
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be tested
+ // * @param b the second array to be tested for a mismatch
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be tested
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be tested
+ // * @return the relative index of the first mismatch between the two arrays
+ // * over the specified ranges, otherwise {@code -1}.
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(boolean[] a, int aFromIndex, int aToIndex,
+ // boolean[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // length);
+ // return (i < 0 && aLength != bLength) ? length : i;
+ // }
+
+ // // Mismatch byte
+
+ // /**
+ // * Finds and returns the index of the first mismatch between two {@code byte}
+ // * arrays, otherwise return -1 if no mismatch is found. The index will be
+ // * in the range of 0 (inclusive) up to the length (inclusive) of the smaller
+ // * array.
+ // *
+ // * If the two arrays share a common prefix then the returned index is the
+ // * length of the common prefix and it follows that there is a mismatch
+ // * between the two elements at that index within the respective arrays.
+ // * If one array is a proper prefix of the other then the returned index is
+ // * the length of the smaller array and it follows that the index is only
+ // * valid for the larger array.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b}, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(a.length, b.length) &&
+ // * Arrays.equals(a, 0, pl, b, 0, pl) &&
+ // * a[pl] != b[pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b}, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * a.length != b.length &&
+ // * Arrays.equals(a, 0, Math.min(a.length, b.length),
+ // * b, 0, Math.min(a.length, b.length))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param b the second array to be tested for a mismatch
+ // * @return the index of the first mismatch between the two arrays,
+ // * otherwise {@code -1}.
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(byte[] a, byte[] b) {
+ // int length = Math.min(a.length, b.length); // Check null array refs
+ // if (a == b)
+ // return -1;
+
+ // int i = ArraysSupport.mismatch(a, b, length);
+ // return (i < 0 && a.length != b.length) ? length : i;
+ // }
+
+ // /**
+ // * Finds and returns the relative index of the first mismatch between two
+ // * {@code byte} arrays over the specified ranges, otherwise return -1 if no
+ // * mismatch is found. The index will be in the range of 0 (inclusive) up to
+ // * the length (inclusive) of the smaller range.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the returned relative index is the length of the common prefix and
+ // * it follows that there is a mismatch between the two elements at that
+ // * relative index within the respective arrays.
+ // * If one array is a proper prefix of the other, over the specified ranges,
+ // * then the returned relative index is the length of the smaller range and
+ // * it follows that the relative index is only valid for the array with the
+ // * larger range.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
+ // * a[aFromIndex + pl] != b[bFromIndex + pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be tested
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be tested
+ // * @param b the second array to be tested for a mismatch
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be tested
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be tested
+ // * @return the relative index of the first mismatch between the two arrays
+ // * over the specified ranges, otherwise {@code -1}.
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(byte[] a, int aFromIndex, int aToIndex,
+ // byte[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // length);
+ // return (i < 0 && aLength != bLength) ? length : i;
+ // }
+
+ // // Mismatch char
+
+ // /**
+ // * Finds and returns the index of the first mismatch between two {@code char}
+ // * arrays, otherwise return -1 if no mismatch is found. The index will be
+ // * in the range of 0 (inclusive) up to the length (inclusive) of the smaller
+ // * array.
+ // *
+ // * If the two arrays share a common prefix then the returned index is the
+ // * length of the common prefix and it follows that there is a mismatch
+ // * between the two elements at that index within the respective arrays.
+ // * If one array is a proper prefix of the other then the returned index is
+ // * the length of the smaller array and it follows that the index is only
+ // * valid for the larger array.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b}, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(a.length, b.length) &&
+ // * Arrays.equals(a, 0, pl, b, 0, pl) &&
+ // * a[pl] != b[pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b}, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * a.length != b.length &&
+ // * Arrays.equals(a, 0, Math.min(a.length, b.length),
+ // * b, 0, Math.min(a.length, b.length))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param b the second array to be tested for a mismatch
+ // * @return the index of the first mismatch between the two arrays,
+ // * otherwise {@code -1}.
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(char[] a, char[] b) {
+ // int length = Math.min(a.length, b.length); // Check null array refs
+ // if (a == b)
+ // return -1;
+
+ // int i = ArraysSupport.mismatch(a, b, length);
+ // return (i < 0 && a.length != b.length) ? length : i;
+ // }
+
+ // /**
+ // * Finds and returns the relative index of the first mismatch between two
+ // * {@code char} arrays over the specified ranges, otherwise return -1 if no
+ // * mismatch is found. The index will be in the range of 0 (inclusive) up to
+ // * the length (inclusive) of the smaller range.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the returned relative index is the length of the common prefix and
+ // * it follows that there is a mismatch between the two elements at that
+ // * relative index within the respective arrays.
+ // * If one array is a proper prefix of the other, over the specified ranges,
+ // * then the returned relative index is the length of the smaller range and
+ // * it follows that the relative index is only valid for the array with the
+ // * larger range.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
+ // * a[aFromIndex + pl] != b[bFromIndex + pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be tested
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be tested
+ // * @param b the second array to be tested for a mismatch
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be tested
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be tested
+ // * @return the relative index of the first mismatch between the two arrays
+ // * over the specified ranges, otherwise {@code -1}.
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(char[] a, int aFromIndex, int aToIndex,
+ // char[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // length);
+ // return (i < 0 && aLength != bLength) ? length : i;
+ // }
+
+ // // Mismatch short
+
+ // /**
+ // * Finds and returns the index of the first mismatch between two {@code short}
+ // * arrays, otherwise return -1 if no mismatch is found. The index will be
+ // * in the range of 0 (inclusive) up to the length (inclusive) of the smaller
+ // * array.
+ // *
+ // * If the two arrays share a common prefix then the returned index is the
+ // * length of the common prefix and it follows that there is a mismatch
+ // * between the two elements at that index within the respective arrays.
+ // * If one array is a proper prefix of the other then the returned index is
+ // * the length of the smaller array and it follows that the index is only
+ // * valid for the larger array.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b}, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(a.length, b.length) &&
+ // * Arrays.equals(a, 0, pl, b, 0, pl) &&
+ // * a[pl] != b[pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b}, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * a.length != b.length &&
+ // * Arrays.equals(a, 0, Math.min(a.length, b.length),
+ // * b, 0, Math.min(a.length, b.length))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param b the second array to be tested for a mismatch
+ // * @return the index of the first mismatch between the two arrays,
+ // * otherwise {@code -1}.
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(short[] a, short[] b) {
+ // int length = Math.min(a.length, b.length); // Check null array refs
+ // if (a == b)
+ // return -1;
+
+ // int i = ArraysSupport.mismatch(a, b, length);
+ // return (i < 0 && a.length != b.length) ? length : i;
+ // }
+
+ // /**
+ // * Finds and returns the relative index of the first mismatch between two
+ // * {@code short} arrays over the specified ranges, otherwise return -1 if no
+ // * mismatch is found. The index will be in the range of 0 (inclusive) up to
+ // * the length (inclusive) of the smaller range.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the returned relative index is the length of the common prefix and
+ // * it follows that there is a mismatch between the two elements at that
+ // * relative index within the respective arrays.
+ // * If one array is a proper prefix of the other, over the specified ranges,
+ // * then the returned relative index is the length of the smaller range and
+ // * it follows that the relative index is only valid for the array with the
+ // * larger range.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
+ // * a[aFromIndex + pl] != b[bFromIndex + pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be tested
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be tested
+ // * @param b the second array to be tested for a mismatch
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be tested
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be tested
+ // * @return the relative index of the first mismatch between the two arrays
+ // * over the specified ranges, otherwise {@code -1}.
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(short[] a, int aFromIndex, int aToIndex,
+ // short[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // length);
+ // return (i < 0 && aLength != bLength) ? length : i;
+ // }
+
+ // // Mismatch int
+
+ // /**
+ // * Finds and returns the index of the first mismatch between two {@code int}
+ // * arrays, otherwise return -1 if no mismatch is found. The index will be
+ // * in the range of 0 (inclusive) up to the length (inclusive) of the smaller
+ // * array.
+ // *
+ // * If the two arrays share a common prefix then the returned index is the
+ // * length of the common prefix and it follows that there is a mismatch
+ // * between the two elements at that index within the respective arrays.
+ // * If one array is a proper prefix of the other then the returned index is
+ // * the length of the smaller array and it follows that the index is only
+ // * valid for the larger array.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b}, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(a.length, b.length) &&
+ // * Arrays.equals(a, 0, pl, b, 0, pl) &&
+ // * a[pl] != b[pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b}, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * a.length != b.length &&
+ // * Arrays.equals(a, 0, Math.min(a.length, b.length),
+ // * b, 0, Math.min(a.length, b.length))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param b the second array to be tested for a mismatch
+ // * @return the index of the first mismatch between the two arrays,
+ // * otherwise {@code -1}.
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(int[] a, int[] b) {
+ // int length = Math.min(a.length, b.length); // Check null array refs
+ // if (a == b)
+ // return -1;
+
+ // int i = ArraysSupport.mismatch(a, b, length);
+ // return (i < 0 && a.length != b.length) ? length : i;
+ // }
+
+ // /**
+ // * Finds and returns the relative index of the first mismatch between two
+ // * {@code int} arrays over the specified ranges, otherwise return -1 if no
+ // * mismatch is found. The index will be in the range of 0 (inclusive) up to
+ // * the length (inclusive) of the smaller range.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the returned relative index is the length of the common prefix and
+ // * it follows that there is a mismatch between the two elements at that
+ // * relative index within the respective arrays.
+ // * If one array is a proper prefix of the other, over the specified ranges,
+ // * then the returned relative index is the length of the smaller range and
+ // * it follows that the relative index is only valid for the array with the
+ // * larger range.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
+ // * a[aFromIndex + pl] != b[bFromIndex + pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be tested
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be tested
+ // * @param b the second array to be tested for a mismatch
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be tested
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be tested
+ // * @return the relative index of the first mismatch between the two arrays
+ // * over the specified ranges, otherwise {@code -1}.
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(int[] a, int aFromIndex, int aToIndex,
+ // int[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // length);
+ // return (i < 0 && aLength != bLength) ? length : i;
+ // }
+
+ // // Mismatch long
+
+ // /**
+ // * Finds and returns the index of the first mismatch between two {@code long}
+ // * arrays, otherwise return -1 if no mismatch is found. The index will be
+ // * in the range of 0 (inclusive) up to the length (inclusive) of the smaller
+ // * array.
+ // *
+ // * If the two arrays share a common prefix then the returned index is the
+ // * length of the common prefix and it follows that there is a mismatch
+ // * between the two elements at that index within the respective arrays.
+ // * If one array is a proper prefix of the other then the returned index is
+ // * the length of the smaller array and it follows that the index is only
+ // * valid for the larger array.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b}, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(a.length, b.length) &&
+ // * Arrays.equals(a, 0, pl, b, 0, pl) &&
+ // * a[pl] != b[pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b}, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * a.length != b.length &&
+ // * Arrays.equals(a, 0, Math.min(a.length, b.length),
+ // * b, 0, Math.min(a.length, b.length))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param b the second array to be tested for a mismatch
+ // * @return the index of the first mismatch between the two arrays,
+ // * otherwise {@code -1}.
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(long[] a, long[] b) {
+ // int length = Math.min(a.length, b.length); // Check null array refs
+ // if (a == b)
+ // return -1;
+
+ // int i = ArraysSupport.mismatch(a, b, length);
+ // return (i < 0 && a.length != b.length) ? length : i;
+ // }
+
+ // /**
+ // * Finds and returns the relative index of the first mismatch between two
+ // * {@code long} arrays over the specified ranges, otherwise return -1 if no
+ // * mismatch is found. The index will be in the range of 0 (inclusive) up to
+ // * the length (inclusive) of the smaller range.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the returned relative index is the length of the common prefix and
+ // * it follows that there is a mismatch between the two elements at that
+ // * relative index within the respective arrays.
+ // * If one array is a proper prefix of the other, over the specified ranges,
+ // * then the returned relative index is the length of the smaller range and
+ // * it follows that the relative index is only valid for the array with the
+ // * larger range.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
+ // * a[aFromIndex + pl] != b[bFromIndex + pl]
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be tested
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be tested
+ // * @param b the second array to be tested for a mismatch
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be tested
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be tested
+ // * @return the relative index of the first mismatch between the two arrays
+ // * over the specified ranges, otherwise {@code -1}.
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(long[] a, int aFromIndex, int aToIndex,
+ // long[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // length);
+ // return (i < 0 && aLength != bLength) ? length : i;
+ // }
+
+ // // Mismatch float
+
+ // /**
+ // * Finds and returns the index of the first mismatch between two {@code float}
+ // * arrays, otherwise return -1 if no mismatch is found. The index will be
+ // * in the range of 0 (inclusive) up to the length (inclusive) of the smaller
+ // * array.
+ // *
+ // * If the two arrays share a common prefix then the returned index is the
+ // * length of the common prefix and it follows that there is a mismatch
+ // * between the two elements at that index within the respective arrays.
+ // * If one array is a proper prefix of the other then the returned index is
+ // * the length of the smaller array and it follows that the index is only
+ // * valid for the larger array.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b}, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(a.length, b.length) &&
+ // * Arrays.equals(a, 0, pl, b, 0, pl) &&
+ // * Float.compare(a[pl], b[pl]) != 0
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b}, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * a.length != b.length &&
+ // * Arrays.equals(a, 0, Math.min(a.length, b.length),
+ // * b, 0, Math.min(a.length, b.length))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param b the second array to be tested for a mismatch
+ // * @return the index of the first mismatch between the two arrays,
+ // * otherwise {@code -1}.
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(float[] a, float[] b) {
+ // int length = Math.min(a.length, b.length); // Check null array refs
+ // if (a == b)
+ // return -1;
+
+ // int i = ArraysSupport.mismatch(a, b, length);
+ // return (i < 0 && a.length != b.length) ? length : i;
+ // }
+
+ // /**
+ // * Finds and returns the relative index of the first mismatch between two
+ // * {@code float} arrays over the specified ranges, otherwise return -1 if no
+ // * mismatch is found. The index will be in the range of 0 (inclusive) up to
+ // * the length (inclusive) of the smaller range.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the returned relative index is the length of the common prefix and
+ // * it follows that there is a mismatch between the two elements at that
+ // * relative index within the respective arrays.
+ // * If one array is a proper prefix of the other, over the specified ranges,
+ // * then the returned relative index is the length of the smaller range and
+ // * it follows that the relative index is only valid for the array with the
+ // * larger range.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
+ // * Float.compare(a[aFromIndex + pl], b[bFromIndex + pl]) != 0
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be tested
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be tested
+ // * @param b the second array to be tested for a mismatch
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be tested
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be tested
+ // * @return the relative index of the first mismatch between the two arrays
+ // * over the specified ranges, otherwise {@code -1}.
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(float[] a, int aFromIndex, int aToIndex,
+ // float[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // length);
+ // return (i < 0 && aLength != bLength) ? length : i;
+ // }
+
+ // // Mismatch double
+
+ // /**
+ // * Finds and returns the index of the first mismatch between two
+ // * {@code double} arrays, otherwise return -1 if no mismatch is found. The
+ // * index will be in the range of 0 (inclusive) up to the length (inclusive)
+ // * of the smaller array.
+ // *
+ // * If the two arrays share a common prefix then the returned index is the
+ // * length of the common prefix and it follows that there is a mismatch
+ // * between the two elements at that index within the respective arrays.
+ // * If one array is a proper prefix of the other then the returned index is
+ // * the length of the smaller array and it follows that the index is only
+ // * valid for the larger array.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b}, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(a.length, b.length) &&
+ // * Arrays.equals(a, 0, pl, b, 0, pl) &&
+ // * Double.compare(a[pl], b[pl]) != 0
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b}, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * a.length != b.length &&
+ // * Arrays.equals(a, 0, Math.min(a.length, b.length),
+ // * b, 0, Math.min(a.length, b.length))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param b the second array to be tested for a mismatch
+ // * @return the index of the first mismatch between the two arrays,
+ // * otherwise {@code -1}.
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(double[] a, double[] b) {
+ // int length = Math.min(a.length, b.length); // Check null array refs
+ // if (a == b)
+ // return -1;
+
+ // int i = ArraysSupport.mismatch(a, b, length);
+ // return (i < 0 && a.length != b.length) ? length : i;
+ // }
+
+ // /**
+ // * Finds and returns the relative index of the first mismatch between two
+ // * {@code double} arrays over the specified ranges, otherwise return -1 if
+ // * no mismatch is found. The index will be in the range of 0 (inclusive) up
+ // * to the length (inclusive) of the smaller range.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the returned relative index is the length of the common prefix and
+ // * it follows that there is a mismatch between the two elements at that
+ // * relative index within the respective arrays.
+ // * If one array is a proper prefix of the other, over the specified ranges,
+ // * then the returned relative index is the length of the smaller range and
+ // * it follows that the relative index is only valid for the array with the
+ // * larger range.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
+ // * Double.compare(a[aFromIndex + pl], b[bFromIndex + pl]) != 0
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be tested
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be tested
+ // * @param b the second array to be tested for a mismatch
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be tested
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be tested
+ // * @return the relative index of the first mismatch between the two arrays
+ // * over the specified ranges, otherwise {@code -1}.
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(double[] a, int aFromIndex, int aToIndex,
+ // double[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // int i = ArraysSupport.mismatch(a, aFromIndex,
+ // b, bFromIndex,
+ // length);
+ // return (i < 0 && aLength != bLength) ? length : i;
+ // }
+
+ // // Mismatch objects
+
+ // /**
+ // * Finds and returns the index of the first mismatch between two
+ // * {@code Object} arrays, otherwise return -1 if no mismatch is found. The
+ // * index will be in the range of 0 (inclusive) up to the length (inclusive)
+ // * of the smaller array.
+ // *
+ // * If the two arrays share a common prefix then the returned index is the
+ // * length of the common prefix and it follows that there is a mismatch
+ // * between the two elements at that index within the respective arrays.
+ // * If one array is a proper prefix of the other then the returned index is
+ // * the length of the smaller array and it follows that the index is only
+ // * valid for the larger array.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b}, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(a.length, b.length) &&
+ // * Arrays.equals(a, 0, pl, b, 0, pl) &&
+ // * !Objects.equals(a[pl], b[pl])
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b}, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * a.length != b.length &&
+ // * Arrays.equals(a, 0, Math.min(a.length, b.length),
+ // * b, 0, Math.min(a.length, b.length))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param b the second array to be tested for a mismatch
+ // * @return the index of the first mismatch between the two arrays,
+ // * otherwise {@code -1}.
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(Object[] a, Object[] b) {
+ // int length = Math.min(a.length, b.length); // Check null array refs
+ // if (a == b)
+ // return -1;
+
+ // for (int i = 0; i < length; i++) {
+ // if (!Objects.equals(a[i], b[i]))
+ // return i;
+ // }
+
+ // return a.length != b.length ? length : -1;
+ // }
+
+ // /**
+ // * Finds and returns the relative index of the first mismatch between two
+ // * {@code Object} arrays over the specified ranges, otherwise return -1 if
+ // * no mismatch is found. The index will be in the range of 0 (inclusive) up
+ // * to the length (inclusive) of the smaller range.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the returned relative index is the length of the common prefix and
+ // * it follows that there is a mismatch between the two elements at that
+ // * relative index within the respective arrays.
+ // * If one array is a proper prefix of the other, over the specified ranges,
+ // * then the returned relative index is the length of the smaller range and
+ // * it follows that the relative index is only valid for the array with the
+ // * larger range.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
+ // * !Objects.equals(a[aFromIndex + pl], b[bFromIndex + pl])
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be tested
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be tested
+ // * @param b the second array to be tested for a mismatch
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be tested
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be tested
+ // * @return the relative index of the first mismatch between the two arrays
+ // * over the specified ranges, otherwise {@code -1}.
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(
+ // Object[] a, int aFromIndex, int aToIndex,
+ // Object[] b, int bFromIndex, int bToIndex) {
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // for (int i = 0; i < length; i++) {
+ // if (!Objects.equals(a[aFromIndex++], b[bFromIndex++]))
+ // return i;
+ // }
+
+ // return aLength != bLength ? length : -1;
+ // }
+
+ // /**
+ // * Finds and returns the index of the first mismatch between two
+ // * {@code Object} arrays, otherwise return -1 if no mismatch is found.
+ // * The index will be in the range of 0 (inclusive) up to the length
+ // * (inclusive) of the smaller array.
+ // *
+ // * The specified comparator is used to determine if two array elements
+ // * from the each array are not equal.
+ // *
+ // *
If the two arrays share a common prefix then the returned index is the
+ // * length of the common prefix and it follows that there is a mismatch
+ // * between the two elements at that index within the respective arrays.
+ // * If one array is a proper prefix of the other then the returned index is
+ // * the length of the smaller array and it follows that the index is only
+ // * valid for the larger array.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b}, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(a.length, b.length) &&
+ // * Arrays.equals(a, 0, pl, b, 0, pl, cmp)
+ // * cmp.compare(a[pl], b[pl]) != 0
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b}, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * a.length != b.length &&
+ // * Arrays.equals(a, 0, Math.min(a.length, b.length),
+ // * b, 0, Math.min(a.length, b.length),
+ // * cmp)
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param b the second array to be tested for a mismatch
+ // * @param cmp the comparator to compare array elements
+ // * @param the type of array elements
+ // * @return the index of the first mismatch between the two arrays,
+ // * otherwise {@code -1}.
+ // * @throws NullPointerException
+ // * if either array or the comparator is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(T[] a, T[] b, Comparator super T> cmp) {
+ // Objects.requireNonNull(cmp);
+ // int length = Math.min(a.length, b.length); // Check null array refs
+ // if (a == b)
+ // return -1;
+
+ // for (int i = 0; i < length; i++) {
+ // T oa = a[i];
+ // T ob = b[i];
+ // if (oa != ob) {
+ // // Null-value comparison is deferred to the comparator
+ // int v = cmp.compare(oa, ob);
+ // if (v != 0) {
+ // return i;
+ // }
+ // }
+ // }
+
+ // return a.length != b.length ? length : -1;
+ // }
+
+ // /**
+ // * Finds and returns the relative index of the first mismatch between two
+ // * {@code Object} arrays over the specified ranges, otherwise return -1 if
+ // * no mismatch is found. The index will be in the range of 0 (inclusive) up
+ // * to the length (inclusive) of the smaller range.
+ // *
+ // * If the two arrays, over the specified ranges, share a common prefix
+ // * then the returned relative index is the length of the common prefix and
+ // * it follows that there is a mismatch between the two elements at that
+ // * relative index within the respective arrays.
+ // * If one array is a proper prefix of the other, over the specified ranges,
+ // * then the returned relative index is the length of the smaller range and
+ // * it follows that the relative index is only valid for the array with the
+ // * larger range.
+ // * Otherwise, there is no mismatch.
+ // *
+ // *
Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a common
+ // * prefix of length {@code pl} if the following expression is true:
+ // *
{@code
+ // * pl >= 0 &&
+ // * pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl, cmp) &&
+ // * cmp.compare(a[aFromIndex + pl], b[bFromIndex + pl]) != 0
+ // * }
+ // * Note that a common prefix length of {@code 0} indicates that the first
+ // * elements from each array mismatch.
+ // *
+ // * Two non-{@code null} arrays, {@code a} and {@code b} with specified
+ // * ranges [{@code aFromIndex}, {@code atoIndex}) and
+ // * [{@code bFromIndex}, {@code btoIndex}) respectively, share a proper
+ // * prefix if the following expression is true:
+ // *
{@code
+ // * (aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
+ // * Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
+ // * cmp)
+ // * }
+ // *
+ // * @param a the first array to be tested for a mismatch
+ // * @param aFromIndex the index (inclusive) of the first element in the
+ // * first array to be tested
+ // * @param aToIndex the index (exclusive) of the last element in the
+ // * first array to be tested
+ // * @param b the second array to be tested for a mismatch
+ // * @param bFromIndex the index (inclusive) of the first element in the
+ // * second array to be tested
+ // * @param bToIndex the index (exclusive) of the last element in the
+ // * second array to be tested
+ // * @param cmp the comparator to compare array elements
+ // * @param the type of array elements
+ // * @return the relative index of the first mismatch between the two arrays
+ // * over the specified ranges, otherwise {@code -1}.
+ // * @throws IllegalArgumentException
+ // * if {@code aFromIndex > aToIndex} or
+ // * if {@code bFromIndex > bToIndex}
+ // * @throws ArrayIndexOutOfBoundsException
+ // * if {@code aFromIndex < 0 or aToIndex > a.length} or
+ // * if {@code bFromIndex < 0 or bToIndex > b.length}
+ // * @throws NullPointerException
+ // * if either array or the comparator is {@code null}
+ // * @since 9
+ // */
+ // public static int mismatch(
+ // T[] a, int aFromIndex, int aToIndex,
+ // T[] b, int bFromIndex, int bToIndex,
+ // Comparator super T> cmp) {
+ // Objects.requireNonNull(cmp);
+ // rangeCheck(a.length, aFromIndex, aToIndex);
+ // rangeCheck(b.length, bFromIndex, bToIndex);
+
+ // int aLength = aToIndex - aFromIndex;
+ // int bLength = bToIndex - bFromIndex;
+ // int length = Math.min(aLength, bLength);
+ // for (int i = 0; i < length; i++) {
+ // T oa = a[aFromIndex++];
+ // T ob = b[bFromIndex++];
+ // if (oa != ob) {
+ // // Null-value comparison is deferred to the comparator
+ // int v = cmp.compare(oa, ob);
+ // if (v != 0) {
+ // return i;
+ // }
+ // }
+ // }
+
+ // return aLength != bLength ? length : -1;
+ // }
}
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/ArraysParallelSortHelpers.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/ArraysParallelSortHelpers.java
index 8fa2262d77..bcf490340f 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/ArraysParallelSortHelpers.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/ArraysParallelSortHelpers.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, 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
@@ -24,7 +24,6 @@
*/
package java.util;
-import java.util.concurrent.RecursiveAction;
import java.util.concurrent.CountedCompleter;
/**
@@ -36,7 +35,7 @@
* Sorter classes based mainly on CilkSort
* Cilk :
* Basic algorithm:
- * if array size is small, just use a sequential quicksort (via Arrays.sort)
+ * if array size is small, just use a sequential sort (via Arrays.sort)
* Otherwise:
* 1. Break array in half.
* 2. For each half,
@@ -63,14 +62,10 @@
* need to keep track of the arrays, and are never themselves forked,
* so don't hold any task state.
*
- * The primitive class versions (FJByte... FJDouble) are
- * identical to each other except for type declarations.
- *
* The base sequential sorts rely on non-public versions of TimSort,
- * ComparableTimSort, and DualPivotQuicksort sort methods that accept
- * temp workspace array slices that we will have already allocated, so
- * avoids redundant allocation. (Except for DualPivotQuicksort byte[]
- * sort, that does not ever use a workspace array.)
+ * ComparableTimSort sort methods that accept temp workspace array
+ * slices that we will have already allocated, so avoids redundant
+ * allocation.
*/
/*package*/ class ArraysParallelSortHelpers {
@@ -87,6 +82,7 @@
* quartile task, that does not need to maintain array state.
*/
static final class EmptyCompleter extends CountedCompleter {
+ @java.io.Serial
static final long serialVersionUID = 2446542900576103244L;
EmptyCompleter(CountedCompleter> p) { super(p); }
public final void compute() { }
@@ -96,6 +92,7 @@ public final void compute() { }
* A trigger for secondary merge of two merges
*/
static final class Relay extends CountedCompleter {
+ @java.io.Serial
static final long serialVersionUID = 2446542900576103244L;
final CountedCompleter> task;
Relay(CountedCompleter> task) {
@@ -111,9 +108,14 @@ public final void onCompletion(CountedCompleter> t) {
/** Object + Comparator support class */
static final class FJObject {
static final class Sorter extends CountedCompleter {
+ @java.io.Serial
static final long serialVersionUID = 2446542900576103244L;
- final T[] a, w;
+ @SuppressWarnings("serial") // Not statically typed as Serializable
+ final T[] a;
+ @SuppressWarnings("serial") // Not statically typed as Serializable
+ final T[] w;
final int base, size, wbase, gran;
+ @SuppressWarnings("serial") // Not statically typed as Serializable
Comparator super T> comparator;
Sorter(CountedCompleter> par, T[] a, T[] w, int base, int size,
int wbase, int gran,
@@ -130,15 +132,15 @@ public final void compute() {
int b = this.base, n = this.size, wb = this.wbase, g = this.gran;
while (n > g) {
int h = n >>> 1, q = h >>> 1, u = h + q; // quartiles
- Relay fc = new Relay(new Merger(s, w, a, wb, h,
- wb+h, n-h, b, g, c));
- Relay rc = new Relay(new Merger(fc, a, w, b+h, q,
- b+u, n-u, wb+h, g, c));
- new Sorter(rc, a, w, b+u, n-u, wb+u, g, c).fork();
- new Sorter(rc, a, w, b+h, q, wb+h, g, c).fork();;
- Relay bc = new Relay(new Merger(fc, a, w, b, q,
- b+q, h-q, wb, g, c));
- new Sorter(bc, a, w, b+q, h-q, wb+q, g, c).fork();
+ Relay fc = new Relay(new Merger<>(s, w, a, wb, h,
+ wb+h, n-h, b, g, c));
+ Relay rc = new Relay(new Merger<>(fc, a, w, b+h, q,
+ b+u, n-u, wb+h, g, c));
+ new Sorter<>(rc, a, w, b+u, n-u, wb+u, g, c).fork();
+ new Sorter<>(rc, a, w, b+h, q, wb+h, g, c).fork();
+ Relay bc = new Relay(new Merger<>(fc, a, w, b, q,
+ b+q, h-q, wb, g, c));
+ new Sorter<>(bc, a, w, b+q, h-q, wb+q, g, c).fork();
s = new EmptyCompleter(bc);
n = q;
}
@@ -148,9 +150,15 @@ public final void compute() {
}
static final class Merger extends CountedCompleter {
+ @java.io.Serial
static final long serialVersionUID = 2446542900576103244L;
- final T[] a, w; // main and workspace arrays
+ // main and workspace arrays
+ @SuppressWarnings("serial") // Not statically typed as Serializable
+ final T[] a;
+ @SuppressWarnings("serial") // Not statically typed as Serializable
+ final T[] w;
final int lbase, lsize, rbase, rsize, wbase, gran;
+ @SuppressWarnings("serial") // Not statically typed as Serializable
Comparator super T> comparator;
Merger(CountedCompleter> par, T[] a, T[] w,
int lbase, int lsize, int rbase,
@@ -199,9 +207,9 @@ public final void compute() {
lo = lm + 1;
}
}
- Merger m = new Merger(this, a, w, lb + lh, ln - lh,
- rb + rh, rn - rh,
- k + lh + rh, g, c);
+ Merger m = new Merger<>(this, a, w, lb + lh, ln - lh,
+ rb + rh, rn - rh,
+ k + lh + rh, g, c);
rn = rh;
ln = lh;
addToPendingCount(1);
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Base64.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Base64.java
index be98fadfa0..8577fee3a6 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Base64.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Base64.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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,6 +25,10 @@
package java.util;
+/* J2ObjC removed
+import jdk.internal.HotSpotIntrinsicCandidate;
+*/
+
import java.io.FilterOutputStream;
import java.io.InputStream;
import java.io.IOException;
@@ -32,6 +36,9 @@
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
+// Android-removed: class is not present in Android.
+// import sun.nio.cs.ISO_8859_1;
+
/**
* This class consists exclusively of static methods for obtaining
* encoders and decoders for the Base64 encoding scheme. The
@@ -41,22 +48,22 @@
* RFC 2045 .
*
*
- * Basic
+ * Basic
* Uses "The Base64 Alphabet" as specified in Table 1 of
* RFC 4648 and RFC 2045 for encoding and decoding operation.
* The encoder does not add any line feed (line separator)
* character. The decoder rejects data that contains characters
* outside the base64 alphabet.
*
- * URL and Filename safe
+ * URL and Filename safe
* Uses the "URL and Filename safe Base64 Alphabet" as specified
* in Table 2 of RFC 4648 for encoding and decoding. The
* encoder does not add any line feed (line separator) character.
* The decoder rejects data that contains characters outside the
* base64 alphabet.
*
- * MIME
- * Uses the "The Base64 Alphabet" as specified in Table 1 of
+ *
MIME
+ * Uses "The Base64 Alphabet" as specified in Table 1 of
* RFC 2045 for encoding and decoding operation. The encoded output
* must be represented in lines of no more than 76 characters each
* and uses a carriage return {@code '\r'} followed immediately by
@@ -116,8 +123,8 @@ public static Encoder getMimeEncoder() {
*
* @param lineLength
* the length of each output line (rounded down to nearest multiple
- * of 4). If {@code lineLength <= 0} the output will not be separated
- * in lines
+ * of 4). If the rounded down line length is not a positive value,
+ * the output will not be separated in lines
* @param lineSeparator
* the line separator for each output line
*
@@ -135,10 +142,12 @@ public static Encoder getMimeEncoder(int lineLength, byte[] lineSeparator) {
throw new IllegalArgumentException(
"Illegal base64 line separator character 0x" + Integer.toString(b, 16));
}
+ // round down to nearest multiple of 4
+ lineLength &= ~0b11;
if (lineLength <= 0) {
return Encoder.RFC4648;
}
- return new Encoder(false, lineSeparator, lineLength >> 2 << 2, true);
+ return new Encoder(false, lineSeparator, lineLength, true);
}
/**
@@ -387,6 +396,22 @@ public Encoder withoutPadding() {
return this;
return new Encoder(isURL, newline, linemax, false);
}
+
+ /* J2ObjC removed
+ @HotSpotIntrinsicCandidate
+ */
+ private void encodeBlock(byte[] src, int sp, int sl, byte[] dst, int dp, boolean isURL) {
+ char[] base64 = isURL ? toBase64URL : toBase64;
+ for (int sp0 = sp, dp0 = dp ; sp0 < sl; ) {
+ int bits = (src[sp0++] & 0xff) << 16 |
+ (src[sp0++] & 0xff) << 8 |
+ (src[sp0++] & 0xff);
+ dst[dp0++] = (byte)base64[(bits >>> 18) & 0x3f];
+ dst[dp0++] = (byte)base64[(bits >>> 12) & 0x3f];
+ dst[dp0++] = (byte)base64[(bits >>> 6) & 0x3f];
+ dst[dp0++] = (byte)base64[bits & 0x3f];
+ }
+ }
private int encode0(byte[] src, int off, int end, byte[] dst) {
char[] base64 = isURL ? toBase64URL : toBase64;
@@ -398,15 +423,7 @@ private int encode0(byte[] src, int off, int end, byte[] dst) {
int dp = 0;
while (sp < sl) {
int sl0 = Math.min(sp + slen, sl);
- for (int sp0 = sp, dp0 = dp ; sp0 < sl0; ) {
- int bits = (src[sp0++] & 0xff) << 16 |
- (src[sp0++] & 0xff) << 8 |
- (src[sp0++] & 0xff);
- dst[dp0++] = (byte)base64[(bits >>> 18) & 0x3f];
- dst[dp0++] = (byte)base64[(bits >>> 12) & 0x3f];
- dst[dp0++] = (byte)base64[(bits >>> 6) & 0x3f];
- dst[dp0++] = (byte)base64[bits & 0x3f];
- }
+ encodeBlock(src, sp, sl0, dst, dp, isURL);
int dlen = (sl0 - sp) / 3 * 4;
dp += dlen;
sp = sl0;
@@ -546,6 +563,8 @@ public byte[] decode(byte[] src) {
* if {@code src} is not in valid Base64 scheme
*/
public byte[] decode(String src) {
+ // Android-changed: keep Java 8 implementation.
+ // return decode(src.getBytes(ISO_8859_1.INSTANCE));
return decode(src.getBytes(StandardCharsets.ISO_8859_1));
}
@@ -556,7 +575,7 @@ public byte[] decode(String src) {
*
*
It is the responsibility of the invoker of this method to make
* sure the output byte array {@code dst} has enough space for decoding
- * all bytes from the input byte array. No bytes will be be written to
+ * all bytes from the input byte array. No bytes will be written to
* the output byte array if the output byte array is not big enough.
*
*
If the input byte array is not in valid Base64 encoding scheme
@@ -690,7 +709,27 @@ private int decode0(byte[] src, int sp, int sl, byte[] dst) {
int dp = 0;
int bits = 0;
int shiftto = 18; // pos of first byte of 4-byte atom
+
while (sp < sl) {
+ if (shiftto == 18 && sp + 4 < sl) { // fast path
+ int sl0 = sp + ((sl - sp) & ~0b11);
+ while (sp < sl0) {
+ int b1 = base64[src[sp++] & 0xff];
+ int b2 = base64[src[sp++] & 0xff];
+ int b3 = base64[src[sp++] & 0xff];
+ int b4 = base64[src[sp++] & 0xff];
+ if ((b1 | b2 | b3 | b4) < 0) { // non base64 byte
+ sp -= 4;
+ break;
+ }
+ int bits0 = b1 << 18 | b2 << 12 | b3 << 6 | b4;
+ dst[dp++] = (byte)(bits0 >> 16);
+ dst[dp++] = (byte)(bits0 >> 8);
+ dst[dp++] = (byte)(bits0);
+ }
+ if (sp >= sl)
+ break;
+ }
int b = src[sp++] & 0xff;
if ((b = base64[b]) < 0) {
if (b == -2) { // padding byte '='
@@ -737,7 +776,7 @@ private int decode0(byte[] src, int sp, int sl, byte[] dst) {
// anything left is invalid, if is not MIME.
// if MIME, ignore all non-base64 character
while (sp < sl) {
- if (isMIME && base64[src[sp++]] < 0)
+ if (isMIME && base64[src[sp++] & 0xff] < 0)
continue;
throw new IllegalArgumentException(
"Input byte array has incorrect ending byte at " + sp);
@@ -760,6 +799,7 @@ private static class EncOutputStream extends FilterOutputStream {
private final int linemax;
private final boolean doPadding;// whether or not to pad
private int linepos = 0;
+ private byte[] buf;
EncOutputStream(OutputStream os, char[] base64,
byte[] newline, int linemax, boolean doPadding) {
@@ -768,6 +808,7 @@ private static class EncOutputStream extends FilterOutputStream {
this.newline = newline;
this.linemax = linemax;
this.doPadding = doPadding;
+ this.buf = new byte[linemax <= 0 ? 8124 : linemax];
}
@Override
@@ -784,13 +825,18 @@ private void checkNewline() throws IOException {
}
}
+ private void writeb4(char b1, char b2, char b3, char b4) throws IOException {
+ buf[0] = (byte)b1;
+ buf[1] = (byte)b2;
+ buf[2] = (byte)b3;
+ buf[3] = (byte)b4;
+ out.write(buf, 0, 4);
+ }
+
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (closed)
throw new IOException("Stream is closed");
- // Android-changed: Upstream fix to avoid overflow.
- // This upstream fix is from beyond OpenJDK8u121-b13. http://b/62368386
- // if (off < 0 || len < 0 || off + len > b.length)
if (off < 0 || len < 0 || len > b.length - off)
throw new ArrayIndexOutOfBoundsException();
if (len == 0)
@@ -807,25 +853,34 @@ public void write(byte[] b, int off, int len) throws IOException {
b2 = b[off++] & 0xff;
len--;
checkNewline();
- out.write(base64[b0 >> 2]);
- out.write(base64[(b0 << 4) & 0x3f | (b1 >> 4)]);
- out.write(base64[(b1 << 2) & 0x3f | (b2 >> 6)]);
- out.write(base64[b2 & 0x3f]);
+ writeb4(base64[b0 >> 2],
+ base64[(b0 << 4) & 0x3f | (b1 >> 4)],
+ base64[(b1 << 2) & 0x3f | (b2 >> 6)],
+ base64[b2 & 0x3f]);
linepos += 4;
}
int nBits24 = len / 3;
leftover = len - (nBits24 * 3);
- while (nBits24-- > 0) {
+
+ while (nBits24 > 0) {
checkNewline();
- int bits = (b[off++] & 0xff) << 16 |
- (b[off++] & 0xff) << 8 |
- (b[off++] & 0xff);
- out.write(base64[(bits >>> 18) & 0x3f]);
- out.write(base64[(bits >>> 12) & 0x3f]);
- out.write(base64[(bits >>> 6) & 0x3f]);
- out.write(base64[bits & 0x3f]);
- linepos += 4;
- }
+ int dl = linemax <= 0 ? buf.length : buf.length - linepos;
+ int sl = off + Math.min(nBits24, dl / 4) * 3;
+ int dp = 0;
+ for (int sp = off; sp < sl; ) {
+ int bits = (b[sp++] & 0xff) << 16 |
+ (b[sp++] & 0xff) << 8 |
+ (b[sp++] & 0xff);
+ buf[dp++] = (byte)base64[(bits >>> 18) & 0x3f];
+ buf[dp++] = (byte)base64[(bits >>> 12) & 0x3f];
+ buf[dp++] = (byte)base64[(bits >>> 6) & 0x3f];
+ buf[dp++] = (byte)base64[bits & 0x3f];
+ }
+ out.write(buf, 0, dp);
+ off = sl;
+ linepos += dp;
+ nBits24 -= dp / 4;
+ }
if (leftover == 1) {
b0 = b[off++] & 0xff;
} else if (leftover == 2) {
@@ -890,6 +945,52 @@ public int read() throws IOException {
return read(sbBuf, 0, 1) == -1 ? -1 : sbBuf[0] & 0xff;
}
+ private int eof(byte[] b, int off, int len, int oldOff)
+ throws IOException
+ {
+ eof = true;
+ if (nextin != 18) {
+ if (nextin == 12)
+ throw new IOException("Base64 stream has one un-decoded dangling byte.");
+ // treat ending xx/xxx without padding character legal.
+ // same logic as v == '=' below
+ b[off++] = (byte)(bits >> (16));
+ if (nextin == 0) { // only one padding byte
+ if (len == 1) { // no enough output space
+ bits >>= 8; // shift to lowest byte
+ nextout = 0;
+ } else {
+ b[off++] = (byte) (bits >> 8);
+ }
+ }
+ }
+ return off == oldOff ? -1 : off - oldOff;
+ }
+
+ private int padding(byte[] b, int off, int len, int oldOff)
+ throws IOException
+ {
+ // = shiftto==18 unnecessary padding
+ // x= shiftto==12 dangling x, invalid unit
+ // xx= shiftto==6 && missing last '='
+ // xx=y or last is not '='
+ if (nextin == 18 || nextin == 12 ||
+ nextin == 6 && is.read() != '=') {
+ throw new IOException("Illegal base64 ending sequence:" + nextin);
+ }
+ b[off++] = (byte)(bits >> (16));
+ if (nextin == 0) { // only one padding byte
+ if (len == 1) { // no enough output space
+ bits >>= 8; // shift to lowest byte
+ nextout = 0;
+ } else {
+ b[off++] = (byte) (bits >> 8);
+ }
+ }
+ eof = true;
+ return off - oldOff;
+ }
+
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (closed)
@@ -899,82 +1000,46 @@ public int read(byte[] b, int off, int len) throws IOException {
if (off < 0 || len < 0 || len > b.length - off)
throw new IndexOutOfBoundsException();
int oldOff = off;
- if (nextout >= 0) { // leftover output byte(s) in bits buf
- do {
- if (len == 0)
- return off - oldOff;
- b[off++] = (byte)(bits >> nextout);
- len--;
- nextout -= 8;
- } while (nextout >= 0);
- bits = 0;
+ while (nextout >= 0) { // leftover output byte(s) in bits buf
+ if (len == 0)
+ return off - oldOff;
+ b[off++] = (byte)(bits >> nextout);
+ len--;
+ nextout -= 8;
}
+ bits = 0;
while (len > 0) {
int v = is.read();
if (v == -1) {
- eof = true;
- if (nextin != 18) {
- if (nextin == 12)
- throw new IOException("Base64 stream has one un-decoded dangling byte.");
- // treat ending xx/xxx without padding character legal.
- // same logic as v == '=' below
- b[off++] = (byte)(bits >> (16));
- len--;
- if (nextin == 0) { // only one padding byte
- if (len == 0) { // no enough output space
- bits >>= 8; // shift to lowest byte
- nextout = 0;
- } else {
- b[off++] = (byte) (bits >> 8);
- }
- }
- }
- if (off == oldOff)
- return -1;
- else
- return off - oldOff;
+ return eof(b, off, len, oldOff);
}
- if (v == '=') { // padding byte(s)
- // = shiftto==18 unnecessary padding
- // x= shiftto==12 dangling x, invalid unit
- // xx= shiftto==6 && missing last '='
- // xx=y or last is not '='
- if (nextin == 18 || nextin == 12 ||
- nextin == 6 && is.read() != '=') {
- throw new IOException("Illegal base64 ending sequence:" + nextin);
+ if ((v = base64[v]) < 0) {
+ if (v == -2) { // padding byte(s)
+ return padding(b, off, len, oldOff);
}
- b[off++] = (byte)(bits >> (16));
- len--;
- if (nextin == 0) { // only one padding byte
- if (len == 0) { // no enough output space
- bits >>= 8; // shift to lowest byte
- nextout = 0;
- } else {
- b[off++] = (byte) (bits >> 8);
- }
+ if (v == -1) {
+ if (!isMIME)
+ throw new IOException("Illegal base64 character " +
+ Integer.toString(v, 16));
+ continue; // skip if for rfc2045
}
- eof = true;
- break;
- }
- if ((v = base64[v]) == -1) {
- if (isMIME) // skip if for rfc2045
- continue;
- else
- throw new IOException("Illegal base64 character " +
- Integer.toString(v, 16));
+ // neve be here
}
bits |= (v << nextin);
if (nextin == 0) {
- nextin = 18; // clear for next
- nextout = 16;
- while (nextout >= 0) {
- b[off++] = (byte)(bits >> nextout);
- len--;
- nextout -= 8;
- if (len == 0 && nextout >= 0) { // don't clean "bits"
- return off - oldOff;
- }
+ nextin = 18; // clear for next in
+ b[off++] = (byte)(bits >> 16);
+ if (len == 1) {
+ nextout = 8; // 2 bytes left in bits
+ break;
+ }
+ b[off++] = (byte)(bits >> 8);
+ if (len == 2) {
+ nextout = 0; // 1 byte left in bits
+ break;
}
+ b[off++] = (byte)bits;
+ len -= 3;
bits = 0;
} else {
nextin -= 6;
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/BitSet.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/BitSet.java
index 261a77c12a..c72970def0 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/BitSet.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/BitSet.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 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
@@ -29,6 +29,7 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.LongBuffer;
+import java.util.function.IntConsumer;
import java.util.stream.IntStream;
import java.util.stream.StreamSupport;
@@ -60,7 +61,7 @@
* @author Arthur van Hoff
* @author Michael McCloskey
* @author Martin Buchholz
- * @since JDK1.0
+ * @since 1.0
*/
public class BitSet implements Cloneable, java.io.Serializable {
/*
@@ -68,9 +69,9 @@ public class BitSet implements Cloneable, java.io.Serializable {
* a long, which consists of 64 bits, requiring 6 address bits.
* The choice of word size is determined purely by performance concerns.
*/
- private final static int ADDRESS_BITS_PER_WORD = 6;
- private final static int BITS_PER_WORD = 1 << ADDRESS_BITS_PER_WORD;
- private final static int BIT_INDEX_MASK = BITS_PER_WORD - 1;
+ private static final int ADDRESS_BITS_PER_WORD = 6;
+ private static final int BITS_PER_WORD = 1 << ADDRESS_BITS_PER_WORD;
+ private static final int BIT_INDEX_MASK = BITS_PER_WORD - 1;
/* Used to shift left or right for a partial word mask */
private static final long WORD_MASK = 0xffffffffffffffffL;
@@ -437,7 +438,7 @@ public void flip(int fromIndex, int toIndex) {
*
* @param bitIndex a bit index
* @throws IndexOutOfBoundsException if the specified index is negative
- * @since JDK1.0
+ * @since 1.0
*/
public void set(int bitIndex) {
if (bitIndex < 0)
@@ -533,7 +534,7 @@ public void set(int fromIndex, int toIndex, boolean value) {
*
* @param bitIndex the index of the bit to be cleared
* @throws IndexOutOfBoundsException if the specified index is negative
- * @since JDK1.0
+ * @since 1.0
*/
public void clear(int bitIndex) {
if (bitIndex < 0)
@@ -1209,40 +1210,186 @@ public String toString() {
* is the number of bits in the set state, equal to the value
* returned by the {@link #cardinality()} method.
*
- *
The bit set must remain constant during the execution of the
- * terminal stream operation. Otherwise, the result of the terminal
- * stream operation is undefined.
+ *
The stream binds to this bit set when the terminal stream operation
+ * commences (specifically, the spliterator for the stream is
+ * late-binding ). If the
+ * bit set is modified during that operation then the result is undefined.
*
* @return a stream of integers representing set indices
* @since 1.8
*/
public IntStream stream() {
- class BitSetIterator implements PrimitiveIterator.OfInt {
- int next = nextSetBit(0);
+ class BitSetSpliterator implements Spliterator.OfInt {
+ private int index; // current bit index for a set bit
+ private int fence; // -1 until used; then one past last bit index
+ private int est; // size estimate
+ private boolean root; // true if root and not split
+ // root == true then size estimate is accurate
+ // index == -1 or index >= fence if fully traversed
+ // Special case when the max bit set is Integer.MAX_VALUE
+
+ BitSetSpliterator(int origin, int fence, int est, boolean root) {
+ this.index = origin;
+ this.fence = fence;
+ this.est = est;
+ this.root = root;
+ }
+
+ private int getFence() {
+ int hi;
+ if ((hi = fence) < 0) {
+ // Round up fence to maximum cardinality for allocated words
+ // This is sufficient and cheap for sequential access
+ // When splitting this value is lowered
+ hi = fence = (wordsInUse >= wordIndex(Integer.MAX_VALUE))
+ ? Integer.MAX_VALUE
+ : wordsInUse << ADDRESS_BITS_PER_WORD;
+ est = cardinality();
+ index = nextSetBit(0);
+ }
+ return hi;
+ }
@Override
- public boolean hasNext() {
- return next != -1;
+ public boolean tryAdvance(IntConsumer action) {
+ Objects.requireNonNull(action);
+
+ int hi = getFence();
+ int i = index;
+ if (i < 0 || i >= hi) {
+ // Check if there is a final bit set for Integer.MAX_VALUE
+ if (i == Integer.MAX_VALUE && hi == Integer.MAX_VALUE) {
+ index = -1;
+ action.accept(Integer.MAX_VALUE);
+ return true;
+ }
+ return false;
+ }
+
+ index = nextSetBit(i + 1, wordIndex(hi - 1));
+ action.accept(i);
+ return true;
}
@Override
- public int nextInt() {
- if (next != -1) {
- int ret = next;
- next = nextSetBit(next+1);
- return ret;
- } else {
- throw new NoSuchElementException();
+ public void forEachRemaining(IntConsumer action) {
+ Objects.requireNonNull(action);
+
+ int hi = getFence();
+ int i = index;
+ index = -1;
+
+ if (i >= 0 && i < hi) {
+ action.accept(i++);
+
+ int u = wordIndex(i); // next lower word bound
+ int v = wordIndex(hi - 1); // upper word bound
+
+ words_loop:
+ for (; u <= v && i <= hi; u++, i = u << ADDRESS_BITS_PER_WORD) {
+ long word = words[u] & (WORD_MASK << i);
+ while (word != 0) {
+ i = (u << ADDRESS_BITS_PER_WORD) + Long.numberOfTrailingZeros(word);
+ if (i >= hi) {
+ // Break out of outer loop to ensure check of
+ // Integer.MAX_VALUE bit set
+ break words_loop;
+ }
+
+ // Flip the set bit
+ word &= ~(1L << i);
+
+ action.accept(i);
+ }
+ }
+ }
+
+ // Check if there is a final bit set for Integer.MAX_VALUE
+ if (i == Integer.MAX_VALUE && hi == Integer.MAX_VALUE) {
+ action.accept(Integer.MAX_VALUE);
}
}
+
+ @Override
+ public OfInt trySplit() {
+ int hi = getFence();
+ int lo = index;
+ if (lo < 0) {
+ return null;
+ }
+
+ // Lower the fence to be the upper bound of last bit set
+ // The index is the first bit set, thus this spliterator
+ // covers one bit and cannot be split, or two or more
+ // bits
+ hi = fence = (hi < Integer.MAX_VALUE || !get(Integer.MAX_VALUE))
+ ? previousSetBit(hi - 1) + 1
+ : Integer.MAX_VALUE;
+
+ // Find the mid point
+ int mid = (lo + hi) >>> 1;
+ if (lo >= mid) {
+ return null;
+ }
+
+ // Raise the index of this spliterator to be the next set bit
+ // from the mid point
+ index = nextSetBit(mid, wordIndex(hi - 1));
+ root = false;
+
+ // Don't lower the fence (mid point) of the returned spliterator,
+ // traversal or further splitting will do that work
+ return new BitSetSpliterator(lo, mid, est >>>= 1, false);
+ }
+
+ @Override
+ public long estimateSize() {
+ getFence(); // force init
+ return est;
+ }
+
+ @Override
+ public int characteristics() {
+ // Only sized when root and not split
+ return (root ? Spliterator.SIZED : 0) |
+ Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED;
+ }
+
+ @Override
+ public Comparator super Integer> getComparator() {
+ return null;
+ }
}
+ return StreamSupport.intStream(new BitSetSpliterator(0, -1, 0, true), false);
+ }
- return StreamSupport.intStream(
- () -> Spliterators.spliterator(
- new BitSetIterator(), cardinality(),
- Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED),
- Spliterator.SIZED | Spliterator.SUBSIZED |
- Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED,
- false);
+ /**
+ * Returns the index of the first bit that is set to {@code true}
+ * that occurs on or after the specified starting index and up to and
+ * including the specified word index
+ * If no such bit exists then {@code -1} is returned.
+ *
+ * @param fromIndex the index to start checking from (inclusive)
+ * @param toWordIndex the last word index to check (inclusive)
+ * @return the index of the next set bit, or {@code -1} if there
+ * is no such bit
+ */
+ private int nextSetBit(int fromIndex, int toWordIndex) {
+ int u = wordIndex(fromIndex);
+ // Check if out of bounds
+ if (u > toWordIndex)
+ return -1;
+
+ long word = words[u] & (WORD_MASK << fromIndex);
+
+ while (true) {
+ if (word != 0)
+ return (u * BITS_PER_WORD) + Long.numberOfTrailingZeros(word);
+ // Check if out of bounds
+ if (++u > toWordIndex)
+ return -1;
+ word = words[u];
+ }
}
+
}
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Calendar.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Calendar.java
index 86e6f69856..a10229e6e4 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Calendar.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Calendar.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 The Android Open Source Project
- * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2017, 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
@@ -42,20 +42,21 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.io.OptionalDataException;
import java.io.Serializable;
-/*import java.security.AccessControlContext;
-import java.security.AccessController;
+import java.security.AccessControlContext;
import java.security.PermissionCollection;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.security.ProtectionDomain;*/
+import java.security.ProtectionDomain;
import java.text.DateFormat;
import java.text.DateFormatSymbols;
+import java.time.Instant;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import libcore.icu.ICU;
import libcore.icu.LocaleData;
+import sun.util.locale.provider.CalendarDataUtility;
+// Android-changed: Remove "rg" support in the javadoc. See http://b/228322300.
+// Android-changed: Support the "fw" extension since Android 13.
/**
* The Calendar class is an abstract class that provides methods
* for converting between a specific instant in time and a set of {@link
@@ -63,7 +64,7 @@
* DAY_OF_MONTH, HOUR, and so on, and for
* manipulating the calendar fields, such as getting the date of the next
* week. An instant in time can be represented by a millisecond value that is
- * an offset from the Epoch , January 1, 1970
+ * an offset from the Epoch , January 1, 1970
* 00:00:00.000 GMT (Gregorian).
*
*
The class also provides additional fields and methods for
@@ -120,13 +121,17 @@
* calculating its time or calendar field values if any out-of-range field
* value has been set.
*
- *
+ *
*
* Calendar defines a locale-specific seven day week using two
* parameters: the first day of the week and the minimal days in first week
- * (from 1 to 7). These numbers are taken from the locale resource data when a
- * Calendar is constructed. They may also be specified explicitly
- * through the methods for setting their values.
+ * (from 1 to 7). These numbers are taken from the locale resource data or the
+ * locale itself when a {@code Calendar} is constructed. If the designated
+ * locale contains "fw"
+ * Unicode extensions , the first day of the week will be obtained according to
+ * those extensions.
+ * They may also be specified explicitly through the methods for setting their
+ * values.
*
* When setting or getting the WEEK_OF_MONTH or
* WEEK_OF_YEAR fields, Calendar must determine the
@@ -150,13 +155,13 @@
* calendar field values to determine the date and time in the
* following way.
*
- *
If there is any conflict in calendar field values,
+ * If there is any conflict in calendar field values,
* Calendar gives priorities to calendar fields that have been set
* more recently. The following are the default combinations of the
* calendar fields. The most recent combination, as determined by the
* most recently set single field, will be used.
*
- *
For the date fields :
+ *
For the date fields :
*
*
* YEAR + MONTH + DAY_OF_MONTH
@@ -166,7 +171,7 @@
* YEAR + DAY_OF_WEEK + WEEK_OF_YEAR
*
*
- * For the time of day fields :
+ * For the time of day fields :
*
*
* HOUR_OF_DAY
@@ -304,7 +309,7 @@
* @see TimeZone
* @see java.text.DateFormat
* @author Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu
- * @since JDK1.1
+ * @since 1.1
*/
public abstract class Calendar implements Serializable, Cloneable, Comparable {
@@ -366,13 +371,13 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the
* year. This is a calendar-specific value; see subclass documentation.
*/
- public final static int YEAR = 1;
+ public static final int YEAR = 1;
/**
* Field number for get and set indicating the
@@ -395,7 +400,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the
@@ -408,7 +413,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the
@@ -421,7 +426,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the
@@ -430,7 +435,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the
@@ -439,13 +444,13 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the day
* number within the current year. The first day of the year has value 1.
*/
- public final static int DAY_OF_YEAR = 6;
+ public static final int DAY_OF_YEAR = 6;
/**
* Field number for get and set indicating the day
@@ -461,7 +466,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the
@@ -486,7 +491,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating
@@ -497,7 +502,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the
@@ -508,7 +513,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the
@@ -517,28 +522,28 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the
* minute within the hour.
* E.g., at 10:04:15.250 PM the MINUTE is 4.
*/
- public final static int MINUTE = 12;
+ public static final int MINUTE = 12;
/**
* Field number for get and set indicating the
* second within the minute.
* E.g., at 10:04:15.250 PM the SECOND is 15.
*/
- public final static int SECOND = 13;
+ public static final int SECOND = 13;
/**
* Field number for get and set indicating the
* millisecond within the second.
* E.g., at 10:04:15.250 PM the MILLISECOND is 250.
*/
- public final static int MILLISECOND = 14;
+ public static final int MILLISECOND = 14;
/**
* Field number for get and set
@@ -549,7 +554,7 @@ public abstract class Calendar implements Serializable, Cloneable, ComparableTimeZone implementation subclass supports
* historical GMT offset changes.
*/
- public final static int ZONE_OFFSET = 15;
+ public static final int ZONE_OFFSET = 15;
/**
* Field number for get and set indicating the
@@ -560,146 +565,146 @@ public abstract class Calendar implements Serializable, Cloneable, ComparableTimeZone implementation subclass supports
* historical Daylight Saving Time schedule changes.
*/
- public final static int DST_OFFSET = 16;
+ public static final int DST_OFFSET = 16;
/**
* The number of distinct fields recognized by get and set.
* Field numbers range from 0..FIELD_COUNT-1.
*/
- public final static int FIELD_COUNT = 17;
+ public static final int FIELD_COUNT = 17;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Sunday.
*/
- public final static int SUNDAY = 1;
+ public static final int SUNDAY = 1;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Monday.
*/
- public final static int MONDAY = 2;
+ public static final int MONDAY = 2;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Tuesday.
*/
- public final static int TUESDAY = 3;
+ public static final int TUESDAY = 3;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Wednesday.
*/
- public final static int WEDNESDAY = 4;
+ public static final int WEDNESDAY = 4;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Thursday.
*/
- public final static int THURSDAY = 5;
+ public static final int THURSDAY = 5;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Friday.
*/
- public final static int FRIDAY = 6;
+ public static final int FRIDAY = 6;
/**
* Value of the {@link #DAY_OF_WEEK} field indicating
* Saturday.
*/
- public final static int SATURDAY = 7;
+ public static final int SATURDAY = 7;
/**
* Value of the {@link #MONTH} field indicating the
* first month of the year in the Gregorian and Julian calendars.
*/
- public final static int JANUARY = 0;
+ public static final int JANUARY = 0;
/**
* Value of the {@link #MONTH} field indicating the
* second month of the year in the Gregorian and Julian calendars.
*/
- public final static int FEBRUARY = 1;
+ public static final int FEBRUARY = 1;
/**
* Value of the {@link #MONTH} field indicating the
* third month of the year in the Gregorian and Julian calendars.
*/
- public final static int MARCH = 2;
+ public static final int MARCH = 2;
/**
* Value of the {@link #MONTH} field indicating the
* fourth month of the year in the Gregorian and Julian calendars.
*/
- public final static int APRIL = 3;
+ public static final int APRIL = 3;
/**
* Value of the {@link #MONTH} field indicating the
* fifth month of the year in the Gregorian and Julian calendars.
*/
- public final static int MAY = 4;
+ public static final int MAY = 4;
/**
* Value of the {@link #MONTH} field indicating the
* sixth month of the year in the Gregorian and Julian calendars.
*/
- public final static int JUNE = 5;
+ public static final int JUNE = 5;
/**
* Value of the {@link #MONTH} field indicating the
* seventh month of the year in the Gregorian and Julian calendars.
*/
- public final static int JULY = 6;
+ public static final int JULY = 6;
/**
* Value of the {@link #MONTH} field indicating the
* eighth month of the year in the Gregorian and Julian calendars.
*/
- public final static int AUGUST = 7;
+ public static final int AUGUST = 7;
/**
* Value of the {@link #MONTH} field indicating the
* ninth month of the year in the Gregorian and Julian calendars.
*/
- public final static int SEPTEMBER = 8;
+ public static final int SEPTEMBER = 8;
/**
* Value of the {@link #MONTH} field indicating the
* tenth month of the year in the Gregorian and Julian calendars.
*/
- public final static int OCTOBER = 9;
+ public static final int OCTOBER = 9;
/**
* Value of the {@link #MONTH} field indicating the
* eleventh month of the year in the Gregorian and Julian calendars.
*/
- public final static int NOVEMBER = 10;
+ public static final int NOVEMBER = 10;
/**
* Value of the {@link #MONTH} field indicating the
* twelfth month of the year in the Gregorian and Julian calendars.
*/
- public final static int DECEMBER = 11;
+ public static final int DECEMBER = 11;
/**
* Value of the {@link #MONTH} field indicating the
* thirteenth month of the year. Although GregorianCalendar
* does not use this value, lunar calendars do.
*/
- public final static int UNDECIMBER = 12;
+ public static final int UNDECIMBER = 12;
/**
* Value of the {@link #AM_PM} field indicating the
* period of the day from midnight to just before noon.
*/
- public final static int AM = 0;
+ public static final int AM = 0;
/**
* Value of the {@link #AM_PM} field indicating the
* period of the day from noon to just before midnight.
*/
- public final static int PM = 1;
+ public static final int PM = 1;
/**
* A style specifier for {@link #getDisplayNames(int, int, Locale)
@@ -852,7 +857,7 @@ public abstract class Calendar implements Serializable, Cloneable, ComparableTrue if zone references to a shared TimeZone object.
*/
- transient private boolean sharedZone = false;
+ private transient boolean sharedZone = false;
/**
* The first day of the week, with possible values SUNDAY,
@@ -990,7 +995,7 @@ public abstract class Calendar implements Serializable, Cloneable, ComparableserialVersionOnStream
* is written.
* @serial
- * @since JDK1.1.6
+ * @since 1.1.6
*/
private int serialVersionOnStream = currentSerialVersion;
@@ -999,24 +1004,24 @@ public abstract class Calendar implements Serializable, Cloneable, ComparableTimeZone} will be used in the {@link #build() build}
* method.
@@ -1396,7 +1401,7 @@ public Builder setLocale(Locale locale) {
/**
* Sets the week definition parameters to the values given by
* {@code firstDayOfWeek} and {@code minimalDaysInFirstWeek} that are
- * used to determine the first
+ * used to determine the first
* week of a year. The parameters given by this method have
* precedence over the default values given by the
* {@linkplain #setLocale(Locale) locale}.
@@ -1421,6 +1426,7 @@ public Builder setWeekDefinition(int firstDayOfWeek, int minimalDaysInFirstWeek)
return this;
}
+ // Android-changed: Support the "tz" extension since Android 13.
/**
* Returns a {@code Calendar} built from the parameters set by the
* setter methods. The calendar type given by the {@link #setCalendarType(String)
@@ -1441,6 +1447,11 @@ public Builder setWeekDefinition(int firstDayOfWeek, int minimalDaysInFirstWeek)
*
* The default values are used for locale and time zone if these
* parameters haven't been given explicitly.
+ *
+ * Since Android 13, if the locale contains the time zone with "tz"
+ * Unicode extension ,
+ * and time zone hasn't been given explicitly, time zone in the locale
+ * is used.
*
*
Any out of range field values are either normalized in lenient
* mode or detected as an invalid value in non-lenient mode.
@@ -1460,7 +1471,7 @@ public Calendar build() {
locale = Locale.getDefault();
}
if (zone == null) {
- zone = TimeZone.getDefault();
+ zone = defaultTimeZone(locale);
}
Calendar cal;
if (type == null) {
@@ -1597,7 +1608,7 @@ protected Calendar()
*/
protected Calendar(TimeZone zone, Locale aLocale)
{
- // BEGIN Android-added: Allow aLocale == null
+ // BEGIN Android-added: Allow aLocale == null.
// http://b/16938922.
//
// TODO: This is for backwards compatibility only. Seems like a better idea to throw
@@ -1605,7 +1616,7 @@ protected Calendar(TimeZone zone, Locale aLocale)
if (aLocale == null) {
aLocale = Locale.getDefault();
}
- // END Android-added: Allow aLocale == null
+ // END Android-added: Allow aLocale == null.
fields = new int[FIELD_COUNT];
isSet = new boolean[FIELD_COUNT];
stamp = new int[FIELD_COUNT];
@@ -1614,17 +1625,23 @@ protected Calendar(TimeZone zone, Locale aLocale)
setWeekCountData(aLocale);
}
+ // Android-changed: Support the "tz" extension since Android 13.
/**
* Gets a calendar using the default time zone and locale. The
* Calendar returned is based on the current time
* in the default time zone with the default
* {@link Locale.Category#FORMAT FORMAT} locale.
+ *
+ * Since Android 13, if the locale contains the time zone with "tz"
+ * Unicode extension ,
+ * that time zone is used instead.
*
* @return a Calendar.
*/
public static Calendar getInstance()
{
- return createCalendar(TimeZone.getDefault(), Locale.getDefault(Locale.Category.FORMAT));
+ Locale aLocale = Locale.getDefault(Locale.Category.FORMAT);
+ return createCalendar(defaultTimeZone(aLocale), aLocale);
}
/**
@@ -1641,17 +1658,22 @@ public static Calendar getInstance(TimeZone zone)
return createCalendar(zone, Locale.getDefault(Locale.Category.FORMAT));
}
+ // Android-changed: Support the "tz" extension since Android 13.
/**
* Gets a calendar using the default time zone and specified locale.
* The Calendar returned is based on the current time
* in the default time zone with the given locale.
+ *
+ * Since Android 13, if the locale contains the time zone with "tz"
+ * Unicode extension ,
+ * that time zone is used instead.
*
* @param aLocale the locale for the week data
* @return a Calendar.
*/
public static Calendar getInstance(Locale aLocale)
{
- return createCalendar(TimeZone.getDefault(), aLocale);
+ return createCalendar(defaultTimeZone(aLocale), aLocale);
}
/**
@@ -1669,12 +1691,40 @@ public static Calendar getInstance(TimeZone zone,
return createCalendar(zone, aLocale);
}
+ // BEGIN Android-added: add getJapaneseImperialInstance().
+ /**
+ * Create a Japanese Imperial Calendar.
+ * @hide
+ */
+ /* J2ObjC removed
+ public static Calendar getJapaneseImperialInstance(TimeZone zone, Locale aLocale) {
+ return new JapaneseImperialCalendar(zone, aLocale);
+ }
+ */
+ // END Android-added: add getJapaneseImperialInstance().
+
+ private static TimeZone defaultTimeZone(Locale l) {
+ TimeZone defaultTZ = TimeZone.getDefault();
+ // Android-added: Accept null locale. http://b/16938922
+ if (l == null) {
+ return defaultTZ;
+ }
+ String shortTZID = l.getUnicodeLocaleType("tz");
+ return shortTZID != null ?
+ // Android-changed: Use ICU to convert LDML short ID
+ // TimeZoneNameUtility.convertLDMLShortID(shortTZID)
+ Optional.ofNullable(ICU.convertToTzId(shortTZID))
+ .map(TimeZone::getTimeZone)
+ .orElse(defaultTZ) :
+ defaultTZ;
+ }
+
private static Calendar createCalendar(TimeZone zone,
Locale aLocale)
{
- // BEGIN Android-changed: only support GregorianCalendar here
+ // BEGIN Android-changed: only support GregorianCalendar here.
return new GregorianCalendar(zone, aLocale);
- // END Android-changed: only support GregorianCalendar here
+ // END Android-changed: only support GregorianCalendar here.
}
/**
@@ -1765,11 +1815,11 @@ public long getTimeInMillis() {
public void setTimeInMillis(long millis) {
// If we don't need to recalculate the calendar field values,
// do nothing.
-// BEGIN Android-changed: Removed ZoneInfo support
+// BEGIN Android-changed: Android doesn't have sun.util.calendar.ZoneInfo.
// if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet
// && (zone instanceof ZoneInfo) && !((ZoneInfo)zone).isDirty()) {
if (time == millis && isTimeSet && areFieldsSet && areAllFieldsSet) {
-// END Android-changed: Removed ZoneInfo support
+// END Android-changed: Android doesn't have sun.util.calendar.ZoneInfo.
return;
}
@@ -2152,7 +2202,7 @@ private Map getDisplayNamesImpl(int field, int style, Locale loc
if (strings != null) {
Map names = new HashMap<>();
for (int i = 0; i < strings.length; i++) {
- if (strings[i].length() == 0) {
+ if (strings[i].isEmpty()) {
continue;
}
names.put(strings[i], i);
@@ -2164,10 +2214,17 @@ private Map getDisplayNamesImpl(int field, int style, Locale loc
boolean checkDisplayNameParams(int field, int style, int minStyle, int maxStyle,
Locale locale, int fieldMask) {
+ int baseStyle = getBaseStyle(style); // Ignore the standalone mask
if (field < 0 || field >= fields.length ||
- style < minStyle || style > maxStyle) {
+ baseStyle < minStyle || baseStyle > maxStyle || baseStyle == 3) {
+ throw new IllegalArgumentException();
+ }
+ // BEGIN Android-added: Check for invalid baseStyle == 3.
+ // 3 is not a valid base style (unlike 1, 2 and 4). Throw if used.
+ if (baseStyle == 3) {
throw new IllegalArgumentException();
}
+ // END Android-added: Check for invalid baseStyle == 3.
if (locale == null) {
throw new NullPointerException();
}
@@ -2175,6 +2232,13 @@ boolean checkDisplayNameParams(int field, int style, int minStyle, int maxStyle,
}
private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols) {
+ int baseStyle = getBaseStyle(style); // ignore the standalone mask
+
+ // DateFormatSymbols doesn't support any narrow names.
+ if (baseStyle == NARROW_FORMAT) {
+ return null;
+ }
+
String[] strings = null;
switch (field) {
case ERA:
@@ -2182,11 +2246,11 @@ private String[] getFieldStrings(int field, int style, DateFormatSymbols symbols
break;
case MONTH:
- strings = (style == LONG) ? symbols.getMonths() : symbols.getShortMonths();
+ strings = (baseStyle == LONG) ? symbols.getMonths() : symbols.getShortMonths();
break;
case DAY_OF_WEEK:
- strings = (style == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
+ strings = (baseStyle == LONG) ? symbols.getWeekdays() : symbols.getShortWeekdays();
break;
case AM_PM:
@@ -2516,6 +2580,31 @@ final int selectFields() {
return fieldMask;
}
+ int getBaseStyle(int style) {
+ return style & ~STANDALONE_MASK;
+ }
+
+ // BEGIN Android-changed: Make toStandaloneStyle() public to use in java.text.SimpleDateFormat.
+ /**
+ * @hide
+ */
+ public static int toStandaloneStyle(int style) {
+ // END Android-changed: Make toStandaloneStyle() public to use in java.text.SimpleDateFormat.
+ return style | STANDALONE_MASK;
+ }
+
+ private boolean isStandaloneStyle(int style) {
+ return (style & STANDALONE_MASK) != 0;
+ }
+
+ private boolean isNarrowStyle(int style) {
+ return style == NARROW_FORMAT || style == NARROW_STANDALONE;
+ }
+
+ private boolean isNarrowFormatStyle(int style) {
+ return style == NARROW_FORMAT;
+ }
+
/**
* Returns the pseudo-time-stamp for two fields, given their
* individual pseudo-time-stamps. If either of the fields
@@ -2720,7 +2809,7 @@ public int compareTo(Calendar anotherCalendar) {
* @see #roll(int,int)
* @see #set(int,int)
*/
- abstract public void add(int field, int amount);
+ public abstract void add(int field, int amount);
/**
* Adds or subtracts (up/down) a single unit of time on the given time
@@ -2742,7 +2831,7 @@ public int compareTo(Calendar anotherCalendar) {
* @see Calendar#add(int,int)
* @see Calendar#set(int,int)
*/
- abstract public void roll(int field, boolean up);
+ public abstract void roll(int field, boolean up);
/**
* Adds the specified (signed) amount to the specified calendar field
@@ -2958,7 +3047,7 @@ public int getWeekYear() {
}
/**
- * Sets the date of this {@code Calendar} with the the given date
+ * Sets the date of this {@code Calendar} with the given date
* specifiers - week year, week of year, and day of week.
*
* Unlike the {@code set} method, all of the calendar fields
@@ -3029,7 +3118,7 @@ public int getWeeksInWeekYear() {
* @see #getActualMinimum(int)
* @see #getActualMaximum(int)
*/
- abstract public int getMinimum(int field);
+ public abstract int getMinimum(int field);
/**
* Returns the maximum value for the given calendar field of this
@@ -3046,7 +3135,7 @@ public int getWeeksInWeekYear() {
* @see #getActualMinimum(int)
* @see #getActualMaximum(int)
*/
- abstract public int getMaximum(int field);
+ public abstract int getMaximum(int field);
/**
* Returns the highest minimum value for the given calendar field
@@ -3064,7 +3153,7 @@ public int getWeeksInWeekYear() {
* @see #getActualMinimum(int)
* @see #getActualMaximum(int)
*/
- abstract public int getGreatestMinimum(int field);
+ public abstract int getGreatestMinimum(int field);
/**
* Returns the lowest maximum value for the given calendar field
@@ -3086,7 +3175,7 @@ public int getWeeksInWeekYear() {
* @see #getActualMinimum(int)
* @see #getActualMaximum(int)
*/
- abstract public int getLeastMaximum(int field);
+ public abstract int getLeastMaximum(int field);
/**
* Returns the minimum value that the specified calendar field
@@ -3241,7 +3330,7 @@ public Object clone()
* @param field the calendar field
* @return the calendar field name
* @exception IndexOutOfBoundsException if field is negative,
- * equal to or greater then FIELD_COUNT.
+ * equal to or greater than {@code FIELD_COUNT}.
*/
static String getFieldName(int field) {
return FIELD_NAME[field];
@@ -3350,8 +3439,7 @@ private void adjustStamp() {
for (;;) {
int min = Integer.MAX_VALUE;
- for (int i = 0; i < stamp.length; i++) {
- int v = stamp[i];
+ for (int v : stamp) {
if (v >= newStamp && min > v) {
min = v;
}
@@ -3434,7 +3522,7 @@ private synchronized void writeObject(ObjectOutputStream stream)
catch (IllegalArgumentException e) {}
}
- // Android-changed: Removed ZoneInfo support/workaround.
+ // Android-changed: Android doesn't have sun.util.calendar.ZoneInfo.
// Write out the 1.1 FCS object.
stream.defaultWriteObject();
}
@@ -3450,7 +3538,10 @@ private static class CalendarAccessControlContext {
new ProtectionDomain(null, perms)
});
}
- }*/
+ private CalendarAccessControlContext() {
+ }
+ }
+ */
/**
* Reconstitutes this object from a stream (i.e., deserialize it).
@@ -3485,7 +3576,36 @@ else if (serialVersionOnStream >= 0)
serialVersionOnStream = currentSerialVersion;
- // Android-changed: removed ZoneInfo support.
+ // Android-changed: Android doesn't have sun.util.calendar.ZoneInfo.
+ /*
+ // If there's a ZoneInfo object, use it for zone.
+ ZoneInfo zi = null;
+ try {
+ zi = AccessController.doPrivileged(
+ new PrivilegedExceptionAction<>() {
+ @Override
+ public ZoneInfo run() throws Exception {
+ return (ZoneInfo) input.readObject();
+ }
+ },
+ CalendarAccessControlContext.INSTANCE);
+ } catch (PrivilegedActionException pae) {
+ Exception e = pae.getException();
+ if (!(e instanceof OptionalDataException)) {
+ if (e instanceof RuntimeException) {
+ throw (RuntimeException) e;
+ } else if (e instanceof IOException) {
+ throw (IOException) e;
+ } else if (e instanceof ClassNotFoundException) {
+ throw (ClassNotFoundException) e;
+ }
+ throw new RuntimeException(e);
+ }
+ }
+ if (zi != null) {
+ zone = zi;
+ }
+ */
// If the deserialized object has a SimpleTimeZone, try to
// replace it with a ZoneInfo equivalent (as of 1.4) in order
@@ -3499,4 +3619,18 @@ else if (serialVersionOnStream >= 0)
}
}
}
+
+ /**
+ * Converts this object to an {@link Instant}.
+ *
+ * The conversion creates an {@code Instant} that represents the
+ * same point on the time-line as this {@code Calendar}.
+ *
+ * @return the instant representing the same point on the time-line
+ * @since 1.8
+ */
+ // TODO(b/287571490): Reimplement code with dependencies outside of the core JRE subset
+ // public final Instant toInstant() {
+ // return Instant.ofEpochMilli(getTimeInMillis());
+ // }
}
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Collection.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Collection.java
index 2ae88727a0..0ded04ba29 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Collection.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Collection.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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,6 +25,7 @@
package java.util;
+import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@@ -35,41 +36,37 @@
* collections allow duplicate elements and others do not. Some are ordered
* and others unordered. The JDK does not provide any direct
* implementations of this interface: it provides implementations of more
- * specific subinterfaces like Set and List . This interface
+ * specific subinterfaces like {@code Set} and {@code List}. This interface
* is typically used to pass collections around and manipulate them where
* maximum generality is desired.
*
*
Bags or multisets (unordered collections that may contain
* duplicate elements) should implement this interface directly.
*
- *
All general-purpose Collection implementation classes (which
- * typically implement Collection indirectly through one of its
+ *
All general-purpose {@code Collection} implementation classes (which
+ * typically implement {@code Collection} indirectly through one of its
* subinterfaces) should provide two "standard" constructors: a void (no
* arguments) constructor, which creates an empty collection, and a
- * constructor with a single argument of type Collection , which
+ * constructor with a single argument of type {@code Collection}, which
* creates a new collection with the same elements as its argument. In
* effect, the latter constructor allows the user to copy any collection,
* producing an equivalent collection of the desired implementation type.
* There is no way to enforce this convention (as interfaces cannot contain
- * constructors) but all of the general-purpose Collection
+ * constructors) but all of the general-purpose {@code Collection}
* implementations in the Java platform libraries comply.
*
- *
The "destructive" methods contained in this interface, that is, the
- * methods that modify the collection on which they operate, are specified to
- * throw UnsupportedOperationException if this collection does not
- * support the operation. If this is the case, these methods may, but are not
- * required to, throw an UnsupportedOperationException if the
- * invocation would have no effect on the collection. For example, invoking
- * the {@link #addAll(Collection)} method on an unmodifiable collection may,
- * but is not required to, throw the exception if the collection to be added
- * is empty.
+ *
Certain methods are specified to be
+ * optional . If a collection implementation doesn't implement a
+ * particular operation, it should define the corresponding method to throw
+ * {@code UnsupportedOperationException}. Such methods are marked "optional
+ * operation" in method specifications of the collections interfaces.
*
- *
- * Some collection implementations have restrictions on the elements that
- * they may contain. For example, some implementations prohibit null elements,
+ *
Some collection implementations
+ * have restrictions on the elements that they may contain.
+ * For example, some implementations prohibit null elements,
* and some have restrictions on the types of their elements. Attempting to
* add an ineligible element throws an unchecked exception, typically
- * NullPointerException or ClassCastException . Attempting
+ * {@code NullPointerException} or {@code ClassCastException}. Attempting
* to query the presence of an ineligible element may throw an exception,
* or it may simply return false; some implementations will exhibit the former
* behavior and some will exhibit the latter. More generally, attempting an
@@ -90,13 +87,13 @@
*
Many methods in Collections Framework interfaces are defined in
* terms of the {@link Object#equals(Object) equals} method. For example,
* the specification for the {@link #contains(Object) contains(Object o)}
- * method says: "returns true if and only if this collection
- * contains at least one element e such that
- * (o==null ? e==null : o.equals(e)) ." This specification should
- * not be construed to imply that invoking Collection.contains
- * with a non-null argument o will cause o.equals(e) to be
- * invoked for any element e . Implementations are free to implement
- * optimizations whereby the equals invocation is avoided, for
+ * method says: "returns {@code true} if and only if this collection
+ * contains at least one element {@code e} such that
+ * {@code (o==null ? e==null : o.equals(e))}." This specification should
+ * not be construed to imply that invoking {@code Collection.contains}
+ * with a non-null argument {@code o} will cause {@code o.equals(e)} to be
+ * invoked for any element {@code e}. Implementations are free to implement
+ * optimizations whereby the {@code equals} invocation is avoided, for
* example, by first comparing the hash codes of the two elements. (The
* {@link Object#hashCode()} specification guarantees that two objects with
* unequal hash codes cannot be equal.) More generally, implementations of
@@ -111,6 +108,86 @@
* methods. Implementations may optionally handle the self-referential scenario,
* however most current implementations do not do so.
*
+ *
+ *
+ * Most collections manage storage for elements they contain. By contrast, view
+ * collections themselves do not store elements, but instead they rely on a
+ * backing collection to store the actual elements. Operations that are not handled
+ * by the view collection itself are delegated to the backing collection. Examples of
+ * view collections include the wrapper collections returned by methods such as
+ * {@link Collections#checkedCollection Collections.checkedCollection},
+ * {@link Collections#synchronizedCollection Collections.synchronizedCollection}, and
+ * {@link Collections#unmodifiableCollection Collections.unmodifiableCollection}.
+ * Other examples of view collections include collections that provide a
+ * different representation of the same elements, for example, as
+ * provided by {@link List#subList List.subList},
+ * {@link NavigableSet#subSet NavigableSet.subSet}, or
+ * {@link Map#entrySet Map.entrySet}.
+ * Any changes made to the backing collection are visible in the view collection.
+ * Correspondingly, any changes made to the view collection — if changes
+ * are permitted — are written through to the backing collection.
+ * Although they technically aren't collections, instances of
+ * {@link Iterator} and {@link ListIterator} can also allow modifications
+ * to be written through to the backing collection, and in some cases,
+ * modifications to the backing collection will be visible to the Iterator
+ * during iteration.
+ *
+ *
+ *
+ * Certain methods of this interface are considered "destructive" and are called
+ * "mutator" methods in that they modify the group of objects contained within
+ * the collection on which they operate. They can be specified to throw
+ * {@code UnsupportedOperationException} if this collection implementation
+ * does not support the operation. Such methods should (but are not required
+ * to) throw an {@code UnsupportedOperationException} if the invocation would
+ * have no effect on the collection. For example, consider a collection that
+ * does not support the {@link #add add} operation. What will happen if the
+ * {@link #addAll addAll} method is invoked on this collection, with an empty
+ * collection as the argument? The addition of zero elements has no effect,
+ * so it is permissible for this collection simply to do nothing and not to throw
+ * an exception. However, it is recommended that such cases throw an exception
+ * unconditionally, as throwing only in certain cases can lead to
+ * programming errors.
+ *
+ *
An unmodifiable collection is a collection, all of whose
+ * mutator methods (as defined above) are specified to throw
+ * {@code UnsupportedOperationException}. Such a collection thus cannot be
+ * modified by calling any methods on it. For a collection to be properly
+ * unmodifiable, any view collections derived from it must also be unmodifiable.
+ * For example, if a List is unmodifiable, the List returned by
+ * {@link List#subList List.subList} is also unmodifiable.
+ *
+ *
An unmodifiable collection is not necessarily immutable. If the
+ * contained elements are mutable, the entire collection is clearly
+ * mutable, even though it might be unmodifiable. For example, consider
+ * two unmodifiable lists containing mutable elements. The result of calling
+ * {@code list1.equals(list2)} might differ from one call to the next if
+ * the elements had been mutated, even though both lists are unmodifiable.
+ * However, if an unmodifiable collection contains all immutable elements,
+ * it can be considered effectively immutable.
+ *
+ *
+ *
+ * An unmodifiable view collection is a collection that is unmodifiable
+ * and that is also a view onto a backing collection. Its mutator methods throw
+ * {@code UnsupportedOperationException}, as described above, while
+ * reading and querying methods are delegated to the backing collection.
+ * The effect is to provide read-only access to the backing collection.
+ * This is useful for a component to provide users with read access to
+ * an internal collection, while preventing them from modifying such
+ * collections unexpectedly. Examples of unmodifiable view collections
+ * are those returned by the
+ * {@link Collections#unmodifiableCollection Collections.unmodifiableCollection},
+ * {@link Collections#unmodifiableList Collections.unmodifiableList}, and
+ * related methods.
+ *
+ *
Note that changes to the backing collection might still be possible,
+ * and if they occur, they are visible through the unmodifiable view. Thus,
+ * an unmodifiable view collection is not necessarily immutable. However,
+ * if the backing collection of an unmodifiable view is effectively immutable,
+ * or if the only reference to the backing collection is through an
+ * unmodifiable view, the view can be considered effectively immutable.
+ *
*
This interface is a member of the
*
* Java Collections Framework .
@@ -146,35 +223,35 @@ public interface Collection extends Iterable {
/**
* Returns the number of elements in this collection. If this collection
- * contains more than Integer.MAX_VALUE elements, returns
- * Integer.MAX_VALUE .
+ * contains more than {@code Integer.MAX_VALUE} elements, returns
+ * {@code Integer.MAX_VALUE}.
*
* @return the number of elements in this collection
*/
int size();
/**
- * Returns true if this collection contains no elements.
+ * Returns {@code true} if this collection contains no elements.
*
- * @return true if this collection contains no elements
+ * @return {@code true} if this collection contains no elements
*/
boolean isEmpty();
/**
- * Returns true if this collection contains the specified element.
- * More formally, returns true if and only if this collection
- * contains at least one element e such that
- * (o==null ? e==null : o.equals(e)) .
+ * Returns {@code true} if this collection contains the specified element.
+ * More formally, returns {@code true} if and only if this collection
+ * contains at least one element {@code e} such that
+ * {@code Objects.equals(o, e)}.
*
* @param o element whose presence in this collection is to be tested
- * @return true if this collection contains the specified
+ * @return {@code true} if this collection contains the specified
* element
* @throws ClassCastException if the type of the specified element
* is incompatible with this collection
- * (optional )
+ * (optional )
* @throws NullPointerException if the specified element is null and this
* collection does not permit null elements
- * (optional )
+ * (optional )
*/
boolean contains(Object o);
@@ -184,7 +261,7 @@ public interface Collection extends Iterable {
* (unless this collection is an instance of some class that provides a
* guarantee).
*
- * @return an Iterator over the elements in this collection
+ * @return an {@code Iterator} over the elements in this collection
*/
Iterator iterator();
@@ -192,17 +269,23 @@ public interface Collection extends Iterable {
* Returns an array containing all of the elements in this collection.
* If this collection makes any guarantees as to what order its elements
* are returned by its iterator, this method must return the elements in
- * the same order.
+ * the same order. The returned array's {@linkplain Class#getComponentType
+ * runtime component type} is {@code Object}.
*
* The returned array will be "safe" in that no references to it are
* maintained by this collection. (In other words, this method must
* allocate a new array even if this collection is backed by an array).
* The caller is thus free to modify the returned array.
*
- *
This method acts as bridge between array-based and collection-based
- * APIs.
+ * @apiNote
+ * This method acts as a bridge between array-based and collection-based APIs.
+ * It returns an array whose runtime type is {@code Object[]}.
+ * Use {@link #toArray(Object[]) toArray(T[])} to reuse an existing
+ * array, or use {@link #toArray(IntFunction)} to control the runtime type
+ * of the array.
*
- * @return an array containing all of the elements in this collection
+ * @return an array, whose {@linkplain Class#getComponentType runtime component
+ * type} is {@code Object}, containing all of the elements in this collection
*/
Object[] toArray();
@@ -216,66 +299,115 @@ public interface Collection extends Iterable {
* If this collection fits in the specified array with room to spare
* (i.e., the array has more elements than this collection), the element
* in the array immediately following the end of the collection is set to
- * null . (This is useful in determining the length of this
+ * {@code null}. (This is useful in determining the length of this
* collection only if the caller knows that this collection does
- * not contain any null elements.)
+ * not contain any {@code null} elements.)
*
*
If this collection makes any guarantees as to what order its elements
* are returned by its iterator, this method must return the elements in
* the same order.
*
- *
Like the {@link #toArray()} method, this method acts as bridge between
- * array-based and collection-based APIs. Further, this method allows
- * precise control over the runtime type of the output array, and may,
- * under certain circumstances, be used to save allocation costs.
+ * @apiNote
+ * This method acts as a bridge between array-based and collection-based APIs.
+ * It allows an existing array to be reused under certain circumstances.
+ * Use {@link #toArray()} to create an array whose runtime type is {@code Object[]},
+ * or use {@link #toArray(IntFunction)} to control the runtime type of
+ * the array.
*
- *
Suppose x is a collection known to contain only strings.
- * The following code can be used to dump the collection into a newly
- * allocated array of String :
+ *
Suppose {@code x} is a collection known to contain only strings.
+ * The following code can be used to dump the collection into a previously
+ * allocated {@code String} array:
*
*
- * String[] y = x.toArray(new String[0]);
+ * String[] y = new String[SIZE];
+ * ...
+ * y = x.toArray(y);
*
- * Note that toArray(new Object[0]) is identical in function to
- * toArray() .
+ * The return value is reassigned to the variable {@code y}, because a
+ * new array will be allocated and returned if the collection {@code x} has
+ * too many elements to fit into the existing array {@code y}.
*
- * @param the runtime type of the array to contain the collection
+ * Note that {@code toArray(new Object[0])} is identical in function to
+ * {@code toArray()}.
+ *
+ * @param the component type of the array to contain the collection
* @param a the array into which the elements of this collection are to be
* stored, if it is big enough; otherwise, a new array of the same
* runtime type is allocated for this purpose.
* @return an array containing all of the elements in this collection
- * @throws ArrayStoreException if the runtime type of the specified array
- * is not a supertype of the runtime type of every element in
- * this collection
+ * @throws ArrayStoreException if the runtime type of any element in this
+ * collection is not assignable to the {@linkplain Class#getComponentType
+ * runtime component type} of the specified array
* @throws NullPointerException if the specified array is null
*/
T[] toArray(T[] a);
+ /**
+ * Returns an array containing all of the elements in this collection,
+ * using the provided {@code generator} function to allocate the returned array.
+ *
+ * If this collection makes any guarantees as to what order its elements
+ * are returned by its iterator, this method must return the elements in
+ * the same order.
+ *
+ * @apiNote
+ * This method acts as a bridge between array-based and collection-based APIs.
+ * It allows creation of an array of a particular runtime type. Use
+ * {@link #toArray()} to create an array whose runtime type is {@code Object[]},
+ * or use {@link #toArray(Object[]) toArray(T[])} to reuse an existing array.
+ *
+ *
Suppose {@code x} is a collection known to contain only strings.
+ * The following code can be used to dump the collection into a newly
+ * allocated array of {@code String}:
+ *
+ *
+ * String[] y = x.toArray(String[]::new);
+ *
+ * @implSpec
+ * The default implementation calls the generator function with zero
+ * and then passes the resulting array to {@link #toArray(Object[]) toArray(T[])}.
+ *
+ * @param the component type of the array to contain the collection
+ * @param generator a function which produces a new array of the desired
+ * type and the provided length
+ * @return an array containing all of the elements in this collection
+ * @throws ArrayStoreException if the runtime type of any element in this
+ * collection is not assignable to the {@linkplain Class#getComponentType
+ * runtime component type} of the generated array
+ * @throws NullPointerException if the generator function is null
+ * @since 11
+ */
+ /* J2ObjC removed
+ default T[] toArray(IntFunction generator) {
+ return toArray(generator.apply(0));
+ }
+ */
+
// Modification Operations
/**
* Ensures that this collection contains the specified element (optional
- * operation). Returns true if this collection changed as a
- * result of the call. (Returns false if this collection does
+ * operation). Returns {@code true} if this collection changed as a
+ * result of the call. (Returns {@code false} if this collection does
* not permit duplicates and already contains the specified element.)
*
* Collections that support this operation may place limitations on what
* elements may be added to this collection. In particular, some
- * collections will refuse to add null elements, and others will
+ * collections will refuse to add {@code null} elements, and others will
* impose restrictions on the type of elements that may be added.
* Collection classes should clearly specify in their documentation any
* restrictions on what elements may be added.
*
* If a collection refuses to add a particular element for any reason
* other than that it already contains the element, it must throw
- * an exception (rather than returning false ). This preserves
+ * an exception (rather than returning {@code false}). This preserves
* the invariant that a collection always contains the specified element
* after this call returns.
*
* @param e element whose presence in this collection is to be ensured
- * @return true if this collection changed as a result of the
+ * @return {@code true} if this collection changed as a result of the
* call
- * @throws UnsupportedOperationException if the add operation
+ * @throws UnsupportedOperationException if the {@code add} operation
* is not supported by this collection
* @throws ClassCastException if the class of the specified element
* prevents it from being added to this collection
@@ -291,14 +423,14 @@ public interface Collection extends Iterable {
/**
* Removes a single instance of the specified element from this
* collection, if it is present (optional operation). More formally,
- * removes an element e such that
- * (o==null ? e==null : o.equals(e)) , if
+ * removes an element {@code e} such that
+ * {@code Objects.equals(o, e)}, if
* this collection contains one or more such elements. Returns
- * true if this collection contained the specified element (or
+ * {@code true} if this collection contained the specified element (or
* equivalently, if this collection changed as a result of the call).
*
* @param o element to be removed from this collection, if present
- * @return true if an element was removed as a result of this call
+ * @return {@code true} if an element was removed as a result of this call
* @throws ClassCastException if the type of the specified element
* is incompatible with this collection
* (optional )
@@ -314,11 +446,11 @@ public interface Collection extends Iterable {
// Bulk Operations
/**
- * Returns true if this collection contains all of the elements
+ * Returns {@code true} if this collection contains all of the elements
* in the specified collection.
*
* @param c collection to be checked for containment in this collection
- * @return true if this collection contains all of the elements
+ * @return {@code true} if this collection contains all of the elements
* in the specified collection
* @throws ClassCastException if the types of one or more elements
* in the specified collection are incompatible with this
@@ -342,8 +474,8 @@ public interface Collection extends Iterable {
* nonempty.)
*
* @param c collection containing elements to be added to this collection
- * @return true if this collection changed as a result of the call
- * @throws UnsupportedOperationException if the addAll operation
+ * @return {@code true} if this collection changed as a result of the call
+ * @throws UnsupportedOperationException if the {@code addAll} operation
* is not supported by this collection
* @throws ClassCastException if the class of an element of the specified
* collection prevents it from being added to this collection
@@ -366,9 +498,9 @@ public interface Collection extends Iterable {
* collection.
*
* @param c collection containing elements to be removed from this collection
- * @return true if this collection changed as a result of the
+ * @return {@code true} if this collection changed as a result of the
* call
- * @throws UnsupportedOperationException if the removeAll method
+ * @throws UnsupportedOperationException if the {@code removeAll} method
* is not supported by this collection
* @throws ClassCastException if the types of one or more elements
* in this collection are incompatible with the specified
@@ -426,8 +558,8 @@ default boolean removeIf(Predicate super E> filter) {
* specified collection.
*
* @param c collection containing elements to be retained in this collection
- * @return true if this collection changed as a result of the call
- * @throws UnsupportedOperationException if the retainAll operation
+ * @return {@code true} if this collection changed as a result of the call
+ * @throws UnsupportedOperationException if the {@code retainAll} operation
* is not supported by this collection
* @throws ClassCastException if the types of one or more elements
* in this collection are incompatible with the specified
@@ -447,7 +579,7 @@ default boolean removeIf(Predicate super E> filter) {
* Removes all of the elements from this collection (optional operation).
* The collection will be empty after this method returns.
*
- * @throws UnsupportedOperationException if the clear operation
+ * @throws UnsupportedOperationException if the {@code clear} operation
* is not supported by this collection
*/
void clear();
@@ -458,30 +590,30 @@ default boolean removeIf(Predicate super E> filter) {
/**
* Compares the specified object with this collection for equality.
*
- * While the Collection interface adds no stipulations to the
- * general contract for the Object.equals , programmers who
- * implement the Collection interface "directly" (in other words,
- * create a class that is a Collection but is not a Set
- * or a List ) must exercise care if they choose to override the
- * Object.equals . It is not necessary to do so, and the simplest
- * course of action is to rely on Object 's implementation, but
+ * While the {@code Collection} interface adds no stipulations to the
+ * general contract for the {@code Object.equals}, programmers who
+ * implement the {@code Collection} interface "directly" (in other words,
+ * create a class that is a {@code Collection} but is not a {@code Set}
+ * or a {@code List}) must exercise care if they choose to override the
+ * {@code Object.equals}. It is not necessary to do so, and the simplest
+ * course of action is to rely on {@code Object}'s implementation, but
* the implementor may wish to implement a "value comparison" in place of
- * the default "reference comparison." (The List and
- * Set interfaces mandate such value comparisons.)
- *
- * The general contract for the Object.equals method states that
- * equals must be symmetric (in other words, a.equals(b) if and
- * only if b.equals(a) ). The contracts for List.equals
- * and Set.equals state that lists are only equal to other lists,
- * and sets to other sets. Thus, a custom equals method for a
- * collection class that implements neither the List nor
- * Set interface must return false when this collection
+ * the default "reference comparison." (The {@code List} and
+ * {@code Set} interfaces mandate such value comparisons.)
+ *
+ * The general contract for the {@code Object.equals} method states that
+ * equals must be symmetric (in other words, {@code a.equals(b)} if and
+ * only if {@code b.equals(a)}). The contracts for {@code List.equals}
+ * and {@code Set.equals} state that lists are only equal to other lists,
+ * and sets to other sets. Thus, a custom {@code equals} method for a
+ * collection class that implements neither the {@code List} nor
+ * {@code Set} interface must return {@code false} when this collection
* is compared to any list or set. (By the same logic, it is not possible
- * to write a class that correctly implements both the Set and
- * List interfaces.)
+ * to write a class that correctly implements both the {@code Set} and
+ * {@code List} interfaces.)
*
* @param o object to be compared for equality with this collection
- * @return true if the specified object is equal to this
+ * @return {@code true} if the specified object is equal to this
* collection
*
* @see Object#equals(Object)
@@ -492,13 +624,13 @@ default boolean removeIf(Predicate super E> filter) {
/**
* Returns the hash code value for this collection. While the
- * Collection interface adds no stipulations to the general
- * contract for the Object.hashCode method, programmers should
- * take note that any class that overrides the Object.equals
- * method must also override the Object.hashCode method in order
- * to satisfy the general contract for the Object.hashCode method.
- * In particular, c1.equals(c2) implies that
- * c1.hashCode()==c2.hashCode() .
+ * {@code Collection} interface adds no stipulations to the general
+ * contract for the {@code Object.hashCode} method, programmers should
+ * take note that any class that overrides the {@code Object.equals}
+ * method must also override the {@code Object.hashCode} method in order
+ * to satisfy the general contract for the {@code Object.hashCode} method.
+ * In particular, {@code c1.equals(c2)} implies that
+ * {@code c1.hashCode()==c2.hashCode()}.
*
* @return the hash code value for this collection
*
@@ -518,7 +650,7 @@ default boolean removeIf(Predicate super E> filter) {
*
The default implementation should be overridden by subclasses that
* can return a more efficient spliterator. In order to
* preserve expected laziness behavior for the {@link #stream()} and
- * {@link #parallelStream()}} methods, spliterators should either have the
+ * {@link #parallelStream()} methods, spliterators should either have the
* characteristic of {@code IMMUTABLE} or {@code CONCURRENT}, or be
* late-binding .
* If none of these is practical, the overriding class should describe the
@@ -537,7 +669,7 @@ default boolean removeIf(Predicate super E> filter) {
* @implSpec
* The default implementation creates a
* late-binding spliterator
- * from the collections's {@code Iterator}. The spliterator inherits the
+ * from the collection's {@code Iterator}. The spliterator inherits the
* fail-fast properties of the collection's iterator.
*
* The created {@code Spliterator} reports {@link Spliterator#SIZED}.
diff --git a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Collections.java b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Collections.java
index 8252d04ea1..59cd1ebf82 100644
--- a/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Collections.java
+++ b/jre_emul/android/platform/libcore/ojluni/src/main/java/java/util/Collections.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 The Android Open Source Project
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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,9 +25,13 @@
*/
package java.util;
-import java.io.Serializable;
-import java.io.ObjectOutputStream;
+
+/* J2ObjC removed.
+import dalvik.system.VMRuntime;
+*/
+
import java.io.IOException;
+import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Array;
@@ -35,14 +39,14 @@
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
+import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
-/* J2ObjC removed.
-import dalvik.system.VMRuntime;
- */
+// Android-changed: SharedSecrets are not moved yet.
+// import jdk.internal.access.SharedSecrets;
/**
* This class consists exclusively of static methods that operate on or return
@@ -50,7 +54,7 @@
* collections, "wrappers", which return a new collection backed by a
* specified collection, and a few other odds and ends.
*
- *
The methods of this class all throw a NullPointerException
+ *
The methods of this class all throw a {@code NullPointerException}
* if the collections or class objects provided to them are null.
*
*
The documentation for the polymorphic algorithms contained in this class
@@ -58,20 +62,20 @@
* descriptions should be regarded as implementation notes , rather than
* parts of the specification . Implementors should feel free to
* substitute other algorithms, so long as the specification itself is adhered
- * to. (For example, the algorithm used by sort does not have to be
+ * to. (For example, the algorithm used by {@code sort} does not have to be
* a mergesort, but it does have to be stable .)
*
*
The "destructive" algorithms contained in this class, that is, the
* algorithms that modify the collection on which they operate, are specified
- * to throw UnsupportedOperationException if the collection does not
- * support the appropriate mutation primitive(s), such as the set
+ * to throw {@code UnsupportedOperationException} if the collection does not
+ * support the appropriate mutation primitive(s), such as the {@code set}
* method. These algorithms may, but are not required to, throw this
* exception if an invocation would have no effect on the collection. For
- * example, invoking the sort method on an unmodifiable list that is
- * already sorted may or may not throw UnsupportedOperationException .
+ * example, invoking the {@code sort} method on an unmodifiable list that is
+ * already sorted may or may not throw {@code UnsupportedOperationException}.
*
*
This class is a member of the
- *
+ *
* Java Collections Framework .
*
* @author Josh Bloch
@@ -245,10 +249,10 @@ public static void sort(List list, Comparator super T> c) {
* @param list the list to be searched.
* @param key the key to be searched for.
* @return the index of the search key, if it is contained in the list;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the list: the index of the first
- * element greater than the key, or list.size() if all
+ * element greater than the key, or {@code list.size()} if all
* elements in the list are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -346,13 +350,13 @@ private static T get(ListIterator extends T> i, int index) {
* @param list the list to be searched.
* @param key the key to be searched for.
* @param c the comparator by which the list is ordered.
- * A null value indicates that the elements'
+ * A {@code null} value indicates that the elements'
* {@linkplain Comparable natural ordering} should be used.
* @return the index of the search key, if it is contained in the list;
- * otherwise, (-(insertion point ) - 1) . The
+ * otherwise, (-(insertion point ) - 1). The
* insertion point is defined as the point at which the
* key would be inserted into the list: the index of the first
- * element greater than the key, or list.size() if all
+ * element greater than the key, or {@code list.size()} if all
* elements in the list are less than the specified key. Note
* that this guarantees that the return value will be >= 0 if
* and only if the key is found.
@@ -418,7 +422,7 @@ else if (cmp > 0)
*
* @param list the list whose elements are to be reversed.
* @throws UnsupportedOperationException if the specified list or
- * its list-iterator does not support the set operation.
+ * its list-iterator does not support the {@code set} operation.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public static void reverse(List> list) {
@@ -466,7 +470,7 @@ public static void reverse(List> list) {
*
* @param list the list to be shuffled.
* @throws UnsupportedOperationException if the specified list or
- * its list-iterator does not support the set operation.
+ * its list-iterator does not support the {@code set} operation.
*/
public static void shuffle(List> list) {
Random rnd = r;
@@ -498,7 +502,7 @@ public static void shuffle(List> list) {
* @param list the list to be shuffled.
* @param rnd the source of randomness to use to shuffle the list.
* @throws UnsupportedOperationException if the specified list or its
- * list-iterator does not support the set operation.
+ * list-iterator does not support the {@code set} operation.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public static void shuffle(List> list, Random rnd) {
@@ -507,7 +511,7 @@ public static void shuffle(List> list, Random rnd) {
for (int i=size; i>1; i--)
swap(list, i-1, rnd.nextInt(i));
} else {
- Object arr[] = list.toArray();
+ Object[] arr = list.toArray();
// Shuffle array
for (int i=size; i>1; i--)
@@ -518,9 +522,9 @@ public static void shuffle(List> list, Random rnd) {
// the wildcard but it will require a call to a supplementary
// private method
ListIterator it = list.listIterator();
- for (int i=0; i list, Random rnd) {
* @param list The list in which to swap elements.
* @param i the index of one element to be swapped.
* @param j the index of the other element to be swapped.
- * @throws IndexOutOfBoundsException if either i or j
+ * @throws IndexOutOfBoundsException if either {@code i} or {@code j}
* is out of range (i < 0 || i >= list.size()
* || j < 0 || j >= list.size()).
* @since 1.4
@@ -566,7 +570,7 @@ private static void swap(Object[] arr, int i, int j) {
* @param list the list to be filled with the specified element.
* @param obj The element with which to fill the specified list.
* @throws UnsupportedOperationException if the specified list or its
- * list-iterator does not support the set operation.
+ * list-iterator does not support the {@code set} operation.
*/
public static void fill(List super T> list, T obj) {
int size = list.size();
@@ -587,8 +591,9 @@ public static void fill(List super T> list, T obj) {
* Copies all of the elements from one list into another. After the
* operation, the index of each copied element in the destination list
* will be identical to its index in the source list. The destination
- * list must be at least as long as the source list. If it is longer, the
- * remaining elements in the destination list are unaffected.
+ * list's size must be greater than or equal to the source list's size.
+ * If it is greater, the remaining elements in the destination list are
+ * unaffected.
*
* This method runs in linear time.
*
@@ -598,7 +603,7 @@ public static void fill(List super T> list, T obj) {
* @throws IndexOutOfBoundsException if the destination list is too small
* to contain the entire source List.
* @throws UnsupportedOperationException if the destination list's
- * list-iterator does not support the set operation.
+ * list-iterator does not support the {@code set} operation.
*/
public static void copy(List super T> dest, List extends T> src) {
int srcSize = src.size();
@@ -622,11 +627,11 @@ public static void copy(List super T> dest, List extends T> src) {
/**
* Returns the minimum element of the given collection, according to the
* natural ordering of its elements. All elements in the
- * collection must implement the Comparable interface.
+ * collection must implement the {@code Comparable} interface.
* Furthermore, all elements in the collection must be mutually
- * comparable (that is, e1.compareTo(e2) must not throw a
- * ClassCastException for any elements e1 and
- * e2 in the collection).
+ * comparable (that is, {@code e1.compareTo(e2)} must not throw a
+ * {@code ClassCastException} for any elements {@code e1} and
+ * {@code e2} in the collection).
*
* This method iterates over the entire collection, hence it requires
* time proportional to the size of the collection.
@@ -657,9 +662,9 @@ public static > T min(Collection exte
* Returns the minimum element of the given collection, according to the
* order induced by the specified comparator. All elements in the
* collection must be mutually comparable by the specified
- * comparator (that is, comp.compare(e1, e2) must not throw a
- * ClassCastException for any elements e1 and
- * e2 in the collection).
+ * comparator (that is, {@code comp.compare(e1, e2)} must not throw a
+ * {@code ClassCastException} for any elements {@code e1} and
+ * {@code e2} in the collection).
*
* This method iterates over the entire collection, hence it requires
* time proportional to the size of the collection.
@@ -667,7 +672,7 @@ public static > T min(Collection exte
* @param the class of the objects in the collection
* @param coll the collection whose minimum element is to be determined.
* @param comp the comparator with which to determine the minimum element.
- * A null value indicates that the elements' natural
+ * A {@code null} value indicates that the elements' natural
* ordering should be used.
* @return the minimum element of the given collection, according
* to the specified comparator.
@@ -695,11 +700,11 @@ public static T min(Collection extends T> coll, Comparator super T> comp
/**
* Returns the maximum element of the given collection, according to the
* natural ordering of its elements. All elements in the
- * collection must implement the Comparable interface.
+ * collection must implement the {@code Comparable} interface.
* Furthermore, all elements in the collection must be mutually
- * comparable (that is, e1.compareTo(e2) must not throw a
- * ClassCastException for any elements e1 and
- * e2 in the collection).
+ * comparable
(that is, {@code e1.compareTo(e2)} must not throw a
+ * {@code ClassCastException} for any elements {@code e1} and
+ * {@code e2} in the collection).
*
* This method iterates over the entire collection, hence it requires
* time proportional to the size of the collection.
@@ -730,9 +735,9 @@ public static > T max(Collection exte
* Returns the maximum element of the given collection, according to the
* order induced by the specified comparator. All elements in the
* collection must be mutually comparable by the specified
- * comparator (that is, comp.compare(e1, e2) must not throw a
- * ClassCastException for any elements e1 and
- * e2 in the collection).
+ * comparator (that is, {@code comp.compare(e1, e2)} must not throw a
+ * {@code ClassCastException} for any elements {@code e1} and
+ * {@code e2} in the collection).
*
* This method iterates over the entire collection, hence it requires
* time proportional to the size of the collection.
@@ -740,7 +745,7 @@ public static > T max(Collection exte
* @param the class of the objects in the collection
* @param coll the collection whose maximum element is to be determined.
* @param comp the comparator with which to determine the maximum element.
- * A null value indicates that the elements' natural
+ * A {@code null} value indicates that the elements' natural
* ordering should be used.
* @return the maximum element of the given collection, according
* to the specified comparator.
@@ -767,32 +772,32 @@ public static T max(Collection extends T> coll, Comparator super T> comp
/**
* Rotates the elements in the specified list by the specified distance.
- * After calling this method, the element at index i will be
- * the element previously at index (i - distance) mod
- * list.size() , for all values of i between 0
- * and list.size()-1 , inclusive. (This method has no effect on
+ * After calling this method, the element at index {@code i} will be
+ * the element previously at index {@code (i - distance)} mod
+ * {@code list.size()}, for all values of {@code i} between {@code 0}
+ * and {@code list.size()-1}, inclusive. (This method has no effect on
* the size of the list.)
*
- * For example, suppose list comprises [t, a, n, k, s] .
- * After invoking Collections.rotate(list, 1) (or
- * Collections.rotate(list, -4) ), list will comprise
- * [s, t, a, n, k] .
+ *
For example, suppose {@code list} comprises{@code [t, a, n, k, s]}.
+ * After invoking {@code Collections.rotate(list, 1)} (or
+ * {@code Collections.rotate(list, -4)}), {@code list} will comprise
+ * {@code [s, t, a, n, k]}.
*
*
Note that this method can usefully be applied to sublists to
* move one or more elements within a list while preserving the
* order of the remaining elements. For example, the following idiom
- * moves the element at index j forward to position
- * k (which must be greater than or equal to j ):
+ * moves the element at index {@code j} forward to position
+ * {@code k} (which must be greater than or equal to {@code j}):
*
* Collections.rotate(list.subList(j, k+1), -1);
*
- * To make this concrete, suppose list comprises
- * [a, b, c, d, e] . To move the element at index 1
- * (b ) forward two positions, perform the following invocation:
+ * To make this concrete, suppose {@code list} comprises
+ * {@code [a, b, c, d, e]}. To move the element at index {@code 1}
+ * ({@code b}) forward two positions, perform the following invocation:
*
* Collections.rotate(l.subList(1, 4), -1);
*
- * The resulting list is [a, c, d, b, e] .
+ * The resulting list is {@code [a, c, d, b, e]}.
*
* To move more than one element forward, increase the absolute value
* of the rotation distance. To move elements backward, use a positive
@@ -805,8 +810,8 @@ public static T max(Collection extends T> coll, Comparator super T> comp
* element is swapped into the first element. If necessary, the process
* is repeated on the second and successive elements, until the rotation
* is complete. If the specified list is large and doesn't implement the
- * RandomAccess interface, this implementation breaks the
- * list into two sublist views around index -distance mod size .
+ * {@code RandomAccess} interface, this implementation breaks the
+ * list into two sublist views around index {@code -distance mod size}.
* Then the {@link #reverse(List)} method is invoked on each sublist view,
* and finally it is invoked on the entire list. For a more complete
* description of both algorithms, see Section 2.3 of Jon Bentley's
@@ -815,9 +820,9 @@ public static T max(Collection extends T> coll, Comparator super T> comp
* @param list the list to be rotated.
* @param distance the distance to rotate the list. There are no
* constraints on this value; it may be zero, negative, or
- * greater than list.size() .
+ * greater than {@code list.size()}.
* @throws UnsupportedOperationException if the specified list or
- * its list-iterator does not support the set operation.
+ * its list-iterator does not support the {@code set} operation.
* @since 1.4
*/
public static void rotate(List> list, int distance) {
@@ -867,21 +872,21 @@ private static void rotate2(List> list, int distance) {
/**
* Replaces all occurrences of one specified value in a list with another.
- * More formally, replaces with newVal each element e
- * in list such that
- * (oldVal==null ? e==null : oldVal.equals(e)) .
+ * More formally, replaces with {@code newVal} each element {@code e}
+ * in {@code list} such that
+ * {@code (oldVal==null ? e==null : oldVal.equals(e))}.
* (This method has no effect on the size of the list.)
*
* @param the class of the objects in the list
* @param list the list in which replacement is to occur.
* @param oldVal the old value to be replaced.
- * @param newVal the new value with which oldVal is to be
+ * @param newVal the new value with which {@code oldVal} is to be
* replaced.
- * @return true if list contained one or more elements
- * e such that
- * (oldVal==null ? e==null : oldVal.equals(e)) .
+ * @return {@code true} if {@code list} contained one or more elements
+ * {@code e} such that
+ * {@code (oldVal==null ? e==null : oldVal.equals(e))}.
* @throws UnsupportedOperationException if the specified list or
- * its list-iterator does not support the set operation.
+ * its list-iterator does not support the {@code set} operation.
* @since 1.4
*/
public static boolean replaceAll(List list, T oldVal, T newVal) {
@@ -927,7 +932,7 @@ public static boolean replaceAll(List list, T oldVal, T newVal) {
/**
* Returns the starting position of the first occurrence of the specified
* target list within the specified source list, or -1 if there is no
- * such occurrence. More formally, returns the lowest index i
+ * such occurrence. More formally, returns the lowest index {@code i}
* such that {@code source.subList(i, i+target.size()).equals(target)},
* or -1 if there is no such index. (Returns -1 if
* {@code target.size() > source.size()})
@@ -937,8 +942,8 @@ public static boolean replaceAll(List list, T oldVal, T newVal) {
* location in turn.
*
* @param source the list in which to search for the first occurrence
- * of target .
- * @param target the list to search for as a subList of source .
+ * of {@code target}.
+ * @param target the list to search for as a subList of {@code source}.
* @return the starting position of the first occurrence of the specified
* target list within the specified source list, or -1 if there
* is no such occurrence.
@@ -980,7 +985,7 @@ public static int indexOfSubList(List> source, List> target) {
/**
* Returns the starting position of the last occurrence of the specified
* target list within the specified source list, or -1 if there is no such
- * occurrence. More formally, returns the highest index i
+ * occurrence. More formally, returns the highest index {@code i}
* such that {@code source.subList(i, i+target.size()).equals(target)},
* or -1 if there is no such index. (Returns -1 if
* {@code target.size() > source.size()})
@@ -990,8 +995,8 @@ public static int indexOfSubList(List> source, List> target) {
* location in turn.
*
* @param source the list in which to search for the last occurrence
- * of target .
- * @param target the list to search for as a subList of source .
+ * of {@code target}.
+ * @param target the list to search for as a subList of {@code source}.
* @return the starting position of the last occurrence of the specified
* target list within the specified source list, or -1 if there
* is no such occurrence.
@@ -1038,28 +1043,32 @@ public static int lastIndexOfSubList(List> source, List> target) {
// Unmodifiable Wrappers
/**
- * Returns an unmodifiable view of the specified collection. This method
- * allows modules to provide users with "read-only" access to internal
- * collections. Query operations on the returned collection "read through"
+ * Returns an unmodifiable view of the
+ * specified collection. Query operations on the returned collection "read through"
* to the specified collection, and attempts to modify the returned
* collection, whether direct or via its iterator, result in an
- * UnsupportedOperationException .
+ * {@code UnsupportedOperationException}.
*
* The returned collection does not pass the hashCode and equals
* operations through to the backing collection, but relies on
- * Object 's equals and hashCode methods. This
+ * {@code Object}'s {@code equals} and {@code hashCode} methods. This
* is necessary to preserve the contracts of these operations in the case
* that the backing collection is a set or a list.
*
* The returned collection will be serializable if the specified collection
* is serializable.
*
+ * @implNote This method may return its argument if the argument is already unmodifiable.
* @param the class of the objects in the collection
* @param c the collection for which an unmodifiable view is to be
* returned.
* @return an unmodifiable view of the specified collection.
*/
+ @SuppressWarnings("unchecked")
public static Collection unmodifiableCollection(Collection extends T> c) {
+ if (c.getClass() == UnmodifiableCollection.class) {
+ return (Collection) c;
+ }
return new UnmodifiableCollection<>(c);
}
@@ -1067,8 +1076,10 @@ public static Collection unmodifiableCollection(Collection extends T> c
* @serial include
*/
static class UnmodifiableCollection implements Collection, Serializable {
+ @java.io.Serial
private static final long serialVersionUID = 1820017752578914078L;
+ @SuppressWarnings("serial") // Conditionally serializable
final Collection extends E> c;
UnmodifiableCollection(Collection extends E> c) {
@@ -1077,12 +1088,13 @@ static class UnmodifiableCollection implements Collection, Serializable {
this.c = c;
}
- public int size() {return c.size();}
- public boolean isEmpty() {return c.isEmpty();}
- public boolean contains(Object o) {return c.contains(o);}
- public Object[] toArray() {return c.toArray();}
- public T[] toArray(T[] a) {return c.toArray(a);}
- public String toString() {return c.toString();}
+ public int size() {return c.size();}
+ public boolean isEmpty() {return c.isEmpty();}
+ public boolean contains(Object o) {return c.contains(o);}
+ public Object[] toArray() {return c.toArray();}
+ public T[] toArray(T[] a) {return c.toArray(a);}
+ // public T[] toArray(IntFunction f) {return c.toArray(f);}
+ public String toString() {return c.toString();}
public Iterator iterator() {
return new Iterator() {
@@ -1151,20 +1163,25 @@ public Stream parallelStream() {
}
/**
- * Returns an unmodifiable view of the specified set. This method allows
- * modules to provide users with "read-only" access to internal sets.
- * Query operations on the returned set "read through" to the specified
+ * Returns an unmodifiable view of the
+ * specified set. Query operations on the returned set "read through" to the specified
* set, and attempts to modify the returned set, whether direct or via its
- * iterator, result in an UnsupportedOperationException .
+ * iterator, result in an {@code UnsupportedOperationException}.
*
* The returned set will be serializable if the specified set
* is serializable.
*
+ * @implNote This method may return its argument if the argument is already unmodifiable.
* @param the class of the objects in the set
* @param s the set for which an unmodifiable view is to be returned.
* @return an unmodifiable view of the specified set.
*/
+ @SuppressWarnings("unchecked")
public static Set unmodifiableSet(Set extends T> s) {
+ // Not checking for subclasses because of heap pollution and information leakage.
+ if (s.getClass() == UnmodifiableSet.class) {
+ return (Set) s;
+ }
return new UnmodifiableSet<>(s);
}
@@ -1173,6 +1190,7 @@ public static Set unmodifiableSet(Set extends T> s) {
*/
static class UnmodifiableSet extends UnmodifiableCollection
implements Set, Serializable {
+ @java.io.Serial
private static final long serialVersionUID = -9215047833775013803L;
UnmodifiableSet(Set extends E> s) {super(s);}
@@ -1181,23 +1199,27 @@ static class UnmodifiableSet extends UnmodifiableCollection
}
/**
- * Returns an unmodifiable view of the specified sorted set. This method
- * allows modules to provide users with "read-only" access to internal
- * sorted sets. Query operations on the returned sorted set "read
+ * Returns an unmodifiable view of the
+ * specified sorted set. Query operations on the returned sorted set "read
* through" to the specified sorted set. Attempts to modify the returned
* sorted set, whether direct, via its iterator, or via its
- * subSet , headSet , or tailSet views, result in
- * an UnsupportedOperationException .
+ * {@code subSet}, {@code headSet}, or {@code tailSet} views, result in
+ * an {@code UnsupportedOperationException}.
*
* The returned sorted set will be serializable if the specified sorted set
* is serializable.
*
+ * @implNote This method may return its argument if the argument is already unmodifiable.
* @param the class of the objects in the set
* @param s the sorted set for which an unmodifiable view is to be
* returned.
* @return an unmodifiable view of the specified sorted set.
*/
public static SortedSet unmodifiableSortedSet(SortedSet s) {
+ // Not checking for subclasses because of heap pollution and information leakage.
+ if (s.getClass() == UnmodifiableSortedSet.class) {
+ return s;
+ }
return new UnmodifiableSortedSet<>(s);
}
@@ -1207,7 +1229,9 @@ public static SortedSet unmodifiableSortedSet(SortedSet