Class BuildingBlock

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

public class BuildingBlock extends 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.
Since:
April 2, 2002, 1:57 PM
  • Constructor Details

    • BuildingBlock

      public BuildingBlock()
      Creates new empty buildingBlock
    • BuildingBlock

      public BuildingBlock(String[] data)
      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

      public BuildingBlock(Vector<String> data)
      Creates a new buildingBlock and fills it with the Vector.
      Parameters:
      data - The Vector can be filled with anything.
    • BuildingBlock

      public BuildingBlock(InputStream is)
  • Method Details

    • readInputStream

      public boolean readInputStream(InputStream is)
    • findStartIndex

      public int findStartIndex(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.
    • findEndIndex

      public int findEndIndex(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.
    • getDataAsString

      public String[] getDataAsString(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(String blockName)
    • getDataAsFloat

      public float[] getDataAsFloat(String blockName)
    • getDataAsDouble

      public double[] getDataAsDouble(String blockName)
    • getDataAsVector

      public List<String> getDataAsVector(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 void createNewBlock()
      Clears the rawData Vector and inserts a default comment and BlockVersion information.
    • writeBlockData

      public boolean writeBlockData(String blockName, String blockData)
      See Also:
    • writeBlockData

      public boolean writeBlockData(String blockName, int blockData)
      See Also:
    • writeBlockData

      public boolean writeBlockData(String blockName, int[] blockData)
      See Also:
    • writeBlockData

      public boolean writeBlockData(String blockName, float blockData)
      See Also:
    • writeBlockData

      public boolean writeBlockData(String blockName, double blockData)
      See Also:
    • writeBlockData

      public boolean writeBlockData(String blockName, float[] blockData)
      See Also:
    • writeBlockData

      public boolean writeBlockData(String blockName, String[] blockData)
      See Also:
    • writeBlockData

      public boolean writeBlockData(String blockName, List<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(String theComment)
      Writes a comment.
      Parameters:
      theComment - The comment to be written.
      Returns:
      Returns true on success.
    • writeBlockFile

      public boolean writeBlockFile(File file)
      Writes the buildingBlock data to a file.
      Parameters:
      file - File to write. Overwrites existing files.
      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 Vector<String> makeVector(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 Vector<String> getVector()
      Useful if you want to copy one buildingBlock into another.
      Returns:
      Returns the rawData Vector.
    • getAllDataAsString

      public String[] getAllDataAsString()
      Gets all the data inside the rawData Vector.
      Returns:
      Returns the data as a String array
    • getAllDataAsVector

      public Vector<String> getAllDataAsVector()
      Just about the same as the getVector() command.
      Returns:
      Returns the rawData Vector.
      See Also:
    • getReturnedArraySize

      public int getReturnedArraySize(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:
    • getReturnedArraySize

      public int getReturnedArraySize(Vector<Object> array)
      Returns:
      Returns array.size()
      See Also:
    • getReturnedArraySize

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

      public int countArray(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

      public int countArray(int[] array)
      See Also:
    • exists

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

      public boolean containsData(String blockName)
      Checks if a block exists and has data.