@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullStringsToDeserialize() { binaryTreeSerialization.deserialize(null); }
public BinaryNode<Integer> deserialize(String tree) { validateInput(tree); if (index >= tree.length()) { return null; } else { char currentChar = tree.charAt(index); if (currentChar == '#') { index++; return null; } else { BinaryNode<Integer> node = new BinaryNode<Integer>(currentChar - 48); index++; node.setLeft(deserialize(tree)); node.setRight(deserialize(tree)); return node; } } }
BinaryTreeSerialization { public BinaryNode<Integer> deserialize(String tree) { validateInput(tree); if (index >= tree.length()) { return null; } else { char currentChar = tree.charAt(index); if (currentChar == '#') { index++; return null; } else { BinaryNode<Integer> node = new BinaryNode<Integer>(currentChar - 48); index++; node.setLeft(deserialize(tree)); node.setRight(deserialize(tree)); return node; } } } }
BinaryTreeSerialization { public BinaryNode<Integer> deserialize(String tree) { validateInput(tree); if (index >= tree.length()) { return null; } else { char currentChar = tree.charAt(index); if (currentChar == '#') { index++; return null; } else { BinaryNode<Integer> node = new BinaryNode<Integer>(currentChar - 48); index++; node.setLeft(deserialize(tree)); node.setRight(deserialize(tree)); return node; } } } BinaryTreeSerialization(); }
BinaryTreeSerialization { public BinaryNode<Integer> deserialize(String tree) { validateInput(tree); if (index >= tree.length()) { return null; } else { char currentChar = tree.charAt(index); if (currentChar == '#') { index++; return null; } else { BinaryNode<Integer> node = new BinaryNode<Integer>(currentChar - 48); index++; node.setLeft(deserialize(tree)); node.setRight(deserialize(tree)); return node; } } } BinaryTreeSerialization(); String serialize(BinaryNode root); BinaryNode<Integer> deserialize(String tree); }
BinaryTreeSerialization { public BinaryNode<Integer> deserialize(String tree) { validateInput(tree); if (index >= tree.length()) { return null; } else { char currentChar = tree.charAt(index); if (currentChar == '#') { index++; return null; } else { BinaryNode<Integer> node = new BinaryNode<Integer>(currentChar - 48); index++; node.setLeft(deserialize(tree)); node.setRight(deserialize(tree)); return node; } } } BinaryTreeSerialization(); String serialize(BinaryNode root); BinaryNode<Integer> deserialize(String tree);  }