Example usage for java.util.stream Node equals

List of usage examples for java.util.stream Node equals

Introduction

In this page you can find the example usage for java.util.stream Node equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.net2plan.interfaces.networkDesign.NetPlan.java

/**
 * <p>Checks that the input sequence of links belong to the same layer and follow a contiguous path. Throws an exception if the path is not contiguous or the sequence of links
 * is empty. </p>/*from  w ww  .j av  a 2 s. c  om*/
 *
 * @param links           Sequence of links
 * @param layer           Network layer
 * @param originNode      Origin node
 * @param destinationNode Destination node
 * @return The input layer
 */
public NetworkLayer checkContiguousPath(List<Link> links, NetworkLayer layer, Node originNode,
        Node destinationNode) {
    if (links.isEmpty())
        throw new Net2PlanException("Empty sequence of links");
    final Link firstLink = links.iterator().next();
    if (layer == null)
        layer = firstLink.layer;
    checkInThisNetPlan(layer);
    if (originNode != null)
        checkInThisNetPlan(originNode);
    if (destinationNode != null)
        checkInThisNetPlan(destinationNode);
    for (Link e : links)
        if (!e.layer.equals(layer))
            throw new Net2PlanException(
                    "The path contains links not attached to the appropriate NetPlan object or layer");

    if ((originNode != null) && (!firstLink.originNode.equals(originNode)))
        throw new Net2PlanException("The initial node of the sequence of links is not correct");
    Node endNodePreviousLink = firstLink.originNode;
    for (Link link : links) {
        if (!endNodePreviousLink.equals(link.originNode))
            throw new Net2PlanException("This is not a contigous sequence of links");
        endNodePreviousLink = link.destinationNode;
    }
    if ((destinationNode != null) && !(endNodePreviousLink.equals(destinationNode)))
        throw new Net2PlanException("The end node of the sequence of links is not correct");
    return layer;
}

From source file:com.net2plan.interfaces.networkDesign.NetPlan.java

/**
 * <p>Adds two demands, one in each direction,.</p>
 * <p><b>Important</b>: Self-demands are not allowed.</p>
 *
 * @param ingressNode            Identifier of the ingress node
 * @param egressNode             Identifier of the egress node
 * @param offeredTraffic         Offered traffic by this demand. It must be greater or equal than zero
 * @param attributes             Map for user-defined attributes ({@code null} means 'no attribute'). Each key represents the attribute name, whereas value represents the attribute value
 * @param optionalLayerParameter Network layer to which add the demand (optional)
 * @return A pair object with the two newly created demands
 * @see com.net2plan.interfaces.networkDesign.Demand
 * @see com.net2plan.utils.Pair//ww w.j a  v  a 2  s .c o m
 */
public Pair<Demand, Demand> addDemandBidirectional(Node ingressNode, Node egressNode, double offeredTraffic,
        Map<String, String> attributes, NetworkLayer... optionalLayerParameter) {
    offeredTraffic = NetPlan.adjustToTolerance(offeredTraffic);
    checkIsModifiable();
    NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayerParameter);
    checkInThisNetPlan(ingressNode);
    checkInThisNetPlan(egressNode);
    if (ingressNode.equals(egressNode))
        throw new Net2PlanException("Self-demands are not allowed");
    if (offeredTraffic < 0)
        throw new Net2PlanException("Offered traffic must be non-negative");

    Demand d1 = addDemand(ingressNode, egressNode, offeredTraffic, attributes, layer);
    Demand d2 = addDemand(egressNode, ingressNode, offeredTraffic, attributes, layer);
    d1.setAttribute(KEY_STRING_BIDIRECTIONALCOUPLE, "" + d2.id);
    d2.setAttribute(KEY_STRING_BIDIRECTIONALCOUPLE, "" + d1.id);
    if (ErrorHandling.isDebugEnabled())
        this.checkCachesConsistency();
    return Pair.of(d1, d2);
}

From source file:com.net2plan.interfaces.networkDesign.NetPlan.java

Demand addDemand(Long demandId, Node ingressNode, Node egressNode, double offeredTraffic,
        Map<String, String> attributes, NetworkLayer... optionalLayerParameter) {
    offeredTraffic = NetPlan.adjustToTolerance(offeredTraffic);
    checkIsModifiable();// w  w w .j ava2  s.c  o  m
    NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayerParameter);
    checkInThisNetPlan(ingressNode);
    checkInThisNetPlan(egressNode);
    if (ingressNode.equals(egressNode))
        throw new Net2PlanException("Self-demands are not allowed");
    if (offeredTraffic < 0)
        throw new Net2PlanException("Offered traffic must be non-negative");

    if (demandId == null) {
        demandId = nextElementId.longValue();
        nextElementId.increment();
    }

    Demand demand = new Demand(this, demandId, layer.demands.size(), layer, ingressNode, egressNode,
            offeredTraffic, new AttributeMap(attributes));

    cache_id2DemandMap.put(demandId, demand);
    layer.demands.add(demand);
    egressNode.cache_nodeIncomingDemands.add(demand);
    ingressNode.cache_nodeOutgoingDemands.add(demand);

    if (layer.routingType == RoutingType.HOP_BY_HOP_ROUTING) {
        layer.forwardingRulesNoFailureState_f_de = DoubleFactory2D.sparse.appendRow(
                layer.forwardingRulesNoFailureState_f_de, DoubleFactory1D.sparse.make(layer.links.size()));
        layer.forwardingRulesCurrentFailureState_x_de = DoubleFactory2D.sparse.appendRow(
                layer.forwardingRulesCurrentFailureState_x_de, DoubleFactory1D.sparse.make(layer.links.size()));
    }
    if (ErrorHandling.isDebugEnabled())
        this.checkCachesConsistency();
    return demand;
}

From source file:com.net2plan.interfaces.networkDesign.NetPlan.java

/**
 * <p>Adds two links, one in each direction.</p>
 * <p><b>Important</b>: Self-links are not allowed.</p>
 *
 * @param originNode                    Link origin node
 * @param destinationNode               Link destination node
 * @param capacity                      Link capacity. It must be greather or equal to zero
 * @param lengthInKm                    Link length. It must be greater or equal than zero. Physical distance between node pais can be otainer through the {@link #getNodePairEuclideanDistance(Node, Node) getNodePairEuclideanDistance}
 *                                      (for Euclidean distance) or {@link #getNodePairHaversineDistanceInKm(Node, Node) getNodePairHaversineDistanceInKm} (for airlinea distance) methods.
 * @param propagationSpeedInKmPerSecond Link propagation speed in km/s. It must be greater than zero ({@code Double.MAX_VALUE} means no propagation delay, a non-positive value is changed into
 *                                      200000 km/seg, a typical speed of light in the wires)
 * @param attributes                    Map for user-defined attributes ({@code null} means 'no attribute'). Each key represents the attribute name, whereas value represents the attribute value
 * @param optionalLayerParameter        Network layer to which add the links (optional)
 * @return A {@code Pair} object with the two newly created links
 * @see com.net2plan.interfaces.networkDesign.Link
 * @see com.net2plan.utils.Pair//from w  w  w  .  j  av a2 s  . c  om
 * @see com.net2plan.interfaces.networkDesign.Node
 */
public Pair<Link, Link> addLinkBidirectional(Node originNode, Node destinationNode, double capacity,
        double lengthInKm, double propagationSpeedInKmPerSecond, Map<String, String> attributes,
        NetworkLayer... optionalLayerParameter) {
    capacity = NetPlan.adjustToTolerance(capacity);
    checkIsModifiable();
    NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayerParameter);
    checkInThisNetPlan(originNode);
    checkInThisNetPlan(destinationNode);
    if (originNode.equals(destinationNode))
        throw new Net2PlanException("Self-links are not allowed");
    if (capacity < 0)
        throw new Net2PlanException("Link capacity must be non-negative");
    if (lengthInKm < 0)
        throw new Net2PlanException("Link length must be non-negative");
    if (propagationSpeedInKmPerSecond <= 0)
        throw new Net2PlanException("Propagation speed must be positive");

    Link link1 = addLink(originNode, destinationNode, capacity, lengthInKm, propagationSpeedInKmPerSecond,
            attributes, layer);
    Link link2 = addLink(destinationNode, originNode, capacity, lengthInKm, propagationSpeedInKmPerSecond,
            attributes, layer);
    link1.setAttribute(KEY_STRING_BIDIRECTIONALCOUPLE, "" + link2.id);
    link2.setAttribute(KEY_STRING_BIDIRECTIONALCOUPLE, "" + link1.id);

    if (ErrorHandling.isDebugEnabled())
        this.checkCachesConsistency();

    return Pair.of(link1, link2);
}

From source file:com.net2plan.interfaces.networkDesign.NetPlan.java

Link addLink(Long linkId, Node originNode, Node destinationNode, double capacity, double lengthInKm,
        double propagationSpeedInKmPerSecond, Map<String, String> attributes,
        NetworkLayer... optionalLayerParameter) {
    capacity = NetPlan.adjustToTolerance(capacity);
    checkIsModifiable();//ww w.j  a  v a2  s.c  om
    NetworkLayer layer = checkInThisNetPlanOptionalLayerParameter(optionalLayerParameter);
    checkInThisNetPlan(originNode);
    checkInThisNetPlan(destinationNode);
    if (originNode.equals(destinationNode))
        throw new Net2PlanException("Self-links are not allowed");
    if (capacity < 0)
        throw new Net2PlanException("Link capacity must be non-negative");
    if (lengthInKm < 0)
        throw new Net2PlanException("Link length must be non-negative");
    if (propagationSpeedInKmPerSecond <= 0)
        throw new Net2PlanException("Propagation speed must be positive");

    if (linkId == null) {
        linkId = nextElementId.longValue();
        nextElementId.increment();
    }

    Link link = new Link(this, linkId, layer.links.size(), layer, originNode, destinationNode, lengthInKm,
            propagationSpeedInKmPerSecond, capacity, new AttributeMap(attributes));

    cache_id2LinkMap.put(linkId, link);
    layer.links.add(link);
    originNode.cache_nodeOutgoingLinks.add(link);
    destinationNode.cache_nodeIncomingLinks.add(link);

    if (layer.routingType == RoutingType.HOP_BY_HOP_ROUTING) {
        layer.forwardingRulesNoFailureState_f_de = DoubleFactory2D.sparse.appendColumn(
                layer.forwardingRulesNoFailureState_f_de, DoubleFactory1D.sparse.make(layer.demands.size()));
        layer.forwardingRulesCurrentFailureState_x_de = DoubleFactory2D.sparse.appendColumn(
                layer.forwardingRulesCurrentFailureState_x_de,
                DoubleFactory1D.sparse.make(layer.demands.size()));
        layer.forwardingRules_Aout_ne = DoubleFactory2D.sparse.appendColumn(layer.forwardingRules_Aout_ne,
                DoubleFactory1D.sparse.make(netPlan.nodes.size()));
        layer.forwardingRules_Ain_ne = DoubleFactory2D.sparse.appendColumn(layer.forwardingRules_Ain_ne,
                DoubleFactory1D.sparse.make(netPlan.nodes.size()));
        layer.forwardingRules_Aout_ne.set(originNode.index, layer.forwardingRules_Aout_ne.columns() - 1, 1.0);
        layer.forwardingRules_Ain_ne.set(destinationNode.index, layer.forwardingRules_Ain_ne.columns() - 1,
                1.0);
    }

    if (ErrorHandling.isDebugEnabled())
        this.checkCachesConsistency();
    return link;
}