LuanTable constructors

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

LuanTable constructors

Hugo <Nabble>
Shouldn't LuanTable have a constructor that takes a Collection<? extends Object>?

This is what I have to do now as a turnaround:
List<Node> list = ...
List<Object> objects = new ArrayList<Object>(list);
return new LuanTable(objects);
Reply | Threaded
Open this post in threaded view
|

Re: LuanTable constructors

fschmidt
Administrator
LuanTable has these constructors:
	public LuanTable(List<Object> list) {
		this.list = list;
	}

	public LuanTable(Map<Object,Object> map) {
		this.map = map;
	}

	public LuanTable(Set<Object> set) {
		map = new HashMap<Object,Object>();
		for( Object obj : set ) {
			map.put(obj,Boolean.TRUE);
		}
	}
Note that in the first 2, the object passed is used directly in the LuanTable which means that modifications to the collection will be available to the caller.  The last constructor is a convenience and I am not sure if it really should be there.  Your example could be done:
List<Node> list = ...
return new LuanTable(new ArrayList<Object>(list));
This makes it clear that the list will not be changed by LuanTable.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: LuanTable constructors

Hugo <Nabble>
This post was updated on .
This is a minor issue, so it is okay for now. It seems to me that LuanTable would be more flexible if it held a collection like I suggested (instead of a List). I am also not sure why you force <Objects> instead of <? extends Object>. But you can decide about this because I don't understand the code well enough.

Besides that, I believe you would be able to simplify the (deep)cloning code by using serialization/deserialization to/from byte code. Cloning the entire graph of objects would be just a few lines of code, but would require objects to implement the Serializable interface. Did you consider that option?

EDIT: ... to/from byte array.
Reply | Threaded
Open this post in threaded view
|

Re: LuanTable constructors

fschmidt
Administrator
Hugo <Nabble> wrote
This is a minor issue, so it is okay for now. It seems to me that LuanTable would be more flexible if it held a collection like I suggested (instead of a List). I am also not sure why you force <Objects> instead of <? extends Object>. But you can decide about this because I don't understand the code well enough.
I can't add objects to a List<? extends Object> because the Java compiler doesn't know what types of objects the list accepts.

Besides that, I believe you would be able to simplify the (deep)cloning code by using serialization/deserialization to/from byte code. Cloning the entire graph of objects would be just a few lines of code, but would require objects to implement the Serializable interface. Did you consider that option?
This doesn't work because I copy references to non-cloneable objects without cloning them.  For example, the compiled Luan code-tree is non-cloneable and is shared by all clones.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: LuanTable constructors

fschmidt
Administrator
Hugo, please close this.
Woe to those who call bad good and good bad -- Isaiah 5:20
Following the Old Testament, not evil modern culture
Reply | Threaded
Open this post in threaded view
|

Re: LuanTable constructors

Hugo <Nabble>
Closing thread.