com.miginfocom.util
Class NameValuePair

java.lang.Object
  extended by com.miginfocom.util.NameValuePair
All Implemented Interfaces:
java.io.Serializable

public class NameValuePair
extends java.lang.Object
implements java.io.Serializable

A class that mapps a name (String) with an Object.
Very useful for putting in a ComboBox or List.
Also contains a few static method to make lookups if a JComboBox that contains NameValuePair objects.

See Also:
Serialized Form

Constructor Summary
NameValuePair(java.lang.String name, java.lang.Object value)
          Constructor
 
Method Summary
 boolean equals(java.lang.Object o)
          Compares this object's value with obj.
static NameValuePair findByName(NameValuePair[] nvps, java.lang.String name)
          Returns the value for the first key in the array that equals name
static NameValuePair findByValue(NameValuePair[] nvps, java.lang.Object value)
          Returns the name for the first value in the array that equals value.
static java.lang.String[] getKeys(NameValuePair[] nvps)
          Returns the keys of the NameValuePairs.
 java.lang.String getName()
          Returnes the name.
 java.lang.Object getValue()
          Returns the value
 boolean getValueAsBoolean()
          Return the value as a boolean.
 int getValueAsInt()
          Return the value as an int.
 long getValueAsLong()
          Return the value as a long.
 java.lang.String getValueAsString()
          Return the value as a.
static java.lang.Object[] getValues(NameValuePair[] nvps)
          Returns the values of the NameValuePairs.
static boolean selectComboBoxItem(javax.swing.JComboBox jComboBox, java.lang.Object value)
          Selects the item in the JComboBox that matches value.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NameValuePair

public NameValuePair(java.lang.String name,
                     java.lang.Object value)
Constructor

Parameters:
name - The name. normally not null.
value - The value. Can be null.
Method Detail

getValueAsInt

public final int getValueAsInt()
Return the value as an int. The value stored must be of type Integer and not null

Returns:
Value as an int

getValueAsLong

public final long getValueAsLong()
Return the value as a long. The value stored must be of type Long and not null

Returns:
Value as an long

getValueAsBoolean

public final boolean getValueAsBoolean()
Return the value as a boolean. If value is null, not a String or Boolean false will be returned. String is checked for "true" ignoring case.

Returns:
Value as an boolean.

getValueAsString

public final java.lang.String getValueAsString()
Return the value as a. If value is null, null will be returned.

Returns:
Value as an int (works on all types, includng null)

getValue

public final java.lang.Object getValue()
Returns the value

Returns:
The value

getName

public final java.lang.String getName()
Returnes the name.

Returns:
The name.

toString

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

equals

public boolean equals(java.lang.Object o)
Compares this object's value with obj. If obj is another NameValuePair, that NameValuePair's value will be comapred instead of the NameValuePair itself. null == null.

Overrides:
equals in class java.lang.Object
Parameters:
o - Another object to compare value to.
Returns:
If they are of same type, have equal value. null == null.

selectComboBoxItem

public static boolean selectComboBoxItem(javax.swing.JComboBox jComboBox,
                                         java.lang.Object value)
Selects the item in the JComboBox that matches value. The combobox's values are iterated and the first the .equas(value) is selected. This method is supposed to be used when the JComboBox consists only of NameValuePairs.

Parameters:
jComboBox - The combobox that contains NameValuePairs
value - The value, either a NameValuePair or an object that will be compared to the values of the combobox's NameValuePair's values.
Returns:
true if the value was found and the corresponding item selected.

findByValue

public static NameValuePair findByValue(NameValuePair[] nvps,
                                        java.lang.Object value)
Returns the name for the first value in the array that equals value.

Parameters:
nvps - The NameValuePairs. Not null.
value - The value to match any of the values in nvps. May be null and if so only matches a null value.
Returns:
The NameValuePair for the first value in the array that equals value. Will be null if there was no matching value found.

findByName

public static NameValuePair findByName(NameValuePair[] nvps,
                                       java.lang.String name)
Returns the value for the first key in the array that equals name

Parameters:
nvps - The NameValuePairs. Not null.
name - The name to match any of the names in nvps. May be null and if so only matches a null name.
Returns:
The NameValuePair for the first key in the array that equals name. Will be null if there was no matching name found.

getValues

public static java.lang.Object[] getValues(NameValuePair[] nvps)
Returns the values of the NameValuePairs.

Parameters:
nvps - The NameValuePairs. If null null is returned.
Returns:
The values of the NameValuePairs or null if nvps was null.

getKeys

public static java.lang.String[] getKeys(NameValuePair[] nvps)
Returns the keys of the NameValuePairs.

Parameters:
nvps - The NameValuePairs. If null null is returned.
Returns:
The keys of the NameValuePairs or null if nvps was null.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.