Example #1
0
  /**
   * Removes a leaf node from the network. If this removal made the network degenerate, it will
   * return <code>true</code>.
   *
   * @param networkingNode Definition of the leaf node position and connecting sides.
   * @return <code>true</code> if the network after the removal is degenerated or empty (no longer
   *     valid).
   */
  public boolean removeLeafNode(NetworkNode networkingNode) {
    // Removal of a leaf node cannot split the network, so it's just safe to remove it
    // We just need to check, if after removal of the node, network becomes degenerated, if so - we
    // need
    // to signal that the network is no longer valid and should be removed.
    final boolean changed = leafNodes.remove(networkingNode.location, networkingNode);
    if (!changed)
      throw new IllegalStateException("Tried to remove a node that is not in the network");

    distanceCache.clear();

    return isDegeneratedNetwork() || isEmptyNetwork();
  }
Example #2
0
 /**
  * Adds a leaf node to the network.
  *
  * @param networkNode Definition of the leaf node position and connecting sides.
  */
 public void addLeafNode(NetworkNode networkNode) {
   if (SANITY_CHECK && (!canAddLeafNode(networkNode) || isEmptyNetwork()))
     throw new IllegalStateException("Unable to add this node to network");
   leafNodes.put(networkNode.location, networkNode);
   distanceCache.clear();
 }
Example #3
0
 /**
  * Adds a networking node to the network.
  *
  * @param networkNode Definition of the networking node position and connecting sides.
  */
 public void addNetworkingNode(NetworkNode networkNode) {
   if (SANITY_CHECK && !canAddNetworkingNode(networkNode))
     throw new IllegalStateException("Unable to add this node to network");
   networkingNodes.put(networkNode.location, networkNode);
   distanceCache.clear();
 }
Example #4
0
 public void removeNetworkingNode(NetworkNode networkNode) {
   if (!networkingNodes.remove(networkNode.location, networkNode))
     throw new IllegalStateException("Tried to remove a node that is not in the network");
   distanceCache.clear();
 }
Example #5
0
 public void removeAllNetworkingNodes() {
   networkingNodes.clear();
   distanceCache.clear();
 }
Example #6
0
 public void removeAllLeafNodes() {
   leafNodes.clear();
   distanceCache.clear();
 }