/** {@inheritDoc} */ @Override public ByteString normalizeValue(ByteSequence value) throws DirectoryException { StringBuilder buffer = new StringBuilder(); prepareUnicode(buffer, value, TRIM, CASE_FOLD); int bufferLength = buffer.length(); if (bufferLength == 0) { if (value.length() > 0) { // This should only happen if the value is composed entirely // of spaces. In that case, the normalized value is a single space. return SINGLE_SPACE_VALUE; } else { // The value is empty, so it is already normalized. return ByteString.empty(); } } // Replace any consecutive spaces with a single space. for (int pos = bufferLength - 1; pos > 0; pos--) { if (buffer.charAt(pos) == ' ') { if (buffer.charAt(pos - 1) == ' ') { buffer.delete(pos, pos + 1); } } } return ByteString.valueOf(buffer.toString()); }