Package org.grouplens.grapht

Examples of org.grouplens.grapht.Component


        if (entry == null) {
            // don't save to disk if it isn't shared
            entry = new CacheEntry(node, false);
        }

        Component label = node.getLabel();
        Satisfaction satisfaction = label.getSatisfaction();
        if (satisfaction.hasInstance()) {
            return node;
        }
        Object obj;
        try {
            obj = entry.getObject(node);
        } catch (IOException e) {
            throw new RuntimeException("Cache I/O error", e);
        }

        Satisfaction instanceSat;
        if (obj == null) {
            instanceSat = Satisfactions.nullOfType(satisfaction.getErasedType());
        } else {
            instanceSat = Satisfactions.instance(obj);
        }
        Component newLabel = Component.create(instanceSat, label.getCachePolicy());
        // build new node with replacement label
        DAGNodeBuilder<Component,Dependency> bld = DAGNode.newBuilder(newLabel);
        // retain all non-transient edges
        for (DAGEdge<Component, Dependency> edge: node.getOutgoingEdges()) {
            if (!GraphtUtils.edgeIsTransient(edge)) {
View Full Code Here


*/
class SimulationNodeProcessor implements NodeProcessor {
    private static final Logger logger = LoggerFactory.getLogger(SimulationNodeProcessor.class);

    public DAGNode<Component, Dependency> processNode(@Nonnull DAGNode<Component, Dependency> node, @Nonnull DAGNode<Component, Dependency> original) {
        Component label = node.getLabel();
        if (!label.getSatisfaction().hasInstance()) {
            Satisfaction instanceSat = Satisfactions.nullOfType(label.getSatisfaction().getErasedType());
            Component newLbl = Component.create(instanceSat,
                                                label.getCachePolicy());
            // build new node with replacement label
            DAGNodeBuilder<Component,Dependency> bld = DAGNode.newBuilder(newLbl);
            // retain all non-transient edges
            for (DAGEdge<Component,Dependency> edge: node.getOutgoingEdges()) {
View Full Code Here

    InstantiatingNodeProcessor(Function<DAGNode<Component,Dependency>,Object> inst) {
        instantiator = inst;
    }

    public DAGNode<Component, Dependency> processNode(@Nonnull DAGNode<Component, Dependency> node, @Nonnull DAGNode<Component, Dependency> original) {
        Component label = node.getLabel();
        Satisfaction satisfaction = label.getSatisfaction();
        if (satisfaction.hasInstance()) {
            return node;
        }
        Object obj = instantiator.apply(node);

        Satisfaction instanceSat;
        if (obj == null) {
            instanceSat = Satisfactions.nullOfType(satisfaction.getErasedType());
        } else {
            instanceSat = Satisfactions.instance(obj);
        }
        Component newLabel = Component.create(instanceSat, label.getCachePolicy());
        // build new node with replacement label
        DAGNodeBuilder<Component,Dependency> bld = DAGNode.newBuilder(newLabel);
        // retain all non-transient edges
        for (DAGEdge<Component, Dependency> edge: node.getOutgoingEdges()) {
            if (!GraphtUtils.edgeIsTransient(edge)) {
View Full Code Here

     */
    public static void checkForPlaceholders(DAGNode<Component, Dependency> graph, Logger logger) throws RecommenderConfigurationException {
        Set<DAGNode<Component, Dependency>> placeholders = getPlaceholderNodes(graph);
        Satisfaction sat = null;
        for (DAGNode<Component,Dependency> node: placeholders) {
            Component csat = node.getLabel();
            if (sat == null) {
                sat = csat.getSatisfaction();
            }
            logger.error("placeholder {} not removed", csat.getSatisfaction());
        }
        if (sat != null) {
            throw new RecommenderConfigurationException("placeholder " + sat + " not removed");
        }
    }
View Full Code Here

     *
     * @param node The node.
     * @return {@code true} if the component is shareable.
     */
    public static boolean isShareable(DAGNode<Component, Dependency> node) {
        Component label = node.getLabel();
        if (label == null) {
            return false;
        }

        if (label.getSatisfaction().hasInstance()) {
            return true;
        }

        if (label.getCachePolicy() == CachePolicy.NEW_INSTANCE) {
            return false;
        }

        Class<?> type = label.getSatisfaction().getErasedType();
        if (type.getAnnotation(Shareable.class) != null) {
            return true;
        }

        if (type.getAnnotation(Singleton.class) != null) {
            return true;
        }

        // finally examine the satisfaction in more detail
        return label.getSatisfaction().visit(new AbstractSatisfactionVisitor<Boolean>() {
            @Override
            public Boolean visitDefault() {
                return false;
            }

View Full Code Here

        String id = nodeIds.get(node);
        String tgt;
        if (id == null) {
            id = "N" + nodeIds.size();
            nodeIds.put(node, id);
            Component csat = node.getLabel();
            assert csat != null;
            Satisfaction sat = csat.getSatisfaction();
            try {
                tgt = sat.visit(new Visitor(node, id));
            } catch (RuntimeException e) {
                if (e.getCause() instanceof IOException) {
                    throw (IOException) e.getCause();
View Full Code Here

            logger.debug("writing root node");
            String rid = dumper.setRoot(graph);
            // process each other node & add an edge
            for (DAGEdge<Component, Dependency> e: graph.getOutgoingEdges()) {
                DAGNode<Component, Dependency> target = e.getTail();
                Component csat = target.getLabel();
                if (!satIsNull(csat.getSatisfaction())) {
                    logger.debug("processing node {}", csat.getSatisfaction());
                    String id = dumper.process(target);
                    gw.putEdge(EdgeBuilder.create(rid, id)
                                          .set("arrowhead", "vee")
                                          .build());
                }
View Full Code Here

            currentNode = nd;
            nodeId = id;
            if (currentNode == null) {
                throw new IllegalStateException("dumper not running");
            }
            Component csat = currentNode.getLabel();
            assert csat != null;
            satisfaction = csat.getSatisfaction();
        }
View Full Code Here

                Desire dep = e.getLabel().getInitialDesire();
                Annotation q = dep.getInjectionPoint().getQualifier();
                DAGNode<Component, Dependency> targetNode = e.getTail();
                if (q != null && q.annotationType().getAnnotation(Parameter.class) != null) {
                    logger.debug("dumping parameter {}", q);
                    Component tcsat = targetNode.getLabel();
                    assert tcsat != null;
                    Satisfaction tsat = tcsat.getSatisfaction();
                    Object val = tsat.visit(new AbstractSatisfactionVisitor<Object>(null) {
                        @Override
                        public Object visitInstance(Object instance) {
                            return instance;
                        }
View Full Code Here

TOP

Related Classes of org.grouplens.grapht.Component

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.