Java
81 строка · 2.4 Кб
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;
23
24/**
25* Implementation helper for {@link TestMapGenerator} for use with maps of strings.
26*
27* @author Chris Povirk
28* @author Jared Levy
29* @author George van den Driessche
30*/
31@GwtCompatible
32@ElementTypesAreNonnullByDefault
33public abstract class TestStringMapGenerator implements TestMapGenerator<String, String> {
34
35@Override
36public SampleElements<Entry<String, String>> samples() {
37return new SampleElements<>(
38Helpers.mapEntry("one", "January"),
39Helpers.mapEntry("two", "February"),
40Helpers.mapEntry("three", "March"),
41Helpers.mapEntry("four", "April"),
42Helpers.mapEntry("five", "May"));
43}
44
45@Override
46public Map<String, String> create(Object... entries) {
47@SuppressWarnings("unchecked")
48Entry<String, String>[] array = (Entry<String, String>[]) new Entry<?, ?>[entries.length];
49int i = 0;
50for (Object o : entries) {
51@SuppressWarnings("unchecked")
52Entry<String, String> e = (Entry<String, String>) o;
53array[i++] = e;
54}
55return create(array);
56}
57
58protected abstract Map<String, String> create(Entry<String, String>[] entries);
59
60@Override
61@SuppressWarnings("unchecked")
62public final Entry<String, String>[] createArray(int length) {
63return (Entry<String, String>[]) new Entry<?, ?>[length];
64}
65
66@Override
67public final String[] createKeyArray(int length) {
68return new String[length];
69}
70
71@Override
72public final String[] createValueArray(int length) {
73return new String[length];
74}
75
76/** Returns the original element list, unchanged. */
77@Override
78public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
79return insertionOrder;
80}
81}
82