: Class PersonsDictionary

Class PersonsDictionary

java.lang.Object
  |
  +--PersonsDictionary

public class PersonsDictionary
extends java.lang.Object

Implements a dictionary of persons


Constructor Summary
PersonsDictionary(java.io.File f)
          Constructs the dictionary from the file.
PersonsDictionary(java.lang.String s)
          Constructs the dictionary from the string.
 
Method Summary
 boolean add(Person p)
          Adds the person to the dictionary.
 boolean delete(java.lang.String name)
          Removes the person from the dictionary.
 Person getByName(java.lang.String name)
          Returns the person with the specified name.
 void toFile(java.io.File f)
          Writes the contents of the dictionary into a specified file.
 java.lang.String toString()
          Returns representation of the dictionary as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PersonsDictionary

public PersonsDictionary(java.lang.String s)
Constructs the dictionary from the string. The string consists of multiple lines, one line for person, in the format:
< name > : < status >
< name > is the name is the name of the person, < status > status of the person (OFFLINE, ONLINE, etc.)

PersonsDictionary

public PersonsDictionary(java.io.File f)
Constructs the dictionary from the file. The format of the file is exactly as the format of the string for the previous constructor.
Method Detail

add

public boolean add(Person p)
Adds the person to the dictionary. A person should be added only if the ditionary does not contain a person with the same name.
Returns:
true if the person was added,
false otherwise (i.e. the dictionary already contains a person with the same name)

delete

public boolean delete(java.lang.String name)
Removes the person from the dictionary.
Returns:
true if the operation was completed,
false otherwise (i.e. the dictionary does not contain a person with the given name)

getByName

public Person getByName(java.lang.String name)
Returns the person with the specified name.
Returns:
if present returns person with the specified name, null otherwise

toString

public java.lang.String toString()
Returns representation of the dictionary as a string. The format of the string is as the format of the string for constructor
Overrides:
toString in class java.lang.Object

toFile

public void toFile(java.io.File f)
Writes the contents of the dictionary into a specified file. The format of the file is as the format of the string for constructor.