corny.addressbook.data
Class MultiValue<T>

java.lang.Object
  extended by corny.addressbook.data.MultiValue<T>
Type Parameters:
T - Type of Values in this MultiValue instance
All Implemented Interfaces:
Searchable, java.lang.Iterable<MultiValue.KeyValuePair<T>>
Direct Known Subclasses:
MutableMultiValue

public class MultiValue<T>
extends java.lang.Object
implements java.lang.Iterable<MultiValue.KeyValuePair<T>>, Searchable

Data model class for multi value properties of Address Book contacts, like a list of phone numbers.

Author:
Corny

Nested Class Summary
static class MultiValue.KeyValuePair<T>
          Data model class for key / value properties of Address Book contacts, like a phone number.
static class MultiValue.MultiValueLabel
          Enumeration which declares the default MultiValue labels
 
Constructor Summary
MultiValue(java.util.List<MultiValue.KeyValuePair<T>> pairs)
          Creates a new MultiValue instance containing the given KeyValuePairs.
 
Method Summary
 void addSearchStringsToList(java.util.List<java.lang.Object> list, java.lang.String propertyLabel)
          Used by Filter classes to fetch the searchable fields of an object.
 boolean equals(java.lang.Object obj)
          Returns true if the instances are the same or if the KeyValuePairs equal pairwise.
 T getFirstHomeValue()
           
 T getFirstMobileValue()
           
 T getFirstValue()
           
 T getFirstWorkValue()
           
 java.util.List<MultiValue.KeyValuePair<T>> getValues(java.lang.String key)
          Returns all KeyValuePairs with the given key.
 java.util.Iterator<MultiValue.KeyValuePair<T>> iterator()
           
 MutableMultiValue<T> mutableClone()
           
 int size()
           
 java.lang.String toString()
           
static java.lang.String translateBackwards(java.lang.String key)
          Translates the human readable key text back to the Apple Address Book's internal description text.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiValue

public MultiValue(java.util.List<MultiValue.KeyValuePair<T>> pairs)
Creates a new MultiValue instance containing the given KeyValuePairs.

Parameters:
pairs - KeyValuePairs for the new MultiValue instance
Method Detail

translateBackwards

public static java.lang.String translateBackwards(java.lang.String key)
Translates the human readable key text back to the Apple Address Book's internal description text. If no translation is found, the passed String will be returned.

Parameters:
key - Key to translate
Returns:
Translated key or passed key if no Translation is found

iterator

public java.util.Iterator<MultiValue.KeyValuePair<T>> iterator()
Specified by:
iterator in interface java.lang.Iterable<MultiValue.KeyValuePair<T>>
Returns:
An Iterator over the KeyValuePairs of this MultiValue instance

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

addSearchStringsToList

public void addSearchStringsToList(java.util.List<java.lang.Object> list,
                                   java.lang.String propertyLabel)
Description copied from interface: Searchable
Used by Filter classes to fetch the searchable fields of an object.

Specified by:
addSearchStringsToList in interface Searchable
Parameters:
list - List to add the searchable fields to
propertyLabel - If this is set, only the properties with a specific label should be added to the list.

getValues

public java.util.List<MultiValue.KeyValuePair<T>> getValues(java.lang.String key)
Returns all KeyValuePairs with the given key.

Parameters:
key - Key of the desired KeyValuePairs
Returns:
KeyValuePairs mathing the key

size

public int size()
Returns:
Item count

getFirstValue

public T getFirstValue()
Returns:
The value of the first KeyValuePair or null if the MultiValue is empty

getFirstHomeValue

public T getFirstHomeValue()
Returns:
The value of the first KeyValuePair whose Key is MultiValue.HOME or null if none exists

getFirstWorkValue

public T getFirstWorkValue()
Returns:
The value of the first KeyValuePair whose Key is MultiValue.WORK or null if none exists

getFirstMobileValue

public T getFirstMobileValue()
Returns:
The value of the first KeyValuePair whose Key is MultiValue.MOBILE or null if none exists

mutableClone

public MutableMultiValue<T> mutableClone()
Returns:
A mutable clone of this MultiValue instance

equals

public boolean equals(java.lang.Object obj)
Returns true if the instances are the same or if the KeyValuePairs equal pairwise.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Other object
Returns:
true, if obj is equal to this.