mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-25 01:30:10 +00:00
8376698: Add Spliterator tests for TreeMap sub-maps
Reviewed-by: liach, rriggs
This commit is contained in:
parent
72b28672ad
commit
932f28c69b
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2026, 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
|
||||
@ -2138,10 +2138,12 @@ public class TreeMap<K,V>
|
||||
return null;
|
||||
}
|
||||
public void forEachRemaining(Consumer<? super K> action) {
|
||||
Objects.requireNonNull(action);
|
||||
while (hasNext())
|
||||
action.accept(next());
|
||||
}
|
||||
public boolean tryAdvance(Consumer<? super K> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if (hasNext()) {
|
||||
action.accept(next());
|
||||
return true;
|
||||
@ -2176,10 +2178,12 @@ public class TreeMap<K,V>
|
||||
return null;
|
||||
}
|
||||
public void forEachRemaining(Consumer<? super K> action) {
|
||||
Objects.requireNonNull(action);
|
||||
while (hasNext())
|
||||
action.accept(next());
|
||||
}
|
||||
public boolean tryAdvance(Consumer<? super K> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if (hasNext()) {
|
||||
action.accept(next());
|
||||
return true;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2026, 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
|
||||
@ -126,12 +126,19 @@ public class SpliteratorTraversingAndSplittingTest extends SpliteratorTestHelper
|
||||
|
||||
List<T> exp;
|
||||
|
||||
List<T> expRev;
|
||||
|
||||
Map<T, T> mExp;
|
||||
|
||||
Map<T, T> mExpRev;
|
||||
|
||||
SpliteratorDataBuilder(List<Object[]> data, List<T> exp) {
|
||||
this.data = data;
|
||||
this.exp = exp;
|
||||
this.expRev = new ArrayList<>(exp);
|
||||
Collections.reverse(this.expRev);
|
||||
this.mExp = createMap(exp);
|
||||
this.mExpRev = createMap(expRev);
|
||||
}
|
||||
|
||||
Map<T, T> createMap(List<T> l) {
|
||||
@ -166,12 +173,23 @@ public class SpliteratorTraversingAndSplittingTest extends SpliteratorTestHelper
|
||||
addMap(m, description);
|
||||
}
|
||||
|
||||
void addDescendingMap(Function<Map<T, T>, ? extends Map<T, T>> m) {
|
||||
String description = "new " + m.apply(Collections.<T, T>emptyMap()).getClass().getName();
|
||||
addDescendingMap(m, description);
|
||||
}
|
||||
|
||||
void addMap(Function<Map<T, T>, ? extends Map<T, T>> m, String description) {
|
||||
add(description + ".keySet().spliterator()", () -> m.apply(mExp).keySet().spliterator());
|
||||
add(description + ".values().spliterator()", () -> m.apply(mExp).values().spliterator());
|
||||
add(description + ".entrySet().spliterator()", mExp.entrySet(), () -> m.apply(mExp).entrySet().spliterator());
|
||||
}
|
||||
|
||||
void addDescendingMap(Function<Map<T, T>, ? extends Map<T, T>> m, String description) {
|
||||
add(description + ".keySet().spliterator()", expRev, () -> m.apply(mExp).keySet().spliterator());
|
||||
add(description + ".values().spliterator()", expRev, () -> m.apply(mExp).values().spliterator());
|
||||
add(description + ".entrySet().spliterator()", mExpRev.entrySet(), () -> m.apply(mExp).entrySet().spliterator());
|
||||
}
|
||||
|
||||
StringBuilder joiner(String description) {
|
||||
return new StringBuilder(description).
|
||||
append(" {").
|
||||
@ -639,8 +657,14 @@ public class SpliteratorTraversingAndSplittingTest extends SpliteratorTestHelper
|
||||
return cm;
|
||||
}, "new java.util.WeakHashMap(1, size + 1)");
|
||||
|
||||
// @@@ Descending maps etc
|
||||
db.addMap(TreeMap::new);
|
||||
db.addMap(m -> new TreeMap<>(m).tailMap(Integer.MIN_VALUE));
|
||||
db.addMap(m -> new TreeMap<>(m).headMap(Integer.MAX_VALUE));
|
||||
db.addMap(m -> new TreeMap<>(m).subMap(Integer.MIN_VALUE, Integer.MAX_VALUE));
|
||||
db.addDescendingMap(m -> new TreeMap<>(m).descendingMap());
|
||||
db.addDescendingMap(m -> new TreeMap<>(m).descendingMap().tailMap(Integer.MAX_VALUE));
|
||||
db.addDescendingMap(m -> new TreeMap<>(m).descendingMap().headMap(Integer.MIN_VALUE));
|
||||
db.addDescendingMap(m -> new TreeMap<>(m).descendingMap().subMap(Integer.MAX_VALUE, Integer.MIN_VALUE));
|
||||
|
||||
db.addMap(ConcurrentHashMap::new);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user