public final class NormalizedString extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<NormalizedString>, java.lang.CharSequence
NormalizedString
allows representing text in a normalized fashion. Strings
with different character case or surrounding whitespace are considered the same.
Used to represent groups of fields, where users may refer to their names using
different character cases or whitespaces.
Where the character case or the surrounding space is relevant, the NormalizedString
will have its isLiteral()
method return true
, meaning the exact
character case and surrounding whitespaces are required for matching it.
Invoking valueOf(String)
with a String
surrounded by single quotes
will create a literal NormalizedString
. Use literalValueOf(String)
to obtain the same NormalizedString
without having to introduce single quotes.Modifier and Type | Field and Description |
---|---|
private int |
hashCode |
private boolean |
literal |
private java.lang.String |
normalized |
private java.lang.String |
original |
private static long |
serialVersionUID |
private static StringCache<NormalizedString> |
stringCache |
Modifier | Constructor and Description |
---|---|
private |
NormalizedString(java.lang.String string) |
Modifier and Type | Method and Description |
---|---|
char |
charAt(int index) |
int |
compareTo(NormalizedString o) |
int |
compareTo(java.lang.String o)
Compares a
NormalizedString against a String lexicographically. |
boolean |
equals(java.lang.Object anObject) |
static StringCache<NormalizedString> |
getCache()
Returns the internal string cache to allow users to tweak its size limit or clear it when appropriate
|
private static <T extends java.util.Collection<NormalizedString>> |
getCollection(T out,
java.util.Collection<java.lang.String> args) |
private static <T extends java.util.Collection<java.lang.String>> |
getCollection(T out,
NormalizedString... args) |
private static <T extends java.util.Collection<NormalizedString>> |
getCollection(T out,
java.lang.String... args) |
private static <T extends java.util.Collection<java.lang.String>> |
getStringCollection(T out,
java.util.Collection<NormalizedString> args) |
int |
hashCode() |
static boolean |
identifyLiterals(NormalizedString[] strings)
Analyzes a group of NormalizedString to identify any instances whose normalized content will generate
clashes.
|
static boolean |
identifyLiterals(NormalizedString[] strings,
boolean lowercaseIdentifiers,
boolean uppercaseIdentifiers)
Analyzes a group of NormalizedString to identify any instances whose normalized content will generate
clashes.
|
boolean |
isLiteral() |
int |
length() |
static NormalizedString |
literalValueOf(java.lang.String string)
Creates a literal
NormalizedString , meaning it will only match with
other String or NormalizedString if they have the exact same content
including character case and surrounding whitespaces. |
private java.lang.String |
normalize(java.lang.Object value) |
private static boolean |
shouldBeLiteral(java.lang.String string,
boolean lowercaseIdentifiers,
boolean uppercaseIdentifiers) |
java.lang.CharSequence |
subSequence(int start,
int end) |
static NormalizedString[] |
toArray(java.util.Collection<java.lang.String> args)
Converts a collection of plain strings into an array of
NormalizedString |
static java.lang.String[] |
toArray(NormalizedString... args)
Converts multiple normalized strings into an array of
String . |
static NormalizedString[] |
toArray(java.lang.String... args)
Converts multiple plain strings into an array of
NormalizedString . |
static java.util.ArrayList<NormalizedString> |
toArrayList(java.util.Collection<java.lang.String> args)
Converts multiple plain strings into an
ArrayList of NormalizedString . |
static java.util.ArrayList<NormalizedString> |
toArrayList(java.lang.String... args)
Converts multiple plain strings into an
ArrayList of NormalizedString . |
static java.util.ArrayList<java.lang.String> |
toArrayListOfStrings(java.util.Collection<NormalizedString> args)
Converts multiple normalized strings into a
HashSet of String . |
static java.util.ArrayList<java.lang.String> |
toArrayListOfStrings(NormalizedString... args)
Converts multiple normalized strings into a
HashSet of String . |
static java.util.HashSet<NormalizedString> |
toHashSet(java.util.Collection<java.lang.String> args)
Converts multiple plain strings into a
HashSet of NormalizedString . |
static java.util.HashSet<NormalizedString> |
toHashSet(java.lang.String... args)
Converts multiple plain strings into a
HashSet of NormalizedString . |
static java.util.HashSet<java.lang.String> |
toHashSetOfStrings(java.util.Collection<NormalizedString> args)
Converts multiple normalized strings into a
HashSet of String . |
static java.util.HashSet<java.lang.String> |
toHashSetOfStrings(NormalizedString... args)
Converts multiple normalized strings into a
HashSet of String . |
static NormalizedString[] |
toIdentifierGroupArray(NormalizedString[] strings)
Analyzes a group of NormalizedString to identify any instances whose normalized content will generate
clashes.
|
static NormalizedString[] |
toIdentifierGroupArray(java.lang.String[] strings)
Analyzes a group of String to identify any instances whose normalized content will generate
clashes.
|
static java.util.LinkedHashSet<NormalizedString> |
toLinkedHashSet(java.util.Collection<java.lang.String> args)
Converts multiple plain strings into a
LinkedHashSet of NormalizedString . |
static java.util.LinkedHashSet<NormalizedString> |
toLinkedHashSet(java.lang.String... args)
Converts multiple plain strings into a
LinkedHashSet of NormalizedString . |
static java.util.LinkedHashSet<java.lang.String> |
toLinkedHashSetOfStrings(java.util.Collection<NormalizedString> args)
Converts multiple normalized strings into a
LinkedHashSet of String . |
static java.util.LinkedHashSet<java.lang.String> |
toLinkedHashSetOfStrings(NormalizedString... args)
Converts multiple normalized strings into a
LinkedHashSet of String . |
NormalizedString |
toLiteral()
Returns the literal representation of this
NormalizedString , meaning it will only match with
other String or NormalizedString if they have the exact same content
including character case and surrounding whitespaces. |
java.lang.String |
toString() |
static java.lang.String[] |
toStringArray(java.util.Collection<NormalizedString> args)
Converts a collection of normalized strings into an array of
String |
static java.util.TreeSet<NormalizedString> |
toTreeSet(java.util.Collection<java.lang.String> args)
Converts multiple plain strings into a
TreeSet of NormalizedString . |
static java.util.TreeSet<NormalizedString> |
toTreeSet(java.lang.String... args)
Converts multiple plain strings into a
TreeSet of NormalizedString . |
static java.util.TreeSet<java.lang.String> |
toTreeSetOfStrings(java.util.Collection<NormalizedString> args)
Converts multiple normalized strings into a
HashSet of String . |
static java.util.TreeSet<java.lang.String> |
toTreeSetOfStrings(NormalizedString... args)
Converts multiple normalized strings into a
HashSet of String . |
static NormalizedString[] |
toUniqueArray(java.lang.String... args)
Converts multiple plain strings into an array of
NormalizedString , ensuring
no duplicate NormalizedString elements exist, even if their original String s
are different. |
static java.lang.String |
valueOf(NormalizedString string)
Converts a
NormalizedString back to its original String representation |
static NormalizedString |
valueOf(java.lang.Object o)
Creates a non-literal
NormalizedString , meaning it will match with
other String or NormalizedString regardless of different
including character case and surrounding whitespaces. |
static NormalizedString |
valueOf(java.lang.String string)
Creates a non-literal
NormalizedString , meaning it will match with
other String or NormalizedString regardless of different
including character case and surrounding whitespaces. |
private static final long serialVersionUID
private static final StringCache<NormalizedString> stringCache
private final java.lang.String original
private final java.lang.String normalized
private final boolean literal
private final int hashCode
private java.lang.String normalize(java.lang.Object value)
public boolean isLiteral()
public boolean equals(java.lang.Object anObject)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public int length()
length
in interface java.lang.CharSequence
public char charAt(int index)
charAt
in interface java.lang.CharSequence
public java.lang.CharSequence subSequence(int start, int end)
subSequence
in interface java.lang.CharSequence
public int compareTo(NormalizedString o)
compareTo
in interface java.lang.Comparable<NormalizedString>
public int compareTo(java.lang.String o)
NormalizedString
against a String
lexicographically.o
- a plain String
String.compareTo(String)
. If this NormalizedString
is a literal, the original argument string will be compared. If this NormalizedString
is not a literal, the result will be from the comparison of the normalized content of both strings
(i.e. surrounding whitespaces and character case differences will be ignored).public java.lang.String toString()
toString
in interface java.lang.CharSequence
toString
in class java.lang.Object
public static NormalizedString literalValueOf(java.lang.String string)
NormalizedString
, meaning it will only match with
other String
or NormalizedString
if they have the exact same content
including character case and surrounding whitespaces.string
- the input String
NormalizedString
version of the given string.public static NormalizedString valueOf(java.lang.Object o)
NormalizedString
, meaning it will match with
other String
or NormalizedString
regardless of different
including character case and surrounding whitespaces.
If the input value is enclosed with single quotes, a literal NormalizedString
will be returned, as described in literalValueOf(String)
o
- the input object whose String
representation will be usedNormalizedString
of the given object.public static NormalizedString valueOf(java.lang.String string)
NormalizedString
, meaning it will match with
other String
or NormalizedString
regardless of different
including character case and surrounding whitespaces.
If the input string is enclosed with single quotes, a literal NormalizedString
will be returned, as described in literalValueOf(String)
string
- the input stringNormalizedString
of the given string.public static java.lang.String valueOf(NormalizedString string)
NormalizedString
back to its original String
representationstring
- the normalized stringpublic static NormalizedString[] toArray(java.util.Collection<java.lang.String> args)
NormalizedString
args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static java.lang.String[] toStringArray(java.util.Collection<NormalizedString> args)
String
args
- the normalized strings to convert back to to String
String
representations of all normalized strings.public static NormalizedString[] toUniqueArray(java.lang.String... args)
NormalizedString
, ensuring
no duplicate NormalizedString
elements exist, even if their original String
s
are different.args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static NormalizedString[] toArray(java.lang.String... args)
NormalizedString
.args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static java.lang.String[] toArray(NormalizedString... args)
String
.args
- the normalized strings to convert to String
String
representations of all input strings.private static <T extends java.util.Collection<NormalizedString>> T getCollection(T out, java.lang.String... args)
private static <T extends java.util.Collection<NormalizedString>> T getCollection(T out, java.util.Collection<java.lang.String> args)
private static <T extends java.util.Collection<java.lang.String>> T getCollection(T out, NormalizedString... args)
private static <T extends java.util.Collection<java.lang.String>> T getStringCollection(T out, java.util.Collection<NormalizedString> args)
public static java.util.ArrayList<NormalizedString> toArrayList(java.lang.String... args)
ArrayList
of NormalizedString
.args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static java.util.ArrayList<NormalizedString> toArrayList(java.util.Collection<java.lang.String> args)
ArrayList
of NormalizedString
.args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static java.util.ArrayList<java.lang.String> toArrayListOfStrings(NormalizedString... args)
HashSet
of String
.args
- the normalized strings to convert to String
String
s of all input normalized strings.public static java.util.ArrayList<java.lang.String> toArrayListOfStrings(java.util.Collection<NormalizedString> args)
HashSet
of String
.args
- the normalized strings to convert to String
String
s of all input normalized strings.public static java.util.TreeSet<NormalizedString> toTreeSet(java.lang.String... args)
TreeSet
of NormalizedString
.args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static java.util.TreeSet<NormalizedString> toTreeSet(java.util.Collection<java.lang.String> args)
TreeSet
of NormalizedString
.args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static java.util.TreeSet<java.lang.String> toTreeSetOfStrings(NormalizedString... args)
HashSet
of String
.args
- the normalized strings to convert to String
String
s of all input normalized strings.public static java.util.TreeSet<java.lang.String> toTreeSetOfStrings(java.util.Collection<NormalizedString> args)
HashSet
of String
.args
- the normalized strings to convert to String
String
s of all input normalized strings.public static java.util.HashSet<NormalizedString> toHashSet(java.lang.String... args)
HashSet
of NormalizedString
.args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static java.util.HashSet<NormalizedString> toHashSet(java.util.Collection<java.lang.String> args)
HashSet
of NormalizedString
.args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static java.util.HashSet<java.lang.String> toHashSetOfStrings(NormalizedString... args)
HashSet
of String
.args
- the normalized strings to convert to String
String
s of all input normalized strings.public static java.util.HashSet<java.lang.String> toHashSetOfStrings(java.util.Collection<NormalizedString> args)
HashSet
of String
.args
- the normalized strings to convert to String
String
s of all input normalized strings.public static java.util.LinkedHashSet<NormalizedString> toLinkedHashSet(java.lang.String... args)
LinkedHashSet
of NormalizedString
.args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static java.util.LinkedHashSet<NormalizedString> toLinkedHashSet(java.util.Collection<java.lang.String> args)
LinkedHashSet
of NormalizedString
.args
- the strings to convert to NormalizedString
NormalizedString
representations of all input strings.public static java.util.LinkedHashSet<java.lang.String> toLinkedHashSetOfStrings(NormalizedString... args)
LinkedHashSet
of String
.args
- the normalized strings to convert to String
String
s of all input normalized strings.public static java.util.LinkedHashSet<java.lang.String> toLinkedHashSetOfStrings(java.util.Collection<NormalizedString> args)
LinkedHashSet
of String
.args
- the normalized strings to convert to String
String
s of all input normalized strings.public NormalizedString toLiteral()
NormalizedString
, meaning it will only match with
other String
or NormalizedString
if they have the exact same content
including character case and surrounding whitespaces.NormalizedString
public static NormalizedString[] toIdentifierGroupArray(NormalizedString[] strings)
toLiteral()
),
making it possible to identify one from the other.strings
- a group of identifiers that may contain ambiguous entries if their character case or surrounding whitespaces is not considered.
This array will be modified.NormalizedString
literals in the positions where clashes would originally occur.public static NormalizedString[] toIdentifierGroupArray(java.lang.String[] strings)
toLiteral()
),
making it possible to identify one from the other.strings
- a group of identifiers that may contain ambiguous entries if their character case or surrounding whitespaces is not considered.NormalizedString
array with literals in the positions where clashes would originally occur.public static boolean identifyLiterals(NormalizedString[] strings)
toLiteral()
),
making it possible to identify one from the other.strings
- a group of identifiers that may contain ambiguous entries if their character case or surrounding whitespaces is not considered.
This array will be modified.true
if any entry has been modified to be a literal, otherwise false
public static boolean identifyLiterals(NormalizedString[] strings, boolean lowercaseIdentifiers, boolean uppercaseIdentifiers)
toLiteral()
),
making it possible to identify one from the other.strings
- a group of identifiers that may contain ambiguous entries if their character case or surrounding whitespaces is not considered.
This array will be modified.lowercaseIdentifiers
- flag indicating that identifiers are stored in lower case (for compatibility with databases).
If a string has a uppercase character, it means it must become a literal.uppercaseIdentifiers
- flag indicating that identifiers are stored in upper case (for compatibility with databases).
If a string has a lowercase character, it means it must become a literal.true
if any entry has been modified to be a literal, otherwise false
private static boolean shouldBeLiteral(java.lang.String string, boolean lowercaseIdentifiers, boolean uppercaseIdentifiers)
public static StringCache<NormalizedString> getCache()
NormalizedString
instances associated with their original String
.