|
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 |
| package edu.rice.cs.plt.collect; |
|
36 |
| |
|
37 |
| import java.util.Collection; |
|
38 |
| import edu.rice.cs.plt.tuple.Pair; |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| public class ImmutableRelation<T1, T2> extends DelegatingRelation<T1, T2> { |
|
49 |
| |
|
50 |
| private ImmutableRelation<T2, T1> _inverse; |
|
51 |
| |
|
52 |
0
| public ImmutableRelation(Relation<T1, T2> relation) { super(relation); _inverse = null; }
|
|
53 |
| |
|
54 |
0
| private ImmutableRelation(Relation<T1, T2> relation, ImmutableRelation<T2, T1> inverse) {
|
|
55 |
0
| super(relation);
|
|
56 |
0
| _inverse = inverse;
|
|
57 |
| } |
|
58 |
| |
|
59 |
0
| public boolean add(Pair<T1, T2> o) { throw new UnsupportedOperationException(); }
|
|
60 |
0
| public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
|
61 |
0
| public boolean addAll(Collection<? extends Pair<T1, T2>> c) { throw new UnsupportedOperationException(); }
|
|
62 |
0
| public boolean retainAll(Collection<?> c) { throw new UnsupportedOperationException(); }
|
|
63 |
0
| public boolean removeAll(Collection<?> c) { throw new UnsupportedOperationException(); }
|
|
64 |
0
| public void clear() { throw new UnsupportedOperationException(); }
|
|
65 |
| |
|
66 |
0
| public boolean contains(T1 first, T2 second) {
|
|
67 |
0
| return _delegate.contains(first, second);
|
|
68 |
| } |
|
69 |
0
| public boolean add(T1 first, T2 second) { throw new UnsupportedOperationException(); }
|
|
70 |
0
| public boolean remove(T1 first, T2 second) { throw new UnsupportedOperationException(); }
|
|
71 |
| |
|
72 |
0
| public Relation<T2, T1> inverse() {
|
|
73 |
0
| if (_inverse == null) {
|
|
74 |
0
| _inverse = new ImmutableRelation<T2, T1>(_delegate.inverse(), this);
|
|
75 |
| } |
|
76 |
0
| return _inverse;
|
|
77 |
| } |
|
78 |
| |
|
79 |
0
| public PredicateSet<T1> firstSet() {
|
|
80 |
0
| return new ImmutableSet<T1>(_delegate.firstSet());
|
|
81 |
| } |
|
82 |
0
| public boolean containsFirst(T1 first) {
|
|
83 |
0
| return _delegate.containsFirst(first);
|
|
84 |
| } |
|
85 |
0
| public PredicateSet<T2> matchFirst(T1 first) {
|
|
86 |
0
| return new ImmutableSet<T2>(_delegate.matchFirst(first));
|
|
87 |
| } |
|
88 |
0
| public PredicateSet<T2> excludeFirsts() {
|
|
89 |
0
| return new ImmutableSet<T2>(_delegate.excludeFirsts());
|
|
90 |
| } |
|
91 |
| |
|
92 |
0
| public PredicateSet<T2> secondSet() {
|
|
93 |
0
| return new ImmutableSet<T2>(_delegate.secondSet());
|
|
94 |
| } |
|
95 |
0
| public boolean containsSecond(T2 second) {
|
|
96 |
0
| return _delegate.containsSecond(second);
|
|
97 |
| } |
|
98 |
0
| public PredicateSet<T1> matchSecond(T2 second) {
|
|
99 |
0
| return new ImmutableSet<T1>(_delegate.matchSecond(second));
|
|
100 |
| } |
|
101 |
0
| public PredicateSet<T1> excludeSeconds() {
|
|
102 |
0
| return new ImmutableSet<T1>(_delegate.excludeSeconds());
|
|
103 |
| } |
|
104 |
| |
|
105 |
| |
|
106 |
0
| public static <T1, T2> ImmutableRelation<T1, T2> make(Relation<T1, T2> relation) {
|
|
107 |
0
| return new ImmutableRelation<T1, T2>(relation);
|
|
108 |
| } |
|
109 |
| |
|
110 |
| } |