changeset 397:5e0acdeaea93

add LuanTable isSet() and asSet() (untested)
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 27 Apr 2015 12:25:30 -0600
parents ba8b0aae6453
children 39c4ac11a58a
files core/src/luan/AbstractLuanTable.java core/src/luan/LuanTable.java core/src/luan/LuanTableImpl.java
diffstat 3 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/AbstractLuanTable.java	Sun Apr 26 21:19:10 2015 -0600
+++ b/core/src/luan/AbstractLuanTable.java	Mon Apr 27 12:25:30 2015 -0600
@@ -32,6 +32,22 @@
 		return Collections.emptyList();
 	}
 
+	@Override public boolean isSet() {
+		for( Map.Entry<Object,Object> entry : this ) {
+			if( !entry.getValue().equals(Boolean.TRUE) )
+				return false;
+		}
+		return true;
+	}
+
+	@Override public Set<Object> asSet() {
+		Set<Object> set = new HashSet<Object>();
+		for( Map.Entry<Object,Object> entry : this ) {
+			set.add(entry.getKey());
+		}
+		return set;
+	}
+
 	@Override public Map<Object,Object> asMap() {
 		Map<Object,Object> map = newMap();
 		for( Map.Entry<Object,Object> entry : this ) {
--- a/core/src/luan/LuanTable.java	Sun Apr 26 21:19:10 2015 -0600
+++ b/core/src/luan/LuanTable.java	Mon Apr 27 12:25:30 2015 -0600
@@ -2,12 +2,15 @@
 
 import java.util.Map;
 import java.util.List;
+import java.util.Set;
 import java.util.Comparator;
 
 
 public interface LuanTable extends Iterable<Map.Entry<Object,Object>> {
 	public boolean isEmpty();
 	public boolean isList();
+	public boolean isSet();
+	public Set<Object> asSet();
 	public List<Object> asList();
 	public Map<Object,Object> asMap();
 	public Object get(Object key);
--- a/core/src/luan/LuanTableImpl.java	Sun Apr 26 21:19:10 2015 -0600
+++ b/core/src/luan/LuanTableImpl.java	Mon Apr 27 12:25:30 2015 -0600
@@ -84,8 +84,8 @@
 	@Override protected Map<Object,Object> map() {
 		return map!=null ? map : Collections.emptyMap();
 	}
-
-	public boolean isSet() {
+/*
+	@Override public boolean isSet() {
 		if( list != null ) {
 			for( Object obj : list ) {
 				if( obj!=null && !obj.equals(Boolean.TRUE) )
@@ -101,7 +101,7 @@
 		return true;
 	}
 
-	public Set<Object> asSet() {
+	@Override public Set<Object> asSet() {
 		if( list == null || list.isEmpty() )
 			return map!=null ? map.keySet() : Collections.emptySet();
 		Set<Object> rtn = map!=null ? new HashSet<Object>(map.keySet()) : new HashSet<Object>();
@@ -110,7 +110,7 @@
 		}
 		return rtn;
 	}
-
+*/
 	@Override protected String type() {
 		return "table";
 	}