1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package Torello.Java.ReadOnly;

import Torello.Java.Additional.RemoveUnsupportedIterator;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.HashSet;
import java.util.TreeSet;

class JavaHTMLReadOnlySet<E> implements ReadOnlySet<E>
{
    private final Set<E> s;

    JavaHTMLReadOnlySet(Set<E> s) { this.s = s; }

    public int      size()                          { return s.size(); }
    public boolean  isEmpty()                       { return s.isEmpty(); }
    public boolean  contains(Object o)              { return s.contains(o); }

    public Object[] toArray()                       { return s.toArray(); }
    public <X> X[]  toArray(X[] a)                  { return s.toArray(a); }
    public boolean  containsAll(Collection<?> c)    { return s.containsAll(c); }

    public RemoveUnsupportedIterator<E> iterator()
    { return new RemoveUnsupportedIterator<>(s.iterator()); }


    // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    // To Java-Collections Types
    // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

    @SuppressWarnings("unchecked")
    public Set<E> cloneToSet()
    {
        if (s instanceof HashSet) return (Set<E>) ((HashSet<E>) s).clone();
        if (s instanceof TreeSet) return (Set<E>) ((TreeSet<E>) s).clone();
        return new HashSet<>(s);
    }

    public Set<E> wrapToImmutableSet()
    { return Collections.unmodifiableSet(s); }


    // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    // java.lang.Object
    // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

    public boolean equals(Object other)
    { return ROHelperEquals.roSetEq(this, other); }

    public int hashCode()
    { return s.hashCode(); }

    public String toString()
    { return s.toString(); }
}