MCPcopy
hub / github.com/dianping/cat / Pair

Class Pair

lib/java/src/main/java/com/dianping/cat/util/Pair.java:21–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19package com.dianping.cat.util;
20
21public class Pair<K, V> implements Tuple {
22 private volatile K key;
23 private volatile V value;
24
25 public Pair(K key, V value) {
26 this.key = key;
27 this.value = value;
28 }
29
30 public static <K, V> Pair<K, V> from(K key, V value) {
31 return new Pair<K, V>(key, value);
32 }
33
34 @Override
35 @SuppressWarnings("unchecked")
36 public boolean equals(Object obj) {
37 if (this == obj) {
38 return true;
39 }
40
41 if (obj instanceof Pair) {
42 Pair<Object, Object> o = (Pair<Object, Object>) obj;
43
44 if (key == null) {
45 if (o.key != null) {
46 return false;
47 }
48 } else if (!key.equals(o.key)) {
49 return false;
50 }
51
52 if (value == null) {
53 if (o.value != null) {
54 return false;
55 }
56 } else if (!value.equals(o.value)) {
57 return false;
58 }
59
60 return true;
61 }
62
63 return false;
64 }
65
66 @Override
67 @SuppressWarnings("unchecked")
68 public <T> T get(int index) {
69 switch (index) {
70 case 0:
71 return (T) key;
72 case 1:
73 return (T) value;
74 default:
75 throw new IndexOutOfBoundsException(String.format("Index from 0 to %s, but was %s!", size(), index));
76 }
77 }
78

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected