com.iodesystems.fn.tree.simple.NodeAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fn Show documentation
Show all versions of fn Show documentation
Fn is a lazy Java Library that helps utilize some rudimentary functional concepts with more nounular
objects
package com.iodesystems.fn.tree.simple;
import com.iodesystems.fn.tree.Adapter;
import java.util.List;
import java.util.Map;
public class NodeAdapter implements Adapter {
@Override
public List from(Node node) {
return node.getChildren();
}
@Override
public Object attribute(Node node, String attribute) {
if ("value".equals(attribute)) {
return node.getValue();
} else if ("type".equals(attribute)) {
return node.getValue().getClass().getSimpleName();
} else if (node.getValue() instanceof Map) {
return ((Map) node.getValue()).get(attribute);
}
return null;
}
@Override
public Node rebuild(Node node, List newChildren) {
return Node.v(node.getValue(), newChildren);
}
}