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 TypeMethodDescriptionvoidClears therawDataVector.booleancontainsData(String blockName) Checks if a block exists and has data.intcountArray(float[] array) intcountArray(int[] array) intcountArray(String[] array) Counts the size of an array.voidClears therawDataVector and inserts a default comment and BlockVersion information.intdataSize()Gets the size of therawDataVector.booleanChecks to see if a block exists...returns true or falseintfindEndIndex(String blockName) Finds the starting index of a block.intfindStartIndex(String blockName) Finds the starting index of a block.String[]Gets all the data inside therawDataVector.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.intgetReturnedArraySize(float[] array) intgetReturnedArraySize(int[] array) intgetReturnedArraySize(String[] array) Tells you the size of an array this thing returned by giving you the number in the [0] position.intgetReturnedArraySize(Vector<Object> array) Useful if you want to copy one buildingBlock into another.makeVector(String[] stringArray) Converts a String array into a Vector.voidvoidwriteBlockComment(String theComment) Writes a comment.booleanwriteBlockData(String blockName, double blockData) booleanwriteBlockData(String blockName, float blockData) booleanwriteBlockData(String blockName, float[] blockData) booleanwriteBlockData(String blockName, int blockData) booleanwriteBlockData(String blockName, int[] blockData) booleanwriteBlockData(String blockName, String blockData) booleanwriteBlockData(String blockName, String[] blockData) booleanwriteBlockData(String blockName, List<String> blockData) Writes a data block to therawDatavector.voidwriteBlockFile(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 therawDataVector.- 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 therawDataVector.- 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 therawDataVector 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 therawDatavector.- 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.
-
writeBlockFile
Writes the buildingBlock data to a file.- Parameters:
file- File to write. Overwrites existing files.
-
clearData
public void clearData()Clears therawDataVector. -
dataSize
public int dataSize()Gets the size of therawDataVector.- 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
rawDataVector.
-
getAllDataAsString
Gets all the data inside therawDataVector.- Returns:
- Returns the data as a String array
-
getAllDataAsVector
Just about the same as thegetVector()command.- Returns:
- Returns the
rawDataVector. - 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.
-