Record Class FieldName

java.lang.Object
java.lang.Record
org.springframework.data.mongodb.core.mapping.FieldName

public record FieldName(String name, FieldName.Type type) extends Record
Value Object representing a field name that should be used to read/write fields within the MongoDB document. Field names field names may contain special characters (such as dot (.)) but may be treated differently depending on their type.
Since:
4.2
Author:
Christoph Strobl
  • Field Details

  • Constructor Details

    • FieldName

      public FieldName(String name, FieldName.Type type)
      Creates an instance of a FieldName record class.
      Parameters:
      name - the value for the name record component
      type - the value for the type record component
  • Method Details

    • name

      public static FieldName name(String value)
      Create a new FieldName that treats the given value as is.
      Parameters:
      value - must not be null.
      Returns:
      new instance of FieldName.
    • path

      public static FieldName path(String value)
      Create a new FieldName that treats the given value as a path. If the value contains dot (.) characters, they are considered deliminators in a path.
      Parameters:
      value - must not be null.
      Returns:
      new instance of FieldName.
    • parts

      public String[] parts()
      Get the parts the field name consists of. If the FieldName is a FieldName.Type.KEY or a FieldName.Type.PATH that does not contain dot (.) characters an array containing a single element is returned. Otherwise the name() is split into segments using dot (.) as a separator.
      Returns:
      never null.
    • isOfType

      public boolean isOfType(FieldName.Type type)
      Parameters:
      type - return true if the given FieldName.Type is equal to type().
      Returns:
      true if values are equal.
    • isKey

      public boolean isKey()
      Returns:
      whether the field name represents a key (i.e. as-is name).
    • isPath

      public boolean isPath()
      Returns:
      whether the field name represents a path (i.e. dot-path).
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • equals

      public boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • type

      public FieldName.Type type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component