guava
69 строк · 2.1 Кб
1/*
2* Copyright (C) 2008 The Guava Authors
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17package com.google.common.collect.testing;
18
19import com.google.common.annotations.GwtCompatible;
20import java.util.List;
21import java.util.Map;
22import java.util.Map.Entry;
23import java.util.Set;
24import org.checkerframework.checker.nullness.qual.Nullable;
25
26/**
27* Creates map entries using sample keys and sample values.
28*
29* @author Jesse Wilson
30*/
31@GwtCompatible
32@ElementTypesAreNonnullByDefault
33public abstract class TestMapEntrySetGenerator<
34K extends @Nullable Object, V extends @Nullable Object>
35implements TestSetGenerator<Map.Entry<K, V>> {
36private final SampleElements<K> keys;
37private final SampleElements<V> values;
38
39protected TestMapEntrySetGenerator(SampleElements<K> keys, SampleElements<V> values) {
40this.keys = keys;
41this.values = values;
42}
43
44@Override
45public SampleElements<Entry<K, V>> samples() {
46return SampleElements.mapEntries(keys, values);
47}
48
49@Override
50public Set<Entry<K, V>> create(Object... elements) {
51Entry<K, V>[] entries = createArray(elements.length);
52System.arraycopy(elements, 0, entries, 0, elements.length);
53return createFromEntries(entries);
54}
55
56public abstract Set<Entry<K, V>> createFromEntries(Entry<K, V>[] entries);
57
58@Override
59@SuppressWarnings("unchecked") // generic arrays make typesafety sad
60public Entry<K, V>[] createArray(int length) {
61return (Entry<K, V>[]) new Entry<?, ?>[length];
62}
63
64/** Returns the original element list, unchanged. */
65@Override
66public List<Entry<K, V>> order(List<Entry<K, V>> insertionOrder) {
67return insertionOrder;
68}
69}
70