FileDocCategorySizeDatePackage
ActionNameMap.javaAPI DocphoneME MR2 API (J2ME)7226Wed May 02 18:00:44 BST 2007javax.microedition.content

ActionNameMap

public final class ActionNameMap extends Object
An ActionNameMap provides a mapping between actions and corresponding action names. The action name SHOULD be used by an application when the action is presented to a user. The action names in each map apply to a single {@link #getLocale locale}. The application should get the appropriate ActionNameMap based on the desired locale from the method {@link ContentHandler#getActionNameMap(String locale) ContentHandler.getActionNameMap}. The actions and corresponding action names are set when the ActionNameMap is created and are immutable thereafter. The indices of the actions and action names are in the range 0 to size-1.

Fields Summary
private final String
locale
The locale for this ActionNameMap.
private final String[]
actions
The array of actions.
private final String[]
actionnames
The array of action names.
Constructors Summary
public ActionNameMap(String[] actions, String[] actionnames, String locale)
Create a new map of actions to action names for a locale. The actions and names are parallel sequences of equal length. Each action maps to the corresponding action name.

param
actions an array of actions; MUST NOT be null
param
actionnames an array of action names; MUST NOT be null
param
locale of the action names; MUST NOT be null; should be formatted according to the locale syntax conventions in {@link ContentHandler}.
exception
IllegalArgumentException:
  • if any of the actions strings or actionname strings have a length of zero,
  • if the length of the actions and actionnames arrays are unequal, or equal to zero, or
  • if the actions array includes any duplicate actions.
exception
NullPointerException if actions, actionnames, locale, or any array element is null.

	if (locale.length() == 0) {	// trigger NullPointerException
	    throw new IllegalArgumentException("empty string");
	}
	if (actions.length != actionnames.length ||
	    actions.length == 0) {
	    throw new IllegalArgumentException("lengths incorrect");
	}

	this.locale = locale;
	this.actions = ContentHandlerImpl.copy(actions);
	this.actionnames = ContentHandlerImpl.copy(actionnames);
	if (findDuplicate(this.actions) >= 0) {
	    throw new IllegalArgumentException("duplicate string");
	}        
    
Methods Summary
private intfind(java.lang.String[] strings, java.lang.String string)
Search a String for a string.

param
strings the array of strings
param
string the string to find
return
the index of the string or -1 if not found
exception
NullPointerException if string is null

	for (int i = 0; i < strings.length; i++) {
	    if (string.equals(strings[i])) {
		return i;
	    }
	}
	return -1;
    
private intfindDuplicate(java.lang.String[] strings)
Check the strings in an array are unique; no duplicates.

param
strings the string array to check.
return
return the index of a string that is duplicated; return -1 if none

	for (int i = 0; i < strings.length; i++) {
	    for (int j = i + 1; j < strings.length; j++) {
		if (strings[i].equals(strings[j])) {
		    return j;
		}
	    }
	}
	return -1;
    
public java.lang.StringgetAction(java.lang.String actionname)
Gets the action for the action name. If the action name appears more than once in the sequence, then any one of the corresponding actions may be returned.

param
actionname the action name for which to get the associated action; MUST NOT be null
return
the action; null is returned if the actionname is not found in the sequence of action names
exception
NullPointerException if actionname is null

	int index = find(actionnames, actionname);
	return (index >= 0) ? actions[index] : null;
    
public java.lang.StringgetAction(int index)
Gets the action at the specified index.

param
index the index of the action
return
the action at the specified index
exception
IndexOutOfBoundsException if index is less than zero or greater than or equal to the value of the {@link #size size} method.

	return actions[index];
    
public java.lang.StringgetActionName(java.lang.String action)
Gets the action name for an action.

param
action the action for which to get the associated action name; MUST NOT be null
return
the action name; null is returned if the action is not found in the sequence of actions
exception
NullPointerException if action is null

	int index = find(actions, action);
	return (index >= 0) ? actionnames[index] : null;
    
public java.lang.StringgetActionName(int index)
Gets the action name at the specified index.

param
index the index of the action name
return
the action name at the specified index
exception
IndexOutOfBoundsException if index is less than zero or greater than or equal to the value of the {@link #size size} method.

	return actionnames[index];
    
public java.lang.StringgetLocale()
Gets the locale for this set of action names.

return
the locale string; must not be null

	return locale;
    
public intsize()
Gets the number of pairs of actions and action names.

return
the number of actions and corresponding action names

	return actions.length;