byucc.edif
Class EdifLibraryManager

java.lang.Object
  extended by byucc.edif.EdifLibraryManager
All Implemented Interfaces:
EdifOut, Trimable, java.io.Serializable

public class EdifLibraryManager
extends java.lang.Object
implements Trimable, java.io.Serializable, EdifOut

Represents a List of related EdifLibraries. When a cell is added, all references to the old cell are replaced with references to the new cell, and all references to the old ports are replaced with references to the new ports. A Cell with the same name can exist in two different libraries, but not in the same library.

Version:
$Id: EdifLibraryManager.java,v 1.96 2006/01/04 23:35:24 ksm4 Exp $
Author:
Mike Wirthlin, Tyler Anderson
See Also:
EdifLibrary, Serialized Form

Field Summary
private  EdifEnvironment _edifEnvironment
          The EdifEnvironment that points to this library manager.
private  ArrayListNameSpaceResolver _libraries
          The EdifLibrary objects of this file.
 
Constructor Summary
EdifLibraryManager(EdifEnvironment edifFile)
          Constructs an EdifLibraryManager Object with the specified EdifEnvironment.
 
Method Summary
 void addCellDeep(EdifCell cell, EdifLibrary targetLib)
          Adds a new EdifCell to the given EdifLibrary as well as all sub-cells instanced by the given EdifCell.
 void addLeafCell(EdifCell leaf)
          This method will search through the libraries within the manager and find the Library that is most appropriate for the given leaf cell to be added.
 boolean addLibrary(EdifLibrary library)
          Adds a library to this library manager, and sets its library manager to 'this'
 EdifLibrary containsCell(EdifCell cell)
          Searches for the given cell among all libraries.
 boolean containsLibrary(EdifLibrary lib)
           
 boolean deleteCell(EdifCell cell, boolean force)
          Deletes a cell from the library manager, and returns whether or not the delete was successful.
 java.util.Collection findBlackBoxes()
          This method will search through all EdifCells in the current Manager and determine which cells are not defined.
 java.util.Collection findCellInstancesOf(EdifCell cell)
          This function will return a list of EdifCellInstances in the entire libraryManager that reference the passed in cell.
 EdifLibrary findEarliestLibraryToAdd(EdifCell cell, boolean addToPrimitiveLibraryOK)
          This method returns the earliest library that this cell can be added to.
 int findEarliestPositionToAdd(EdifLibrary add)
          Returns the earliest position to add the library within the collection of libraries, so as to avoid violating the define before use rule.
 EdifLibrary findLatestLibraryToAdd(EdifCell cell, boolean addToPrimitiveLibraryOK)
          This method returns the latest library that this cell can be added to.
 int findLatestPositionToAdd(EdifLibrary add)
          Returns the latest position to add the library within the collection of libraries, so as to avoid violating the define before use rule.
 EdifLibrary findMatchingLibrary(EdifLibrary inputLibrary)
          This method will investigate all EdifCell objects found within same library as the passed-in library and find out which target library matches closest.
 java.util.Collection findNonReferencedCells()
          This function will return a list of EdifCells that aren't referenced at all within the entire LibraryManager.
 EdifCell getCell(java.lang.String name)
          Returns the first cell whose name matches the give String.
 java.util.List getCells()
          This method will return a List of all cells in the library manager.
 java.util.Collection getCells(java.lang.String name)
          Returns all the EdifCell objects whose name matches the give String.
 java.util.Collection getContainingLibraries(java.lang.String name)
          Returns a Collection of Libraries that contain a cell of the specified name.
 EdifEnvironment getEdifEnvironment()
          Returns the file pointing to this library manager.
 EdifLibrary getFirstPrimitiveLibrary()
          Returns the first primitive library in the collection of libraries.
 java.util.List getLibraries()
          Returns the libraries contained by this library manager.
 EdifLibrary getLibrary(java.lang.String lib)
          Returns the library based on the string lib.
 java.util.Collection getNextLibraries(EdifLibrary lib)
          Return the Collection of libraries that are defined after the specified library in the libarary manager.
 java.util.Collection getPreviousLibraries(EdifLibrary lib)
          Return the Collection of libraries that are defined before the specified library in the libarary manager.
 java.util.Iterator iterator()
          Returns the libraries contained by this library manager.
 boolean nameClash(EdifLibrary lib)
          Returns true if the library can be added to the library name space, otherwise false.
 void pruneNonReferencedCells()
          Prunes non referenced cells within the entire library manager.
 void tagLeafCellsAsPrimitives()
          Tags all leaf cells as primitive.
 void tagPrimitives(EdifLibrary primitives)
          Tags all primitive cells by comparing them to the cells contained within the passed-in library.
 void toEdif(EdifPrintWriter epw)
          Print the Edif equivalent of this EdifLibraryManager.
 java.lang.String toString()
           
 void trimToSize()
          Trims to size all Trimmable objects in this library manager.
 void validateOrder()
          Re-orders the libraries, and the cells within into a proper order (if they aren't already).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_libraries

private ArrayListNameSpaceResolver _libraries
The EdifLibrary objects of this file. The key of this Map is the name of the library and the value is the EdifLibrary object. Note that the order of libraries within this list matter - there is a partial order between libraries (i.e. sub-cells must be defined previous to the instance of the sub-cell).


_edifEnvironment

private EdifEnvironment _edifEnvironment
The EdifEnvironment that points to this library manager.

Constructor Detail

EdifLibraryManager

public EdifLibraryManager(EdifEnvironment edifFile)
Constructs an EdifLibraryManager Object with the specified EdifEnvironment.

Parameters:
edifFile - The EdifEnvironment that contains this EdifLibraryManager
Method Detail

containsCell

public EdifLibrary containsCell(EdifCell cell)
Searches for the given cell among all libraries. If the EdifCell exists in a library, it returns the given library. Otherwise, it returns null.


containsLibrary

public boolean containsLibrary(EdifLibrary lib)

addLeafCell

public void addLeafCell(EdifCell leaf)
This method will search through the libraries within the manager and find the Library that is most appropriate for the given leaf cell to be added. Once the library is found, add the cell to the library.


addCellDeep

public void addCellDeep(EdifCell cell,
                        EdifLibrary targetLib)
Adds a new EdifCell to the given EdifLibrary as well as all sub-cells instanced by the given EdifCell. This method will add EdifCell objects to multiple libraries within this object during the deep add. TODO: recursive?

Parameters:
cell - The EdifCell to add
targetLib - The library to add the cell to

addLibrary

public boolean addLibrary(EdifLibrary library)
Adds a library to this library manager, and sets its library manager to 'this'

Parameters:
library - The library to add into this manager, defaulted to add at the earliest position
Returns:
True if the library was added
See Also:
EdifLibraryManager#findPositionToAdd

deleteCell

public boolean deleteCell(EdifCell cell,
                          boolean force)
Deletes a cell from the library manager, and returns whether or not the delete was successful.

Parameters:
cell - The cell to be deleted.
force - Forces the cell to be deleted even if it's still referenced within the library manager.
Returns:
True if the cell was deleted.
See Also:
EdifLibrary.deleteCell(EdifCell,boolean)

findMatchingLibrary

public EdifLibrary findMatchingLibrary(EdifLibrary inputLibrary)
This method will investigate all EdifCell objects found within same library as the passed-in library and find out which target library matches closest.

Returns:
The matching library

findCellInstancesOf

public java.util.Collection findCellInstancesOf(EdifCell cell)
This function will return a list of EdifCellInstances in the entire libraryManager that reference the passed in cell. This method will return null if no EdifCellInstances are found.

Parameters:
cell - The cell to check references for
Returns:
A collection of EdifCellInstance Objects in this library manager that refer to the passed-in cell
See Also:
EdifLibrary.findCellInstancesOf(byucc.edif.EdifCell)

findNonReferencedCells

public java.util.Collection findNonReferencedCells()
This function will return a list of EdifCells that aren't referenced at all within the entire LibraryManager.

Returns:
A collection of cells that aren't referenced at all in the entire library manager (these could be pruned to reduce the size of the file)
See Also:
pruneNonReferencedCells()

findEarliestPositionToAdd

public int findEarliestPositionToAdd(EdifLibrary add)
Returns the earliest position to add the library within the collection of libraries, so as to avoid violating the define before use rule.

Parameters:
add - The library to add to the earliest position
Returns:
The exact position to add this library to
See Also:
EdifLibraryManager#findPositionToAdd

findLatestPositionToAdd

public int findLatestPositionToAdd(EdifLibrary add)
Returns the latest position to add the library within the collection of libraries, so as to avoid violating the define before use rule.

Parameters:
add - The library to add to the latest position
Returns:
The exact position to add this library to
See Also:
EdifLibraryManager#findPositionToAdd

findEarliestLibraryToAdd

public EdifLibrary findEarliestLibraryToAdd(EdifCell cell,
                                            boolean addToPrimitiveLibraryOK)
This method returns the earliest library that this cell can be added to. All of the passed in EdifCell's EdifCellInstances must instance cells declared inside or after the library it will get added to.

Parameters:
cell - The cell to be added into which library.
addToPrimitiveLibraryOK - Specifies whether or not it is ok to add the cell to a primitive library.
Returns:
The earliest library to add the cell in.
See Also:
EdifLibrary.findEarliestPositionToAdd(byucc.edif.EdifCell)

findLatestLibraryToAdd

public EdifLibrary findLatestLibraryToAdd(EdifCell cell,
                                          boolean addToPrimitiveLibraryOK)
This method returns the latest library that this cell can be added to. If the passed in EdifCell is referenced in a library then it has to be added to the position at or before the referring library.

Parameters:
cell - The cell to be added into which library.
addToPrimitiveLibraryOK - Specifies whether or not it is ok to add the cell to a primitive library.
Returns:
The latest library to add the cell in.
See Also:
EdifLibrary.findLatestPositionToAdd(byucc.edif.EdifCell)

findBlackBoxes

public java.util.Collection findBlackBoxes()
This method will search through all EdifCells in the current Manager and determine which cells are not defined. The purpose of this method is to identify those EdifCell objects that are "undefined". This may be used to search for other Edif files that describe the given black box.

Returns:
A collection of EdifCells that are Black boxes, or undefined, and non-primitive
See Also:
EdifLibrary.findBlackBoxes()

getFirstPrimitiveLibrary

public EdifLibrary getFirstPrimitiveLibrary()
Returns the first primitive library in the collection of libraries. Useful when a primitive must be added to a primitive library.

Returns:
The first Primitive Library

getLibrary

public EdifLibrary getLibrary(java.lang.String lib)
Returns the library based on the string lib. TODO: lower case compare?

Parameters:
lib - The String that will be used to find the library
Returns:
The EdifLibrary whose name matches lib

getEdifEnvironment

public EdifEnvironment getEdifEnvironment()
Returns the file pointing to this library manager.

Returns:
The EdifEnvironment that contains this library manager.

getLibraries

public java.util.List getLibraries()
Returns the libraries contained by this library manager.

Returns:
An Iterator Object of the libraries within this library manager.

getCells

public java.util.List getCells()
This method will return a List of all cells in the library manager. The cells will be returned in proper order (from lowest to highest).

Returns:
A List Object of all the cells in the entire library manager.

getCell

public EdifCell getCell(java.lang.String name)
Returns the first cell whose name matches the give String.

Parameters:
name - The name of the cell to return
Returns:
An EdifCell whose name matches the given String
See Also:
EdifLibrary.getCell(String)

getCells

public java.util.Collection getCells(java.lang.String name)
Returns all the EdifCell objects whose name matches the give String.

Parameters:
name - The name of the cell to return
Returns:
A Collection of EdifCell objects
See Also:
EdifLibrary.getCell(String)

getContainingLibraries

public java.util.Collection getContainingLibraries(java.lang.String name)
Returns a Collection of Libraries that contain a cell of the specified name. This will return null if no libraries contain a cell by that name.

Parameters:
name - String name of cell to search for.
Returns:
A Collection of EdifLibrary Objects containing the cell with the specified name, or null if none exist.

getNextLibraries

public java.util.Collection getNextLibraries(EdifLibrary lib)
Return the Collection of libraries that are defined after the specified library in the libarary manager.

Parameters:
lib - The library that designates the point after which libraries will begin to be returned
Returns:
A Collection of EdifLibrary objects defined after the passed-in EdifLibrary Object

getPreviousLibraries

public java.util.Collection getPreviousLibraries(EdifLibrary lib)
Return the Collection of libraries that are defined before the specified library in the libarary manager.

Parameters:
lib - The library that designates the point where the list of libraries stops
Returns:
A Collection of EdifLibrary objects defined before the passed-in EdifLibrary Object

iterator

public java.util.Iterator iterator()
Returns the libraries contained by this library manager.

Returns:
An Iterator Object of the libraries within this library manager.

nameClash

public boolean nameClash(EdifLibrary lib)
Returns true if the library can be added to the library name space, otherwise false.

Parameters:
lib - The library to chech to see if there is a name clash with this libraries of this library manager
Returns:
True if there is a clash, false if not

pruneNonReferencedCells

public void pruneNonReferencedCells()
Prunes non referenced cells within the entire library manager. Pruned cells are cells that aren't referenced within the entire library manager.


tagLeafCellsAsPrimitives

public void tagLeafCellsAsPrimitives()
Tags all leaf cells as primitive.


tagPrimitives

public void tagPrimitives(EdifLibrary primitives)
Tags all primitive cells by comparing them to the cells contained within the passed-in library.

Parameters:
primitives - Library containing primitives to be compared to cells.
See Also:
EdifCell.tagAsPrimitive(byucc.edif.EdifLibrary)

trimToSize

public void trimToSize()
Trims to size all Trimmable objects in this library manager.

Specified by:
trimToSize in interface Trimable

validateOrder

public void validateOrder()
Re-orders the libraries, and the cells within into a proper order (if they aren't already).


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toEdif

public void toEdif(EdifPrintWriter epw)
Print the Edif equivalent of this EdifLibraryManager.

Specified by:
toEdif in interface EdifOut
Parameters:
epw - The EdifPrintWriter Object that the interfacing Object will write EDIF data to