Package org.exbin.xbup.core.block
Class XBDefaultEditableBlock
- java.lang.Object
-
- org.exbin.xbup.core.block.XBDefaultEditableBlock
-
- All Implemented Interfaces:
XBBlock
,XBEditableBlock
@ParametersAreNonnullByDefault public class XBDefaultEditableBlock extends java.lang.Object implements XBEditableBlock
Basic plain implementation of XBEditableBlock interface.
-
-
Constructor Summary
Constructors Constructor Description XBDefaultEditableBlock()
Creates new instance of XBDefaultBlock as an empty data block.XBDefaultEditableBlock(XBBlock parent, XBBlockTerminationMode terminationMode, org.exbin.auxiliary.paged_data.BinaryData data)
Creates new instance of XBDefaultBlock as a data block with given values.XBDefaultEditableBlock(XBBlock parent, XBBlockTerminationMode terminationMode, XBAttribute[] attributes, XBBlock[] children)
Creates new instance of XBDefaultBlock as a node block with given values.XBDefaultEditableBlock(XBBlockTerminationMode terminationMode, org.exbin.auxiliary.paged_data.BinaryData data)
Creates new instance of XBDefaultBlock as a data block with given values and no parent block.XBDefaultEditableBlock(XBBlockTerminationMode terminationMode, XBAttribute[] attributes, XBBlock[] children)
Creates new instance of XBDefaultBlock as a node block with given values and no parent block.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears all data, attributes and child blocks.XBBlock
createNewChild(int childIndex)
This method instantiates new child node.XBAttribute
getAttributeAt(int attributeIndex)
Gets attribute of given index / order.XBAttribute[]
getAttributes()
Gets array of attributes in order of appearance.int
getAttributesCount()
Gets count of attributes.org.exbin.auxiliary.paged_data.BinaryData
getBlockData()
Gets block data.static int
getBlockIndex(XBBlock block)
Gets block position in depth-first scan of the tree.java.io.InputStream
getData()
Gets block data.XBBlockDataMode
getDataMode()
Returns mode whether this block is data block.long
getDataSize()
XBBlock
getChildAt(int childIndex)
Gets child block of given index.static int
getChildIndexOf(XBBlock parent, XBBlock block)
Gets block position in parents direct child list.XBBlock[]
getChildren()
Gets array of all children blocks.int
getChildrenCount()
Gets count of children.java.util.Optional<XBBlock>
getParentBlock()
Gets parent block or empty if block has no parent.XBBlockTerminationMode
getTerminationMode()
Returns whether this block is using sequence of children ended with termination block.void
removeAttribute(int attributeIndex)
Removes attribute on given position.void
removeChild(int childIndex)
Removes child on given position.void
setAttributeAt(XBAttribute attribute, int attributeIndex)
Sets attribute of given index.void
setAttributes(XBAttribute[] attributes)
Sets array of attributes in order of appearance.void
setAttributesCount(int count)
Sets count of attributes.void
setData(java.io.InputStream data)
Sets block data.void
setData(org.exbin.auxiliary.paged_data.BinaryData data)
Sets block data.void
setDataMode(XBBlockDataMode dataMode)
Sets data block mode.void
setChildAt(XBBlock block, int childIndex)
Sets children of given index.void
setChildren(XBBlock[] blocks)
Sets array of all children.void
setChildrenCount(int count)
Gets count of children blocks.void
setParent(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.void
setTerminationMode(XBBlockTerminationMode terminationMode)
Sets terminated mode.
-
-
-
Constructor Detail
-
XBDefaultEditableBlock
public XBDefaultEditableBlock()
Creates new instance of XBDefaultBlock as an empty data block.
-
XBDefaultEditableBlock
public XBDefaultEditableBlock(@Nullable XBBlock parent, 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 nodeterminationMode
- termination modedata
- block data
-
XBDefaultEditableBlock
public XBDefaultEditableBlock(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 modedata
- block data
-
XBDefaultEditableBlock
public XBDefaultEditableBlock(@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 nodeterminationMode
- termination modeattributes
- attributeschildren
- children blocks
-
XBDefaultEditableBlock
public XBDefaultEditableBlock(@Nonnull 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 modeattributes
- attributeschildren
- 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 interfaceXBBlock
- 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.- Specified by:
setParent
in interfaceXBEditableBlock
- 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 interfaceXBBlock
- 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 interfaceXBBlock
- 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 interfaceXBBlock
- 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 interfaceXBBlock
- 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 interfaceXBBlock
- Returns:
- count of attributes
-
getChildren
@Nullable public XBBlock[] getChildren()
Description copied from interface:XBBlock
Gets array of all children blocks.- Specified by:
getChildren
in interfaceXBBlock
- 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 interfaceXBBlock
- 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 interfaceXBBlock
- Returns:
- count of children
-
getData
@Nonnull public java.io.InputStream getData()
Description copied from interface:XBBlock
Gets block data.
-
getBlockData
@Nonnull public org.exbin.auxiliary.paged_data.BinaryData getBlockData()
Description copied from interface:XBBlock
Gets block data.- Specified by:
getBlockData
in interfaceXBBlock
- 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(@Nullable XBBlock parent, @Nullable XBBlock block)
Gets block position in parents direct child list.- Parameters:
parent
- parent blockblock
- target block- Returns:
- position index
-
setTerminationMode
public void setTerminationMode(XBBlockTerminationMode terminationMode)
Description copied from interface:XBEditableBlock
Sets terminated mode.- Specified by:
setTerminationMode
in interfaceXBEditableBlock
- Parameters:
terminationMode
- terminated mode flag
-
setDataMode
public void setDataMode(XBBlockDataMode dataMode)
Description copied from interface:XBEditableBlock
Sets data block mode.- Specified by:
setDataMode
in interfaceXBEditableBlock
- Parameters:
dataMode
- data block mode
-
setAttributes
public void setAttributes(@Nullable XBAttribute[] attributes)
Description copied from interface:XBEditableBlock
Sets array of attributes in order of appearance.- Specified by:
setAttributes
in interfaceXBEditableBlock
- Parameters:
attributes
- array of attributes
-
setAttributeAt
public void setAttributeAt(XBAttribute attribute, int attributeIndex)
Description copied from interface:XBEditableBlock
Sets attribute of given index. If index is greater than current count of attributes, new zero attributes will be filled.- Specified by:
setAttributeAt
in interfaceXBEditableBlock
- Parameters:
attribute
- attribute valueattributeIndex
- attribute index
-
setAttributesCount
public void setAttributesCount(int count)
Description copied from interface:XBEditableBlock
Sets count of attributes. List of attributes will be trimmed/extended with zero values.- Specified by:
setAttributesCount
in interfaceXBEditableBlock
- Parameters:
count
- count of attributes
-
removeAttribute
public void removeAttribute(int attributeIndex)
Description copied from interface:XBEditableBlock
Removes attribute on given position.- Specified by:
removeAttribute
in interfaceXBEditableBlock
- Parameters:
attributeIndex
- attribute index
-
setChildren
public void setChildren(XBBlock[] blocks)
Description copied from interface:XBEditableBlock
Sets array of all children.- Specified by:
setChildren
in interfaceXBEditableBlock
- Parameters:
blocks
- array of children blocks
-
setChildAt
public void setChildAt(XBBlock block, int childIndex)
Description copied from interface:XBEditableBlock
Sets children of given index. If index is greater than current count of children, new empty blocks will be filled.- Specified by:
setChildAt
in interfaceXBEditableBlock
- Parameters:
block
- child blockchildIndex
- index of child block
-
setChildrenCount
public void setChildrenCount(int count)
Description copied from interface:XBEditableBlock
Gets count of children blocks. List of children will be trimmed/extended with empty blocks.- Specified by:
setChildrenCount
in interfaceXBEditableBlock
- Parameters:
count
- count of children
-
createNewChild
public XBBlock createNewChild(int childIndex)
Description copied from interface:XBEditableBlock
This method instantiates new child node.- Specified by:
createNewChild
in interfaceXBEditableBlock
- Parameters:
childIndex
- child index- Returns:
- new instance of block
-
removeChild
public void removeChild(int childIndex)
Description copied from interface:XBEditableBlock
Removes child on given position.- Specified by:
removeChild
in interfaceXBEditableBlock
- Parameters:
childIndex
- child index
-
setData
public void setData(java.io.InputStream data) throws java.io.IOException
Description copied from interface:XBEditableBlock
Sets block data.- Specified by:
setData
in interfaceXBEditableBlock
- Parameters:
data
- data stream- Throws:
java.io.IOException
- exception on input/output error
-
setData
public void setData(org.exbin.auxiliary.paged_data.BinaryData data)
Description copied from interface:XBEditableBlock
Sets block data.- Specified by:
setData
in interfaceXBEditableBlock
- Parameters:
data
- data stream
-
clear
public void clear()
Description copied from interface:XBEditableBlock
Clears all data, attributes and child blocks.- Specified by:
clear
in interfaceXBEditableBlock
-
-