mnemonic-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject incubator-mnemonic git commit: MNEMONIC-186: Add convenient funtions to shift durable parameters
Date Thu, 26 Jan 2017 23:28:50 GMT
Repository: incubator-mnemonic
Updated Branches:
  refs/heads/0.5.0-dev b2d186022 -> 59051d41a


MNEMONIC-186: Add convenient funtions to shift durable parameters


Project: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/commit/59051d41
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/tree/59051d41
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/diff/59051d41

Branch: refs/heads/0.5.0-dev
Commit: 59051d41a7e9ae4468a3bfc63fee151934363d7c
Parents: b2d1860
Author: Wang, Gang(Gary) <gang1.wang@intel.com>
Authored: Thu Jan 26 14:56:20 2017 -0800
Committer: Wang, Gang(Gary) <gang1.wang@intel.com>
Committed: Thu Jan 26 15:25:06 2017 -0800

----------------------------------------------------------------------
 .../DurableSinglyLinkedListNGTest.java          | 24 ++++-------------
 .../DurableSinglyLinkedListNGPrintTest.java     | 24 ++++-------------
 .../DurableSinglyLinkedListNGSortTest.java      | 24 ++++-------------
 .../main/java/org/apache/mnemonic/Utils.java    | 28 ++++++++++++++++++++
 4 files changed, 43 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/59051d41/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableSinglyLinkedListNGTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableSinglyLinkedListNGTest.java
b/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableSinglyLinkedListNGTest.java
index 09e00d7..2be362b 100644
--- a/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableSinglyLinkedListNGTest.java
+++ b/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableSinglyLinkedListNGTest.java
@@ -19,13 +19,13 @@ package org.apache.mnemonic.collections;
 
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Random;
 
 import org.apache.mnemonic.NonVolatileMemAllocator;
 import org.apache.mnemonic.RestorableAllocator;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.mnemonic.Durable;
 import org.apache.mnemonic.EntityFactoryProxy;
 import org.apache.mnemonic.Reclaim;
@@ -220,29 +220,15 @@ public class DurableSinglyLinkedListNGTest {
       @Override
       public <A extends RestorableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
           DurableType[] gfields, long phandler, boolean autoreclaim) {
-        EntityFactoryProxy[] val_efproxies = null;
-        DurableType[] val_gftypes = null;
-        if (null != factoryproxys && factoryproxys.length >= 2) {
-          val_efproxies = Arrays.copyOfRange(factoryproxys, 1, factoryproxys.length);
-        }
-        if (null != gfields && gfields.length >= 2) {
-          val_gftypes = Arrays.copyOfRange(gfields, 1, gfields.length);
-        }
-        return DurableSinglyLinkedListFactory.restore(allocator, val_efproxies, val_gftypes,
phandler, autoreclaim);
+        Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields,
factoryproxys, 1);
+        return DurableSinglyLinkedListFactory.restore(allocator, dpt.getRight(), dpt.getLeft(),
phandler, autoreclaim);
       }
       @Override
       public <A extends RestorableAllocator<A>> Durable create(
           A allocator, EntityFactoryProxy[] factoryproxys,
           DurableType[] gfields, boolean autoreclaim) {
-        EntityFactoryProxy[] val_efproxies = null;
-        DurableType[] val_gftypes = null;
-        if (null != factoryproxys && factoryproxys.length >= 2) {
-          val_efproxies = Arrays.copyOfRange(factoryproxys, 1, factoryproxys.length);
-        }
-        if (null != gfields && gfields.length >= 2) {
-          val_gftypes = Arrays.copyOfRange(gfields, 1, gfields.length);
-        }
-        return DurableSinglyLinkedListFactory.create(allocator, val_efproxies, val_gftypes,
autoreclaim);
+        Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields,
factoryproxys, 1);
+        return DurableSinglyLinkedListFactory.create(allocator, dpt.getRight(), dpt.getLeft(),
autoreclaim);
       }
     } };
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/59051d41/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGPrintTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGPrintTest.java
b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGPrintTest.java
index b64bfe2..67176f1 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGPrintTest.java
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGPrintTest.java
@@ -19,12 +19,12 @@ package org.apache.mnemonic.service.computingservice;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Random;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.mnemonic.NonVolatileMemAllocator;
 import org.apache.mnemonic.RestorableAllocator;
 import org.apache.mnemonic.Durable;
@@ -162,28 +162,14 @@ public class DurableSinglyLinkedListNGPrintTest {
       @Override
       public <A extends RestorableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
           DurableType[] gfields, long phandler, boolean autoreclaim) {
-        EntityFactoryProxy[] val_efproxies = null;
-        DurableType[] val_gftypes = null;
-        if (null != factoryproxys && factoryproxys.length >= 2) {
-          val_efproxies = Arrays.copyOfRange(factoryproxys, 1, factoryproxys.length);
-        }
-        if (null != gfields && gfields.length >= 2) {
-          val_gftypes = Arrays.copyOfRange(gfields, 1, gfields.length);
-        }
-        return DurableSinglyLinkedListFactory.restore(allocator, val_efproxies, val_gftypes,
phandler, autoreclaim);
+        Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields,
factoryproxys, 1);
+        return DurableSinglyLinkedListFactory.restore(allocator, dpt.getRight(), dpt.getLeft(),
phandler, autoreclaim);
       }
       @Override
       public <A extends RestorableAllocator<A>> Durable create(A allocator, EntityFactoryProxy[]
factoryproxys,
           DurableType[] gfields, boolean autoreclaim) {
-        EntityFactoryProxy[] val_efproxies = null;
-        DurableType[] val_gftypes = null;
-        if (null != factoryproxys && factoryproxys.length >= 2) {
-          val_efproxies = Arrays.copyOfRange(factoryproxys, 1, factoryproxys.length);
-        }
-        if (null != gfields && gfields.length >= 2) {
-          val_gftypes = Arrays.copyOfRange(gfields, 1, gfields.length);
-        }
-        return DurableSinglyLinkedListFactory.create(allocator, val_efproxies, val_gftypes,
autoreclaim);
+        Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields,
factoryproxys, 1);
+        return DurableSinglyLinkedListFactory.create(allocator, dpt.getRight(), dpt.getLeft(),
autoreclaim);
       }
     } };
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/59051d41/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGSortTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGSortTest.java
b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGSortTest.java
index 9389d74..ff10bae 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGSortTest.java
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGSortTest.java
@@ -19,12 +19,12 @@ package org.apache.mnemonic.service.computingservice;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Random;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.mnemonic.NonVolatileMemAllocator;
 import org.apache.mnemonic.RestorableAllocator;
 import org.apache.mnemonic.Durable;
@@ -187,28 +187,14 @@ public class DurableSinglyLinkedListNGSortTest {
       @Override
       public <A extends RestorableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
           DurableType[] gfields, long phandler, boolean autoreclaim) {
-        EntityFactoryProxy[] val_efproxies = null;
-        DurableType[] val_gftypes = null;
-        if (null != factoryproxys && factoryproxys.length >= 2) {
-          val_efproxies = Arrays.copyOfRange(factoryproxys, 1, factoryproxys.length);
-        }
-        if (null != gfields && gfields.length >= 2) {
-          val_gftypes = Arrays.copyOfRange(gfields, 1, gfields.length);
-        }
-        return DurableSinglyLinkedListFactory.restore(allocator, val_efproxies, val_gftypes,
phandler, autoreclaim);
+        Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields,
factoryproxys, 1);
+        return DurableSinglyLinkedListFactory.restore(allocator, dpt.getRight(), dpt.getLeft(),
phandler, autoreclaim);
       }
       @Override
       public <A extends RestorableAllocator<A>> Durable create(A allocator, EntityFactoryProxy[]
factoryproxys,
           DurableType[] gfields, boolean autoreclaim) {
-        EntityFactoryProxy[] val_efproxies = null;
-        DurableType[] val_gftypes = null;
-        if (null != factoryproxys && factoryproxys.length >= 2) {
-          val_efproxies = Arrays.copyOfRange(factoryproxys, 1, factoryproxys.length);
-        }
-        if (null != gfields && gfields.length >= 2) {
-          val_gftypes = Arrays.copyOfRange(gfields, 1, gfields.length);
-        }
-        return DurableSinglyLinkedListFactory.create(allocator, val_efproxies, val_gftypes,
autoreclaim);
+        Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields,
factoryproxys, 1);
+        return DurableSinglyLinkedListFactory.create(allocator, dpt.getRight(), dpt.getLeft(),
autoreclaim);
       }
     } };
 

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/59051d41/mnemonic-core/src/main/java/org/apache/mnemonic/Utils.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/Utils.java b/mnemonic-core/src/main/java/org/apache/mnemonic/Utils.java
index c448138..faadec4 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/Utils.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/Utils.java
@@ -31,6 +31,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.ServiceLoader;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Pair;
 import org.apache.mnemonic.service.memoryservice.VolatileMemoryAllocatorService;
 import org.apache.mnemonic.service.computingservice.GeneralComputingService;
 import org.apache.mnemonic.service.memoryservice.NonVolatileMemoryAllocatorService;
@@ -496,4 +497,31 @@ public class Utils {
     }
     return ret.toArray(new EntityFactoryProxy[0]);
   }
+
+  /**
+   * shift durable parameters.
+   *
+   * @param gtypes
+   *          an array of entity generic types
+   *
+   * @param factoryproxies
+   *          an array of entity factory proxies
+   *
+   * @param len
+   *          the length to shift from start
+   *
+   * @return the pair of shifted parameters.
+   */
+  public static Pair<DurableType[], EntityFactoryProxy[]> shiftDurableParams(
+      DurableType[] gtypes, EntityFactoryProxy[] factoryproxies, int len) {
+    DurableType[] ret_gtypes = {};
+    EntityFactoryProxy[] ret_proxies = {};
+    if (null != gtypes && gtypes.length > len) {
+      ret_gtypes = Arrays.copyOfRange(gtypes, len, gtypes.length);
+    }
+    if (null != factoryproxies && factoryproxies.length > len) {
+      ret_proxies = Arrays.copyOfRange(factoryproxies, len, factoryproxies.length);
+    }
+    return Pair.of(ret_gtypes, ret_proxies);
+  }
 }


Mime
View raw message