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

org.bidib.wizard.common.node.OccupancyNode Maven / Gradle / Ivy

package org.bidib.wizard.common.node;

import java.lang.ref.WeakReference;

import org.bidib.jbidibc.messages.BidibLibrary;
import org.bidib.jbidibc.messages.Feature;
import org.bidib.wizard.api.model.NodeInterface;
import org.bidib.wizard.api.model.OccupancyNodeInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jgoodies.binding.beans.Model;

public class OccupancyNode extends Model implements OccupancyNodeInterface {
    private static final long serialVersionUID = 1L;

    private static final Logger LOGGER = LoggerFactory.getLogger(OccupancyNode.class);

    private final WeakReference parent;

    public OccupancyNode(final NodeInterface parent) {
        this.parent = new WeakReference<>(parent);
    }

    @Override
    public NodeInterface getNode() {
        return parent.get();
    }

    @Override
    public int getFeedbackPortCount() {
        int feedbackPortCount = 0;
        try {
            Feature featureBmSize =
                Feature.findFeature(getNode().getNode().getFeatures(), BidibLibrary.FEATURE_BM_SIZE);

            if (featureBmSize != null) {
                feedbackPortCount = featureBmSize.getValue();
            }
            LOGGER.info("Number of feedbackPorts: {}", feedbackPortCount);
        }
        catch (Exception ex) {
            LOGGER.warn("Get the number of feedback ports failed.", ex);
            throw new RuntimeException("Get the number of feedback ports failed.", ex);
        }
        return feedbackPortCount;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy