A simple and rather inefficient implementation of BinaryRelation which employs a HashSet underneath. @author David J. Pearce @param
| 57 | * @param <T> |
| 58 | */ |
| 59 | public static class HashSet<T> implements BinaryRelation<T> { |
| 60 | private java.util.HashSet<Pair<T, T>> relations; |
| 61 | |
| 62 | public HashSet() { |
| 63 | this.relations = new java.util.HashSet<>(); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public boolean get(T lhs, T rhs) { |
| 68 | return relations.contains(new Pair<>(lhs, rhs)); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void set(T lhs, T rhs, boolean value) { |
| 73 | Pair<T, T> p = new Pair<>(lhs, rhs); |
| 74 | if (value) { |
| 75 | relations.add(p); |
| 76 | } else { |
| 77 | relations.remove(p); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
nothing calls this directly
no outgoing calls
no test coverage detected