1090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/*
2090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Copyright (C) 2007 Google Inc.
3090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
4090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License");
5090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * you may not use this file except in compliance with the License.
6090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * You may obtain a copy of the License at
7090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
8090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0
9090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
10090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Unless required by applicable law or agreed to in writing, software
11090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS,
12090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * See the License for the specific language governing permissions and
14090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * limitations under the License.
15090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */
16090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
17090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonpackage com.google.common.collect;
18090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
19090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport com.google.common.annotations.GwtCompatible;
20090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport com.google.common.base.Objects;
21090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
22090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport java.util.Map.Entry;
23090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
24090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport javax.annotation.Nullable;
25090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
26090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/**
27090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Implementation of the {@code equals}, {@code hashCode}, and {@code toString}
28090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * methods of {@code Entry}.
29090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson *
30090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @author Jared Levy
31090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */
32090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson@GwtCompatible
33090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonabstract class AbstractMapEntry<K, V> implements Entry<K, V> {
34090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
35090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  public abstract K getKey();
36090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
37090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  public abstract V getValue();
38090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
39090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  public V setValue(V value) {
40090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    throw new UnsupportedOperationException();
41090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
42090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
43090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  @Override public boolean equals(@Nullable Object object) {
44090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    if (object instanceof Entry) {
45090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson      Entry<?, ?> that = (Entry<?, ?>) object;
46090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson      return Objects.equal(this.getKey(), that.getKey())
47090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson          && Objects.equal(this.getValue(), that.getValue());
48090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    }
49090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return false;
50090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
51090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
52090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  @Override public int hashCode() {
53090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    K k = getKey();
54090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    V v = getValue();
55090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return ((k == null) ? 0 : k.hashCode()) ^ ((v == null) ? 0 : v.hashCode());
56090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
57090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson
58090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  /**
59090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   * Returns a string representation of the form <code>{key}={value}</code>.
60090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson   */
61090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  @Override public String toString() {
62090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson    return getKey() + "=" + getValue();
63090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson  }
64090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson}
65