### Question:
InstanceIdentifier { public static Map<InstanceIdentifier, Integer> createOrderMap(Stream<String> hostnameExpressions) { List<InstanceIdentifier> instanceIdentifiers = createIdentifiers(hostnameExpressions).sorted(HOST_IDENTIFIER_COMPARATOR).collect(Collectors.toList()); Map<InstanceIdentifier, Integer> result = new HashMap<>(); for (int i = 0; i < instanceIdentifiers.size(); i++) { result.put(instanceIdentifiers.get(i), i + 1); } return result; } InstanceIdentifier(String hostname, int number); static Map<InstanceIdentifier, Integer> createOrderMap(Stream<String> hostnameExpressions); static Stream<InstanceIdentifier> createIdentifiers(Stream<String> hostnameExpressions); String getHostname(); int getNumber(); @Override boolean equals(Object o); @Override int hashCode(); static final Comparator<InstanceIdentifier> HOST_IDENTIFIER_COMPARATOR; }### Answer:
@Test public void testCreateOrderMap() { String abc123 = "abc[1-3]"; String abc0123 = "abc[01-3]"; String b = "b"; Map<InstanceIdentifier, Integer> orderMap = InstanceIdentifier.createOrderMap(Stream.of(abc123, abc0123 + "(2)", b)); AtomicInteger num = new AtomicInteger(1); Consumer<InstanceIdentifier> action = id -> { int i = num.getAndIncrement(); assertEquals(i, orderMap.get(id).intValue()); }; InstanceIdentifier.extractHostnames(abc0123).flatMap(s -> Stream.of(new InstanceIdentifier(s, 1), new InstanceIdentifier(s, 2))).forEach(action); InstanceIdentifier.extractHostnames(abc123).map(s -> new InstanceIdentifier(s, 1)).forEach(action); InstanceIdentifier.extractHostnames(b).map(s -> new InstanceIdentifier(s, 1)).forEach(action); }