class CompositeUtils {

    public static String decrementBound(String orig) {
        // decrement string
        int[] codePoints = orig.codePoints().toArray();
        int length = codePoints.length;
        int lastCodePoint = codePoints[length - 1];
        while (lastCodePoint == Character.MIN_CODE_POINT) {
            if (length == 1)
                throw new RuntimeException("Cannot decrement bound without decreasing the number of characters.");
            codePoints[length - 1] = Character.MAX_CODE_POINT;
            lastCodePoint = codePoints[--length - 1];
        }
        
        // keep decrementing until we reach a valid code point
        while (!Character.isValidCodePoint(--lastCodePoint))
            ;
        codePoints[length - 1] = lastCodePoint;
        
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < codePoints.length; i++)
            sb.appendCodePoint(codePoints[i]);
        
        return sb.toString();
    }

}