You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by ma...@apache.org on 2015/12/16 00:09:15 UTC

reef git commit: [REEF-1074] Merge `parseList` and `parseListCmp` into one generic function

Repository: reef
Updated Branches:
  refs/heads/master f4d19ca40 -> 52518d137


[REEF-1074] Merge `parseList` and `parseListCmp` into one generic function

This also marks `parseListCmp` as deprecated for future removal.

JIRA:
  [REEF-1074](https://issues.apache.org/jira/browse/REEF-1074)

Pull request:
  This closes #727


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

Branch: refs/heads/master
Commit: 52518d1372a3b0a3a5407a38e76c01d44284f06c
Parents: f4d19ca
Author: Dongjoon Hyun <do...@apache.org>
Authored: Sun Dec 13 01:33:02 2015 +0900
Committer: Mariia Mykhailova <ma...@apache.org>
Committed: Tue Dec 15 15:06:56 2015 -0800

----------------------------------------------------------------------
 .../org/apache/reef/io/network/util/Utils.java  | 20 ++++++---
 .../reef/io/network/util/package-info.java      |  2 +-
 .../apache/reef/io/network/util/UtilsTest.java  | 43 ++++++++++++++++++++
 .../reef/io/network/util/package-info.java      |  2 +-
 4 files changed, 59 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/reef/blob/52518d13/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/Utils.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/Utils.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/Utils.java
index e0433a3..a34d92e 100644
--- a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/Utils.java
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/Utils.java
@@ -31,25 +31,33 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
+/**
+ * Utility class for REEF IO network module.
+ */
 public final class Utils {
 
   private static final String DELIMITER = "-";
 
   /**
-   * TODO: Merge with parseListCmp() into one generic implementation.
+   * Parse a string of multiple IDs.
+   *
+   * @param ids A string containing multiple IDs
+   * @param factory An Identifier factory
+   * @param <T> A type
+   * @return A list of identifier
    */
-  public static List<Identifier> parseList(
-      final String ids, final IdentifierFactory factory) {
-    final List<Identifier> result = new ArrayList<>();
+  public static <T extends Identifier> List<T> parseList(final String ids, final IdentifierFactory factory) {
+    final List<T> result = new ArrayList<>();
     for (final String token : ids.split(DELIMITER)) {
-      result.add(factory.getNewInstance(token.trim()));
+      result.add((T) factory.getNewInstance(token.trim()));
     }
     return result;
   }
 
   /**
-   * TODO: Merge with parseList() into one generic implementation.
+   * @deprecated in 0.14. Please use parseList instead.
    */
+  @Deprecated
   public static List<ComparableIdentifier> parseListCmp(
       final String ids, final IdentifierFactory factory) {
     final List<ComparableIdentifier> result = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/reef/blob/52518d13/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/package-info.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/package-info.java
index 819a2df..50c230e 100644
--- a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/package-info.java
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/package-info.java
@@ -17,6 +17,6 @@
  * under the License.
  */
 /**
- * TODO: Document.
+ * Utility for REEF IO network module.
  */
 package org.apache.reef.io.network.util;

http://git-wip-us.apache.org/repos/asf/reef/blob/52518d13/lang/java/reef-io/src/test/java/org/apache/reef/io/network/util/UtilsTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/io/network/util/UtilsTest.java b/lang/java/reef-io/src/test/java/org/apache/reef/io/network/util/UtilsTest.java
new file mode 100644
index 0000000..7a27917
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/io/network/util/UtilsTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.reef.io.network.util;
+
+import org.apache.reef.wake.ComparableIdentifier;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * Tests for REEF IO network utilities.
+ */
+public class UtilsTest {
+
+  /**
+   * Generic parseList test.
+   */
+  @Test
+  public void testParseList() {
+    final IdentifierFactory factory = new StringIdentifierFactory();
+
+    final List<Identifier> list1 = Utils.parseList("1,2,3", factory);
+    final List<ComparableIdentifier> list2 = Utils.parseList("1,2,3", factory);
+  }
+}

http://git-wip-us.apache.org/repos/asf/reef/blob/52518d13/lang/java/reef-io/src/test/java/org/apache/reef/io/network/util/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/io/network/util/package-info.java b/lang/java/reef-io/src/test/java/org/apache/reef/io/network/util/package-info.java
index 819a2df..8270b83 100644
--- a/lang/java/reef-io/src/test/java/org/apache/reef/io/network/util/package-info.java
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/io/network/util/package-info.java
@@ -17,6 +17,6 @@
  * under the License.
  */
 /**
- * TODO: Document.
+ * Tests for REEF IO network utilities.
  */
 package org.apache.reef.io.network.util;