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 SortedSet implementation that does not implement NavigableSet. Useful for
30  * testing ReverseOrderSortedSetView. Underlying implementation provided by TreeSet.
31  */
32 public class SimpleSortedSet<E> implements SortedSet<E> {
33 
34     final SortedSet<E> set;
35 
SimpleSortedSet()36     public SimpleSortedSet() {
37         set = new TreeSet<E>();
38     }
39 
SimpleSortedSet(Collection<? extends E> c)40     public SimpleSortedSet(Collection<? extends E> c) {
41         set = new TreeSet<>(c);
42     }
43 
SimpleSortedSet(Comparator<? super E> comparator)44     public SimpleSortedSet(Comparator<? super E> comparator) {
45         set = new TreeSet<>(comparator);
46     }
47 
48     // ========== Object ==========
49 
equals(Object o)50     public boolean equals(Object o) {
51         return set.equals(o);
52     }
53 
hashCode()54     public int hashCode() {
55         return set.hashCode();
56     }
57 
toString()58     public String toString() {
59         return set.toString();
60     }
61 
62     // ========== Collection ==========
63 
add(E e)64     public boolean add(E e) {
65         return set.add(e);
66     }
67 
addAll(Collection<? extends E> c)68     public boolean addAll(Collection<? extends E> c) {
69         return set.addAll(c);
70     }
71 
clear()72     public void clear() {
73         set.clear();
74     }
75 
contains(Object o)76     public boolean contains(Object o) {
77         return set.contains(o);
78     }
79 
containsAll(Collection<?> c)80     public boolean containsAll(Collection<?> c) {
81         return set.containsAll(c);
82     }
83 
isEmpty()84     public boolean isEmpty() {
85         return set.isEmpty();
86     }
87 
iterator()88     public Iterator<E> iterator() {
89         return set.iterator();
90     }
91 
remove(Object o)92     public boolean remove(Object o) {
93         return set.remove(o);
94     }
95 
removeAll(Collection<?> c)96     public boolean removeAll(Collection<?> c) {
97         return set.removeAll(c);
98     }
99 
retainAll(Collection<?> c)100     public boolean retainAll(Collection<?> c) {
101         return set.retainAll(c);
102     }
103 
size()104     public int size() {
105         return set.size();
106     }
107 
toArray()108     public Object[] toArray() {
109         return set.toArray();
110     }
111 
toArray(T[] a)112     public <T> T[] toArray(T[] a) {
113         return set.toArray(a);
114     }
115 
116     // ========== SortedSet ==========
117 
comparator()118     public Comparator<? super E> comparator() {
119         return set.comparator();
120     }
121 
first()122     public E first() {
123         return set.first();
124     }
125 
headSet(E toElement)126     public SortedSet<E> headSet(E toElement) {
127         return set.headSet(toElement);
128     }
129 
last()130     public E last() {
131         return set.last();
132     }
133 
subSet(E fromElement, E toElement)134     public SortedSet<E> subSet(E fromElement, E toElement) {
135         return set.subSet(fromElement, toElement);
136     }
137 
tailSet(E fromElement)138     public SortedSet<E> tailSet(E fromElement) {
139         return set.tailSet(fromElement);
140     }
141 }
142