dLife Home Page

dlife.gui.connectiondialog
Class BluetoothNameMap

java.lang.Object
  extended by dlife.sys.SerializationBase
      extended by dlife.gui.connectiondialog.BluetoothNameMap
All Implemented Interfaces:
Serializable

public class BluetoothNameMap
extends SerializationBase

This class maintains a mapping from bluetooth address to a user defined name for the device. The mapping is unserialized from the file specified file upon construction and is serialized each time it is changed. If the file doesn't exist then the map will initially be empty.

Version:
May 22, 2010
Author:
Grant Braught, Dickinson College
See Also:
Serialized Form

Constructor Summary
BluetoothNameMap(String filename)
          Construct a new BluetoothNameMap containing all of the mappings in the specified file.
 
Method Summary
 void addName(String btAddr, String name)
          Add a new bluetooth address to name mapping.
 String getInfoLine(String btAddr)
          Get a string containing both the user defined name and the bluetooth address of the device.
 ArrayList<String> getInfoLineList()
          Get a list of the Strings returned by getInfoLine for all of the devices in this BluetoothNameMap.
 String getName(String btAddr)
          Get the user assigned name associated with the provided bluetooth address.
 int size()
          Get the number of names that appear in this map.
 
Methods inherited from class dlife.sys.SerializationBase
read, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BluetoothNameMap

public BluetoothNameMap(String filename)
Construct a new BluetoothNameMap containing all of the mappings in the specified file. If the file does not exist then an empty mapping is created.

Parameters:
filename - the name of the serialization file for this map.
Method Detail

size

public int size()
Get the number of names that appear in this map.

Returns:
the size.

getName

public String getName(String btAddr)
Get the user assigned name associated with the provided bluetooth address. If there is no name associated with the bluetooth address then null is returned.

Parameters:
btAddr - the bluetooth address.
Returns:
the user defined name.

addName

public void addName(String btAddr,
                    String name)
Add a new bluetooth address to name mapping. If the mapping already exists it is replaced by the one specified. If the map is changed it is serialized to the serialization file.

Parameters:
btAddr - the bluetooth address of the device.
name - the user defined name for the device.

getInfoLine

public String getInfoLine(String btAddr)
Get a string containing both the user defined name and the bluetooth address of the device. If there is a user defined name for the provided bluetooth address then the format of the returned line is: "name (bluetooth address)". If there is no user defined name then the returned line is simply the provided bluetooth address.

Parameters:
btAddr - the bluetooth address of the device.
Returns:
a String containing the user defined name (if one exists) and the address.

getInfoLineList

public ArrayList<String> getInfoLineList()
Get a list of the Strings returned by getInfoLine for all of the devices in this BluetoothNameMap.

Returns:
the info lines for all of the devices.

dLife Home Page