1 /* 2 * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package test.java.util.SequencedCollection; 25 26 import java.util.*; 27 28 /** 29 * A SortedMap implementation that does not implement NavigableMap. Useful for 30 * testing ReverseOrderSortedMapView. Underlying implementation provided by TreeMap. 31 */ 32 public class SimpleSortedMap<K,V> implements SortedMap<K,V> { 33 final SortedMap<K,V> map; 34 SimpleSortedMap()35 public SimpleSortedMap() { 36 map = new TreeMap<>(); 37 } 38 SimpleSortedMap(Comparator<? super K> comparator)39 public SimpleSortedMap(Comparator<? super K> comparator) { 40 map = new TreeMap<>(comparator); 41 } 42 SimpleSortedMap(Map<? extends K,? extends V> m)43 public SimpleSortedMap(Map<? extends K,? extends V> m) { 44 map = new TreeMap<>(m); 45 } 46 47 // ========== Object ========== 48 equals(Object o)49 public boolean equals(Object o) { 50 return map.equals(o); 51 } 52 hashCode()53 public int hashCode() { 54 return map.hashCode(); 55 } 56 toString()57 public String toString() { 58 return map.toString(); 59 } 60 61 // ========== Map ========== 62 clear()63 public void clear() { 64 map.clear(); 65 } 66 containsKey(Object key)67 public boolean containsKey(Object key) { 68 return map.containsKey(key); 69 } 70 containsValue(Object value)71 public boolean containsValue(Object value) { 72 return map.containsValue(value); 73 } 74 entrySet()75 public Set<Map.Entry<K,V>> entrySet() { 76 return map.entrySet(); 77 } 78 get(Object key)79 public V get(Object key) { 80 return map.get(key); 81 } 82 isEmpty()83 public boolean isEmpty() { 84 return map.isEmpty(); 85 } 86 keySet()87 public Set<K> keySet() { 88 return map.keySet(); 89 } 90 put(K key, V value)91 public V put(K key, V value) { 92 return map.put(key, value); 93 } 94 putAll(Map<? extends K,? extends V> m)95 public void putAll(Map<? extends K,? extends V> m) { 96 map.putAll(m); 97 } 98 remove(Object key)99 public V remove(Object key) { 100 return map.remove(key); 101 } 102 size()103 public int size() { 104 return map.size(); 105 } 106 values()107 public Collection<V> values() { 108 return map.values(); 109 } 110 111 // ========== SortedMap ========== 112 comparator()113 public Comparator<? super K> comparator() { 114 return map.comparator(); 115 } 116 firstKey()117 public K firstKey() { 118 return map.firstKey(); 119 } 120 headMap(K toKey)121 public SortedMap<K,V> headMap(K toKey) { 122 return map.headMap(toKey); 123 } 124 lastKey()125 public K lastKey() { 126 return map.lastKey(); 127 } 128 subMap(K fromKey, K toKey)129 public SortedMap<K,V> subMap(K fromKey, K toKey) { 130 return map.subMap(fromKey, toKey); 131 } 132 tailMap(K fromKey)133 public SortedMap<K,V> tailMap(K fromKey) { 134 return map.tailMap(fromKey); 135 } 136 } 137