/**
   * Put a node into the given linear segment and check for following parts of a long edge.
   *
   * @param node the node to put into the linear segment
   * @param segment a linear segment
   * @return {@code true} if the given node was not already part of another segment and was thus
   *     added to the given segment.
   */
  private boolean fillSegment(final LNode node, final LinearSegment segment) {
    NodeType nodeType = node.getType();

    // handle initial big nodes as big node type
    if (node.getProperty(InternalProperties.BIG_NODE_INITIAL)) {
      nodeType = NodeType.BIG_NODE;
    }

    if (node.id >= 0) {
      // The node is already part of another linear segment
      return false;
    } else if (segment.nodeType != null
        && (nodeType == NodeType.BIG_NODE && nodeType != segment.nodeType)) {
      // Big nodes are not allowed to share a linear segment with other dummy nodes
      return false;
    } else {
      // Add the node to the given linear segment
      node.id = segment.id;
      segment.nodes.add(node);
    }
    segment.nodeType = nodeType;

    if (nodeType == NodeType.LONG_EDGE
        || nodeType == NodeType.NORTH_SOUTH_PORT
        || nodeType == NodeType.BIG_NODE) {

      // This is a LONG_EDGE, NORTH_SOUTH_PORT or BIG_NODE dummy; check if any of its
      // successors are of one of these types too. If so, we can form a linear segment
      // with one of them. (not with more than one, though)
      // Note 1: LONG_EDGES and NORTH_SOUTH_PORTs can share a common linear segment
      // Note 2: we must take care not to make a segment out of nodes that are in the same layer
      // Note 3: for BIG_NODEs also the first BIG_NODE_INITIAL which is no actual dummy node has
      // to be considered here
      for (LPort sourcePort : node.getPorts()) {
        for (LPort targetPort : sourcePort.getSuccessorPorts()) {
          LNode targetNode = targetPort.getNode();
          NodeType targetNodeType = targetNode.getType();

          if (node.getLayer() != targetNode.getLayer()) {
            if (nodeType == NodeType.BIG_NODE) {
              // current AND the next node are BIG_NODE dummies
              if (targetNodeType == NodeType.BIG_NODE) {
                if (fillSegment(targetNode, segment)) {
                  // We just added another node to this node's linear segment.
                  // That's quite enough.
                  return true;
                }
              }
            } else {
              // current no bignode and next node is LONG_EDGE and NORTH_SOUTH_PORT
              if (targetNodeType == NodeType.LONG_EDGE
                  || targetNodeType == NodeType.NORTH_SOUTH_PORT) {
                if (fillSegment(targetNode, segment)) {
                  // We just added another node to this node's linear segment.
                  // That's quite enough.
                  return true;
                }
              }
            }
          }
        }
      }
    }

    return true;
  }