test_class.declarator: THREE_CONNECTED_LINES = 3
test_class.modifier: private static final
test_class.original_string: private static final int THREE_CONNECTED_LINES = 3;
test_class.type: int
test_class.var_name: THREE_CONNECTED_LINES
test_class.declarator: FOUR_CONNECTED_LINES = 4
test_class.modifier: private static final
test_class.original_string: private static final int FOUR_CONNECTED_LINES = 4;
test_class.type: int
test_class.var_name: FOUR_CONNECTED_LINES
test_class.declarator: FIVE_CONNECTED_LINES = 5
test_class.modifier: private static final
test_class.original_string: private static final int FIVE_CONNECTED_LINES = 5;
test_class.type: int
test_class.var_name: FIVE_CONNECTED_LINES
test_class.file: map/src/test/java/openlr/map/utils/NodeCheckTest.java
test_class.identifier: NodeCheckTest
test_case.body: @Test
      public void testIsNodeValid() {
          Mockery context = new Mockery();
          final Node valid1 = context.mock(Node.class, "valid1");
          final Node valid2 = context.mock(Node.class, "valid2");
          final Node valid3 = context.mock(Node.class, "valid3");
          final Node valid4 = context.mock(Node.class, "valid4");
          final Node valid5 = context.mock(Node.class, "valid5");
  
          final Node invalid2 = context.mock(Node.class, "invalid2");
          final Node invalid4 = context.mock(Node.class, "invalid4");
  
          final Node n1 = context.mock(Node.class, "n1");
          final Node n2 = context.mock(Node.class, "n2");
          final Node n3 = context.mock(Node.class, "n3");
  
          final Line l1 = context.mock(Line.class, "l1");
          final Line l2 = context.mock(Line.class, "l2");
          final Line l3 = context.mock(Line.class, "l3");
          final Line l4 = context.mock(Line.class, "l4");
          final Line l5 = context.mock(Line.class, "l5");
  
          context.checking(new Expectations() {
              {
                  allowing(valid2).getID();
                  will(returnValue(2l));
              }
          });
          context.checking(new Expectations() {
              {
                  allowing(valid1).getNumberConnectedLines();
                  will(returnValue(1));
              }
          });
  
          final HashSet<Line> set2 = new HashSet<Line>();
          set2.add(l1);
          set2.add(l2);
          context.checking(new Expectations() {
              {
                  allowing(valid2).getNumberConnectedLines();
                  will(returnValue(2));
              }
  
              {
                  allowing(valid2).getConnectedLines();
                  will(returnValue(set2.iterator()));
              }
          });
          context.checking(new Expectations() {
              {
                  allowing(n1).getID();
                  will(returnValue(1l));
              }
  
              {
                  allowing(n2).getID();
                  will(returnValue(2l));
              }
  
              {
                  allowing(n3).getID();
                  will(returnValue(3l));
              }
          });
          context.checking(new Expectations() {
              {
                  allowing(l1).getStartNode();
                  will(returnValue(n1));
              }
  
              {
                  allowing(l1).getEndNode();
                  will(returnValue(valid2));
              }
          });
          context.checking(new Expectations() {
              {
                  allowing(l2).getStartNode();
                  will(returnValue(valid2));
              }
  
              {
                  allowing(l2).getEndNode();
                  will(returnValue(n1));
              }
          });
  
          context.checking(new Expectations() {
              {
                  allowing(valid3).getNumberConnectedLines();
                  will(returnValue(THREE_CONNECTED_LINES));
              }
          });
  
          context.checking(new Expectations() {
              {
                  allowing(valid5).getNumberConnectedLines();
                  will(returnValue(FIVE_CONNECTED_LINES));
              }
          });
  
          final HashSet<Line> set4 = new HashSet<Line>();
          set4.addAll(set2);
          set4.add(l3);
          set4.add(l4);
          context.checking(new Expectations() {
              {
                  allowing(valid4).getNumberConnectedLines();
                  will(returnValue(FOUR_CONNECTED_LINES));
              }
  
              {
                  allowing(valid4).getConnectedLines();
                  will(returnValue(set4.iterator()));
              }
          });
          context.checking(new Expectations() {
              {
                  allowing(l3).getStartNode();
                  will(returnValue(n2));
              }
  
              {
                  allowing(l3).getEndNode();
                  will(returnValue(valid2));
              }
          });
          context.checking(new Expectations() {
              {
                  allowing(l4).getStartNode();
                  will(returnValue(valid2));
              }
  
              {
                  allowing(l4).getEndNode();
                  will(returnValue(n3));
              }
          });
  
          context.checking(new Expectations() {
              {
                  allowing(l5).getStartNode();
                  will(returnValue(valid2));
              }
  
              {
                  allowing(l5).getEndNode();
                  will(returnValue(n2));
              }
          });
  
          final HashSet<Line> set4invalid = new HashSet<Line>();
          set4invalid.addAll(set2);
          set4invalid.add(l3);
          set4invalid.add(l5);
          context.checking(new Expectations() {
              {
                  allowing(invalid4).getNumberConnectedLines();
                  will(returnValue(FOUR_CONNECTED_LINES));
              }
  
              {
                  allowing(invalid4).getConnectedLines();
                  will(returnValue(set4invalid.iterator()));
              }
          });
  
          final HashSet<Line> set2invalid = new HashSet<Line>();
          set2invalid.add(l3);
          set2invalid.add(l4);
          context.checking(new Expectations() {
              {
                  allowing(invalid2).getNumberConnectedLines();
                  will(returnValue(2));
              }
  
              {
                  allowing(invalid2).getConnectedLines();
                  will(returnValue(set2invalid.iterator()));
              }
          });
  
          assertTrue(NodeCheck.isValidNode(valid1));
          assertTrue(NodeCheck.isValidNode(valid2));
          assertTrue(NodeCheck.isValidNode(valid3));
          assertTrue(NodeCheck.isValidNode(valid4));
          assertTrue(NodeCheck.isValidNode(valid5));
  
          assertFalse(NodeCheck.isValidNode(invalid2));
          assertFalse(NodeCheck.isValidNode(invalid4));
      }
test_case.class_method_signature: NodeCheckTest.testIsNodeValid()
test_case.full_signature: @Test public void testIsNodeValid()
test_case.identifier: testIsNodeValid
test_case.invocations: mock mock mock mock mock mock mock mock mock mock mock mock mock mock mock checking getID allowing will returnValue checking getNumberConnectedLines allowing will returnValue add add checking getNumberConnectedLines allowing will returnValue getConnectedLines allowing will returnValue iterator checking getID allowing will returnValue getID allowing will returnValue getID allowing will returnValue checking getStartNode allowing will returnValue getEndNode allowing will returnValue checking getStartNode allowing will returnValue getEndNode allowing will returnValue checking getNumberConnectedLines allowing will returnValue checking getNumberConnectedLines allowing will returnValue addAll add add checking getNumberConnectedLines allowing will returnValue getConnectedLines allowing will returnValue iterator checking getStartNode allowing will returnValue getEndNode allowing will returnValue checking getStartNode allowing will returnValue getEndNode allowing will returnValue checking getStartNode allowing will returnValue getEndNode allowing will returnValue addAll add add checking getNumberConnectedLines allowing will returnValue getConnectedLines allowing will returnValue iterator add add checking getNumberConnectedLines allowing will returnValue getConnectedLines allowing will returnValue iterator assertTrue isValidNode assertTrue isValidNode assertTrue isValidNode assertTrue isValidNode assertTrue isValidNode assertFalse isValidNode assertFalse isValidNode
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testIsNodeValid()
focal_class.declarator: DEGREE_2 = 2
focal_class.modifier: private static final
focal_class.original_string: private static final int DEGREE_2 = 2;
focal_class.type: int
focal_class.var_name: DEGREE_2
focal_class.declarator: DEGREE_4 = 4
focal_class.modifier: private static final
focal_class.original_string: private static final int DEGREE_4 = 4;
focal_class.type: int
focal_class.var_name: DEGREE_4
focal_class.file: map/src/main/java/openlr/map/utils/NodeCheck.java
focal_class.identifier: NodeCheck
focal_class.class_method_signature: NodeCheck.NodeCheck()
focal_class.full_signature: private  NodeCheck()
focal_class.identifier: NodeCheck
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.signature:  NodeCheck()
focal_class.class_method_signature: NodeCheck.isValidNode(final Node n)
focal_class.full_signature: public static boolean isValidNode(final Node n)
focal_class.identifier: isValidNode
focal_class.modifiers: public static
focal_class.parameters: (final Node n)
focal_class.return: boolean
focal_class.signature: boolean isValidNode(final Node n)
focal_class.class_method_signature: NodeCheck.isPair(final Line line1, final Line line2)
focal_class.full_signature: public static boolean isPair(final Line line1, final Line line2)
focal_class.identifier: isPair
focal_class.modifiers: public static
focal_class.parameters: (final Line line1, final Line line2)
focal_class.return: boolean
focal_class.signature: boolean isPair(final Line line1, final Line line2)
focal_method.body: public static boolean isValidNode(final Node n) {
          if (n == null) {
              return false;
          }
          // node degree is 2
          int degree = n.getNumberConnectedLines();
          if (degree == DEGREE_2) {
              Iterator<? extends Line> iter = n.getConnectedLines();
              Line line1 = iter.next();
              Line line2 = iter.next();
              // if isPair then we have a dead-end street
              // otherwise we can travel along the streets without coming back to
              // the start point
              return isPair(line1, line2);
          }
          // node degree is 4
          if (degree == DEGREE_4) {
              Iterator<? extends Line> connectedLines = n.getConnectedLines();
              List<Line> lines = new ArrayList<Line>();
              while (connectedLines.hasNext()) {
                  lines.add(connectedLines.next());
              }
  
              // find two pairs within this array
              // if there are two pairs then the node is avoidable otherwise we
              // are connecting more than
              // two nodes and this node needs to be considered
              Line line = lines.get(0);
              boolean found = false;
              int pos = 1;
              // find a pair containing the first line and delete both lines
              while (!found && pos < lines.size()) {
                  if (isPair(line, lines.get(pos))) {
                      found = true;
                      lines.remove(pos);
                      lines.remove(0);
                  }
                  pos++;
              }
              // if no pair containing the first line can be found then we have a
              // considerable node
              if (!found) {
                  return true;
              }
              // check the remaining edges if they form a pair and if so, then
              // avoid the node
              if (isPair(lines.get(0), lines.get(1))) {
                  return false;
              }
              return true;
          }
          return true;
      }
focal_method.class_method_signature: NodeCheck.isValidNode(final Node n)
focal_method.full_signature: public static boolean isValidNode(final Node n)
focal_method.identifier: isValidNode
focal_method.invocations: getNumberConnectedLines getConnectedLines next next isPair getConnectedLines hasNext add next get size isPair get remove remove isPair get get
focal_method.modifiers: public static
focal_method.parameters: (final Node n)
focal_method.return: boolean
focal_method.signature: boolean isValidNode(final Node n)