File tree Expand file tree Collapse file tree
koans-tests/test/com/sandwich/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .sandwich .util ;
2+
3+ import java .util .Map .Entry ;
4+
5+ /**
6+ * Why on earth this wasn't around when JDK5 was released is just as bad as
7+ * string.isEmpty()'s absence jeesh!
8+ *
9+ * @param <K>
10+ * @param <V>
11+ */
12+ public class SimpleEntry <K ,V > implements Entry <K ,V >{
13+
14+ private K k ;
15+ private V v ;
16+
17+ public SimpleEntry (K k , V v ){
18+ this .k = k ;
19+ this .v = v ;
20+ }
21+
22+ public K getKey () {
23+ return k ;
24+ }
25+
26+ public V getValue () {
27+ return v ;
28+ }
29+
30+ public V setValue (V value ) {
31+ V tmp = v ;
32+ v = value ;
33+ return tmp ;
34+ }
35+
36+ @ Override
37+ public int hashCode () {
38+ final int prime = 31 ;
39+ int result = 1 ;
40+ result = prime * result + ((k == null ) ? 0 : k .hashCode ());
41+ result = prime * result + ((v == null ) ? 0 : v .hashCode ());
42+ return result ;
43+ }
44+
45+ @ Override
46+ public boolean equals (Object obj ) {
47+ if (this == obj )
48+ return true ;
49+ if (obj == null )
50+ return false ;
51+ if (!Entry .class .isAssignableFrom (SimpleEntry .class )){
52+ return false ;
53+ }
54+ Entry <?,?> other = (Entry <?,?>) obj ;
55+ if (k == null ) {
56+ if (other .getKey () != null )
57+ return false ;
58+ } else if (!k .equals (other .getKey ()))
59+ return false ;
60+ if (v == null ) {
61+ if (other .getValue () != null )
62+ return false ;
63+ } else if (!v .equals (other .getValue ()))
64+ return false ;
65+ return true ;
66+ }
67+
68+ }
You can’t perform that action at this time.
0 commit comments