org.baswell.routes
Class RequestPath

java.lang.Object
  extended by org.baswell.routes.RequestPath

public class RequestPath
extends java.lang.Object

Details of the HTTP request path (minus the application's context path). The request path is broken up into segments where a segment is the text between slashes.

For example there are three path segments ("one", "two", and "three") in the URL:

 http://localhost:8080/context_path/one/two/three
 

This class is immutable. All modification operations (ex. pop()) result in new RequestPath objects returned.


Method Summary
 boolean equals(java.util.List<java.lang.String> segments)
           
 boolean equals(java.lang.Object object)
           
 boolean equals(java.lang.String path)
           
 java.lang.String get(int index)
           
 boolean getBoolean(int index)
           
 byte getByte(int index)
           
 char getCharacter(int index)
           
 double getDouble(int index)
           
 java.lang.String getFileExtension()
          If this path contains a file name this method returns the text to the right of the last '.' in the file name.
 java.lang.String getFileName()
          If the last segment in this path has a '.' then the full (last) segment will be returned.
 float getFloat(int index)
           
 int getInteger(int index)
           
 long getLong(int index)
           
 short getShort(int index)
           
 RequestPath pop()
          Same as pop(1).
 RequestPath pop(int numberSegments)
          Returns a new RequestPath with the given number of segments removed from the start of the path.
 int size()
           
 boolean startsWith(java.util.List<java.lang.String> segments)
           
 boolean startsWith(java.lang.String path)
           
 RequestPath substring(int index)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

size

public int size()
Returns:
The number of segments in this path.

get

public java.lang.String get(int index)
                     throws java.lang.IndexOutOfBoundsException
Parameters:
index -
Returns:
The segment at the given index.
Throws:
java.lang.IndexOutOfBoundsException - If index < 0 or index >= size()

getCharacter

public char getCharacter(int index)
                  throws java.lang.IndexOutOfBoundsException
Parameters:
index -
Returns:
The first character of the segment at the given index.
Throws:
java.lang.IndexOutOfBoundsException - If index < 0 or index >= size()

getBoolean

public boolean getBoolean(int index)
                   throws java.lang.IndexOutOfBoundsException
Parameters:
index -
Returns:
The parsed boolean segment at the given index.
Throws:
java.lang.IndexOutOfBoundsException - If index < 0 or index >= size()

getByte

public byte getByte(int index)
             throws java.lang.IndexOutOfBoundsException,
                    java.lang.NumberFormatException
Parameters:
index -
Returns:
The parsed byte segment at the given index
Throws:
java.lang.IndexOutOfBoundsException - If index < 0 or index >= size()
java.lang.NumberFormatException - If the segment at the given index cannot be parsed into a byte.

getShort

public short getShort(int index)
               throws java.lang.IndexOutOfBoundsException,
                      java.lang.NumberFormatException
Parameters:
index -
Returns:
The parsed short segment at the given index
Throws:
java.lang.IndexOutOfBoundsException - If index < 0 or index >= size()
java.lang.NumberFormatException - If the segment at the given index cannot be parsed into a short.

getInteger

public int getInteger(int index)
               throws java.lang.IndexOutOfBoundsException,
                      java.lang.NumberFormatException
Parameters:
index -
Returns:
The parsed int segment at the given index
Throws:
java.lang.IndexOutOfBoundsException - If index < 0 or index >= size()
java.lang.NumberFormatException - If the segment at the given index cannot be parsed into a int.

getLong

public long getLong(int index)
             throws java.lang.IndexOutOfBoundsException,
                    java.lang.NumberFormatException
Parameters:
index -
Returns:
The parsed long segment at the given index
Throws:
java.lang.IndexOutOfBoundsException - If index < 0 or index >= size()
java.lang.NumberFormatException - If the segment at the given index cannot be parsed into a long.

getFloat

public float getFloat(int index)
               throws java.lang.IndexOutOfBoundsException,
                      java.lang.NumberFormatException
Parameters:
index -
Returns:
The parsed float segment at the given index
Throws:
java.lang.IndexOutOfBoundsException - If index < 0 or index >= size()
java.lang.NumberFormatException - If the segment at the given index cannot be parsed into a float.

getDouble

public double getDouble(int index)
                 throws java.lang.IndexOutOfBoundsException,
                        java.lang.NumberFormatException
Parameters:
index -
Returns:
The parsed double segment at the given index
Throws:
java.lang.IndexOutOfBoundsException - If index < 0 or index >= size()
java.lang.NumberFormatException - If the segment at the given index cannot be parsed into a double.

startsWith

public boolean startsWith(java.lang.String path)
Parameters:
path -
Returns:
True if this request path starts with the given path, false otherwise.

startsWith

public boolean startsWith(java.util.List<java.lang.String> segments)
Parameters:
segments -
Returns:
True if this request path starts with the given path segments, false otherwise.

pop

public RequestPath pop(int numberSegments)
                throws java.lang.IndexOutOfBoundsException
Returns a new RequestPath with the given number of segments removed from the start of the path. The RequestPath this method is called is unaltered. requestPath.pop(2) performed on: /one/two/three results in: /three

Parameters:
numberSegments - The number of segments to pop from this path.
Returns:
A new RequestPath with the given number of segments removed from the head of the path.
Throws:
java.lang.IndexOutOfBoundsException - If numberSegments < 0 or numberSegments >= size().

pop

public RequestPath pop()
                throws java.lang.IndexOutOfBoundsException
Same as pop(1).

Returns:
A new RequestPath with the 1 segment removed from the head of the path.
Throws:
java.lang.IndexOutOfBoundsException - if size() == 0.
See Also:
pop(int)

getFileName

public java.lang.String getFileName()
If the last segment in this path has a '.' then the full (last) segment will be returned. If the last segment does not have a '.' then null is returned.

Returns:
The file name of the path or null if this path does not contain a file name at the end.

getFileExtension

public java.lang.String getFileExtension()
If this path contains a file name this method returns the text to the right of the last '.' in the file name. If the path does not contain a file name then null is returned.

Returns:
The file name extension or null if the path does contain a file name.

substring

public RequestPath substring(int index)
                      throws java.lang.IndexOutOfBoundsException
Parameters:
index -
Returns:
A new RequestPath from segment 0 to the given index.
Throws:
java.lang.IndexOutOfBoundsException - If index < 0 or index >= size().

equals

public boolean equals(java.lang.String path)
Parameters:
path -
Returns:
True if the segments of this request path match the segments of the given path, false otherwise.

equals

public boolean equals(java.util.List<java.lang.String> segments)
Parameters:
segments -
Returns:
True if the segments of this request path match the given segments, false otherwise.

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

toString

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