java.lang.Object
org.springframework.data.mongodb.core.query.Collation

public class Collation extends Object
Central abstraction for MongoDB collation support.
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:
  • Method Details

    • simple

      public static Collation simple()
      Create a Collation using simple binary comparison.
      Returns:
      a Collation for simple binary comparison.
    • of

      public static Collation of(Locale locale)
      Create new Collation with locale set to {Locale.getLanguage()} and Locale.getVariant().
      Parameters:
      locale - must not be null.
      Returns:
      new instance of Collation.
    • of

      public static Collation of(String language)
      Create new Collation with locale set to the given ICU language.
      Parameters:
      language - must not be null.
      Returns:
      new instance of Collation.
    • of

      public static Collation of(Collation.CollationLocale locale)
      Create new Collation with locale set to the given Collation.CollationLocale.
      Parameters:
      locale - must not be null.
      Returns:
      new instance of Collation.
    • parse

      public static Collation parse(String collation)
      Parse the given collation string into a Collation.
      Parameters:
      collation - the collation to parse. Can be a simple string like en_US or a parsable document like { 'locale' : '?0' } .
      Returns:
      never null.
      Throws:
      IllegalArgumentException - if collation is null.
      Since:
      2.2
    • from

      public static Collation from(org.bson.Document source)
      Create new Collation from values in Document.
      Parameters:
      source - must not be null.
      Returns:
      new instance of Collation.
      See Also:
    • strength

      public Collation strength(int strength)
      Set the level of comparison to perform.
      Parameters:
      strength - comparison level.
      Returns:
      new Collation.
    • strength

      public Collation strength(Collation.ComparisonLevel comparisonLevel)
      Set the level of comparison to perform.
      Parameters:
      comparisonLevel - must not be null.
      Returns:
      new Collation
    • caseLevel

      public Collation caseLevel(boolean caseLevel)
      Set whether to include caseLevel comparison.
      Parameters:
      caseLevel - use true to enable caseLevel comparison.
      Returns:
      new Collation.
    • caseFirst

      public Collation caseFirst(String 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

      public Collation caseFirst(Collation.CaseFirst sort)
      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

      public Collation numericOrderingEnabled()
      Treat numeric strings as numbers for comparison.
      Returns:
      new Collation.
    • numericOrderingDisabled

      public Collation numericOrderingDisabled()
      Treat numeric strings as string for comparison.
      Returns:
      new Collation.
    • numericOrdering

      public Collation numericOrdering(boolean flag)
      Set the flag that determines whether to compare numeric strings as numbers or as strings.
      Returns:
      new Collation.
    • alternate

      public Collation alternate(String 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

      public Collation alternate(Collation.Alternate 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

      public Collation backwardDiacriticSort()
      Sort string with diacritics sort from back of the string.
      Returns:
      new Collation.
    • forwardDiacriticSort

      public Collation forwardDiacriticSort()
      Do not sort string with diacritics sort from back of the string.
      Returns:
      new Collation.
    • backwards

      public Collation backwards(boolean 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

      public Collation normalizationEnabled()
      Enable text normalization.
      Returns:
      new Collation.
    • normalizationDisabled

      public Collation normalizationDisabled()
      Disable text normalization.
      Returns:
      new Collation.
    • normalization

      public Collation normalization(boolean 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

      public Collation maxVariable(String maxVariable)
      Set the field that determines up to which characters are considered ignorable when alternate is shifted.
      Parameters:
      maxVariable - must not be null.
      Returns:
      new Collation.
    • toDocument

      public org.bson.Document toDocument()
      Get the Document representation of the Collation.
      Returns:
      the native MongoDB Document representation of the Collation.
    • toMongoCollation

      public com.mongodb.client.model.Collation toMongoCollation()
      Get the Collation representation of the Collation.
      Returns:
      he native MongoDB representation of the Collation.
    • map

      public <R> R map(Converter<? super Collation,? extends R> mapper)
      Transform this Collation by applying a Converter.
      Type Parameters:
      R -
      Parameters:
      mapper - must not be null.
      Returns:
      the converted result.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object