guava

Форк
0
/
TestMapEntrySetGenerator.java 
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

17
package com.google.common.collect.testing;
18

19
import com.google.common.annotations.GwtCompatible;
20
import java.util.List;
21
import java.util.Map;
22
import java.util.Map.Entry;
23
import java.util.Set;
24
import 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
33
public abstract class TestMapEntrySetGenerator<
34
        K extends @Nullable Object, V extends @Nullable Object>
35
    implements TestSetGenerator<Map.Entry<K, V>> {
36
  private final SampleElements<K> keys;
37
  private final SampleElements<V> values;
38

39
  protected TestMapEntrySetGenerator(SampleElements<K> keys, SampleElements<V> values) {
40
    this.keys = keys;
41
    this.values = values;
42
  }
43

44
  @Override
45
  public SampleElements<Entry<K, V>> samples() {
46
    return SampleElements.mapEntries(keys, values);
47
  }
48

49
  @Override
50
  public Set<Entry<K, V>> create(Object... elements) {
51
    Entry<K, V>[] entries = createArray(elements.length);
52
    System.arraycopy(elements, 0, entries, 0, elements.length);
53
    return createFromEntries(entries);
54
  }
55

56
  public abstract Set<Entry<K, V>> createFromEntries(Entry<K, V>[] entries);
57

58
  @Override
59
  @SuppressWarnings("unchecked") // generic arrays make typesafety sad
60
  public Entry<K, V>[] createArray(int length) {
61
    return (Entry<K, V>[]) new Entry<?, ?>[length];
62
  }
63

64
  /** Returns the original element list, unchanged. */
65
  @Override
66
  public List<Entry<K, V>> order(List<Entry<K, V>> insertionOrder) {
67
    return insertionOrder;
68
  }
69
}
70

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.