edu.byu.ece.edif.core
Class NamedObject

java.lang.Object
  extended by edu.byu.ece.edif.core.NamedObject
All Implemented Interfaces:
EdifNameable, EdifOut, Nameable, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
MultiNamedObject, RenamedObject

public class NamedObject
extends java.lang.Object
implements EdifNameable, java.lang.Cloneable

A named String object with a valid EDIF name. These names are assumed to be valid EDIF 2.0 String names. This object is immutable.

This class has a number of helper functions for evaluating and manipulating Strings according to the EDIF specification.

Edif Identifier Specification:

Identifier is a basic token type; it is used for name definition, name reference, keywords, and symbolic constants. It contains alphanumeric or underscore characters and must be preceded with an ampersand if the first character is not a letter. This will normally be recognized by a lexical scanner.

Case is not significant in identifiers. There are no reserved identifiers, except within keywordNameDef. The length of an identifier must be between 1 and 256 characters, excluding the optional ampersand character. Identifiers are terminated by whiteSpace or by a left or right parenthesis.

Rename can be used to express external names which do not conform to the identifier syntax.

Example:

a12
&a12
A12
abc
&12s
&120

The first three identifiers in this example are identical. The last two must include the ampersand.

Version:
$Id:NamedObject.java 198 2008-04-16 21:14:21Z jamesfcarroll $
See Also:
Serialized Form

Field Summary
protected  java.lang.String _name
          The String name of this object.
 
Constructor Summary
protected NamedObject()
           
  NamedObject(EdifNameable n)
           
  NamedObject(java.lang.String name)
          Construct a NamedObject with the name string initialized.
 
Method Summary
 java.lang.Object clone()
          Perform a "deep" clone of the object.
static EdifNameable createValidEdifNameable(java.lang.String string)
          This method will create a new EdifNameable object from the given string.
static java.lang.String createValidEdifString(java.lang.String string)
          This method will check the string to see if it is a valid Edif string.
 boolean equals(java.lang.Object cmp)
          Compare this Object's name to the given Object.
 java.lang.String getName()
          Return the String name.
 java.lang.String getOldName()
           
static boolean isValidEdifName(java.lang.String string)
          Test if the input string is a valid Edif name
 void toEdif(EdifPrintWriter epw)
          Convert this object to EDIF format, and write the data to the passed-in EdifPrintWriter Object.
 java.lang.String toString()
          Return the name of the object (same as the getName() method).
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_name

protected java.lang.String _name
The String name of this object.

Constructor Detail

NamedObject

protected NamedObject()

NamedObject

public NamedObject(java.lang.String name)
            throws InvalidEdifNameException
Construct a NamedObject with the name string initialized.

Parameters:
name - String name of NamedObject.
Throws:
InvalidEdifNameException

NamedObject

public NamedObject(EdifNameable n)
Method Detail

clone

public java.lang.Object clone()
Perform a "deep" clone of the object. Specifically, create a new String with the same name as the name in this object.

Overrides:
clone in class java.lang.Object
Returns:
An Object that is a copy of clone of this NamedObject

createValidEdifNameable

public static EdifNameable createValidEdifNameable(java.lang.String string)
This method will create a new EdifNameable object from the given string. The object will represent a valid Edif name. In this implementation, a NamedObject will be returned. If an invalid string is passed in, the old name will not be remembered.

Parameters:
string - The Name of this Object that will be used to create a valid EDIF name if it isn't one already
Returns:
An EdifNameable Object that contains name information about this NamedObject Object

createValidEdifString

public static java.lang.String createValidEdifString(java.lang.String string)
This method will check the string to see if it is a valid Edif string. If it is valid, it will return the original string. If it is not valid, it will create a new string that is a valid "variation" of the original string.

Parameters:
string - The String representation for a Name, which will be used as a base to make the name valid, unless it already is
Returns:
A String Object representing a valid EDIF name

equals

public boolean equals(java.lang.Object cmp)
Compare this Object's name to the given Object.

Overrides:
equals in class java.lang.Object
Parameters:
cmp - The Object to compare to this one
Returns:
True if the name of this Object equals the name of the passed in one

getName

public java.lang.String getName()
Return the String name.

Specified by:
getName in interface Nameable
Returns:
A String Object representing the name of this NamedObject

getOldName

public java.lang.String getOldName()
Specified by:
getOldName in interface EdifNameable

isValidEdifName

public static boolean isValidEdifName(java.lang.String string)
Test if the input string is a valid Edif name

Parameters:
string - the input string
Returns:
true if it is a valid Edif name, false if it is invalid

toEdif

public void toEdif(EdifPrintWriter epw)
Convert this object to EDIF format, and write the data to the passed-in EdifPrintWriter Object.

Specified by:
toEdif in interface EdifOut
Parameters:
epw - The EdifPrintWriter that the EDIF data will be written to

toString

public java.lang.String toString()
Return the name of the object (same as the getName() method).

Overrides:
toString in class java.lang.Object
Returns:
a String representing this object