net.javamud.data
Class Right

java.lang.Object
  |
  +--net.javamud.data.Right
All Implemented Interfaces:
Comparable

public class Right
extends Object
implements Comparable

A Right represents being allowed to do something.

Rights are immutable, and therefor thread safe.
A Right has no concept of who has the Right, nor what the Right applies to. There is also no concept of inheritance nor whether this is a granting or a revoking.

Rights do NOT implement SISCapable as their internal String is inherently single instance via the intern() call.

Author:
Timothy Hinchcliffe
See Also:
SISCapable
Created On:
15 June 2002

Field Summary
protected  int depth
          "Depth" of field.
static int maxQuality
          Maximum allowably quality value.
protected  String name
          Name of the right.
 
Constructor Summary
Right(String setName)
          Constructor for the Right object
 
Method Summary
 int compareTo(Object o)
          See java.lang.Comparable.
static int Depth(String s)
          Description of the Method
 boolean equals(Object o)
          Equality test.
 int getDepth()
          Gets the depth attribute of the Right object
protected static int getDepth(String str)
          Calculates the depth of the given Right String.
 String getName()
          Gets the name attribute of the Right object
 int hashCode()
          Returns name.hashCode().
 boolean impliedBy(Right impliesMe)
          The same as impliesMe .implies(this).
 boolean impliedBy(String impliesMe)
          Returns true if impliesMe implies this right.
protected static boolean implies_impl(String a, String b)
          Implementation of implies and impliedBy functions.
 boolean implies(Right iImply)
          If iImply is implied by this Right.
 boolean implies(String iImply)
          If iImply is implied by this Right.
protected  int impliesQuality_impl(String iImply)
          Returns a quality of match associated with the implies operation.
 int impliesQuality(Right right)
          Quality of implies match.
 int impliesQuality(String right)
          Quality of implies match.
static String Resolve(String s)
          Resolves a String in to a correct Right string.
 String toString()
          Returns name which is already a String representation of the Right.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

maxQuality

public static final int maxQuality
Maximum allowably quality value. Used for not a match.

See Also:
Constant Field Values

depth

protected int depth
"Depth" of field. How many '.'s are in the string.


name

protected String name
Name of the right.
Full stop (".") groups releated right groups.
All rights start with ".".
Rights that end with "." imply rights which start with the same sequence.

Constructor Detail

Right

public Right(String setName)
Constructor for the Right object

Parameters:
setName - The right that this object represents.
Method Detail

getDepth

public int getDepth()
Gets the depth attribute of the Right object

Returns:
The depth value

getName

public String getName()
Gets the name attribute of the Right object

Returns:
The name value

getDepth

protected static int getDepth(String str)
Calculates the depth of the given Right String.

Parameters:
str - String to get depth of.
Returns:
The depth value

Depth

public static int Depth(String s)
Description of the Method

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

Resolve

public static String Resolve(String s)
Resolves a String in to a correct Right string.

Parameters:
s - String to resolve.
Returns:
A String starting with "." and containing no more than one "." in a row.

compareTo

public int compareTo(Object o)
              throws ClassCastException
See java.lang.Comparable.

Specified by:
compareTo in interface Comparable
Parameters:
o - See java.lang.Comparable.
Returns:
See java.lang.Comparable.
Throws:
ClassCastException - See java.lang.Comparable.
See Also:
Comparable

equals

public boolean equals(Object o)
Equality test. Can match against a Right or a String.

Overrides:
equals in class Object
Parameters:
o - See Object
Returns:
See Object
See Also:
Object

hashCode

public int hashCode()
Returns name.hashCode().

Overrides:
hashCode in class Object
Returns:
name.hashCode()

impliedBy

public boolean impliedBy(String impliesMe)
Returns true if impliesMe implies this right.
A right always implies itself.

Parameters:
impliesMe - A right.
Returns:
if the specified right implies me or not.
See Also:
implies(String), implies(Right), impliedBy(Right)

impliedBy

public boolean impliedBy(Right impliesMe)
The same as impliesMe .implies(this).

Parameters:
impliesMe - Right to test.
Returns:
Whether or not this right is implied by impliesMe .

implies

public boolean implies(String iImply)
If iImply is implied by this Right.

Parameters:
iImply - Right to test.
Returns:
If it is implied or not.

implies

public boolean implies(Right iImply)
If iImply is implied by this Right.

Parameters:
iImply - Right to test.
Returns:
If it is implied or not.

impliesQuality

public int impliesQuality(Right right)
Quality of implies match.

Parameters:
right - Right to compare.
Returns:
Quality of the match.

impliesQuality

public int impliesQuality(String right)
Quality of implies match.

Parameters:
right - Right to compare.
Returns:
Quality of the match.

toString

public String toString()
Returns name which is already a String representation of the Right.

Overrides:
toString in class Object
Returns:
name

impliesQuality_impl

protected int impliesQuality_impl(String iImply)
Returns a quality of match associated with the implies operation. Quality is maxQuality for no match, 0 for perfect match, >0 for imperfect match. Lower qualities are a closer match.

Parameters:
iImply - Right to test. MUST be Resolve(java.lang.String)()d.
Returns:
Quality of match.

implies_impl

protected static boolean implies_impl(String a,
                                      String b)
Implementation of implies and impliedBy functions. For efficiency. a and b should already be Resolve(java.lang.String)()d.

Parameters:
a - String that may imply b
b - String that may be implied by a
Returns:
If a implies b