@Test(expected = IllegalArgumentException.class) public void testCreateIdentifiersCharactersAfterNumber() { InstanceIdentifier.createIdentifiers(Stream.of("test(2)a")).count(); }
public static Stream<InstanceIdentifier> createIdentifiers(Stream<String> hostnameExpressions) { return hostnameExpressions.flatMap(hostnameExpression -> extractHostnames(hostnameExpression).flatMap(hostname -> { ExtractedRange extractedRange = new ExtractedRange(hostname, '(', ')'); if (extractedRange.range == null) { return Stream.of(new InstanceIdentifier(hostname, 1)); } if (!StringUtils.isEmpty(extractedRange.afterClose)) { throw new IllegalArgumentException("No characters expected after )"); } return extractedRange.range.map(numString -> new InstanceIdentifier(extractedRange.beforeOpen, Integer.parseInt(numString))); })); }
InstanceIdentifier { public static Stream<InstanceIdentifier> createIdentifiers(Stream<String> hostnameExpressions) { return hostnameExpressions.flatMap(hostnameExpression -> extractHostnames(hostnameExpression).flatMap(hostname -> { ExtractedRange extractedRange = new ExtractedRange(hostname, '(', ')'); if (extractedRange.range == null) { return Stream.of(new InstanceIdentifier(hostname, 1)); } if (!StringUtils.isEmpty(extractedRange.afterClose)) { throw new IllegalArgumentException("No characters expected after )"); } return extractedRange.range.map(numString -> new InstanceIdentifier(extractedRange.beforeOpen, Integer.parseInt(numString))); })); } }
InstanceIdentifier { public static Stream<InstanceIdentifier> createIdentifiers(Stream<String> hostnameExpressions) { return hostnameExpressions.flatMap(hostnameExpression -> extractHostnames(hostnameExpression).flatMap(hostname -> { ExtractedRange extractedRange = new ExtractedRange(hostname, '(', ')'); if (extractedRange.range == null) { return Stream.of(new InstanceIdentifier(hostname, 1)); } if (!StringUtils.isEmpty(extractedRange.afterClose)) { throw new IllegalArgumentException("No characters expected after )"); } return extractedRange.range.map(numString -> new InstanceIdentifier(extractedRange.beforeOpen, Integer.parseInt(numString))); })); } InstanceIdentifier(String hostname, int number); }
InstanceIdentifier { public static Stream<InstanceIdentifier> createIdentifiers(Stream<String> hostnameExpressions) { return hostnameExpressions.flatMap(hostnameExpression -> extractHostnames(hostnameExpression).flatMap(hostname -> { ExtractedRange extractedRange = new ExtractedRange(hostname, '(', ')'); if (extractedRange.range == null) { return Stream.of(new InstanceIdentifier(hostname, 1)); } if (!StringUtils.isEmpty(extractedRange.afterClose)) { throw new IllegalArgumentException("No characters expected after )"); } return extractedRange.range.map(numString -> new InstanceIdentifier(extractedRange.beforeOpen, Integer.parseInt(numString))); })); } 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(); }
InstanceIdentifier { public static Stream<InstanceIdentifier> createIdentifiers(Stream<String> hostnameExpressions) { return hostnameExpressions.flatMap(hostnameExpression -> extractHostnames(hostnameExpression).flatMap(hostname -> { ExtractedRange extractedRange = new ExtractedRange(hostname, '(', ')'); if (extractedRange.range == null) { return Stream.of(new InstanceIdentifier(hostname, 1)); } if (!StringUtils.isEmpty(extractedRange.afterClose)) { throw new IllegalArgumentException("No characters expected after )"); } return extractedRange.range.map(numString -> new InstanceIdentifier(extractedRange.beforeOpen, Integer.parseInt(numString))); })); } 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; }