All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.iodesystems.fn.tree.simple.NodeAdapter Maven / Gradle / Ivy

Go to download

Fn is a lazy Java Library that helps utilize some rudimentary functional concepts with more nounular objects

There is a newer version: 3.0.4
Show newest version
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);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy