Class XBDefaultBlock

  • All Implemented Interfaces:
    XBBlock

    @ParametersAreNonnullByDefault
    public class XBDefaultBlock
    extends java.lang.Object
    implements XBBlock
    Basic plain implementation of XBBlock interface.
    • Constructor Detail

      • XBDefaultBlock

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

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

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

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

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

      • getParentBlock

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

        public void setParent​(@Nullable
                              XBBlock 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: XBBlock
        Returns mode whether this block is data block.
        Specified by:
        getDataMode in interface XBBlock
        Returns:
        data mode
      • getTerminationMode

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

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

        @Nullable
        public XBAttribute getAttributeAt​(int attributeIndex)
        Description copied from interface: XBBlock
        Gets attribute of given index / order.
        Specified by:
        getAttributeAt in interface XBBlock
        Parameters:
        attributeIndex - index/order of attribute
        Returns:
        attribute value
      • getAttributesCount

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

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

        @Nullable
        public XBBlock getChildAt​(int childIndex)
        Description copied from interface: XBBlock
        Gets child block of given index.
        Specified by:
        getChildAt in interface XBBlock
        Parameters:
        childIndex - index of child block
        Returns:
        child block
      • getChildrenCount

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

        @Nonnull
        public java.io.InputStream getData()
        Description copied from interface: XBBlock
        Gets block data.
        Specified by:
        getData in interface XBBlock
        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: XBBlock
        Gets block data.
        Specified by:
        getBlockData in interface XBBlock
        Returns:
        block data or throws invalid operation on non-data block
      • getDataSize

        public long getDataSize()
      • getBlockIndex

        public static int getBlockIndex​(@Nullable
                                        XBBlock 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​(XBBlock parent,
                                          XBBlock block)
        Gets block position in parents direct child list.
        Parameters:
        parent - parent block
        block - target block
        Returns:
        position index