net.xqhs.graphs.representation.text
Class TextRepresentationElement

java.lang.Object
  extended by net.xqhs.util.config.Config
      extended by net.xqhs.graphs.representation.RepresentationElement
          extended by net.xqhs.graphs.representation.text.TextRepresentationElement
All Implemented Interfaces:
net.xqhs.util.config.Configurable

public class TextRepresentationElement
extends RepresentationElement

The class contains the information that is necessary to represent one component of the graph represented by the parent TextGraphRepresentation, such as a node, an edge, a subgraph, a graph.

The class contains method for displaying a textual representation of the represented element (and its children) and for reading a textual representation of such an element and its children.

Author:
Andrei Olaru

Nested Class Summary
static class TextRepresentationElement.Symbol
          An enumeration of the characters that may appear in a textual representation.
static class TextRepresentationElement.Type
          Enumeration containing the types of elements that may appear in a textual graph representation.
 
Nested classes/interfaces inherited from class net.xqhs.util.config.Config
net.xqhs.util.config.Config.ConfigLockedException
 
Field Summary
(package private)  java.util.List<TextRepresentationElement> content
          The nested elements.
static java.lang.String DEFAULT_INDENT
          The indent for the default representation used in toString().
static java.lang.String DEFAULT_INDENT_INCREMENT
          The indent increment for the default representation used in toString().
static int DEFAULT_INDENT_LIMIT
          The limit to indent incrementing for the default representation used in toString().
(package private)  boolean isFirstSubgraph
          true if it is the first subgraph in the container.
(package private)  boolean isLastChild
          true if it is the last child of the parent.
(package private)  boolean isOnlyChild
          true if it is the only child of the parent.
(package private)  TextRepresentationElement.Type linkType
          The type of the element (as one of TextRepresentationElement.Type).
(package private)  int nestingLevel
          Not currently used.
 
Constructor Summary
  TextRepresentationElement(GraphRepresentation root, TextRepresentationElement.Type type)
          Creates a text representation for an element container (a level in a multi-level representation).
  TextRepresentationElement(GraphRepresentation root, TextRepresentationElement.Type type, boolean first)
          Creates a text representation of a subgraph (connected part of a graph).
  TextRepresentationElement(GraphRepresentation root, VisualizableGraphComponent representedNode, TextRepresentationElement.Type type)
          Creates a text representation of a graph node.
  TextRepresentationElement(GraphRepresentation root, VisualizableGraphComponent representedEdge, TextRepresentationElement.Type type, int level, boolean lastChild, boolean alone)
          Creates a text representation of a graph edge.
protected TextRepresentationElement(GraphRepresentation root, VisualizableGraphComponent representedElement, TextRepresentationElement.Type type, int level, boolean lastChild, boolean alone, boolean firstSubgraph)
          Constructor aggregating all the other constructors.
 
Method Summary
protected  TextRepresentationElement addSub(java.util.List<TextRepresentationElement> subs)
          Adds a list of subordinate elements to this representation element.
protected  TextRepresentationElement addSub(TextRepresentationElement sub)
          Adds a subordinate element to this representation element.
protected static int getFirstUnmatchedClosingSymbolIndex(java.lang.String input, java.lang.String openingSymbol, java.lang.String closingSymbol)
          Considering the input contains various enclosures delimited by an opening symbol and a closing symbol, the methods gets the index of the first closing symbol which is not matched by an opening symbol appearing before it.
protected static boolean isEdgeType(TextRepresentationElement.Type elementType)
          True if the specified TextRepresentationElement.Type is a type of edge.
protected static TextRepresentationElement readRepresentation(ContentHolder<java.lang.String> input, TextGraphRepresentation root, net.xqhs.util.logging.UnitComponent log)
          Same as readRepresentation(String, TextGraphRepresentation, UnitComponent), but using a content holder and leaving all un-consumed input in the holder.
protected static TextRepresentationElement readRepresentation(ContentHolder<java.lang.String> input, TextRepresentationElement.Type type, boolean firstSibling, TextGraphRepresentation root, net.xqhs.util.logging.UnitComponent log)
          The method uses the input string to read the representation of an element, removing the representation from the input and leaving other calls of the method to read the rest (if any).
protected static TextRepresentationElement readRepresentation(java.lang.String input, TextGraphRepresentation root, net.xqhs.util.logging.UnitComponent log)
          The method reads the representation of a whole graph from the given text input.
 java.lang.String toString()
          Creates a textual rendering of the current representation element, using default settings ( DEFAULT_INDENT, DEFAULT_INDENT_INCREMENT, DEFAULT_INDENT_LIMIT).
 java.lang.String toString(java.lang.String indent, java.lang.String indentIncrement, int indentLimit, boolean isBackwards)
          The method creates a textual rendering of the current representation element, as well as of its children.
 
Methods inherited from class net.xqhs.graphs.representation.RepresentationElement
getParentRepresentation, getRepresentedComponent, getRootRepresentation
 
Methods inherited from class net.xqhs.util.config.Config
build, ensureLocked, lock, locked, lockedEx, makeDefaults
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_INDENT

public static final java.lang.String DEFAULT_INDENT
The indent for the default representation used in toString(). See toString(String, String, int, boolean)

See Also:
Constant Field Values

DEFAULT_INDENT_INCREMENT

public static final java.lang.String DEFAULT_INDENT_INCREMENT
The indent increment for the default representation used in toString(). See toString(String, String, int, boolean).

See Also:
Constant Field Values

DEFAULT_INDENT_LIMIT

public static final int DEFAULT_INDENT_LIMIT
The limit to indent incrementing for the default representation used in toString(). See toString(String, String, int, boolean).

See Also:
Constant Field Values

nestingLevel

int nestingLevel
Not currently used. TODO


isLastChild

boolean isLastChild
true if it is the last child of the parent.


isOnlyChild

boolean isOnlyChild
true if it is the only child of the parent.


isFirstSubgraph

boolean isFirstSubgraph
true if it is the first subgraph in the container.


linkType

TextRepresentationElement.Type linkType
The type of the element (as one of TextRepresentationElement.Type).


content

java.util.List<TextRepresentationElement> content
The nested elements.

Constructor Detail

TextRepresentationElement

public TextRepresentationElement(GraphRepresentation root,
                                 TextRepresentationElement.Type type)
Creates a text representation for an element container (a level in a multi-level representation).

Parameters:
root - - the root representation.
type - - must be TextRepresentationElement.Type.ELEMENT_CONTAINER (otherwise an exception is thrown).

TextRepresentationElement

public TextRepresentationElement(GraphRepresentation root,
                                 TextRepresentationElement.Type type,
                                 boolean first)
Creates a text representation of a subgraph (connected part of a graph).

Parameters:
root - - the root representation.
type - - must be TextRepresentationElement.Type.SUBGRAPH (otherwise an exception is thrown).
first - - true if it is the first subgraph in a series (otherwise, a separator will be included in the representation).

TextRepresentationElement

public TextRepresentationElement(GraphRepresentation root,
                                 VisualizableGraphComponent representedEdge,
                                 TextRepresentationElement.Type type,
                                 int level,
                                 boolean lastChild,
                                 boolean alone)
Creates a text representation of a graph edge.

Parameters:
root - - the root representation.
representedEdge - - the Edge instance (must also implement VisualizableGraphComponent.
type - - must be one of TextRepresentationElement.Type.EXTERNAL_LINK, TextRepresentationElement.Type.INTERNAL_LINK or TextRepresentationElement.Type.BRANCH (otherwise an exception is thrown).
level - - currently not used // FIXME
lastChild - - true it it is the last edge going out of its source node.
alone - - true if it is the only outgoing edge of its source node.

TextRepresentationElement

public TextRepresentationElement(GraphRepresentation root,
                                 VisualizableGraphComponent representedNode,
                                 TextRepresentationElement.Type type)
Creates a text representation of a graph node.

Parameters:
root - - the root representation.
representedNode - - the Node instance (must also implement VisualizableGraphComponent.
type - - must be TextRepresentationElement.Type.NODE (otherwise an exception is thrown).

TextRepresentationElement

protected TextRepresentationElement(GraphRepresentation root,
                                    VisualizableGraphComponent representedElement,
                                    TextRepresentationElement.Type type,
                                    int level,
                                    boolean lastChild,
                                    boolean alone,
                                    boolean firstSubgraph)
Constructor aggregating all the other constructors.

Parameters:
root - - the root representation.
representedElement - - the VisualizableGraphComponent that is beign represented.
type - - the type of the element (as one of TextRepresentationElement.Type).
level - - TODO
lastChild - - true if it is the last child of the parent.
alone - - true if it is the only child of the parent.
firstSubgraph - - true if it is the first subgraph in the container.
Method Detail

addSub

protected TextRepresentationElement addSub(TextRepresentationElement sub)
Adds a subordinate element to this representation element.

Parameters:
sub - - the subordinate element to add.
Returns:
the instance itself.

addSub

protected TextRepresentationElement addSub(java.util.List<TextRepresentationElement> subs)
Adds a list of subordinate elements to this representation element.

Parameters:
subs - - the subordinate elements to add, as a List.
Returns:
the instance itself.

toString

public java.lang.String toString()
Creates a textual rendering of the current representation element, using default settings ( DEFAULT_INDENT, DEFAULT_INDENT_INCREMENT, DEFAULT_INDENT_LIMIT).

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String indent,
                                 java.lang.String indentIncrement,
                                 int indentLimit,
                                 boolean isBackwards)
The method creates a textual rendering of the current representation element, as well as of its children.

See TextGraphRepresentation.

Parameters:
indent - - this will precede each new element, before indentLimit is reached. 'Only' children and nodes will not be prexeded by indent.
indentIncrement - - will be added to the current increment every time the rendering advances one level, but no more than indentLimit times. It is not added to the indent when the next level contains only one child.
indentLimit - - maximum times indentIncrement is added to indent. After this limit is reached, no more indent will be displayed.
isBackwards - - true if the representation should be 'backwards' (edges point to the left instead of right).
Returns:
the String representation of the element.

isEdgeType

protected static boolean isEdgeType(TextRepresentationElement.Type elementType)
True if the specified TextRepresentationElement.Type is a type of edge. True for TextRepresentationElement.Type.INTERNAL_LINK, TextRepresentationElement.Type.EXTERNAL_LINK and TextRepresentationElement.Type.BRANCH.

Parameters:
elementType - - the type of element.
Returns:
true if the type is a type of edge.

readRepresentation

protected static TextRepresentationElement readRepresentation(java.lang.String input,
                                                              TextGraphRepresentation root,
                                                              net.xqhs.util.logging.UnitComponent log)
The method reads the representation of a whole graph from the given text input. If more top-level graph representations are present in the input, only the first one will be read. To read the representation and get the remaining input, use readRepresentation(ContentHolder, Type, boolean, TextGraphRepresentation, UnitComponent).

While the edges are placed correctly, they have no adjacent nodes. They will be filed in later, in TextGraphRepresentation.readRepresentation(String). Basically, elements are currently correct with respect to their labels and their placement in a textual layout (toString() returns an apparently correct representation). The actual, correct graph is build later.

Parameters:
input - - the input, as a String.
root - - the root representation that the read element belongs to.
log - - a UnitComponent to use for logging messages.
Returns:
the root element (of type TextRepresentationElement.Type.ELEMENT_CONTAINER) of the representation.

readRepresentation

protected static TextRepresentationElement readRepresentation(ContentHolder<java.lang.String> input,
                                                              TextGraphRepresentation root,
                                                              net.xqhs.util.logging.UnitComponent log)
Same as readRepresentation(String, TextGraphRepresentation, UnitComponent), but using a content holder and leaving all un-consumed input in the holder.

Parameters:
input - - the input, held be a ContentHolder instance.
root - - the root representation that the read element belongs to.
log - - a UnitComponent to use for logging messages.
Returns:
the root element (of type TextRepresentationElement.Type.ELEMENT_CONTAINER) of the representation.

readRepresentation

protected static TextRepresentationElement readRepresentation(ContentHolder<java.lang.String> input,
                                                              TextRepresentationElement.Type type,
                                                              boolean firstSibling,
                                                              TextGraphRepresentation root,
                                                              net.xqhs.util.logging.UnitComponent log)
The method uses the input string to read the representation of an element, removing the representation from the input and leaving other calls of the method to read the rest (if any).

If the representation contains any hyper nodes, it is mandatory that the representation f the graph is enclosed between TextRepresentationElement.Symbol.ELEMENT_CONTAINER_IN and TextRepresentationElement.Symbol.ELEMENT_CONTAINER_OUT.

The input argument is modified by using ContentHolder.set(Object).

Parameters:
input - - the input, held be a ContentHolder instance. It is assumed to be a non-empty, correct representation.
type - - the type of element to read from the input, as one of TextRepresentationElement.Type.
firstSibling - - true if this is the first instance in a list of sibling instances (first child of a parent).
root - - the root representation that the read element belongs to.
log - - a UnitComponent to use for logging messages.
Returns:
the element read from the input, as a TextRepresentationElement.

getFirstUnmatchedClosingSymbolIndex

protected static int getFirstUnmatchedClosingSymbolIndex(java.lang.String input,
                                                         java.lang.String openingSymbol,
                                                         java.lang.String closingSymbol)
Considering the input contains various enclosures delimited by an opening symbol and a closing symbol, the methods gets the index of the first closing symbol which is not matched by an opening symbol appearing before it.

In other words, the methods gets the index of the closing symbol that closes the current enclosure (that has been opened before the beginning of input.

Example, for opening and closing symbols '(' and ')', respectively: the returned index for the input
aaa ( bbb (ccc) b) (dd) aaaa) xxxx )
is the closing parenthesis after the group aaaa.

Parameters:
input - - the input string.
openingSymbol - - the opening symbol for enclosures.
closingSymbol - - the closing symbol for enclosures.
Returns:
the index of the first unmatched closing symbol.