com.threerings.media.tile.tools
Class MapFileTileSetIDBroker

java.lang.Object
  extended by com.threerings.media.tile.tools.MapFileTileSetIDBroker
All Implemented Interfaces:
TileSetIDBroker

public class MapFileTileSetIDBroker
extends Object
implements TileSetIDBroker

Stores a set of tileset name to id mappings in a map file.


Field Summary
protected  HashMap<String,Integer> _map
          Our mapping from tileset names to ids.
protected  File _mapfile
          Our persistent map file.
protected  int _nextTileSetID
          The next tileset id that we'll assign.
protected  int _storedTileSetID
          The last tileset id assigned when we were unserialized.
protected static String SEP_STR
          The character we use to separate tileset name from code in the map file.
 
Constructor Summary
MapFileTileSetIDBroker(File mapfile)
          Creates a broker that will use the specified file as its persistent store.
 
Method Summary
 void commit()
          When the user of a tilset id broker is done obtaining tileset ids, it must call this method to give the tileset id broker an opportunity to flush any newly created tileset ids back to its persistent store.
protected  Iterator<String> enumerateMappings()
          Used by DumpTileSetMap to enumerate our tileset ID mappings.
 int getTileSetID(String tileSetName)
          Returns the unique identifier for the named tileset.
protected  int readInt(BufferedReader bin)
           
static void readMapFile(BufferedReader bin, HashMap<String,Integer> map)
          Reads in a mapping from strings to integers, which should have been written via writeMapFile(java.io.BufferedWriter, java.util.HashMap).
protected  boolean renameTileSet(String oldName, String newName)
          Copies the ID from the old tileset to the new tileset which is useful when a tileset is renamed.
 boolean tileSetMapped(String tileSetName)
          Returns true if the specified tileset name is currently mapped to some value by this broker.
static void writeMapFile(BufferedWriter bout, HashMap<String,Integer> map)
          Writes out a mapping from strings to integers in a manner that can be read back in via readMapFile(java.io.BufferedReader, java.util.HashMap).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_mapfile

protected File _mapfile
Our persistent map file.


_nextTileSetID

protected int _nextTileSetID
The next tileset id that we'll assign.


_storedTileSetID

protected int _storedTileSetID
The last tileset id assigned when we were unserialized.


_map

protected HashMap<String,Integer> _map
Our mapping from tileset names to ids.


SEP_STR

protected static final String SEP_STR
The character we use to separate tileset name from code in the map file.

See Also:
Constant Field Values
Constructor Detail

MapFileTileSetIDBroker

public MapFileTileSetIDBroker(File mapfile)
                       throws PersistenceException
Creates a broker that will use the specified file as its persistent store. The persistent store will be created if it does not yet exist.

Throws:
PersistenceException
Method Detail

readInt

protected int readInt(BufferedReader bin)
               throws IOException
Throws:
IOException

getTileSetID

public int getTileSetID(String tileSetName)
                 throws PersistenceException
Description copied from interface: TileSetIDBroker
Returns the unique identifier for the named tileset. If no identifier has yet been assigned to the specified named tileset, one should be assigned and returned.

Specified by:
getTileSetID in interface TileSetIDBroker
Throws:
PersistenceException - thrown if an error occurs communicating with the underlying persistence mechanism used to store the name to id mappings.

tileSetMapped

public boolean tileSetMapped(String tileSetName)
                      throws PersistenceException
Description copied from interface: TileSetIDBroker
Returns true if the specified tileset name is currently mapped to some value by this broker.

Specified by:
tileSetMapped in interface TileSetIDBroker
Throws:
PersistenceException - thrown if an error occurs communicating with the underlying persistence mechanism used to store the name to id mappings.

commit

public void commit()
            throws PersistenceException
Description copied from interface: TileSetIDBroker
When the user of a tilset id broker is done obtaining tileset ids, it must call this method to give the tileset id broker an opportunity to flush any newly created tileset ids back to its persistent store.

Specified by:
commit in interface TileSetIDBroker
Throws:
PersistenceException

readMapFile

public static void readMapFile(BufferedReader bin,
                               HashMap<String,Integer> map)
                        throws IOException
Reads in a mapping from strings to integers, which should have been written via writeMapFile(java.io.BufferedWriter, java.util.HashMap).

Throws:
IOException

writeMapFile

public static void writeMapFile(BufferedWriter bout,
                                HashMap<String,Integer> map)
                         throws IOException
Writes out a mapping from strings to integers in a manner that can be read back in via readMapFile(java.io.BufferedReader, java.util.HashMap).

Throws:
IOException

renameTileSet

protected boolean renameTileSet(String oldName,
                                String newName)
Copies the ID from the old tileset to the new tileset which is useful when a tileset is renamed. This is called by the RenameTileSet utility.


enumerateMappings

protected Iterator<String> enumerateMappings()
Used by DumpTileSetMap to enumerate our tileset ID mappings.