changeset 781:fbbdd369a13a

rename DeepCloner to LuanCloner
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 29 Aug 2016 22:49:32 -0600
parents 6a87d51ae0ed
children 655280eab1e2
files src/luan/DeepCloneable.java src/luan/DeepCloner.java src/luan/LuanCloneable.java src/luan/LuanCloner.java src/luan/LuanException.java src/luan/LuanJava.java src/luan/LuanState.java src/luan/LuanTable.java src/luan/impl/Closure.java src/luan/impl/Pointer.java src/luan/modules/ThreadLuan.java src/luan/modules/http/HttpServicer.java src/luan/modules/http/LuanHandler.java
diffstat 13 files changed, 91 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/DeepCloneable.java	Mon Aug 29 21:47:19 2016 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-package luan;
-
-
-public interface DeepCloneable {
-	public DeepCloneable shallowClone();
-	public void deepenClone(DeepCloneable clone,DeepCloner cloner);
-}
--- a/src/luan/DeepCloner.java	Mon Aug 29 21:47:19 2016 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-package luan;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-
-
-public final class DeepCloner {
-	private final Map cloned = new IdentityHashMap();
-
-	public DeepCloneable deepClone(DeepCloneable obj) {
-		if( obj==null )
-			return null;
-		DeepCloneable rtn = (DeepCloneable)cloned.get(obj);
-		if( rtn == null ) {
-			rtn = obj.shallowClone();
-			cloned.put(obj,rtn);
-			obj.deepenClone(rtn,this);
-		}
-		return rtn;
-	}
-
-	public Object[] deepClone(Object[] obj) {
-		if( obj.length == 0 )
-			return obj;
-		Object[] rtn = (Object[])cloned.get(obj);
-		if( rtn == null ) {
-			rtn = obj.clone();
-			cloned.put(obj,rtn);
-			for( int i=0; i<rtn.length; i++ ) {
-				rtn[i] = get(rtn[i]);
-			}
-		}
-		return rtn;
-	}
-
-	public Map deepClone(Map obj) {
-		if( !obj.getClass().equals(HashMap.class) )
-			throw new RuntimeException("can only clone HashMap");
-		Map rtn = (Map)cloned.get(obj);
-		if( rtn == null ) {
-			rtn = new HashMap();
-			for( Object stupid : obj.entrySet() ) {
-				Map.Entry entry = (Map.Entry)stupid;
-				rtn.put( get(entry.getKey()), get(entry.getValue()) );
-			}
-		}
-		return rtn;
-	}
-
-	public Object get(Object obj) {
-		if( obj instanceof DeepCloneable )
-			return deepClone((DeepCloneable)obj);
-		if( obj instanceof Object[] )
-			return deepClone((Object[])obj);
-		if( obj instanceof Map )
-			return deepClone((Map)obj);
-		return obj;
-	}
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/LuanCloneable.java	Mon Aug 29 22:49:32 2016 -0600
@@ -0,0 +1,7 @@
+package luan;
+
+
+public interface LuanCloneable {
+	public LuanCloneable shallowClone();
+	public void deepenClone(LuanCloneable clone,LuanCloner cloner);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/LuanCloner.java	Mon Aug 29 22:49:32 2016 -0600
@@ -0,0 +1,60 @@
+package luan;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+
+
+public final class LuanCloner {
+	private final Map cloned = new IdentityHashMap();
+
+	public LuanCloneable deepClone(LuanCloneable obj) {
+		if( obj==null )
+			return null;
+		LuanCloneable rtn = (LuanCloneable)cloned.get(obj);
+		if( rtn == null ) {
+			rtn = obj.shallowClone();
+			cloned.put(obj,rtn);
+			obj.deepenClone(rtn,this);
+		}
+		return rtn;
+	}
+
+	public Object[] deepClone(Object[] obj) {
+		if( obj.length == 0 )
+			return obj;
+		Object[] rtn = (Object[])cloned.get(obj);
+		if( rtn == null ) {
+			rtn = obj.clone();
+			cloned.put(obj,rtn);
+			for( int i=0; i<rtn.length; i++ ) {
+				rtn[i] = get(rtn[i]);
+			}
+		}
+		return rtn;
+	}
+
+	public Map deepClone(Map obj) {
+		if( !obj.getClass().equals(HashMap.class) )
+			throw new RuntimeException("can only clone HashMap");
+		Map rtn = (Map)cloned.get(obj);
+		if( rtn == null ) {
+			rtn = new HashMap();
+			for( Object stupid : obj.entrySet() ) {
+				Map.Entry entry = (Map.Entry)stupid;
+				rtn.put( get(entry.getKey()), get(entry.getValue()) );
+			}
+		}
+		return rtn;
+	}
+
+	public Object get(Object obj) {
+		if( obj instanceof LuanCloneable )
+			return deepClone((LuanCloneable)obj);
+		if( obj instanceof Object[] )
+			return deepClone((Object[])obj);
+		if( obj instanceof Map )
+			return deepClone((Map)obj);
+		return obj;
+	}
+}
--- a/src/luan/LuanException.java	Mon Aug 29 21:47:19 2016 -0600
+++ b/src/luan/LuanException.java	Mon Aug 29 22:49:32 2016 -0600
@@ -6,7 +6,7 @@
 import java.util.ArrayList;
 
 
-public final class LuanException extends Exception implements DeepCloneable {
+public final class LuanException extends Exception implements LuanCloneable {
 	private LuanTable table;
 
 	public LuanException(String msg,Throwable cause) {
@@ -32,7 +32,7 @@
 		return new LuanException(getMessage(),getCause(),99);
 	}
 
-	@Override public void deepenClone(DeepCloneable dc,DeepCloner cloner) {
+	@Override public void deepenClone(LuanCloneable dc,LuanCloner cloner) {
 		LuanException clone = (LuanException)dc;
 		clone.table = (LuanTable)cloner.get(table);
 	}
--- a/src/luan/LuanJava.java	Mon Aug 29 21:47:19 2016 -0600
+++ b/src/luan/LuanJava.java	Mon Aug 29 22:49:32 2016 -0600
@@ -1,10 +1,7 @@
 package luan;
 
-import luan.DeepCloneable;
-import luan.DeepCloner;
 
-
-public final class LuanJava implements DeepCloneable {
+public final class LuanJava implements LuanCloneable {
 	public boolean ok = false;
 
 	@Override public LuanJava shallowClone() {
@@ -13,5 +10,5 @@
 		return java;
 	}
 
-	@Override public void deepenClone(DeepCloneable clone,DeepCloner cloner) {}
+	@Override public void deepenClone(LuanCloneable clone,LuanCloner cloner) {}
 }
--- a/src/luan/LuanState.java	Mon Aug 29 21:47:19 2016 -0600
+++ b/src/luan/LuanState.java	Mon Aug 29 22:49:32 2016 -0600
@@ -13,7 +13,7 @@
 import luan.modules.JavaLuan;
 
 
-public final class LuanState implements DeepCloneable {
+public final class LuanState implements LuanCloneable {
 
 	public LuanJava java;
 	private Map registry;
@@ -30,7 +30,7 @@
 		return new LuanState(this);
 	}
 
-	@Override public void deepenClone(DeepCloneable dc,DeepCloner cloner) {
+	@Override public void deepenClone(LuanCloneable dc,LuanCloner cloner) {
 		LuanState clone = (LuanState)dc;
 		clone.registry = cloner.deepClone(registry);
 		clone.java = (LuanJava)cloner.deepClone(java);
--- a/src/luan/LuanTable.java	Mon Aug 29 21:47:19 2016 -0600
+++ b/src/luan/LuanTable.java	Mon Aug 29 22:49:32 2016 -0600
@@ -13,7 +13,7 @@
 import java.util.HashSet;
 
 
-public final class LuanTable implements DeepCloneable {
+public final class LuanTable implements LuanCloneable {
 	private Map map = null;
 	private List list = null;
 	private LuanTable metatable = null;
@@ -59,7 +59,7 @@
 		return new LuanTable();
 	}
 
-	@Override public void deepenClone(DeepCloneable dc,DeepCloner cloner) {
+	@Override public void deepenClone(LuanCloneable dc,LuanCloner cloner) {
 		LuanTable clone = (LuanTable)dc;
 		if( map != null ) {
 			clone.map = newMap();
--- a/src/luan/impl/Closure.java	Mon Aug 29 21:47:19 2016 -0600
+++ b/src/luan/impl/Closure.java	Mon Aug 29 22:49:32 2016 -0600
@@ -4,12 +4,12 @@
 import luan.LuanFunction;
 import luan.LuanState;
 import luan.LuanException;
-import luan.DeepCloner;
-import luan.DeepCloneable;
+import luan.LuanCloner;
+import luan.LuanCloneable;
 import luan.LuanJava;
 
 
-public abstract class Closure extends LuanFunction implements DeepCloneable, Cloneable {
+public abstract class Closure extends LuanFunction implements LuanCloneable, Cloneable {
 	public Pointer[] upValues;
 	public LuanJava java;
 
@@ -26,7 +26,7 @@
 		}
 	}
 
-	@Override public void deepenClone(DeepCloneable dc,DeepCloner cloner) {
+	@Override public void deepenClone(LuanCloneable dc,LuanCloner cloner) {
 		Closure clone = (Closure)dc;
 		clone.upValues = (Pointer[])cloner.deepClone(upValues);
 		clone.java = (LuanJava)cloner.deepClone(java);
--- a/src/luan/impl/Pointer.java	Mon Aug 29 21:47:19 2016 -0600
+++ b/src/luan/impl/Pointer.java	Mon Aug 29 22:49:32 2016 -0600
@@ -1,10 +1,10 @@
 package luan.impl;
 
-import luan.DeepCloneable;
-import luan.DeepCloner;
+import luan.LuanCloneable;
+import luan.LuanCloner;
 
 
-public final class Pointer implements DeepCloneable {
+public final class Pointer implements LuanCloneable {
 	public Object o;
 
 	public Pointer() {}
@@ -17,7 +17,7 @@
 		return new Pointer();
 	}
 
-	@Override public void deepenClone(DeepCloneable clone,DeepCloner cloner) {
+	@Override public void deepenClone(LuanCloneable clone,LuanCloner cloner) {
 		((Pointer)clone).o = cloner.get(o);
 	}
 }
--- a/src/luan/modules/ThreadLuan.java	Mon Aug 29 21:47:19 2016 -0600
+++ b/src/luan/modules/ThreadLuan.java	Mon Aug 29 22:49:32 2016 -0600
@@ -11,7 +11,7 @@
 import luan.LuanFunction;
 import luan.LuanTable;
 import luan.LuanException;
-import luan.DeepCloner;
+import luan.LuanCloner;
 
 
 public final class ThreadLuan {
@@ -19,7 +19,7 @@
 	private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
 
 	public static void fork(LuanState luan,LuanFunction fn,Object... args) {
-		DeepCloner cloner = new DeepCloner();
+		LuanCloner cloner = new LuanCloner();
 		final LuanState newLuan = (LuanState)cloner.deepClone(luan);
 		final LuanFunction newFn = (LuanFunction)cloner.get(fn);
 		final Object[] newArgs = cloner.deepClone(args);
@@ -44,7 +44,7 @@
 	}
 
 	public static void schedule(LuanState luan,long delay,boolean repeat,LuanFunction fn,Object... args) {
-		DeepCloner cloner = new DeepCloner();
+		LuanCloner cloner = new LuanCloner();
 		final LuanState newLuan = (LuanState)cloner.deepClone(luan);
 		final LuanFunction newFn = (LuanFunction)cloner.get(fn);
 		final Object[] newArgs = cloner.deepClone(args);
--- a/src/luan/modules/http/HttpServicer.java	Mon Aug 29 21:47:19 2016 -0600
+++ b/src/luan/modules/http/HttpServicer.java	Mon Aug 29 22:49:32 2016 -0600
@@ -30,7 +30,7 @@
 import luan.LuanTable;
 import luan.LuanMeta;
 import luan.LuanPropertyMeta;
-import luan.DeepCloner;
+import luan.LuanCloner;
 import luan.modules.PackageLuan;
 import luan.modules.IoLuan;
 import luan.modules.TableLuan;
@@ -59,13 +59,13 @@
 				if( sessionLuan!=null ) {
 					luan = sessionLuan;
 				} else {
-					DeepCloner cloner = new DeepCloner();
+					LuanCloner cloner = new LuanCloner();
 					luan = (LuanState)cloner.deepClone(luan);
 					session.setAttribute("luan",luan);
 				}
 				fn = (LuanFunction)PackageLuan.require(luan,modName);
 			} else {
-				DeepCloner cloner = new DeepCloner();
+				LuanCloner cloner = new LuanCloner();
 				luan = (LuanState)cloner.deepClone(luan);
 				fn = (LuanFunction)cloner.get(mod);
 			}
--- a/src/luan/modules/http/LuanHandler.java	Mon Aug 29 21:47:19 2016 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Mon Aug 29 22:49:32 2016 -0600
@@ -12,7 +12,7 @@
 import luan.LuanState;
 import luan.LuanTable;
 import luan.LuanFunction;
-import luan.DeepCloner;
+import luan.LuanCloner;
 import luan.LuanException;
 import luan.modules.PackageLuan;
 
@@ -70,7 +70,7 @@
 
 	public static Object callRpc(LuanState luan,String fnName,Object... args) throws LuanException {
 		synchronized(luan) {
-			DeepCloner cloner = new DeepCloner();
+			LuanCloner cloner = new LuanCloner();
 			luan = (LuanState)cloner.deepClone(luan);
 		}
 		LuanTable rpc = (LuanTable)PackageLuan.require(luan,"luan:Rpc.luan");