Business Objects
Quark Platform Documentation
Version 1.7.0_0
Business Objects

org.openquark.cal.compiler
Class ModuleName

java.lang.Object
  extended by org.openquark.cal.compiler.ModuleName
All Implemented Interfaces:
Comparable<ModuleName>, Name

public final class ModuleName
extends Object
implements Name, Comparable<ModuleName>

This class abstracts a module name in CAL. A module name is composed of one or more components separated by dots. For example, Foo and Cal.Core.Prelude are valid module names. Each component must start with an uppercase letter.

Author:
Joseph Wong

Nested Class Summary
static class ModuleName.FullyQualifiedComparator
          A Comparator which compares ModuleNames by their fully-qualified form, comparing on a component-by-component basis.
 
Method Summary
 int compareTo(ModuleName other)
          
 boolean equals(ModuleName other)
          Compares whether the given module name is equal to this module name.
 boolean equals(Object other)
          
 ModuleName getCommonPrefix(ModuleName other)
          Returns the common prefix of this module name and the given module name (which may be equal to either one if one is an improper prefix of the other), or null if they do not share a common prefix.
 String[] getComponents()
           
 String[] getComponents(int start, int end)
          Returns an array of some of the components in this module name, as specified by the given start and end indices.
 ModuleName getImmediatePrefix()
          Returns a module name that is the immediate prefix of this name, i.e. it is this name, but dropping the last component.
 String getLastComponent()
          Returns the last component.
 ModuleName getModuleName()
          
 int getNComponents()
          Returns the number of components in this module name.
 String getNthComponent(int n)
          Returns the component at the position specified by the given index.
 ModuleName getPrefix(int nComponents)
          Returns a module name that is a prefix of this name.
 int hashCode()
          
 boolean isProperPrefixOf(ModuleName other)
          Returns whether this module name is a proper prefix of the given module name.
static ModuleName make(String moduleName)
          Factory method for constructing an instance of this class.
static ModuleName make(String[] components)
          Factory method for constructing an instance of this class.
static ModuleName maybeMake(String maybeModuleName)
          Factory method for constructing an instance of this class which accepts nulls and invalid module name strings.
 String toSourceText()
           Returns the module name as it would appear in source, fully-qualified.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

make

public static ModuleName make(String moduleName)
Factory method for constructing an instance of this class.

Parameters:
moduleName - a module name. Cannot be null.
Returns:
an instance of this class.

maybeMake

public static ModuleName maybeMake(String maybeModuleName)
Factory method for constructing an instance of this class which accepts nulls and invalid module name strings.

Parameters:
maybeModuleName - a string which may or may not represent a valid module name. Can be null.
Returns:
an instance of this class, or null if the argument is null or does not represent a valid module name.

make

public static ModuleName make(String[] components)
Factory method for constructing an instance of this class.

Parameters:
components - an array of the components for the module name. Cannot be null.
Returns:
an instance of this class.

toString

public String toString()

Overrides:
toString in class Object

toSourceText

public String toSourceText()
Returns the module name as it would appear in source, fully-qualified.

Specified by:
toSourceText in interface Name
Returns:
the module name as it would appear in source, fully-qualified.

equals

public boolean equals(Object other)

Overrides:
equals in class Object

equals

public boolean equals(ModuleName other)
Compares whether the given module name is equal to this module name.

Parameters:
other - another module name.
Returns:
true if the given module name is non-null and equals this one, false otherwise.

hashCode

public int hashCode()

Overrides:
hashCode in class Object

compareTo

public int compareTo(ModuleName other)

Specified by:
compareTo in interface Comparable<ModuleName>

getNComponents

public int getNComponents()
Returns the number of components in this module name.

Returns:
the number of components in this module name.

getNthComponent

public String getNthComponent(int n)
Returns the component at the position specified by the given index.

Parameters:
n - the index of the component to return.
Returns:
the specified component.

getLastComponent

public String getLastComponent()
Returns the last component.

Returns:
the last component.

getComponents

public String[] getComponents()
Returns:
an array of the components in this module name.
See Also:
getNComponents(), getNthComponent(int), getComponents(int, int)

getComponents

public String[] getComponents(int start,
                              int end)
Returns an array of some of the components in this module name, as specified by the given start and end indices.

Parameters:
start - the start position, inclusive.
end - the end position, exclusive.
Returns:
an array of the components indexed from start to (end-1).

isProperPrefixOf

public boolean isProperPrefixOf(ModuleName other)
Returns whether this module name is a proper prefix of the given module name.

Parameters:
other - another module name.
Returns:
true if this module name is a proper prefix of the given module name, false otherwise.

getPrefix

public ModuleName getPrefix(int nComponents)
Returns a module name that is a prefix of this name.

Parameters:
nComponents - the number of components in the prefix.
Returns:
a prefix of this module name, which may be this name if the specified number of components is equal to the number of components in this name.

getImmediatePrefix

public ModuleName getImmediatePrefix()
Returns a module name that is the immediate prefix of this name, i.e. it is this name, but dropping the last component. If this name only has one component, then null is returned.

Returns:
the immediate prefix of this module name, or null if this name has only one component.

getCommonPrefix

public ModuleName getCommonPrefix(ModuleName other)
Returns the common prefix of this module name and the given module name (which may be equal to either one if one is an improper prefix of the other), or null if they do not share a common prefix.

Parameters:
other - another module name.
Returns:
the common prefix, or null.

getModuleName

public ModuleName getModuleName()

Specified by:
getModuleName in interface Name
Returns:
the ModuleName of this name. This is never null.

Business Objects
Quark Platform Documentation
Version 1.7.0_0
Business Objects

Copyright © 2007 Business Objects. All rights reserved.