Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ public static CompositeKey parseCompositeKey(final String compositeKey) {
throw CompositeKeyFormatException.forInputString(compositeKey, compositeKey, 0);
}
// relying on the fact that NAMESPACE == DELIMETER
final String[] segments = compositeKey.split(DELIMITER, 0);
return new CompositeKey(segments[1], Arrays.stream(segments).skip(2).toArray(String[]::new));
// keep empty segments so that empty attributes are preserved
final String[] segments = compositeKey.split(DELIMITER, -1);
// the final delimiter terminates the last attribute, so the empty segment after it is not an attribute
final int end = compositeKey.endsWith(DELIMITER) ? segments.length - 1 : segments.length;
return new CompositeKey(segments[1], Arrays.copyOfRange(segments, 2, Math.max(2, end)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ void testParseCompositeKey() {
assertThat(key.toString(), is(equalTo("\u0000abc\u0000def\u0000ghi\u0000jkl\u0000mno\u0000")));
}

@Test
void testParseCompositeKeyWithEmptyAttributes() {
final CompositeKey key = CompositeKey.parseCompositeKey("\u0000abc\u0000\u0000def\u0000\u0000\u0000");
assertThat(key.getObjectType(), is(equalTo("abc")));
assertThat(key.getAttributes(), contains("", "def", "", ""));
assertThat(key.toString(), is(equalTo("\u0000abc\u0000\u0000def\u0000\u0000\u0000")));
}

@Test
void testParseCompositeKeyWithEmptyObjectType() {
final CompositeKey key = CompositeKey.parseCompositeKey("\u0000\u0000");
assertThat(key.getObjectType(), is(equalTo("")));
assertThat(key.getAttributes(), hasSize(0));
assertThat(key.toString(), is(equalTo("\u0000\u0000")));
}

@Test
void testParseCompositeKeyInvalidObjectType() {
assertThatThrownBy(() ->
Expand Down