info.aduna.gee.publication.content
Class PathString

java.lang.Object
  extended by info.aduna.gee.publication.content.PathString
All Implemented Interfaces:
Comparable

public class PathString
extends Object
implements Comparable

A PathString is a cpu and memory efficient implementation of path names. Previously, a complete path was just a String. However, there is a lot to be gained by a dedicated class for this type of String usage. A PathString is IMMUTABLE!


Field Summary
protected  String[] _chunks
          The path chunks
protected  int _hashCode
           
 
Constructor Summary
PathString(PathString pre, Object post)
          Construct a new PathString, concatenating a PathStrings and an Object.
PathString(PathString pre, PathString post)
          Construct a new PathString, concatenating two existing PathStrings.
PathString(String path)
          Construct a new PathString.
PathString(String[] chunks)
          Construct PathString by taking an existing chunks array.
 
Method Summary
static String bestMatch(Vector names, String aName, int matchPercentage)
          Find the best matching String from a Vector of Strings.
static int bestMatchIndex(Vector names, String aName, int matchPercentage)
           
static int chunkCompare(String one, String two)
          Due to the special interpretation of numbers we can not use the original String compare.
 int compareTo(Object other)
           
 int depth()
           
 boolean equals(Object other)
           
 String getChunk(int index)
           
 String[] getChunks()
          Get a clone of the Chunk array.
 String getLastName()
           
 PathString getParent()
           
 PathString getParent(int g)
           
 int hashCode()
           
 boolean isChildOf(PathString other)
           
 PathString remainder(PathString prefix)
           
 boolean startsWith(PathString other)
           
 PathString subPath(int beginIndex)
           
 PathString subPath(int beginIndex, int endIndex)
          Note that subPath will automatically adapt the parameters to valid ones.
 String toSafeString()
          Avoid ' in section names when used in javascript arguments.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

_chunks

protected String[] _chunks
The path chunks


_hashCode

protected int _hashCode
Constructor Detail

PathString

public PathString(String path)
Construct a new PathString.


PathString

public PathString(PathString pre,
                  PathString post)
Construct a new PathString, concatenating two existing PathStrings.


PathString

public PathString(PathString pre,
                  Object post)
Construct a new PathString, concatenating a PathStrings and an Object.


PathString

public PathString(String[] chunks)
Construct PathString by taking an existing chunks array.

Method Detail

depth

public int depth()
Returns:
the depth (number of chunks) in the path.

toString

public String toString()
Overrides:
toString in class Object

toSafeString

public String toSafeString()
Avoid ' in section names when used in javascript arguments. Replace a ' by ` it avoids problems. Note that we depend upon Zpads 'intelligent behaviour' in order to match Cote d'Azur Cote d`Azur.


hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object

compareTo

public int compareTo(Object other)
Specified by:
compareTo in interface Comparable

chunkCompare

public static int chunkCompare(String one,
                               String two)
Due to the special interpretation of numbers we can not use the original String compare.


getParent

public PathString getParent()
Returns:
the parent of this PathString or null

getParent

public PathString getParent(int g)
Parameters:
g - the number of generations up
Returns:
the parent a number of generations up of this PathString or null

startsWith

public boolean startsWith(PathString other)
Returns:
true if the current PathString starts with other

isChildOf

public boolean isChildOf(PathString other)
Returns:
true if the current PathString is the immediate child of other

remainder

public PathString remainder(PathString prefix)
Returns:
the remainder after removing the prefix

getLastName

public String getLastName()
Returns:
the name of the last chunk.

getChunk

public String getChunk(int index)
Returns:
the name of the chunk

getChunks

public String[] getChunks()
Get a clone of the Chunk array.


bestMatch

public static String bestMatch(Vector names,
                               String aName,
                               int matchPercentage)
Find the best matching String from a Vector of Strings.

Parameters:
names - the names to match against
aName - the name to match
matchPercentage - between 0 and 100 (exact match only)
Returns:
the best match or null when names is empty or the match percentage isn't reached

bestMatchIndex

public static int bestMatchIndex(Vector names,
                                 String aName,
                                 int matchPercentage)
Returns:
the index of the best match or -1 (not a sufficiently match)

subPath

public PathString subPath(int beginIndex)
See Also:
String.substring(int)

subPath

public PathString subPath(int beginIndex,
                          int endIndex)
Note that subPath will automatically adapt the parameters to valid ones.

Returns:
the best effort for the request
See Also:
String.substring(int)


Copyright © 1997-2008 Aduna. All Rights Reserved.