net.sourceforge.stripes.controller
Class ParameterName

java.lang.Object
  extended by net.sourceforge.stripes.controller.ParameterName
All Implemented Interfaces:
Comparable<ParameterName>

public class ParameterName
extends Object
implements Comparable<ParameterName>

Encapsulates the name of a parameter in the HttpServletRequest. Detects whether or not the name refers to an indexed or mapped property.

Author:
Tim Fennell

Field Summary
static Pattern pattern
          Stores the regular expression that will remove all [] segments.
 
Constructor Summary
ParameterName(String name)
          Constructs a ParameterName for a given name from the HttpServletRequest.
 
Method Summary
 int compareTo(ParameterName that)
          Orders ParameterNames so that those with shorter (unstripped) names come first.
 boolean equals(Object obj)
          Checks for equality as efficiently as possible.
 String getName()
          Always returns the parameter name as passed in to the constructor.
 String getStrippedName()
          Returns the name with all indexing and mapping components stripped.
 int hashCode()
          Simple hashcode method based on the name of the parameter.
 boolean isIndexed()
          Returns true if the name has indexing or mapping components, otherwise false.
 String toString()
          Uses the original name as the string representation of the class.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

pattern

public static final Pattern pattern
Stores the regular expression that will remove all [] segments.

Constructor Detail

ParameterName

public ParameterName(String name)
Constructs a ParameterName for a given name from the HttpServletRequest. As it is constructed, detects whether or not the name contains indexing or mapping components, and if it does, also creates and stores the stripped name.

Parameters:
name - a name that may or may not contain indexing or mapping
Method Detail

isIndexed

public boolean isIndexed()
Returns true if the name has indexing or mapping components, otherwise false.


getName

public String getName()
Always returns the parameter name as passed in to the constructor. If it contained indexing or mapping components (e.g. [3] or (foo)) they will be present in the String returned.

Returns:
String the name as supplied in the request

getStrippedName

public String getStrippedName()
Returns the name with all indexing and mapping components stripped. E.g. if the name in the request was 'foo[1].bar', this method will return 'foo.bar'.

Returns:
String the name minus indexing and mapping

compareTo

public int compareTo(ParameterName that)
Orders ParameterNames so that those with shorter (unstripped) names come first. Two names of the same length are then ordered alphabetically by String.compareTo().

Specified by:
compareTo in interface Comparable<ParameterName>
Parameters:
that - another ParameterName to compare to
Returns:
-1 if this value sorts first, 0 if the values are identical and +1 if the parameter passed in sorts first.

equals

public boolean equals(Object obj)
Checks for equality as efficiently as possible. First checks for JVM equality to see if we can short circuit, and then checks for equality of the name attribute for a real test.

Overrides:
equals in class Object

hashCode

public int hashCode()
Simple hashcode method based on the name of the parameter.

Overrides:
hashCode in class Object

toString

public String toString()
Uses the original name as the string representation of the class. This is probably the most useful thing to see in log messages, which is the only place toString will be used.

Overrides:
toString in class Object


? Copyright 2005-2006, Stripes Development Team.