Package megamek.common.util
Class BuildingBlock
java.lang.Object
megamek.common.util.BuildingBlock
buildingBlock is based on a file format I used in an online game. The
original was written in PHP, this one is more robust, and written in Java.
- Since:
- April 2, 2002, 1:57 PM
-
Constructor Summary
ConstructorsConstructorDescriptionCreates new empty buildingBlockBuildingBlock
(String[] data) Creates a new buildingBlock and fills it with the data in the String[] array.BuildingBlock
(Vector<String> data) Creates a new buildingBlock and fills it with the Vector. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears therawData
Vector.boolean
containsData
(String blockName) Checks if a block exists and has data.int
countArray
(float[] array) int
countArray
(int[] array) int
countArray
(String[] array) Counts the size of an array.void
Clears therawData
Vector and inserts a default comment and BlockVersion information.int
dataSize()
Gets the size of therawData
Vector.boolean
Checks to see if a block exists...returns true or falseint
findEndIndex
(String blockName) Finds the starting index of a block.int
findStartIndex
(String blockName) Finds the starting index of a block.String[]
Gets all the data inside therawData
Vector.Just about the same as thegetVector()
command.double[]
getDataAsDouble
(String blockName) float[]
getDataAsFloat
(String blockName) int[]
getDataAsInt
(String blockName) String[]
getDataAsString
(String blockName) Gets data from inside a block.getDataAsVector
(String blockName) Gets data from a block.int
getReturnedArraySize
(float[] array) int
getReturnedArraySize
(int[] array) int
getReturnedArraySize
(String[] array) Tells you the size of an array this thing returned by giving you the number in the [0] position.int
getReturnedArraySize
(Vector<Object> array) Useful if you want to copy one buildingBlock into another.makeVector
(String[] stringArray) Converts a String array into a Vector.boolean
boolean
writeBlockComment
(String theComment) Writes a comment.boolean
writeBlockData
(String blockName, double blockData) boolean
writeBlockData
(String blockName, float blockData) boolean
writeBlockData
(String blockName, float[] blockData) boolean
writeBlockData
(String blockName, int blockData) boolean
writeBlockData
(String blockName, int[] blockData) boolean
writeBlockData
(String blockName, String blockData) boolean
writeBlockData
(String blockName, String[] blockData) boolean
writeBlockData
(String blockName, List<String> blockData) Writes a data block to therawData
vector.boolean
writeBlockFile
(File file) Writes the buildingBlock data to a file.
-
Constructor Details
-
BuildingBlock
public BuildingBlock()Creates new empty buildingBlock -
BuildingBlock
Creates a new buildingBlock and fills it with the data in the String[] array.- Parameters:
data
- This is most useful for storing one block file inside another...but data can be an array of anything...such as comments.
-
BuildingBlock
Creates a new buildingBlock and fills it with the Vector.- Parameters:
data
- The Vector can be filled with anything.
-
BuildingBlock
-
-
Method Details
-
readInputStream
-
findStartIndex
Finds the starting index of a block. This is used by the class to locate data, but is a public function that can be useful if you know what you want to do with therawData
Vector.- Parameters:
blockName
- The name of the data block to locate.- Returns:
- Returns the start index of the block data. Or -1 if not found.
-
findEndIndex
Finds the starting index of a block. This is used by the class to locate data, but is a public function that can be useful if you know what you want to do with therawData
Vector.- Parameters:
blockName
- The name of the data block to locate.- Returns:
- Returns the end index of the block data. Or -1 if not found.
-
getDataAsString
Gets data from inside a block.- Parameters:
blockName
- The name of the block to grab the data from.- Returns:
- Returns an array of data.
-
getDataAsInt
-
getDataAsFloat
-
getDataAsDouble
-
getDataAsVector
Gets data from a block.- Parameters:
blockName
- Name of the block to get data from.- Returns:
- Returns the data as a Vector.
-
createNewBlock
public void createNewBlock()Clears therawData
Vector and inserts a default comment and BlockVersion information. -
writeBlockData
- See Also:
-
writeBlockData
- See Also:
-
writeBlockData
- See Also:
-
writeBlockData
- See Also:
-
writeBlockData
- See Also:
-
writeBlockData
- See Also:
-
writeBlockData
- See Also:
-
writeBlockData
Writes a data block to therawData
vector.- Parameters:
blockName
- Name of the block to be created.blockData
- Data to be written inside the block.- Returns:
- Returns true on success.
-
writeBlockComment
Writes a comment.- Parameters:
theComment
- The comment to be written.- Returns:
- Returns true on success.
-
writeBlockFile
Writes the buildingBlock data to a file.- Parameters:
file
- File to write. Overwrites existing files.- Returns:
- true on success.
-
clearData
public void clearData()Clears therawData
Vector. -
dataSize
public int dataSize()Gets the size of therawData
Vector.- Returns:
- Returns
rawData.size()
-
makeVector
Converts a String array into a Vector.- Parameters:
stringArray
- The String array to convert.- Returns:
- Returns the Vector created by the String[]
-
getVector
Useful if you want to copy one buildingBlock into another.- Returns:
- Returns the
rawData
Vector.
-
getAllDataAsString
Gets all the data inside therawData
Vector.- Returns:
- Returns the data as a String array
-
getAllDataAsVector
Just about the same as thegetVector()
command.- Returns:
- Returns the
rawData
Vector. - See Also:
-
getReturnedArraySize
Tells you the size of an array this thing returned by giving you the number in the [0] position.- Parameters:
array
- The array to get the size of.- Returns:
- Returns the number in the [0] position.
-
getReturnedArraySize
public int getReturnedArraySize(int[] array) - See Also:
-
getReturnedArraySize
- Returns:
- Returns
array.size()
- See Also:
-
getReturnedArraySize
public int getReturnedArraySize(float[] array) - See Also:
-
countArray
Counts the size of an array.- Parameters:
array
- The array to count.- Returns:
- Returns the array's size.
-
countArray
public int countArray(float[] array) - See Also:
-
countArray
public int countArray(int[] array) - See Also:
-
exists
Checks to see if a block exists...returns true or false -
containsData
Checks if a block exists and has data.
-