nz.ac.waikato.jdsl.core.ref
Class ToString

java.lang.Object
  extended by nz.ac.waikato.jdsl.core.ref.ToString

public class ToString
extends java.lang.Object

Collection of static methods that generate a string representing a container or accessor. Since all the useful methods are static, it should never be necessary to create an instance of ToString.

Every stringfor(.) method that takes a container type comes in two flavors: a default and one parametrized for how to stringify an accessor. The former is used in the toString() method of the applicable containers. The latter may be used if you want more or less information about each accessor than the default gives.

Since it is not possible to guarantee a snapshot of a given container when many threads are running (unless the container is synchronized), the stringfor(.) methods cannot guarantee snapshot semantics for output.

Version:
JDSL 2.1.1
Author:
Keith Schmidt, Mark Handy

Nested Class Summary
static class ToString.LocatorCollectionsStyle
          Stringifies a locator in the Java Collections style: (key)=(element).
static interface ToString.LocatorToString
          Way to parameterize the stringifying of a locator, within the stringifying of a container.
static interface ToString.PositionToString
          Way to parametrize the stringifying of a position, within the stringifying of a container.
static class ToString.PositionWritesElementOnly
          Stringifies a position by giving the string representation of the position's element.
 
Field Summary
static ToString.LocatorToString loc_to_collections_style_s
           
static ToString.PositionToString pos_to_element_s
           
 
Method Summary
static java.lang.String stringfor(InspectableKeyBasedContainer k)
          Default version of stringfor( InspKBC, LTS ).
static java.lang.String stringfor(InspectableKeyBasedContainer k, ToString.LocatorToString lts)
          Gives string representation of a dictionary or priority queue, parameterized by how to represent each locator (i.e., constructs a string by iterating over all locators of the container, concatenating the specified string representation of each locator).
static java.lang.String stringfor(InspectableSequence s)
          Default version of stringfor( InspSeq, PTS ).
static java.lang.String stringfor(InspectableSequence s, ToString.PositionToString pts)
          Gives string representation of a sequence, parameterized by how to represent each position (i.e., constructs a string by iterating over all positions of the sequence, concatenating the specified string representation of each position).
static java.lang.String stringfor(InspectableTree t)
          Default version of stringfor( InspTree, PTS ).
static java.lang.String stringfor(InspectableTree t, ToString.PositionToString pts)
          Gives string representation of a tree, parametrized by how to represent each position.
static java.lang.String stringfor(Locator loc)
           
static java.lang.String stringfor(Position pos)
           
static void writeNodeAndChildren(Position subtreeRoot, ToString.PositionToString pts, java.io.DataOutputStream ostream, InspectableTree t, int indentation, int indentation_increment)
          Recursively dumps a byte representation of a subtree onto a stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pos_to_element_s

public static final ToString.PositionToString pos_to_element_s

loc_to_collections_style_s

public static final ToString.LocatorToString loc_to_collections_style_s
Method Detail

stringfor

public static java.lang.String stringfor(InspectableSequence s,
                                         ToString.PositionToString pts)
Gives string representation of a sequence, parameterized by how to represent each position (i.e., constructs a string by iterating over all positions of the sequence, concatenating the specified string representation of each position). Iteration is in the natural order for a sequence.

Parameters:
s - sequence to stringify
pts - how to stringify each position
Returns:
the string representation of s

stringfor

public static java.lang.String stringfor(InspectableSequence s)
Default version of stringfor( InspSeq, PTS ). Each position is stringified with the string representation of its element only.


writeNodeAndChildren

public static void writeNodeAndChildren(Position subtreeRoot,
                                        ToString.PositionToString pts,
                                        java.io.DataOutputStream ostream,
                                        InspectableTree t,
                                        int indentation,
                                        int indentation_increment)
Recursively dumps a byte representation of a subtree onto a stream. Used by stringfor( InspTree ). Publicly available in case you want to stringify a subtree and really think this way is less work than doing it yourself. You'll want to make sure the "spaces" static variable is initialized first :)

Parameters:
subtreeRoot - root of subtree to represent
pts - way to stringify each position
ostream - stream on which to represent the subtree
t - tree, so children(.) can be called
indentation - number of spaces to indent this level
indentation_increment - amount by which indentation will be increased before writing children

stringfor

public static java.lang.String stringfor(InspectableTree t,
                                         ToString.PositionToString pts)
Gives string representation of a tree, parametrized by how to represent each position. It does a preorder traversal, giving a newline and some indentation before each node, then represents each node as specified. It can print a tree which is at most 100 levels deep.

Parameters:
t - tree to stringify
pts - how to stringify each position
Returns:
the string representation of t
Throws:
java.lang.IndexOutOfBoundsException - if the tree is more then 100 levels deep

stringfor

public static java.lang.String stringfor(InspectableTree t)
Default version of stringfor( InspTree, PTS ). Each position is stringified with the string representation of its element only.


stringfor

public static java.lang.String stringfor(InspectableKeyBasedContainer k,
                                         ToString.LocatorToString lts)
Gives string representation of a dictionary or priority queue, parameterized by how to represent each locator (i.e., constructs a string by iterating over all locators of the container, concatenating the specified string representation of each locator). Iteration is in whatever order the container's locators() method provides.

Parameters:
k - key-based container to stringify
lts - how to stringify each locator
Returns:
the string representation of k

stringfor

public static java.lang.String stringfor(InspectableKeyBasedContainer k)
Default version of stringfor( InspKBC, LTS ). Each locator is stringified in the Java Collections style: (key)=(element).


stringfor

public static java.lang.String stringfor(Position pos)
Parameters:
pos - Position for which string representation is desired
Returns:
verbose string representation of pos

stringfor

public static java.lang.String stringfor(Locator loc)
Parameters:
loc - Locator for which string representation is desired
Returns:
verbose string representation of loc


Copyright © 2009 ModelJUnit Project. All Rights Reserved.