meaningless comment
[ephemerata.git] / KezvhLib / src-lib / net / kezvh / collections / views / MapAsView.java
blobe11ca6214730cad21d6f3667d4cc6f84f25a5f43
1 /**
3 */
4 package net.kezvh.collections.views;
6 import java.util.AbstractMap;
7 import java.util.Map;
8 import java.util.Set;
10 import net.kezvh.collections.MapEntryImpl;
11 import net.kezvh.functional.Operations;
12 import net.kezvh.functional.lambda.L1;
14 /**
15 * @author afflux
16 * @param <S> COMMENT
17 * @param <D> COMMENT
19 public class MapAsView<S, D> extends AbstractMap<S, D> {
21 private final Set<S> sourceSet;
22 private final L1<D, S> mapOp;
23 private final L1<S, D> inverseMapOp;
25 private final L1<Entry<S, D>, S> entryOp = new L1<Entry<S, D>, S>() {
26 /**
27 * @see net.kezvh.functional.lambda.L1#op(java.lang.Object)
28 * @param param COMMENT
29 * @return COMMENT
31 @Override
32 public Map.Entry<S, D> op(final S param) {
33 return new MapEntryImpl<S, D>(param, MapAsView.this.mapOp.op(param));
36 private final L1<S, Entry<S, D>> inverseEntryOp = new L1<S, Entry<S, D>>() {
37 /**
38 * @see net.kezvh.functional.lambda.L1#op(java.lang.Object)
39 * @param param COMMENT
40 * @return COMMENT
42 @Override
43 public S op(final Map.Entry<S, D> param) {
44 return param.getKey();
47 private final Set<Entry<S, D>> entrySet;
49 /**
50 * @param sourceSet COMMENT
51 * @param op COMMENT
52 * @param inverseOp COMMENT
54 public MapAsView(final Set<S> sourceSet, final L1<D, S> op, final L1<S, D> inverseOp) {
55 super();
56 this.sourceSet = sourceSet;
57 this.mapOp = op;
58 this.inverseMapOp = inverseOp;
59 this.entrySet = new SetView<S, Map.Entry<S, D>>(this.sourceSet, this.entryOp, this.inverseEntryOp);
62 /**
63 * @param sourceSet COMMENT
64 * @param op COMMENT
66 @SuppressWarnings("unchecked")
67 public MapAsView(final Set<S> sourceSet, final L1<D, S> op) {
68 this(sourceSet, op, (L1<S, D>) Operations.UNSUPPORTED);
71 /**
72 * @see java.util.AbstractMap#entrySet()
73 * @return COMMENT
75 @Override
76 public Set<Map.Entry<S, D>> entrySet() {
77 return this.entrySet;
80 @SuppressWarnings("unchecked")
81 @Override
82 public D get(final Object key) {
83 return this.mapOp.op((S) key);
86 @SuppressWarnings("unchecked")
87 @Override
88 public boolean containsValue(final Object value) {
89 if (Operations.UNSUPPORTED.equals(this.inverseEntryOp))
90 return super.containsValue(value);
92 return this.sourceSet.contains(this.inverseMapOp.op((D) value));
95 @Override
96 public boolean containsKey(final Object key) {
97 return this.sourceSet.contains(key);
100 @Override
101 public int hashCode() {
102 final int prime = 31;
103 int result = super.hashCode();
104 result = prime * result + ((this.inverseMapOp == null) ? 0 : this.inverseMapOp.hashCode());
105 result = prime * result + ((this.mapOp == null) ? 0 : this.mapOp.hashCode());
106 result = prime * result + ((this.sourceSet == null) ? 0 : this.sourceSet.hashCode());
107 return result;
110 @Override
111 public boolean equals(final Object obj) {
112 if (this == obj)
113 return true;
114 if (!super.equals(obj))
115 return false;
116 if (this.getClass() != obj.getClass())
117 return false;
118 final MapAsView<?, ?> other = (MapAsView<?, ?>) obj;
119 if (this.inverseMapOp == null) {
120 if (other.inverseMapOp != null)
121 return false;
122 } else if (!this.inverseMapOp.equals(other.inverseMapOp))
123 return false;
124 if (this.mapOp == null) {
125 if (other.mapOp != null)
126 return false;
127 } else if (!this.mapOp.equals(other.mapOp))
128 return false;
129 if (this.sourceSet == null) {
130 if (other.sourceSet != null)
131 return false;
132 } else if (!this.sourceSet.equals(other.sourceSet))
133 return false;
134 return true;