Record Class FieldName
java.lang.Object
java.lang.Record
org.springframework.data.mongodb.core.mapping.FieldName
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
-
Field Summary
-
Constructor Summary
ConstructorDescriptionFieldName
(String name, FieldName.Type type) Creates an instance of aFieldName
record class. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Indicates whether some other object is "equal to" this one.int
hashCode()
Returns a hash code value for this object.boolean
isKey()
boolean
isOfType
(FieldName.Type type) boolean
isPath()
name()
Returns the value of thename
record component.static FieldName
Create a newFieldName
that treats the given value as is.String[]
parts()
Get the parts the field name consists of.static FieldName
Create a newFieldName
that treats the given value as a path.toString()
Returns a string representation of this record class.type()
Returns the value of thetype
record component.
-
Field Details
-
ID
-
-
Constructor Details
-
FieldName
Creates an instance of aFieldName
record class.- Parameters:
name
- the value for thename
record componenttype
- the value for thetype
record component
-
-
Method Details
-
name
Create a newFieldName
that treats the given value as is.- Parameters:
value
- must not be null.- Returns:
- new instance of
FieldName
.
-
path
Create a newFieldName
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
Get the parts the field name consists of. If theFieldName
is aFieldName.Type.KEY
or aFieldName.Type.PATH
that does not contain dot (.) characters an array containing a single element is returned. Otherwise thename()
is split into segments using dot (.) as a separator.- Returns:
- never null.
-
isOfType
- Parameters:
type
- return true if the givenFieldName.Type
is equal totype()
.- 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
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. -
equals
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 withObjects::equals(Object,Object)
. -
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. -
name
Returns the value of thename
record component.- Returns:
- the value of the
name
record component
-
type
Returns the value of thetype
record component.- Returns:
- the value of the
type
record component
-