org.apache.cassandra.db.marshal

## Class AbstractType<T>

- java.lang.Object
- - org.apache.cassandra.db.marshal.AbstractType<T>

- All Implemented Interfaces:
    java.util.Comparator<java.nio.ByteBuffer>, AssignmentTestable
  Direct Known Subclasses:
    AbstractCompositeType, AsciiType, BooleanType, BytesType, ByteType, CollectionType, ColumnToCollectionType, CounterColumnType, DateType, DecimalType, DoubleType, DurationType, EmptyType, FloatType, FrozenType, InetAddressType, Int32Type, IntegerType, LexicalUUIDType, LongType, PartitionerDefinedOrder, ReversedType, ShortType, SimpleDateType, TimestampType, TimeType, TimeUUIDType, TupleType, UTF8Type, UUIDType

      public abstract class AbstractType<T>
      extends java.lang.Object
      implements java.util.Comparator<java.nio.ByteBuffer>, AssignmentTestable

  Specifies a Comparator for a specific type of ByteBuffer. Note that empty ByteBuffer are used to represent "start at the beginning" or "stop at the end" arguments to get_slice, so the Comparator should always handle those values even if they normally do not represent a valid ByteBuffer for the type being compared.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `AbstractType.ComparisonType`

    - ### Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.AssignmentTestable

      `AssignmentTestable.TestResult`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `AbstractType.ComparisonType` | `comparisonType`
    `boolean` | `isByteOrderComparable`
    `java.util.Comparator<java.nio.ByteBuffer>` | `reverseComparator`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractType(AbstractType.ComparisonType comparisonType)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `CQL3Type` | `asCQL3Type()`
    `static java.util.List<java.lang.String>` | `asCQLTypeStringList(java.util.List<AbstractType<?>> abstractTypes)`
    `void` | `checkComparable()`
    `int` | `compare(java.nio.ByteBuffer left, java.nio.ByteBuffer right)`
    `int` | `compareCollectionMembers(java.nio.ByteBuffer v1, java.nio.ByteBuffer v2, java.nio.ByteBuffer collectionName)` An alternative comparison function used by CollectionsType in conjunction with CompositeType.
    `int` | `compareCustom(java.nio.ByteBuffer left, java.nio.ByteBuffer right)` Implement IFF ComparisonType is CUSTOM Compares the ByteBuffer representation of two instances of this class, for types where this cannot be done by simple in-order comparison of the unsigned bytes Standard Java compare semantics
    `int` | `compareForCQL(java.nio.ByteBuffer v1, java.nio.ByteBuffer v2)` Same as compare except that this ignore ReversedType.
    `int` | `componentsCount()` The number of subcomponents this type has.
    `T` | `compose(java.nio.ByteBuffer bytes)`
    `java.nio.ByteBuffer` | `decompose(T value)`
    `boolean` | `equals(java.lang.Object other, boolean ignoreFreezing)` Checks to see if two types are equal when ignoring or not ignoring differences in being frozen, depending on the value of the ignoreFreezing parameter.
    `AbstractType<?>` | `freeze()`
    `AbstractType<?>` | `freezeNestedMulticellTypes()` Returns an AbstractType instance that is equivalent to this one, but with all nested UDTs and collections explicitly frozen.
    `abstract Term` | `fromJSONObject(java.lang.Object parsed)` Given a parsed JSON string, return a byte representation of the object.
    `abstract java.nio.ByteBuffer` | `fromString(java.lang.String source)` get a byte representation of the given string.
    `java.util.List<AbstractType<?>>` | `getComponents()` Return a list of the "subcomponents" this type has.
    `abstract TypeSerializer<T>` | `getSerializer()`
    `java.lang.String` | `getString(java.nio.ByteBuffer bytes)` get a string representation of the bytes used for various identifier (NOT just for log messages)
    `java.lang.String` | `getString(java.util.Collection<java.nio.ByteBuffer> names)`
    `boolean` | `isCollection()`
    `boolean` | `isCompatibleWith(AbstractType<?> previous)` Returns true if this comparator is compatible with the provided previous comparator, that is if previous can safely be replaced by this.
    `boolean` | `isCounter()`
    `boolean` | `isEmptyValueMeaningless()` Returns `true` for types where empty should be handled like `null` like `Int32Type`.
    `boolean` | `isFreezable()`
    `boolean` | `isFrozenCollection()`
    `boolean` | `isMultiCell()`
    `boolean` | `isReversed()`
    `boolean` | `isTuple()`
    `boolean` | `isUDT()`
    `boolean` | `isValueCompatibleWith(AbstractType<?> otherType)` Returns true if values of the other AbstractType can be read and "reasonably" interpreted by the this AbstractType.
    `protected boolean` | `isValueCompatibleWithInternal(AbstractType<?> otherType)` Needed to handle ReversedType in value-compatibility checks.
    `static AbstractType<?>` | `parseDefaultParameters(AbstractType<?> baseType, TypeParser parser)`
    `java.nio.ByteBuffer` | `readValue(DataInputPlus in)`
    `java.nio.ByteBuffer` | `readValue(DataInputPlus in, int maxValueSize)`
    `boolean` | `referencesDuration()`
    `boolean` | `referencesUserType(java.lang.String userTypeName)`
    `void` | `skipValue(DataInputPlus in)`
    `AssignmentTestable.TestResult` | `testAssignment(java.lang.String keyspace, ColumnSpecification receiver)`
    `java.lang.String` | `toJSONString(java.nio.ByteBuffer buffer, ProtocolVersion protocolVersion)` Converts the specified value into its JSON representation.
    `java.lang.String` | `toString()` This must be overriden by subclasses if necessary so that for any AbstractType, this == TypeParser.parse(toString()).
    `java.lang.String` | `toString(boolean ignoreFreezing)`
    `void` | `validate(java.nio.ByteBuffer bytes)`
    `void` | `validateCellValue(java.nio.ByteBuffer cellValue)` Validate cell value.
    `void` | `validateCollectionMember(java.nio.ByteBuffer bytes, java.nio.ByteBuffer collectionName)` An alternative validation function used by CollectionsType in conjunction with CompositeType.
    `protected int` | `valueLengthIfFixed()` The length of values for this type if all values are of fixed length, -1 otherwise.
    `void` | `writeValue(java.nio.ByteBuffer value, DataOutputPlus out)`
    `long` | `writtenLength(java.nio.ByteBuffer value)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Comparator

      `comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

- - ### Field Detail

    - #### reverseComparator

          public final java.util.Comparator<java.nio.ByteBuffer> reverseComparator

    - #### comparisonType

          public final AbstractType.ComparisonType comparisonType

    - #### isByteOrderComparable

          public final boolean isByteOrderComparable

  - ### Constructor Detail

    - #### AbstractType

          protected AbstractType(AbstractType.ComparisonType comparisonType)

  - ### Method Detail

    - #### asCQLTypeStringList

          public static java.util.List<java.lang.String> asCQLTypeStringList(java.util.List<AbstractType<?>> abstractTypes)

    - #### compose

          public T compose(java.nio.ByteBuffer bytes)

    - #### decompose

          public java.nio.ByteBuffer decompose(T value)

    - #### getString

          public java.lang.String getString(java.nio.ByteBuffer bytes)

      get a string representation of the bytes used for various identifier (NOT just for log messages)

    - #### fromString

          public abstract java.nio.ByteBuffer fromString(java.lang.String source)
                                                  throws MarshalException

      get a byte representation of the given string.
      Throws:
        `MarshalException`

    - #### fromJSONObject

          public abstract Term fromJSONObject(java.lang.Object parsed)
                                       throws MarshalException

      Given a parsed JSON string, return a byte representation of the object.
      Parameters:
        `parsed` - the result of parsing a json string
      Throws:
        `MarshalException`

    - #### toJSONString

          public java.lang.String toJSONString(java.nio.ByteBuffer buffer,
                                               ProtocolVersion protocolVersion)

      Converts the specified value into its JSON representation.

      The buffer position will stay the same.

      Parameters:
        `buffer` - the value to convert
        `protocolVersion` - the protocol version to use for the conversion
      Returns:
        a JSON string representing the specified value

    - #### validate

          public void validate(java.nio.ByteBuffer bytes)
                        throws MarshalException

      Throws:
        `MarshalException`

    - #### compare

          public final int compare(java.nio.ByteBuffer left,
                                   java.nio.ByteBuffer right)

      Specified by:
        `compare` in interface `java.util.Comparator<java.nio.ByteBuffer>`

    - #### compareCustom

          public int compareCustom(java.nio.ByteBuffer left,
                                   java.nio.ByteBuffer right)

      Implement IFF ComparisonType is CUSTOM Compares the ByteBuffer representation of two instances of this class, for types where this cannot be done by simple in-order comparison of the unsigned bytes Standard Java compare semantics

    - #### validateCellValue

          public void validateCellValue(java.nio.ByteBuffer cellValue)
                                 throws MarshalException

      Validate cell value. Unlike validate(java.nio.ByteBuffer), cell value is passed to validate its content. Usually, this is the same as validate except collection.
      Parameters:
        `cellValue` - ByteBuffer representing cell value
      Throws:
        `MarshalException`

    - #### asCQL3Type

          public CQL3Type asCQL3Type()

    - #### compareForCQL

          public int compareForCQL(java.nio.ByteBuffer v1,
                                   java.nio.ByteBuffer v2)

      Same as compare except that this ignore ReversedType. This is to be use when comparing 2 values to decide for a CQL condition (see Operator.isSatisfiedBy) as for CQL, ReversedType is simply an "hint" to the storage engine but it does not change the meaning of queries per-se.

    - #### getSerializer

          public abstract TypeSerializer<T> getSerializer()

    - #### getString

          public java.lang.String getString(java.util.Collection<java.nio.ByteBuffer> names)

    - #### isCounter

          public boolean isCounter()

    - #### isFrozenCollection

          public boolean isFrozenCollection()

    - #### isReversed

          public boolean isReversed()

    - #### parseDefaultParameters

          public static AbstractType<?> parseDefaultParameters(AbstractType<?> baseType,
                                                               TypeParser parser)
                                                        throws SyntaxException

      Throws:
        `SyntaxException`

    - #### isCompatibleWith

          public boolean isCompatibleWith(AbstractType<?> previous)

      Returns true if this comparator is compatible with the provided previous comparator, that is if previous can safely be replaced by this. A comparator cn should be compatible with a previous one cp if forall columns c1 and c2, if cn.validate(c1) and cn.validate(c2) and cn.compare(c1, c2) == v, then cp.validate(c1) and cp.validate(c2) and cp.compare(c1, c2) == v. Note that a type should be compatible with at least itself and when in doubt, keep the default behavior of not being compatible with any other comparator!

    - #### isValueCompatibleWith

          public boolean isValueCompatibleWith(AbstractType<?> otherType)

      Returns true if values of the other AbstractType can be read and "reasonably" interpreted by the this AbstractType. Note that this is a weaker version of isCompatibleWith, as it does not require that both type compare values the same way. The restriction on the other type being "reasonably" interpreted is to prevent, for example, IntegerType from being compatible with all other types. Even though any byte string is a valid IntegerType value, it doesn't necessarily make sense to interpret a UUID or a UTF8 string as an integer. Note that a type should be compatible with at least itself.

    - #### isValueCompatibleWithInternal

          protected boolean isValueCompatibleWithInternal(AbstractType<?> otherType)

      Needed to handle ReversedType in value-compatibility checks. Subclasses should implement this instead of isValueCompatibleWith().

    - #### compareCollectionMembers

          public int compareCollectionMembers(java.nio.ByteBuffer v1,
                                              java.nio.ByteBuffer v2,
                                              java.nio.ByteBuffer collectionName)

      An alternative comparison function used by CollectionsType in conjunction with CompositeType. This comparator is only called to compare components of a CompositeType. It gets the value of the previous component as argument (or null if it's the first component of the composite). Unless you're doing something very similar to CollectionsType, you shouldn't override this.

    - #### validateCollectionMember

          public void validateCollectionMember(java.nio.ByteBuffer bytes,
                                               java.nio.ByteBuffer collectionName)
                                        throws MarshalException

      An alternative validation function used by CollectionsType in conjunction with CompositeType. This is similar to the compare function above.
      Throws:
        `MarshalException`

    - #### isCollection

          public boolean isCollection()

    - #### isUDT

          public boolean isUDT()

    - #### isTuple

          public boolean isTuple()

    - #### isMultiCell

          public boolean isMultiCell()

    - #### isFreezable

          public boolean isFreezable()

    - #### freeze

          public AbstractType<?> freeze()

    - #### freezeNestedMulticellTypes

          public AbstractType<?> freezeNestedMulticellTypes()

      Returns an AbstractType instance that is equivalent to this one, but with all nested UDTs and collections explicitly frozen. This is only necessary for `2.x -> 3.x` schema migrations, and can be removed in Cassandra 4.0. See CASSANDRA-11609 and CASSANDRA-11613.

    - #### isEmptyValueMeaningless

          public boolean isEmptyValueMeaningless()

      Returns `true` for types where empty should be handled like `null` like `Int32Type`.

    - #### toString

          public java.lang.String toString(boolean ignoreFreezing)

      Parameters:
        `ignoreFreezing` - if true, the type string will not be wrapped with FrozenType(...), even if this type is frozen.

    - #### componentsCount

          public int componentsCount()

      The number of subcomponents this type has. This is always 1, i.e. the type has only itself as "subcomponents", except for CompositeType.

    - #### getComponents

          public java.util.List<AbstractType<?>> getComponents()

      Return a list of the "subcomponents" this type has. This always return a singleton list with the type itself except for CompositeType.

    - #### valueLengthIfFixed

          protected int valueLengthIfFixed()

      The length of values for this type if all values are of fixed length, -1 otherwise.

    - #### writeValue

          public void writeValue(java.nio.ByteBuffer value,
                                 DataOutputPlus out)
                          throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### writtenLength

          public long writtenLength(java.nio.ByteBuffer value)

    - #### readValue

          public java.nio.ByteBuffer readValue(DataInputPlus in)
                                        throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### readValue

          public java.nio.ByteBuffer readValue(DataInputPlus in,
                                               int maxValueSize)
                                        throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### skipValue

          public void skipValue(DataInputPlus in)
                         throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### referencesUserType

          public boolean referencesUserType(java.lang.String userTypeName)

    - #### referencesDuration

          public boolean referencesDuration()

    - #### toString

          public java.lang.String toString()

      This must be overriden by subclasses if necessary so that for any AbstractType, this == TypeParser.parse(toString()). Note that for backwards compatibility this includes the full classname. For CQL purposes the short name is fine.
      Overrides:
        `toString` in class `java.lang.Object`

    - #### equals

          public boolean equals(java.lang.Object other,
                                boolean ignoreFreezing)

      Checks to see if two types are equal when ignoring or not ignoring differences in being frozen, depending on the value of the ignoreFreezing parameter.
      Parameters:
        `other` - type to compare
        `ignoreFreezing` - if true, differences in the types being frozen will be ignored

    - #### checkComparable

          public void checkComparable()

    - #### testAssignment

          public final AssignmentTestable.TestResult testAssignment(java.lang.String keyspace,
                                                                    ColumnSpecification receiver)

      Specified by:
        `testAssignment` in interface `AssignmentTestable`
      Returns:
        whether this object can be assigned to the provided receiver. We distinguish between 3 values: - EXACT_MATCH if this object is exactly of the type expected by the receiver - WEAKLY_ASSIGNABLE if this object is not exactly the expected type but is assignable nonetheless - NOT_ASSIGNABLE if it's not assignable Most caller should just call the isAssignable() method on the result, though functions have a use for testing "strong" equality to decide the most precise overload to pick when multiple could match.

Copyright © 2018 The Apache Software Foundation