Class Collation
java.lang.Object
org.springframework.data.mongodb.core.query.Collation
Central abstraction for MongoDB collation support.
Allows fluent creation of a collation
NOTE: Please keep in mind that queries will only make use of an index with collation settings if the query itself specifies the same collation.
Allows fluent creation of a collation
Document that can be used for creating collections & indexes as well as
querying data.
NOTE: Please keep in mind that queries will only make use of an index with collation settings if the query itself specifies the same collation.
- Since:
- 2.0
- Author:
- Christoph Strobl, Mark Paluch, Jens Schauder
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classstatic classICU locale abstraction for usage with MongoDBCollation.static interfaceAbstraction for the ICU Comparison Levels.static classPrimary-strengthCollation.ICUComparisonLevel.static classSecondary-strengthCollation.ICUComparisonLevel.static classTertiary-strengthCollation.ICUComparisonLevel. -
Method Summary
Modifier and TypeMethodDescriptionSet the Field that determines whether collation should consider whitespace and punctuation as base characters for purposes of comparison.alternate(Collation.Alternate alternate) Set the Field that determines whether collation should consider whitespace and punctuation as base characters for purposes of comparison.Sort string with diacritics sort from back of the string.backwards(boolean backwards) Set the flag that determines whether strings with diacritics sort from back of the string.Set the flag that determines sort order of case differences during tertiary level comparisons.caseFirst(Collation.CaseFirst sort) Set the flag that determines sort order of case differences during tertiary level comparisons.caseLevel(boolean caseLevel) Set whether to includecaseLevelcomparison.booleanDo not sort string with diacritics sort from back of the string.static Collationfrom(org.bson.Document source) Create newCollationfrom values inDocument.inthashCode()<R> @Nullable RmaxVariable(String maxVariable) Set the field that determines up to which characters are considered ignorable when alternate isshifted.normalization(boolean normalization) Set the flag that determines whether to check if text require normalization and to perform normalization.Disable text normalization.Enable text normalization.numericOrdering(boolean flag) Set the flag that determines whether to compare numeric strings as numbers or as strings.Treat numeric strings as string for comparison.Treat numeric strings as numbers for comparison.static CollationCreate newCollationwith locale set to the given ICU language.static Collationstatic Collationof(Collation.CollationLocale locale) Create newCollationwith locale set to the givenCollation.CollationLocale.static CollationParse the givencollationstring into aCollation.static Collationsimple()Create aCollationusing simple binary comparison.strength(int strength) Set the level of comparison to perform.strength(Collation.ComparisonLevel comparisonLevel) Set the level of comparison to perform.org.bson.DocumentGet theDocumentrepresentation of theCollation.@Nullable com.mongodb.client.model.CollationGet theCollationrepresentation of theCollation.toString()
-
Method Details
-
simple
Create aCollationusing simple binary comparison.- Returns:
- a
Collationfor simple binary comparison.
-
of
- Parameters:
locale- must not be null.- Returns:
- new instance of
Collation.
-
of
Create newCollationwith locale set to the given ICU language.- Parameters:
language- must not be null.- Returns:
- new instance of
Collation.
-
of
Create newCollationwith locale set to the givenCollation.CollationLocale.- Parameters:
locale- must not be null.- Returns:
- new instance of
Collation.
-
parse
Parse the givencollationstring into aCollation.- Parameters:
collation- the collation to parse. Can be a simple string likeen_USor aparsabledocument like{ 'locale' : '?0' }.- Returns:
- never null.
- Throws:
IllegalArgumentException- if collation is null.- Since:
- 2.2
-
from
Create newCollationfrom values inDocument.- Parameters:
source- must not be null.- Returns:
- new instance of
Collation. - See Also:
-
strength
Set the level of comparison to perform.- Parameters:
strength- comparison level.- Returns:
- new
Collation.
-
strength
Set the level of comparison to perform.- Parameters:
comparisonLevel- must not be null.- Returns:
- new
Collation
-
caseLevel
Set whether to includecaseLevelcomparison.- Parameters:
caseLevel- use true to enablecaseLevelcomparison.- Returns:
- new
Collation.
-
caseFirst
Set the flag that determines sort order of case differences during tertiary level comparisons.- Parameters:
caseFirst- must not be null.- Returns:
- new instance of
Collation.
-
caseFirst
Set the flag that determines sort order of case differences during tertiary level comparisons.- Parameters:
sort- must not be null.- Returns:
- new instance of
Collation.
-
numericOrderingEnabled
Treat numeric strings as numbers for comparison.- Returns:
- new
Collation.
-
numericOrderingDisabled
Treat numeric strings as string for comparison.- Returns:
- new
Collation.
-
numericOrdering
Set the flag that determines whether to compare numeric strings as numbers or as strings.- Returns:
- new
Collation.
-
alternate
Set the Field that determines whether collation should consider whitespace and punctuation as base characters for purposes of comparison.- Parameters:
alternate- must not be null.- Returns:
- new
Collation.
-
alternate
Set the Field that determines whether collation should consider whitespace and punctuation as base characters for purposes of comparison.- Parameters:
alternate- must not be null.- Returns:
- new
Collation.
-
backwardDiacriticSort
Sort string with diacritics sort from back of the string.- Returns:
- new
Collation.
-
forwardDiacriticSort
Do not sort string with diacritics sort from back of the string.- Returns:
- new
Collation.
-
backwards
Set the flag that determines whether strings with diacritics sort from back of the string.- Parameters:
backwards- must not be null.- Returns:
- new
Collation.
-
normalizationEnabled
Enable text normalization.- Returns:
- new
Collation.
-
normalizationDisabled
Disable text normalization.- Returns:
- new
Collation.
-
normalization
Set the flag that determines whether to check if text require normalization and to perform normalization.- Parameters:
normalization- must not be null.- Returns:
- new
Collation.
-
maxVariable
Set the field that determines up to which characters are considered ignorable when alternate isshifted.- Parameters:
maxVariable- must not be null.- Returns:
- new
Collation.
-
toDocument
public org.bson.Document toDocument()Get theDocumentrepresentation of theCollation.- Returns:
- the native MongoDB
Documentrepresentation of theCollation.
-
toMongoCollation
public @Nullable com.mongodb.client.model.Collation toMongoCollation()Get theCollationrepresentation of theCollation.- Returns:
- he native MongoDB representation of the
Collation.
-
map
- Type Parameters:
R-- Parameters:
mapper- must not be null.- Returns:
- the converted result.
-
toString
-
equals
-
hashCode
public int hashCode()
-