class IndexLengthRestrictionEnforcer {

    public Optional<JsonValue> enforce(final JsonPointer pointer, final JsonValue value) {
        final int keyOverhead = jsonPointerBytes(pointer) + thingIdNamespaceOverhead;
        if (keyOverhead > MAX_INDEX_CONTENT_LENGTH - DEFAULT_VALUE_LENGTH) {
            // not possible to trim key-value pair; do not index this entry.
            return Optional.empty();
        } else if (value.isString()) {
            return Optional.of(fixViolation(value, keyOverhead));
        } else if (isNonEmptyComposite(value)) {
            // unexpected composite value - complain
            throw new IllegalArgumentException("value should not be an array or object but it is");
        } else {
            return Optional.of(value);
        }
    }

    private  IndexLengthRestrictionEnforcer(final String thingId);

}