@Test public void testParsePath() { Object[] tv = { "M / 44H / 0H / 0H / 1 / 1", ImmutableList.of( new ChildNumber(44, true), new ChildNumber(0, true), new ChildNumber(0, true), new ChildNumber(1, false), new ChildNumber(1, false) ), "M/7H/3/3/1H/", ImmutableList.of( new ChildNumber(7, true), new ChildNumber(3, false), new ChildNumber(3, false), new ChildNumber(1, true) ), "1 H / 2 H / 3 H /", ImmutableList.of( new ChildNumber(1, true), new ChildNumber(2, true), new ChildNumber(3, true) ), "1 / 2 / 3 /", ImmutableList.of( new ChildNumber(1, false), new ChildNumber(2, false), new ChildNumber(3, false) ) }; for (int i = 0; i < tv.length; i += 2) { String strPath = (String) tv[i]; List<ChildNumber> expectedPath = (List<ChildNumber>) tv[i+1]; List<ChildNumber> path = HDUtils.parsePath(strPath); Assert.assertEquals(path, expectedPath); } }
public static List<ChildNumber> parsePath(@Nonnull String path) { String[] parsedNodes = path.replace("M", "").split("/"); List<ChildNumber> nodes = new ArrayList<>(); for (String n : parsedNodes) { n = n.replaceAll(" ", ""); if (n.length() == 0) continue; boolean isHard = n.endsWith("H"); if (isHard) n = n.substring(0, n.length() - 1); int nodeNumber = Integer.parseInt(n); nodes.add(new ChildNumber(nodeNumber, isHard)); } return nodes; }
HDUtils { public static List<ChildNumber> parsePath(@Nonnull String path) { String[] parsedNodes = path.replace("M", "").split("/"); List<ChildNumber> nodes = new ArrayList<>(); for (String n : parsedNodes) { n = n.replaceAll(" ", ""); if (n.length() == 0) continue; boolean isHard = n.endsWith("H"); if (isHard) n = n.substring(0, n.length() - 1); int nodeNumber = Integer.parseInt(n); nodes.add(new ChildNumber(nodeNumber, isHard)); } return nodes; } }
HDUtils { public static List<ChildNumber> parsePath(@Nonnull String path) { String[] parsedNodes = path.replace("M", "").split("/"); List<ChildNumber> nodes = new ArrayList<>(); for (String n : parsedNodes) { n = n.replaceAll(" ", ""); if (n.length() == 0) continue; boolean isHard = n.endsWith("H"); if (isHard) n = n.substring(0, n.length() - 1); int nodeNumber = Integer.parseInt(n); nodes.add(new ChildNumber(nodeNumber, isHard)); } return nodes; }  }
HDUtils { public static List<ChildNumber> parsePath(@Nonnull String path) { String[] parsedNodes = path.replace("M", "").split("/"); List<ChildNumber> nodes = new ArrayList<>(); for (String n : parsedNodes) { n = n.replaceAll(" ", ""); if (n.length() == 0) continue; boolean isHard = n.endsWith("H"); if (isHard) n = n.substring(0, n.length() - 1); int nodeNumber = Integer.parseInt(n); nodes.add(new ChildNumber(nodeNumber, isHard)); } return nodes; }  static byte[] hmacSha512(byte[] key, byte[] data); static ImmutableList<ChildNumber> append(List<ChildNumber> path, ChildNumber childNumber); static ImmutableList<ChildNumber> concat(List<ChildNumber> path, List<ChildNumber> path2); static String formatPath(List<ChildNumber> path); static List<ChildNumber> parsePath(@Nonnull String path); }
HDUtils { public static List<ChildNumber> parsePath(@Nonnull String path) { String[] parsedNodes = path.replace("M", "").split("/"); List<ChildNumber> nodes = new ArrayList<>(); for (String n : parsedNodes) { n = n.replaceAll(" ", ""); if (n.length() == 0) continue; boolean isHard = n.endsWith("H"); if (isHard) n = n.substring(0, n.length() - 1); int nodeNumber = Integer.parseInt(n); nodes.add(new ChildNumber(nodeNumber, isHard)); } return nodes; }  static byte[] hmacSha512(byte[] key, byte[] data); static ImmutableList<ChildNumber> append(List<ChildNumber> path, ChildNumber childNumber); static ImmutableList<ChildNumber> concat(List<ChildNumber> path, List<ChildNumber> path2); static String formatPath(List<ChildNumber> path); static List<ChildNumber> parsePath(@Nonnull String path);  }