quoggles.auxiliary
Class Util

java.lang.Object
  |
  +--quoggles.auxiliary.Util

public class Util
extends java.lang.Object

A set of public static auxialiary methods.


Nested Class Summary
(package private) static class Util.Unique
           
 
Field Summary
static double CLICK_TOLERANCE
           
static java.lang.Object UNIQUE
           
 
Constructor Summary
Util()
           
 
Method Summary
static void addLabel(IBox iBox, org.graffiti.graph.Node node)
          Adds the name (id) of the given box as a label to the given node.
static OptionParameter buildAttrPath()
          Builds an OptionParameter using paths of the default node and edge graphics attributes as options.
static java.lang.Object convertFromParameter(org.graffiti.plugin.parameter.Parameter param)
          Converts the given Parameter to an object.
static org.graffiti.plugin.parameter.Parameter convertToParameter(java.lang.Object obj, java.lang.String parType)
          Converts the given object to a parameter.
static org.graffiti.plugin.parameter.Parameter[] convertToParameters(java.lang.Object[] in)
          Converts an array of objects to an array of parameters.
static java.util.Collection ensureSize(java.util.Collection col, int minSize)
          Adds null values to the end of the given collection until the size of the collection is at least as large as the second parameter.
static org.graffiti.graph.Node findMaybeNestedPredicateEnd(org.graffiti.graph.Node node, boolean foundOne)
          Find a BoolPredicateEnd_Box that may be hidden in a SubQuery_Box.
static java.util.Set gatherPaths(org.graffiti.attributes.Attribute attr, java.util.Set set)
          Recursively adds attribute paths to the given set.
static java.awt.Point[] getAbsoluteInputPos(IBoxRepresentation iBoxRep)
          Calculate the absolute positions from the relative positions given by the box representation.
static java.awt.Point[] getAbsoluteOutputPos(IBoxRepresentation iBoxRep)
          Calculate the absolute positions from the relative positions given by the box representation.
static java.awt.Point getAbsPos(IBoxRepresentation iBoxRep, boolean isInput, int index)
          Calculate the absolute position from the relative position of the given input / output (via index) of the given box representation.
static IBox getBox(org.graffiti.graph.Node n)
          Returns the box that is saved via a BoxAttribute in the given Node.
static javax.swing.JComponent getCorrectSource(java.awt.event.MouseEvent e)
          Used by the MouseListener methods.
static org.graffiti.attributes.Attribute getFreshAttribute(java.lang.String id, java.lang.Object value, org.graffiti.attributes.Attributable attbl, java.lang.String type)
          According to the type specified by first (0) parameter, create a new instance of an attribute.
static int getIOIndex(org.graffiti.graph.Edge e, boolean out)
          Returns index of the input / putput (depending on the value of the second parameter) of the given edge.
static java.awt.geom.Point2D getNextFreeConnection(org.graffiti.graph.Graph graph, java.awt.geom.Point2D mousePos, boolean lookForFreeOutput, java.awt.Component dComp)
          Get position of a free IO connection next to the given position.
static java.util.Collection getSourcesFrom(org.graffiti.graph.Node endNode, java.util.Collection preNodes)
          See the QPreNodesAlgorithm.
static boolean interpretAsBoolean(java.lang.Object obj)
          An object evaluates to false, if one of the following holds (tried in the given order; if the class pattern matches, but the rest of the condition fails, the initial object is considered to evaluate to true): it is an empty Collection it is a non-empty Collection and one of its elements evaluates to false it is a Boolean and its value is false it is a Number and its value is 0d or NaN it is null it is the special value quoggles.constants.QConstants.EMPTY its value as a string (what a call to toString() yields) is equal to "false" (ignoring case)
static boolean isControlDown(java.awt.event.MouseEvent me)
          Returns true iff the MouseEvent indicates that the control or the shift key has been pressed while generating the event.
static boolean lineContains(java.awt.geom.Line2D line, double x, double y)
          Checks whether or not a point is said to be located on a line.
static java.lang.Boolean match(java.lang.Object compObject, org.graffiti.plugin.parameter.Parameter[] parameters)
          Checks whether compObject matches the value given by the parameters.
static int max(int a, int b, int c)
           
static int max(int a, int b, int c, int d)
           
static int min(int a, int b, int c)
           
static int min(int a, int b, int c, int d)
           
static void pushOutputs(org.graffiti.graph.Node node, IBox box)
          Set output from the given node/box, as input to its successors.
static void pushOutputs(org.graffiti.graph.Node node, IBox box, int notIndex)
          Set output from the given node/box, as input to its successors.
static void resetAllBoxes(org.graffiti.graph.Graph qGraph)
          Calls reset() for all boxes in the given graph.
static void resetAllBoxesFrom(org.graffiti.graph.Graph qGraph, java.util.Collection startNodes)
          Calls reset(int) for all boxes where there exists a path from one of the nodes in the collection startNodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIQUE

public static final java.lang.Object UNIQUE

CLICK_TOLERANCE

public static final double CLICK_TOLERANCE
See Also:
Constant Field Values
Constructor Detail

Util

public Util()
Method Detail

max

public static int max(int a,
                      int b,
                      int c,
                      int d)

min

public static int min(int a,
                      int b,
                      int c,
                      int d)

max

public static int max(int a,
                      int b,
                      int c)

min

public static int min(int a,
                      int b,
                      int c)

getBox

public static IBox getBox(org.graffiti.graph.Node n)
Returns the box that is saved via a BoxAttribute in the given Node.

Parameters:
n -
Returns:

isControlDown

public static boolean isControlDown(java.awt.event.MouseEvent me)
Returns true iff the MouseEvent indicates that the control or the shift key has been pressed while generating the event.

Parameters:
me - mouse event
Returns:
true if user pressed the control or shift key while initiating the mouse event

getIOIndex

public static int getIOIndex(org.graffiti.graph.Edge e,
                             boolean out)
Returns index of the input / putput (depending on the value of the second parameter) of the given edge.

false means that the index is returned that indicates into which input (number) the edge's output (target) leads.

true means that the index is returned that indicates from which output (number) the edge's input (source) comes from.

Parameters:
e -
out -
Returns:
index saved as attribute of the edge

interpretAsBoolean

public static boolean interpretAsBoolean(java.lang.Object obj)
An object evaluates to false, if one of the following holds (tried in the given order; if the class pattern matches, but the rest of the condition fails, the initial object is considered to evaluate to true):
  1. it is an empty Collection
  2. it is a non-empty Collection and one of its elements evaluates to false
  3. it is a Boolean and its value is false
  4. it is a Number and its value is 0d or NaN
  5. it is null
  6. it is the special value quoggles.constants.QConstants.EMPTY
  7. its value as a string (what a call to toString() yields) is equal to "false" (ignoring case)

Returns:
a boolean evaluation of the given object

match

public static java.lang.Boolean match(java.lang.Object compObject,
                                      org.graffiti.plugin.parameter.Parameter[] parameters)
                               throws InvalidInputException,
                                      InvalidParameterException
Checks whether compObject matches the value given by the parameters.

It uses conversions to the format specified via the parameters.

A null value always leads to false except when string comparison is applied. In this case, the object is converted to the string "null" prior to testing.

Parameters:
compObject - the object to check
Returns:
true if compObject matches the value given by the parameters
Throws:
InvalidInputException
InvalidParameterException

getAbsPos

public static java.awt.Point getAbsPos(IBoxRepresentation iBoxRep,
                                       boolean isInput,
                                       int index)
Calculate the absolute position from the relative position of the given input / output (via index) of the given box representation.

Parameters:
iBoxRep -
Returns:

lineContains

public static boolean lineContains(java.awt.geom.Line2D line,
                                   double x,
                                   double y)
Checks whether or not a point is said to be located on a line. It uses the field CLICK_TOLERANCE as a certain tolerance, i.e. it really checks whether or not the point lies on a thicker line.

Parameters:
line -
x -
y -
Returns:
true if point lies close enough to the line

buildAttrPath

public static OptionParameter buildAttrPath()
Builds an OptionParameter using paths of the default node and edge graphics attributes as options.

Returns:
an OptionParameter holding paths of the default node and edge graphics attributes as options.

gatherPaths

public static java.util.Set gatherPaths(org.graffiti.attributes.Attribute attr,
                                        java.util.Set set)
Recursively adds attribute paths to the given set.

Parameters:
attr - the attribute that is added / searched
set - the set to which paths are added
Returns:
a set of attribute paths

findMaybeNestedPredicateEnd

public static org.graffiti.graph.Node findMaybeNestedPredicateEnd(org.graffiti.graph.Node node,
                                                                  boolean foundOne)
                                                           throws QueryExecutionException
Find a BoolPredicateEnd_Box that may be hidden in a SubQuery_Box.

Parameters:
node - the associated box must be a sink; find a predicate end box (maybe hidden in nested sub query boxes)
QueryExecutionException

ensureSize

public static java.util.Collection ensureSize(java.util.Collection col,
                                              int minSize)
Adds null values to the end of the given collection until the size of the collection is at least as large as the second parameter.

Parameters:
col - the collection the size of which should be ensured
minSize - the minimum size the collection must have
Returns:
the given (and maybe manipulated) collection for convenience

pushOutputs

public static void pushOutputs(org.graffiti.graph.Node node,
                               IBox box)
                        throws QueryExecutionException
Set output from the given node/box, as input to its successors.

Parameters:
node -
box -
Throws:
QueryExecutionException

pushOutputs

public static void pushOutputs(org.graffiti.graph.Node node,
                               IBox box,
                               int notIndex)
                        throws QueryExecutionException
Set output from the given node/box, as input to its successors. Does not try to get the output with the index specified via the third parameter.

Parameters:
node -
box -
Throws:
QueryExecutionException

getCorrectSource

public static javax.swing.JComponent getCorrectSource(java.awt.event.MouseEvent e)
Used by the MouseListener methods. Find the IBoxIcon or BoxRepresentation at the point from the given MouseEvent. If no such component can be found, returns the source saved in the MouseEvent.

Parameters:
e - mouse event
Returns:
component that has been hit

getNextFreeConnection

public static java.awt.geom.Point2D getNextFreeConnection(org.graffiti.graph.Graph graph,
                                                          java.awt.geom.Point2D mousePos,
                                                          boolean lookForFreeOutput,
                                                          java.awt.Component dComp)
Get position of a free IO connection next to the given position. The boolean parameter specifies whether to look for inputs or outputs.

Parameters:
graph - the graph whose node contain the boxes to be searched
mousePos -
lookForFreeOutput - true if the box we work for has a free input i.e. only outputs from other boxes need to be searched
Returns:
position of a free IO connection next to the given position

getAbsoluteInputPos

public static java.awt.Point[] getAbsoluteInputPos(IBoxRepresentation iBoxRep)
Calculate the absolute positions from the relative positions given by the box representation.

Parameters:
iBoxRep -
Returns:
absolute positions of inputs

getAbsoluteOutputPos

public static java.awt.Point[] getAbsoluteOutputPos(IBoxRepresentation iBoxRep)
Calculate the absolute positions from the relative positions given by the box representation.

Parameters:
iBoxRep -
Returns:
absolute positions of outputs

getSourcesFrom

public static java.util.Collection getSourcesFrom(org.graffiti.graph.Node endNode,
                                                  java.util.Collection preNodes)
See the QPreNodesAlgorithm. Fills second parameter with all nodes from which a path exists to the given end node. Returns all source nodes (indegree == 0) from that collection.

Parameters:
endNode -
Returns:
all source nodes (indegree == 0) from which a path exists to the given end node
See Also:
QPreNodesAlgorithm

resetAllBoxesFrom

public static void resetAllBoxesFrom(org.graffiti.graph.Graph qGraph,
                                     java.util.Collection startNodes)
Calls reset(int) for all boxes where there exists a path from one of the nodes in the collection startNodes. That does not include the nodes contained in startNodes. It only resets those inputs that can be reached, not the whole box.

Parameters:
qGraph -
startNodes - nodes that should not be reset but where the search starts

resetAllBoxes

public static void resetAllBoxes(org.graffiti.graph.Graph qGraph)
Calls reset() for all boxes in the given graph.

Parameters:
qGraph -

addLabel

public static void addLabel(IBox iBox,
                            org.graffiti.graph.Node node)
Adds the name (id) of the given box as a label to the given node.

Parameters:
iBox -
node -

convertToParameters

public static org.graffiti.plugin.parameter.Parameter[] convertToParameters(java.lang.Object[] in)
                                                                     throws java.lang.Exception
Converts an array of objects to an array of parameters.

Parameters:
in -
Returns:
Parameter[] version of the given object array
Throws:
java.lang.Exception

convertToParameter

public static org.graffiti.plugin.parameter.Parameter convertToParameter(java.lang.Object obj,
                                                                         java.lang.String parType)
                                                                  throws java.lang.Exception
Converts the given object to a parameter. If the given string is not null, it should contain a (fully-quantified) class name of the parameter to which the given object should be converted.

If the string is null, the best fitting parameter type is automatically deduced.

Parameters:
obj -
parType -
Returns:
A Parameter holding the given object as value
Throws:
java.lang.Exception - if the object cannot be converted

convertFromParameter

public static java.lang.Object convertFromParameter(org.graffiti.plugin.parameter.Parameter param)
Converts the given Parameter to an object.

Parameters:
param -
Returns:
the object associated with the given parameter

getFreshAttribute

public static org.graffiti.attributes.Attribute getFreshAttribute(java.lang.String id,
                                                                  java.lang.Object value,
                                                                  org.graffiti.attributes.Attributable attbl,
                                                                  java.lang.String type)
                                                           throws InvalidInputException
According to the type specified by first (0) parameter, create a new instance of an attribute. Uses value as its initial value.

Parameters:
id - id of the new attribute
value - value of the new attribute
attbl - Attributable; used to further distinguish type of attribute (e.g. labels: node label / edge label)
Returns:
a new attribute
Throws:
InvalidInputException - if type and value do not correspond