Repository: accumulo
Updated Branches:
  refs/heads/master 05e2b12a8 -> beb494478


ACCUMULO-2490 Slight improvement to fromEntry w/test


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/beb49447
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/beb49447
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/beb49447

Branch: refs/heads/master
Commit: beb494478f64ad6ec02f975edc8fb680bf012d8e
Parents: 05e2b12
Author: Christopher Tubbs <ctubb...@apache.org>
Authored: Tue Mar 18 13:15:02 2014 -0400
Committer: Christopher Tubbs <ctubb...@apache.org>
Committed: Tue Mar 18 13:15:02 2014 -0400

----------------------------------------------------------------------
 .../org/apache/accumulo/core/util/Pair.java     |   4 +-
 .../org/apache/accumulo/core/util/PairTest.java | 114 +++++++++++++++++++
 2 files changed, 116 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/beb49447/core/src/main/java/org/apache/accumulo/core/util/Pair.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/Pair.java 
b/core/src/main/java/org/apache/accumulo/core/util/Pair.java
index 00eab0e..293d126 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/Pair.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/Pair.java
@@ -80,8 +80,8 @@ public class Pair<A,B> {
     return new Pair<B,A>(getSecond(), getFirst());
   }
 
-  public static <K,V> Pair<K,V> fromEntry(Entry<K,V> entry) {
-    return new Pair<K,V>(entry.getKey(), entry.getValue());
+  public static <K2,V2,K1 extends K2,V1 extends V2> Pair<K2,V2> 
fromEntry(Entry<K1,V1> entry) {
+    return new Pair<K2,V2>(entry.getKey(), entry.getValue());
   }
 
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/beb49447/core/src/test/java/org/apache/accumulo/core/util/PairTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/PairTest.java 
b/core/src/test/java/org/apache/accumulo/core/util/PairTest.java
new file mode 100644
index 0000000..04af1ba
--- /dev/null
+++ b/core/src/test/java/org/apache/accumulo/core/util/PairTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.AbstractMap.SimpleImmutableEntry;
+import java.util.Map.Entry;
+
+import org.junit.Test;
+
+public class PairTest {
+
+  /**
+   * Test method for {@link 
org.apache.accumulo.core.util.Pair#equals(java.lang.Object)}.
+   */
+  @Test
+  public void testEqualsObject() {
+    Pair<Integer,String> pair = new Pair<Integer,String>(25, "twenty-five");
+    Pair<Integer,String> pair2 = new Pair<Integer,String>(25, "twenty-five");
+    assertEquals(pair, pair2);
+  }
+
+  /**
+   * Test method for {@link org.apache.accumulo.core.util.Pair#getFirst()}.
+   */
+  @Test
+  public void testGetFirst() {
+    Pair<Integer,String> pair = new Pair<Integer,String>(25, "twenty-five");
+    assertEquals((Integer) 25, pair.getFirst());
+  }
+
+  /**
+   * Test method for {@link org.apache.accumulo.core.util.Pair#getSecond()}.
+   */
+  @Test
+  public void testGetSecond() {
+    Pair<Integer,String> pair = new Pair<Integer,String>(25, "twenty-five");
+    assertEquals("twenty-five", pair.getSecond());
+  }
+
+  /**
+   * Test method for {@link org.apache.accumulo.core.util.Pair#toString()}.
+   */
+  @Test
+  public void testToString() {
+    Pair<Integer,String> pair = new Pair<Integer,String>(25, "twenty-five");
+    assertEquals("(25,twenty-five)", pair.toString());
+  }
+
+  /**
+   * Test method for {@link 
org.apache.accumulo.core.util.Pair#toString(java.lang.String, java.lang.String, 
java.lang.String)}.
+   */
+  @Test
+  public void testToStringStringStringString() {
+    Pair<Integer,String> pair = new Pair<Integer,String>(25, "twenty-five");
+    assertEquals("---25~~~twenty-five+++", pair.toString("---", "~~~", "+++"));
+  }
+
+  /**
+   * Test method for {@link org.apache.accumulo.core.util.Pair#toMapEntry()}.
+   */
+  @Test
+  public void testToMapEntry() {
+    Pair<Integer,String> pair = new Pair<Integer,String>(10, "IO");
+
+    Entry<Integer,String> entry = pair.toMapEntry();
+    assertEquals(pair.getFirst(), entry.getKey());
+    assertEquals(pair.getSecond(), entry.getValue());
+  }
+
+  /**
+   * Test method for {@link org.apache.accumulo.core.util.Pair#swap()}.
+   */
+  @Test
+  public void testSwap() {
+    Pair<Integer,String> pair = new Pair<Integer,String>(25, "twenty-five");
+    assertEquals(pair, pair.swap().swap());
+    Pair<String,Integer> pair2 = new Pair<String,Integer>("twenty-five", 25);
+    assertEquals(pair, pair2.swap());
+    assertEquals(pair2, pair.swap());
+  }
+
+  /**
+   * Test method for {@link 
org.apache.accumulo.core.util.Pair#fromEntry(java.util.Map.Entry)}.
+   */
+  @Test
+  public void testFromEntry() {
+    Entry<Integer,String> entry = new SimpleImmutableEntry<Integer,String>(10, 
"IO");
+
+    Pair<Object,Object> pair = Pair.fromEntry(entry);
+    assertEquals(entry.getKey(), pair.getFirst());
+    assertEquals(entry.getValue(), pair.getSecond());
+
+    Pair<Number,CharSequence> pair2 = Pair.fromEntry(entry);
+    assertEquals(entry.getKey(), pair2.getFirst());
+    assertEquals(entry.getValue(), pair2.getSecond());
+  }
+
+}

Reply via email to