class ImmutableJsonPointer implements JsonPointer {

    public static JsonPointer ofParsed(final CharSequence slashDelimitedCharSequence) {
        requireNonNull(slashDelimitedCharSequence, "The JSON pointer character sequence must not be null!");

        final JsonPointer result;

        if (JsonPointer.class.isAssignableFrom(slashDelimitedCharSequence.getClass())) {
            result = (JsonPointer) slashDelimitedCharSequence;
        } else if (JsonKey.class.isAssignableFrom(slashDelimitedCharSequence.getClass())) {
            result = newInstance(Collections.singletonList(((JsonKey) slashDelimitedCharSequence)));
        } else if (0 == slashDelimitedCharSequence.length()) {
            result = empty();
        } else if (DOUBLE_SLASH_PATTERN.matcher(slashDelimitedCharSequence).find()) {
            throw JsonPointerInvalidException.newBuilderForConsecutiveSlashes(slashDelimitedCharSequence)
                    .build();
        } else {
            final List<JsonKey> jsonKeys = Stream.of(SINGLE_SLASH_REGEX_PATTERN.split(slashDelimitedCharSequence))
                    .filter(keyName -> !keyName.isEmpty()) // ignore empty segments
                    .map(ImmutableJsonPointer::decodeTilde)
                    .map(JsonFactory::newKey)
                    .collect(toList());

            result = newInstance(jsonKeys);
        }

        return result;
    }

    private  ImmutableJsonPointer(final List<JsonKey> theJsonKeys);

}