Class Type

  • Direct Known Subclasses:
    GroupType, PrimitiveType

    public abstract class Type
    extends Object
    Represents the declared type for a field in a schema. The Type object represents both the actual underlying type of the object (eg a primitive or group) as well as its attributes such as whether it is repeated, required, or optional.
    • Constructor Detail

      • Type

        @Deprecated
        public Type​(String name,
                    Type.Repetition repetition)
        Deprecated.
        Parameters:
        name - the name of the type
        repetition - OPTIONAL, REPEATED, REQUIRED
      • Type

        @Deprecated
        public Type​(String name,
                    Type.Repetition repetition,
                    OriginalType originalType)
        Deprecated.
        Parameters:
        name - the name of the type
        repetition - OPTIONAL, REPEATED, REQUIRED
        originalType - (optional) the original type to help with cross schema conversion (LIST, MAP, ...)
    • Method Detail

      • withId

        public abstract Type withId​(int id)
        Parameters:
        id - an integer id
        Returns:
        the same type with the id field set
      • getName

        public String getName()
        Returns:
        the name of the type
      • isRepetition

        public boolean isRepetition​(Type.Repetition rep)
        Parameters:
        rep - repetition level to test
        Returns:
        if repetition of the type is rep
      • getRepetition

        public Type.Repetition getRepetition()
        Returns:
        the repetition constraint
      • getId

        public Type.ID getId()
        Returns:
        the id of the field (if defined)
      • getOriginalType

        public OriginalType getOriginalType()
        Returns:
        the original type (LIST, MAP, ...)
      • isPrimitive

        public abstract boolean isPrimitive()
        Returns:
        if this is a primitive type
      • writeToStringBuilder

        public abstract void writeToStringBuilder​(StringBuilder sb,
                                                  String indent)
        Writes a string representation to the provided StringBuilder
        Parameters:
        sb - the StringBuilder to write itself to
        indent - indentation level
      • accept

        public abstract void accept​(TypeVisitor visitor)
        Visits this type with the given visitor
        Parameters:
        visitor - the visitor to visit this type
      • typeHashCode

        @Deprecated
        protected abstract int typeHashCode()
        Deprecated.
      • typeEquals

        @Deprecated
        protected abstract boolean typeEquals​(Type other)
        Deprecated.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • equals

        protected boolean equals​(Type other)
      • eqOrBothNull

        protected boolean eqOrBothNull​(Object o1,
                                       Object o2)
      • getMaxRepetitionLevel

        protected abstract int getMaxRepetitionLevel​(String[] path,
                                                     int i)
      • getMaxDefinitionLevel

        protected abstract int getMaxDefinitionLevel​(String[] path,
                                                     int i)
      • getType

        protected abstract Type getType​(String[] path,
                                        int i)
      • getPaths

        protected abstract List<String[]> getPaths​(int depth)
      • containsPath

        protected abstract boolean containsPath​(String[] path,
                                                int depth)
      • union

        protected abstract Type union​(Type toMerge)
        Parameters:
        toMerge - the type to merge into this one
        Returns:
        the union result of merging toMerge into this
      • union

        protected abstract Type union​(Type toMerge,
                                      boolean strict)
        Parameters:
        toMerge - the type to merge into this one
        strict - should schema primitive types match
        Returns:
        the union result of merging toMerge into this