net.derquinse.common.jaxrs
Class PathSegments

java.lang.Object
  extended by com.google.common.collect.ForwardingObject
      extended by com.google.common.collect.ForwardingCollection<E>
          extended by com.google.common.collect.ForwardingList<String>
              extended by net.derquinse.common.jaxrs.PathSegments
All Implemented Interfaces:
Iterable<String>, Collection<String>, List<String>

@Immutable
public final class PathSegments
extends com.google.common.collect.ForwardingList<String>

List of non-encoded URI path segments.

Author:
Andres Rodriguez.

Method Summary
 PathSegments append(PathSegments other)
          Appends some segments after this list.
 com.google.common.base.Function<PathSegments,PathSegments> appender()
          Returns a new transformer that appends this segments to the provided path.
 PathSegments appendExtension(String extension)
          Appends an extension to the last segment.
 PathSegments consume()
           
 PathSegments consume(int n)
           
 PathSegments consumeLast()
           
 PathSegments consumeLast(int n)
           
protected  List<String> delegate()
           
 boolean equals(Object object)
           
 String getExtension()
          Extracts the extension from the last segment.
static String getSegmentExtension(String segment)
          Extracts the extension from a segment.
 int hashCode()
           
 String head()
           
 com.google.common.base.Function<PathSegments,PathSegments> inserter()
          Returns a new transformer that inserts this segments at the beginning of the provided path.
 String join()
           
 String last()
           
static PathSegments of()
          Returns an empty list of segments.
static PathSegments of(boolean encoded, Iterable<String> segments)
          Turns a collection of string into a list of decoded segments.
static PathSegments of(boolean encoded, String... segments)
          Turns an array of strings into a list of decoded segments.
static PathSegments of(String path, boolean encoded)
          Turns a path string into a list of decoded segments.
 PathSegments removeExtension()
          Removes the extension from the last segment.
static String removeSegmentExtension(String segment)
          Removes the extension from a segment.
static PathSegments segment(String segment, boolean encoded)
          Turns a single segment into a list of decoded segments.
 String toString()
           
 
Methods inherited from class com.google.common.collect.ForwardingList
add, addAll, get, indexOf, lastIndexOf, listIterator, listIterator, remove, set, standardAdd, standardAddAll, standardEquals, standardHashCode, standardIndexOf, standardIterator, standardLastIndexOf, standardListIterator, standardListIterator, standardSubList, subList
 
Methods inherited from class com.google.common.collect.ForwardingCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, standardAddAll, standardClear, standardContains, standardContainsAll, standardIsEmpty, standardRemove, standardRemoveAll, standardRetainAll, standardToArray, standardToArray, standardToString, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Method Detail

of

public static PathSegments of()
Returns an empty list of segments.

Returns:
An empty list of segments.

segment

public static PathSegments segment(@Nullable
                                   String segment,
                                   boolean encoded)
Turns a single segment into a list of decoded segments.

Parameters:
segment - Segment.
encoded - If the segment is encoded.
Returns:
The never null list of segments.

of

public static PathSegments of(@Nullable
                              String path,
                              boolean encoded)
Turns a path string into a list of decoded segments.

Parameters:
path - Path to split.
encoded - If the path is encoded.
Returns:
The never null list of segments.

of

public static PathSegments of(boolean encoded,
                              @Nullable
                              Iterable<String> segments)
Turns a collection of string into a list of decoded segments.

Parameters:
encoded - If the segments are encoded.
segments - String segments.
Returns:
The never null list of segments.

of

public static PathSegments of(boolean encoded,
                              String... segments)
Turns an array of strings into a list of decoded segments.

Parameters:
encoded - If the segments are encoded.
segments - String segments.
Returns:
The never null list of segments.

getSegmentExtension

public static String getSegmentExtension(String segment)
Extracts the extension from a segment.

Parameters:
segment - Segment.
Returns:
The extension or null if no extension is found.

removeSegmentExtension

public static String removeSegmentExtension(String segment)
Removes the extension from a segment.

Parameters:
segment - Segment.
Returns:
The segment without the extension (and without the dot) or the same segment if no extension is found.

delegate

protected List<String> delegate()
Overrides:
delegate in class com.google.common.collect.ForwardingList<String>

consume

public PathSegments consume(int n)

consumeLast

public PathSegments consumeLast(int n)

head

public String head()

last

public String last()

consume

public PathSegments consume()

consumeLast

public PathSegments consumeLast()

getExtension

public String getExtension()
Extracts the extension from the last segment.

Parameters:
segment - Segment.
Returns:
The extension or null if no extension is found or the object is empty.

appendExtension

public PathSegments appendExtension(@Nullable
                                    String extension)
Appends an extension to the last segment. If this object is empty no operation is performed.

Parameters:
extension - Extension to add. If null or only whitespace no operation is performed.
Returns:
The modified segments.

removeExtension

public PathSegments removeExtension()
Removes the extension from the last segment.

Returns:
The modified segments.

join

public String join()

append

public PathSegments append(@Nullable
                           PathSegments other)
Appends some segments after this list.

Parameters:
other - Segments to add.
Returns:
The resulting segments.

inserter

public com.google.common.base.Function<PathSegments,PathSegments> inserter()
Returns a new transformer that inserts this segments at the beginning of the provided path.

Returns:
The requested transformer.

appender

public com.google.common.base.Function<PathSegments,PathSegments> appender()
Returns a new transformer that appends this segments to the provided path.

Parameters:
segments - Segments to append.
Returns:
The requested transformer.

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<String>
Specified by:
hashCode in interface List<String>
Overrides:
hashCode in class com.google.common.collect.ForwardingList<String>

equals

public boolean equals(Object object)
Specified by:
equals in interface Collection<String>
Specified by:
equals in interface List<String>
Overrides:
equals in class com.google.common.collect.ForwardingList<String>

toString

public String toString()
Overrides:
toString in class com.google.common.collect.ForwardingObject


Copyright © 2012 Derquinse Projects.. All Rights Reserved.