Class XBTDefaultBlock

  • All Implemented Interfaces:
    XBTBlock

    public class XBTDefaultBlock
    extends java.lang.Object
    implements XBTBlock
    Basic plain implementation of XBTBlock interface.
    • Constructor Detail

      • XBTDefaultBlock

        public XBTDefaultBlock()
        Creates new instance of XBDefaultBlock as an empty data block.
      • XBTDefaultBlock

        public XBTDefaultBlock​(@Nullable
                               XBTBlock parent,
                               @Nullable
                               XBBlockTerminationMode terminationMode,
                               @Nullable
                               org.exbin.auxiliary.paged_data.BinaryData data)
        Creates new instance of XBTDefaultBlock as a data block with given values.
        Parameters:
        parent - parent node
        terminationMode - termination mode
        data - block data
      • XBTDefaultBlock

        public XBTDefaultBlock​(@Nullable
                               XBBlockTerminationMode terminationMode,
                               @Nullable
                               org.exbin.auxiliary.paged_data.BinaryData data)
        Creates new instance of XBTDefaultBlock as a data block with given values and no parent block.
        Parameters:
        terminationMode - termination mode
        data - block data
      • XBTDefaultBlock

        public XBTDefaultBlock​(@Nullable
                               XBTBlock parent,
                               @Nullable
                               XBBlockTerminationMode terminationMode,
                               @Nullable
                               XBBlockType blockType,
                               @Nullable
                               XBAttribute[] attributes,
                               @Nullable
                               XBTBlock[] children)
        Creates new instance of XBTDefaultBlock as a node block with given values.
        Parameters:
        parent - parent node
        terminationMode - termination mode
        blockType - block type
        attributes - attributes
        children - children blocks
      • XBTDefaultBlock

        public XBTDefaultBlock​(@Nullable
                               XBBlockTerminationMode terminationMode,
                               @Nullable
                               XBBlockType blockType,
                               @Nullable
                               XBAttribute[] attributes,
                               @Nullable
                               XBTBlock[] children)
        Creates new instance of XBTDefaultBlock as a node block with given values and no parent block.
        Parameters:
        terminationMode - termination mode
        blockType - block type
        attributes - attributes
        children - children blocks
    • Method Detail

      • getParentBlock

        @Nonnull
        public java.util.Optional<XBTBlock> getParentBlock()
        Description copied from interface: XBTBlock
        Gets parent block or null if block has no parent.
        Specified by:
        getParentBlock in interface XBTBlock
        Returns:
        parent block
      • setParent

        public void setParent​(@Nullable
                              XBTBlock parent)
        Allows to set parent block, which is not cosidered as a part of the block value and allows to move this block in tree.
        Parameters:
        parent - parent block
      • getDataMode

        @Nonnull
        public XBBlockDataMode getDataMode()
        Description copied from interface: XBTBlock
        Returns whether this block is data block.
        Specified by:
        getDataMode in interface XBTBlock
        Returns:
        data mode
      • getTerminationMode

        @Nonnull
        public XBBlockTerminationMode getTerminationMode()
        Description copied from interface: XBTBlock
        Returns whether this block is using sequence of children ended with termination block.
        Specified by:
        getTerminationMode in interface XBTBlock
        Returns:
        terminated mode
      • getAttributes

        @Nullable
        public XBAttribute[] getAttributes()
        Description copied from interface: XBTBlock
        Gets array of attributes in order of appearance.
        Specified by:
        getAttributes in interface XBTBlock
        Returns:
        array of attributes
      • getAttributeAt

        @Nullable
        public XBAttribute getAttributeAt​(int attributeIndex)
        Description copied from interface: XBTBlock
        Gets attribute of given index. Returns zero if attribute index greater than attributes count.
        Specified by:
        getAttributeAt in interface XBTBlock
        Parameters:
        attributeIndex - index of attribute
        Returns:
        attribute value
      • getAttributesCount

        public int getAttributesCount()
        Description copied from interface: XBTBlock
        Gets count of attributes.
        Specified by:
        getAttributesCount in interface XBTBlock
        Returns:
        count of attributes
      • getChildren

        @Nullable
        public XBTBlock[] getChildren()
        Description copied from interface: XBTBlock
        Gets array of all children.
        Specified by:
        getChildren in interface XBTBlock
        Returns:
        array of child blocks
      • getChildAt

        @Nullable
        public XBTBlock getChildAt​(int childIndex)
        Description copied from interface: XBTBlock
        Gets children of given index. If no child for given index exist, return null.
        Specified by:
        getChildAt in interface XBTBlock
        Parameters:
        childIndex - index of child block
        Returns:
        child block
      • getChildrenCount

        public int getChildrenCount()
        Description copied from interface: XBTBlock
        Gets count of children blocks.
        Specified by:
        getChildrenCount in interface XBTBlock
        Returns:
        count of children
      • getData

        @Nonnull
        public java.io.InputStream getData()
        Description copied from interface: XBTBlock
        Gets block data.
        Specified by:
        getData in interface XBTBlock
        Returns:
        block data or throws invalid operation on non-data block
      • getBlockData

        @Nonnull
        public org.exbin.auxiliary.paged_data.BinaryData getBlockData()
        Description copied from interface: XBTBlock
        Gets block data.
        Specified by:
        getBlockData in interface XBTBlock
        Returns:
        block data or throws invalid operation on non-data block
      • getBlockIndex

        public static int getBlockIndex​(@Nullable
                                        XBTBlock block)
        Gets block position in depth-first scan of the tree. Returns -1 for null block or if tree structure is corrupted.
        Parameters:
        block - target block
        Returns:
        position index
      • getChildIndexOf

        public static int getChildIndexOf​(@Nullable
                                          XBTBlock parent,
                                          @Nullable
                                          XBTBlock block)
        Gets block position in parents direct child list.
        Parameters:
        parent - parent block
        block - target block
        Returns:
        position index