History log of /libcore/luni/src/test/java/libcore/java/util/CollectionsTest.java
Revision Date Author Comments
f0d9b8aea94c2a207b7b71faaa7a8a2f78ddf1ea 20-Apr-2016 Shubham Ajmera <shubhamajmera@google.com> Add missed overrides for OpenJDK 8 Map default methods

Both the replace methods in TreeMap were left intentionally in the
commit 0e83756c4295f4df3853047205d94fe845573522 as there were no
behavioral differences and the default implementation was considered
sufficient. However, the upstream version is more efficient so that is
being added here.

As of now, all the overrides for the Map default implementation have
been put from the upstream, except for Hashtable and HashMap. Both
of these classes are quite different from their OpenJDK 8 versions to
accommodate the overrides. HashMap depends on the default implementation
for the following methods:

#getOrDefault
#replace(K, V)
#computeIfAbsent
#computeIfPresent
#compute
#merge

#replace(K, V, V) was reimplemented due to the behavioral differences
with the default implementation.

The following Hashtable methods are also dependent on the map default
implementation, though, they have added synchronization.

#getOrDefault
#putIfAbsent
#remove
#replace(K, V, V)
#replace(K, V)
#computeIfAbsent
#computeIfPresent
#compute

Once the classes get ready with the new changes comes with OpenJDK 8,
the above methods would be put in.

Bug: 27426743
Change-Id: Iee4fb156eddee17187386bbfffc8517415030a94
76e57a17f0a1c1eb5487974f02ef3453b8d65d17 29-Mar-2016 Shubham Ajmera <shubhamajmera@google.com> Build Fix

Change-Id: I312f8278e6a9f8b0d287522bd5ed87bcf3673e9b
ed47d30308588e419164d9311a41b04b8eefa04c 18-Mar-2016 Shubham Ajmera <shubhamajmera@google.com> Add OpenJDK 8 java.util.List Default Methods

and corresponding tests.

Added replaceAll and sort methods from the upstream except for the
CopyOnWriteArrayList.

Added forEach method along with the above two methods in
CopyOnWriteArrayList.

Bug: 27693350
Bug: 27540008
(cherry-picked from commit 67b8c3f1414bf04e53c094b951c8ea7903998d90)
Change-Id: Id32df836e79bee614c0dce8c61dbc7b06731265d
0e83756c4295f4df3853047205d94fe845573522 08-Mar-2016 Shubham Ajmera <shubhamajmera@google.com> Port OpenJDK8 changes in java.util.Map

& add tests.

The CL add tests for map default methods added in Java 8 - getOrDefault,
putIfAbsent, remove(K, V), replace(K, V, V), replace(K, V), forEach,
replaceAll, compute, computeIfAbsent, computeIfPresent, putIfAbsent,
merge.

Methods have been made synchronzed in Hashtable. They are using the
default map methods instead of taking the upstream changes.

Replace(K, V, V) in LinkedHashMap has been overridden as it doesn't
record access when the replace method doesn't make any replacement.

Bug: 27426743
(cherry-picked from commit 88f1a4f0b1efb746419672919654c285ce44fbc5)
Change-Id: Ifb2130698dd0ed42acc5c0f429496eebb444e21c
def94956afbfc17ea65390d16d032f9b790a5dca 18-Mar-2016 Narayan Kamath <narayan@google.com> Spliterators: pull in additional specializations.

This change also pulls in a few javadoc improvements to Collections
to make our lives easier.

bug: 27605529

(cherry picked from commit c86e0fa98d8274d7ea01213a20e3a14575406dd0)

Change-Id: I97f05ae833034f1e5a7d32329f8e19de6b97e779
16dfe442b6b6e73e230b289dae9bb2b3dbbd3d2a 14-Oct-2015 Narayan Kamath <narayan@google.com> Collections: Remove bogus test-case and optimize sort.

As inconsistent as it might sound, ArrayList modCounts are not
incremented during #set (and by extension #sort).

While we're here, also add a zero-copy path for sorting an arraylist,
where we can directly sort the underlying array.

Change-Id: I018a521144040552d99499a798a7a04a712cf320
f6b0c8b47c903d47cedf182e5aa78276283a2f32 15-Apr-2015 Narayan Kamath <narayan@google.com> Fix bad negation in Collections#binarySearch.

bug: 19749094
Change-Id: Id1d7bcf4abebb423fd3bbb7c8f379bf9e6234969
fa080b83161fa8f2c538009b312d074dd17016bc 24-Dec-2014 Narayan Kamath <narayan@google.com> Add a zero-copy path for Collections.sort() on ArrayList.

Given that ArrayLists are array backed, we can sort the underlying
array in place. A similar optimisation can be applied to Vector and
CopyOnWriteArrayList but vector isn't used often enough to slow
everything else down with an instanceof check and nobody should be
daft enough to try sorting a CopyOnWriteArrayList.

Note that it's possible to apply the same optimisation to
Collections.sort(List<T>, Comparator<? super T>) but it involves a
larger refactoring to allow us to use Object[] instead of T[] and is
accompanied by a general loss of readability.

ArrayList performance improves for all array sizes :

BEFORE

Scenario{vm=app_process, trial=0, benchmark=Sort_arrayList, arrayListLength=4} 39021.26 ns; σ=206.27 ns @ 3 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_arrayList, arrayListLength=16} 120903.59 ns; σ=1188.88 ns @ 5 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_arrayList, arrayListLength=64} 435484.98 ns; σ=19141.88 ns @ 10 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_arrayList, arrayListLength=256} 1772876.81 ns; σ=5542.74 ns @ 3 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_arrayList, arrayListLength=1024} 7289431.83 ns; σ=110869.13 ns @ 10 trials

AFTER

Scenario{vm=app_process, trial=0, benchmark=Sort_arrayList, arrayListLength=4} 9161.79 ns; σ=90.04 ns @ 6 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_arrayList, arrayListLength=16} 29988.90 ns; σ=74.05 ns @ 3 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_arrayList, arrayListLength=64} 118142.86 ns; σ=1133.52 ns @ 7 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_arrayList, arrayListLength=256} 456091.11 ns; σ=9110.18 ns @ 10 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_arrayList, arrayListLength=1024} 1851939.39 ns; σ=69542.41 ns @ 10 trials

For all other lists, there's no measurable difference for
most sizes. length == 4 is harder to be sure about, given the
large standard deviations and we'd expect the time spent in
instanceof to be larger relative to the rest of what's going on.

BEFORE

Scenario{vm=app_process, trial=0, benchmark=Sort_vector, arrayListLength=4} 49002.02 ns; σ=1392.58 ns @ 10 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_vector, arrayListLength=16} 154967.88 ns; σ=332.29 ns @ 3 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_vector, arrayListLength=64} 588207.14 ns; σ=1863.60 ns @ 3 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_vector, arrayListLength=256} 2292967.79 ns; σ=4578.14 ns @ 3 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_vector, arrayListLength=1024} 9299582.60 ns; σ=179459.24 ns @ 10 trials

AFTER

Scenario{vm=app_process, trial=0, benchmark=Sort_vector, arrayListLength=4} 49324.98 ns; σ=240.86 ns @ 3 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_vector, arrayListLength=16} 155639.91 ns; σ=215.12 ns @ 3 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_vector, arrayListLength=64} 581950.81 ns; σ=938.11 ns @ 3 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_vector, arrayListLength=256} 2285933.64 ns; σ=13265.42 ns @ 3 trials
Scenario{vm=app_process, trial=0, benchmark=Sort_vector, arrayListLength=1024} 8981475.84 ns; σ=431676.48 ns @ 10 trials

bug: 18821961

Change-Id: I30a3eaf89ff478663f555c93556167107da10873
e3cd663de1c5fa4651500289e6df9150667e2db9 12-Mar-2011 Jesse Wilson <jessewilson@google.com> Empty enumeration, iterator, listIterator for Java 7 interoperability.

This change also fixes several missing @Overrides in Collections.

Change-Id: Ibfc4f3f0fcc0307f2401caca15cda3ee2ff01dbc
http://b/3484927