Return-Path: X-Original-To: apmail-accumulo-commits-archive@www.apache.org Delivered-To: apmail-accumulo-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BB0A4106FE for ; Tue, 18 Mar 2014 17:15:33 +0000 (UTC) Received: (qmail 23236 invoked by uid 500); 18 Mar 2014 17:15:32 -0000 Delivered-To: apmail-accumulo-commits-archive@accumulo.apache.org Received: (qmail 22671 invoked by uid 500); 18 Mar 2014 17:15:29 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 22655 invoked by uid 99); 18 Mar 2014 17:15:27 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Mar 2014 17:15:27 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 8CF80947853; Tue, 18 Mar 2014 17:15:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ctubbsii@apache.org To: commits@accumulo.apache.org Message-Id: <7a48ce4c9fb6401c9980512b708da4b4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: ACCUMULO-2490 Slight improvement to fromEntry w/test Date: Tue, 18 Mar 2014 17:15:27 +0000 (UTC) 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 Authored: Tue Mar 18 13:15:02 2014 -0400 Committer: Christopher Tubbs 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 { return new Pair(getSecond(), getFirst()); } - public static Pair fromEntry(Entry entry) { - return new Pair(entry.getKey(), entry.getValue()); + public static Pair fromEntry(Entry entry) { + return new Pair(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 pair = new Pair(25, "twenty-five"); + Pair pair2 = new Pair(25, "twenty-five"); + assertEquals(pair, pair2); + } + + /** + * Test method for {@link org.apache.accumulo.core.util.Pair#getFirst()}. + */ + @Test + public void testGetFirst() { + Pair pair = new Pair(25, "twenty-five"); + assertEquals((Integer) 25, pair.getFirst()); + } + + /** + * Test method for {@link org.apache.accumulo.core.util.Pair#getSecond()}. + */ + @Test + public void testGetSecond() { + Pair pair = new Pair(25, "twenty-five"); + assertEquals("twenty-five", pair.getSecond()); + } + + /** + * Test method for {@link org.apache.accumulo.core.util.Pair#toString()}. + */ + @Test + public void testToString() { + Pair pair = new Pair(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 pair = new Pair(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 pair = new Pair(10, "IO"); + + Entry 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 pair = new Pair(25, "twenty-five"); + assertEquals(pair, pair.swap().swap()); + Pair pair2 = new Pair("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 entry = new SimpleImmutableEntry(10, "IO"); + + Pair pair = Pair.fromEntry(entry); + assertEquals(entry.getKey(), pair.getFirst()); + assertEquals(entry.getValue(), pair.getSecond()); + + Pair pair2 = Pair.fromEntry(entry); + assertEquals(entry.getKey(), pair2.getFirst()); + assertEquals(entry.getValue(), pair2.getSecond()); + } + +}