maps unpack
This commit is contained in:
1 parent
5ec664240f
commit
e22474156b
6 files changed
+35
-32
No files matched your search
@@ -1,12 +1,15 @@
|
||||
package carpet.script.value;
|
||||
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractListValue extends Value implements Iterable<Value>
|
||||
{
|
||||
public abstract Iterator<Value> iterator();
|
||||
public List<Value> unpack() { return Lists.newArrayList(iterator()); }
|
||||
public void fatality() { }
|
||||
public void append(Value v)
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ import static java.lang.Math.abs;
|
||||
|
||||
public class ListValue extends AbstractListValue implements ContainerValueInterface
|
||||
{
|
||||
protected List<Value> items;
|
||||
protected final List<Value> items;
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
@@ -99,9 +99,7 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
|
||||
public static ListValue wrap(List<Value> list)
|
||||
{
|
||||
ListValue created = new ListValue();
|
||||
created.items = list;
|
||||
return created;
|
||||
return new ListValue(list);
|
||||
}
|
||||
public static ListValue of(Value ... list)
|
||||
{
|
||||
@@ -283,10 +281,14 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
|
||||
public Iterator<Value> iterator() { return new ArrayList<>(items).iterator(); } // should be thread safe
|
||||
|
||||
public List<Value> unpack()
|
||||
{
|
||||
return new ArrayList<>(items);
|
||||
}
|
||||
|
||||
public void extend(List<Value> subList)
|
||||
{
|
||||
for (Value v: subList)
|
||||
items.add(v);
|
||||
items.addAll(subList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,6 +48,12 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
|
||||
return new ArrayList<>(map.keySet()).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Value> unpack()
|
||||
{
|
||||
return map.entrySet().stream().map(e -> ListValue.of(e.getKey(), e.getValue())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user