megamek.common.util
Class BuildingBlock

java.lang.Object
  extended by megamek.common.util.BuildingBlock

public class BuildingBlock
extends java.lang.Object

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.


Constructor Summary
BuildingBlock()
          Creates new empty buildingBlock
BuildingBlock(java.io.InputStream is)
           
BuildingBlock(java.lang.String[] data)
          Creates a new buildingBlock and fills it with the data in the String[] array.
BuildingBlock(java.util.Vector<java.lang.String> data)
          Creates a new buildingBlock and fills it with the Vector.
 
Method Summary
 void clearData()
          Clears the rawData Vector.
 int countArray(float[] array)
           
 int countArray(int[] array)
           
 int countArray(java.lang.String[] array)
          Counts the size of an array.
 boolean createNewBlock()
          Clears the rawData Vector and inserts a default comment and BlockVersion information.
 int dataSize()
          Gets the size of the rawData Vector.
 boolean exists(java.lang.String blockName)
          Checks to see if a block exists...returns true or false
 int findEndIndex(java.lang.String blockName)
          Finds the starting index of a block.
 int findStartIndex(java.lang.String blockName)
          Finds the starting index of a block.
 java.lang.String[] getAllDataAsString()
          Gets all the data inside the rawData Vector.
 java.util.Vector<java.lang.String> getAllDataAsVector()
          Just about the same as the getVector() command.
 float[] getDataAsFloat(java.lang.String blockName)
           
 int[] getDataAsInt(java.lang.String blockName)
           
 java.lang.String[] getDataAsString(java.lang.String blockName)
          Gets data from inside a block.
 java.util.Vector<java.lang.String> getDataAsVector(java.lang.String blockName)
          Gets data from a block.
 int getReturnedArraySize(float[] array)
           
 int getReturnedArraySize(int[] array)
           
 int getReturnedArraySize(java.lang.String[] array)
          Tells you the size of an array this thing returned by giving you the number in the [0] position.
 int getReturnedArraySize(java.util.Vector<java.lang.Object> array)
           
 java.util.Vector<java.lang.String> getVector()
          Useful if you want to copy one buildingBlock into another.
 java.util.Vector<java.lang.String> makeVector(java.lang.String[] stringArray)
          Converts a String array into a Vector.
 boolean readInputStream(java.io.InputStream is)
           
 boolean writeBlockComment(java.lang.String theComment)
          Writes a comment.
 boolean writeBlockData(java.lang.String blockName, float blockData)
           
 boolean writeBlockData(java.lang.String blockName, float[] blockData)
           
 boolean writeBlockData(java.lang.String blockName, int blockData)
           
 boolean writeBlockData(java.lang.String blockName, int[] blockData)
           
 boolean writeBlockData(java.lang.String blockName, java.lang.String blockData)
           
 boolean writeBlockData(java.lang.String blockName, java.lang.String[] blockData)
           
 boolean writeBlockData(java.lang.String blockName, java.util.Vector<java.lang.String> blockData)
          Writes a data block to the rawData vector.
 boolean writeBlockFile(java.lang.String fileName)
          Writes the buildingBlock data to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BuildingBlock

public BuildingBlock()
Creates new empty buildingBlock


BuildingBlock

public BuildingBlock(java.lang.String[] data)
Creates a new buildingBlock and fills it with the data in the String[] array.

Parameters:
data - This is most usefull for storing one block file inside another...but data can be an array of anything...such as comments.

BuildingBlock

public BuildingBlock(java.util.Vector<java.lang.String> data)
Creates a new buildingBlock and fills it with the Vector.

Parameters:
data - The Vector can be filled with anything.

BuildingBlock

public BuildingBlock(java.io.InputStream is)
Method Detail

readInputStream

public boolean readInputStream(java.io.InputStream is)

findStartIndex

public int findStartIndex(java.lang.String blockName)
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 the rawData 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.
See Also:
findEndIndex(), getAllDataAsVector()

findEndIndex

public int findEndIndex(java.lang.String blockName)
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 the rawData 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.
See Also:
findStartIndex(), getAllDataAsVector()

getDataAsString

public java.lang.String[] getDataAsString(java.lang.String blockName)
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

public int[] getDataAsInt(java.lang.String blockName)
See Also:
getDataAsString()

getDataAsFloat

public float[] getDataAsFloat(java.lang.String blockName)
See Also:
getDataAsString()

getDataAsVector

public java.util.Vector<java.lang.String> getDataAsVector(java.lang.String blockName)
Gets data from a block.

Parameters:
blockName - Name of the block to get data from.
Returns:
Returns the data as a Vector.

createNewBlock

public boolean createNewBlock()
Clears the rawData Vector and inserts a default comment and BlockVersion information.

Returns:
Returns true on success.

writeBlockData

public boolean writeBlockData(java.lang.String blockName,
                              java.lang.String blockData)
See Also:
(String, Vector)

writeBlockData

public boolean writeBlockData(java.lang.String blockName,
                              int blockData)
See Also:
(String, Vector)

writeBlockData

public boolean writeBlockData(java.lang.String blockName,
                              int[] blockData)
See Also:
(String, Vector)

writeBlockData

public boolean writeBlockData(java.lang.String blockName,
                              float blockData)
See Also:
(String, Vector)

writeBlockData

public boolean writeBlockData(java.lang.String blockName,
                              float[] blockData)
See Also:
(String, Vector)

writeBlockData

public boolean writeBlockData(java.lang.String blockName,
                              java.lang.String[] blockData)
See Also:
(String, Vector)

writeBlockData

public boolean writeBlockData(java.lang.String blockName,
                              java.util.Vector<java.lang.String> blockData)
Writes a data block to the rawData vector.

Parameters:
blockName - Name of the block to be created.
blockData - Data to be written inside the block.
Returns:
Returns true on success.

writeBlockComment

public boolean writeBlockComment(java.lang.String theComment)
Writes a comment.

Parameters:
theComment - The comment to be written.
Returns:
Returns true on success.

writeBlockFile

public boolean writeBlockFile(java.lang.String fileName)
Writes the buildingBlock data to a file.

Parameters:
fileName - File to write. Overwrites existing files.
Returns:
Returns true on success.

clearData

public void clearData()
Clears the rawData Vector.


dataSize

public int dataSize()
Gets the size of the rawData Vector.

Returns:
Returns rawData.size()

makeVector

public java.util.Vector<java.lang.String> makeVector(java.lang.String[] stringArray)
Converts a String array into a Vector.

Parameters:
stringArray - The String array to convert.
Returns:
Returns the Vector created by the String[]

getVector

public java.util.Vector<java.lang.String> getVector()
Useful if you want to copy one buildingBlock into another.

Returns:
Returns the rawData Vector.

getAllDataAsString

public java.lang.String[] getAllDataAsString()
Gets all the data inside the rawData Vector.

Returns:
Returns the data as a String array

getAllDataAsVector

public java.util.Vector<java.lang.String> getAllDataAsVector()
Just about the same as the getVector() command.

Returns:
Returns the rawData Vector.
See Also:
()

getReturnedArraySize

public int getReturnedArraySize(java.lang.String[] array)
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:
(String[])

getReturnedArraySize

public int getReturnedArraySize(java.util.Vector<java.lang.Object> array)
Returns:
Returns array.size()
See Also:
(String[])

getReturnedArraySize

public int getReturnedArraySize(float[] array)
See Also:
(String[])

countArray

public int countArray(java.lang.String[] array)
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( String[] )

countArray

public int countArray(int[] array)
See Also:
countArray( String[] )

exists

public boolean exists(java.lang.String blockName)
Checks to see if a block exists...returns true or false