/** * Create a new CQL identifier, optionally force-quoting it. Force-quoting can be used to preserve identifier case. * <ul> * <li>If the given identifier is a legal quoted identifier or {@code forceQuote} is <code>true</code>, * {@link #isQuoted()} will return {@code true} and the identifier will be quoted when rendered.</li> * <li>If the given identifier is a legal unquoted identifier, {@link #isQuoted()} will return {@code false}, plus the * name will be converted to lower case and rendered as such.</li> * <li>If the given identifier is illegal, an {@link IllegalArgumentException} is thrown.</li> * </ul> * * @see #of(CharSequence, boolean) * @see #quoted(CharSequence) */ private CqlIdentifier(CharSequence identifier, boolean forceQuote) { Assert.notNull(identifier, "Identifier must not be null"); String string = identifier.toString(); Assert.hasText(string, "Identifier must not be empty"); if (forceQuote || isQuotedIdentifier(string)) { this.unquoted = string; this.identifier = "\"" + string + "\""; this.quoted = true; } else if (isUnquotedIdentifier(string)) { this.identifier = this.unquoted = string.toLowerCase(); this.quoted = false; } else { throw new IllegalArgumentException( String.format("given string [%s] is not a valid quoted or unquoted identifier", identifier)); } }