aa
AbstractEntry.java
Go to the documentation of this file.
1 package com.cliffc.aa.util;
2 
3 import java.util.Map;
4 
15 abstract class AbstractEntry<TypeK,TypeV> implements Map.Entry<TypeK,TypeV> {
17  protected final TypeK _key;
19  protected TypeV _val;
20 
21  public AbstractEntry(final TypeK key, final TypeV val) { _key = key; _val = val; }
22  public AbstractEntry(final Map.Entry<TypeK,TypeV> e ) { _key = e.getKey(); _val = e.getValue(); }
24  public String toString() { return _key + "=" + _val; }
26  public TypeK getKey () { return _key; }
28  public TypeV getValue() { return _val; }
29 
31  public boolean equals(final Object o) {
32  if (!(o instanceof Map.Entry)) return false;
33  final Map.Entry e = (Map.Entry)o;
34  return eq(_key, e.getKey()) && eq(_val, e.getValue());
35  }
36 
38  public int hashCode() {
39  return
40  ((_key == null) ? 0 : _key.hashCode()) ^
41  ((_val == null) ? 0 : _val.hashCode());
42  }
43 
44  private static boolean eq(final Object o1, final Object o2) {
45  return (o1 == null ? o2 == null : o1.equals(o2));
46  }
47 }
com.cliffc.aa.util.AbstractEntry.getKey
TypeK getKey()
Return key.
Definition: AbstractEntry.java:26
com.cliffc.aa.util.AbstractEntry.getValue
TypeV getValue()
Return val.
Definition: AbstractEntry.java:28
com.cliffc.aa.util.AbstractEntry.equals
boolean equals(final Object o)
Equal if the underlying key & value are equal.
Definition: AbstractEntry.java:31
com.cliffc.aa.util.AbstractEntry
A simple implementation of java.util.Map.Entry.
Definition: AbstractEntry.java:15
com.cliffc.aa.util.AbstractEntry.hashCode
int hashCode()
Compute "key.hashCode() ^ val.hashCode()"
Definition: AbstractEntry.java:38
com.cliffc.aa.util.AbstractEntry.eq
static boolean eq(final Object o1, final Object o2)
Definition: AbstractEntry.java:44
com.cliffc.aa.util.AbstractEntry.AbstractEntry
AbstractEntry(final Map.Entry< TypeK, TypeV > e)
Definition: AbstractEntry.java:22
com.cliffc.aa.util.AbstractEntry._val
TypeV _val
Strongly typed value.
Definition: AbstractEntry.java:19
com.cliffc.aa.util.AbstractEntry._key
final TypeK _key
Strongly typed key.
Definition: AbstractEntry.java:17
com.cliffc.aa.util.AbstractEntry.AbstractEntry
AbstractEntry(final TypeK key, final TypeV val)
Definition: AbstractEntry.java:21
com.cliffc.aa.util.AbstractEntry.toString
String toString()
Return "key=val" string.
Definition: AbstractEntry.java:24