SandMark version 2.0


sandmark.util.graph.codec
Class GraphCodec

java.lang.Object
  |
  +--sandmark.util.graph.codec.GraphCodec
Direct Known Subclasses:
PermutationGraph, PPCT, RadixGraph

public abstract class GraphCodec
extends java.lang.Object

Base-class for watermark encoders/decoders (codecs). Each class in this package should implement sandmark.util.graph.codec.GraphCodec. This entails implementing the encode and decode methods.

To encode an integer into a graph, use the package like this:

    java.math.BigInteger value = ...
    sandmark.util.graph.codec.GraphCodec E = new sandmark.util.graph.codec.RadixGraph(value);
    sandmark.util.graph.Graph graph = E.graph; 
 

To decode a graph into an integer, use the package like this:

    sandmark.util.graph.Graph graph = ...; 
    sandmark.util.graph.Node  root  = ...; 
    int[] kidMap = {1,2};
    sandmark.util.graph.codec.GraphCodec E = new sandmark.util.graph.codec.RadixGraph(graph,root,kidMap);
    sandmark.util.graph.Graph graph = E.graph; 
 


Field Summary
static java.lang.Class[] codecs
           
 java.lang.String fullName
           
 Graph graph
           
protected  int[] kidMap
           
(package private) static java.util.Random random
          Return a random codec.
protected  Node root
           
 java.lang.String shortName
           
 java.math.BigInteger value
           
 
Constructor Summary
GraphCodec()
           
GraphCodec(java.math.BigInteger value)
          Constructor to be used when encoding an integer into a graph.
GraphCodec(Graph graph, int[] kidMap)
          Constructor to be used when decoding a graph to an integer.
 
Method Summary
static java.lang.Class codecByName(java.lang.String name)
          Return the codec whose name is 'name'.
(package private) abstract  void decode()
          Codecs should implement this method to convert the 'graph' into 'value'.
(package private) abstract  void encode()
          Codecs should implement this method to convert the 'value' into 'graph'.
(package private)  Node getKid(Node node, int edgeNumber)
          Use the kidMap to get the edgeNumber:th child of the node.
static java.lang.Class randomCodec()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

value

public java.math.BigInteger value

graph

public Graph graph

root

protected Node root

kidMap

protected int[] kidMap

fullName

public java.lang.String fullName

shortName

public java.lang.String shortName

codecs

public static java.lang.Class[] codecs

random

static java.util.Random random
Return a random codec.

Constructor Detail

GraphCodec

public GraphCodec()

GraphCodec

public GraphCodec(java.math.BigInteger value)
Constructor to be used when encoding an integer into a graph.

Parameters:
value - The value to be encoded.

GraphCodec

public GraphCodec(Graph graph,
                  int[] kidMap)
           throws DecodeFailure
Constructor to be used when decoding a graph to an integer.

Parameters:
graph - The graph to be decoded.
kidMap - An array of ints describing which field should represent the first child, the second child, etc.
Method Detail

encode

abstract void encode()
Codecs should implement this method to convert the 'value' into 'graph'.


decode

abstract void decode()
              throws DecodeFailure
Codecs should implement this method to convert the 'graph' into 'value'. Whenever the decoding failes (eg. because the graph has the wrong shape) the codec should simply throw an exception.

DecodeFailure

codecByName

public static java.lang.Class codecByName(java.lang.String name)
                                   throws java.lang.Exception
Return the codec whose name is 'name'.

Parameters:
name - The short name of the codec. A java.util.NoSuchElementException is thrown if a codec by this name does not exist.
java.lang.Exception

randomCodec

public static java.lang.Class randomCodec()
                                   throws java.lang.Exception
java.lang.Exception

getKid

Node getKid(Node node,
            int edgeNumber)
Use the kidMap to get the edgeNumber:th child of the node. This is a utility method used by decoders.

Parameters:
node - Look up this node
edgeNumber - The edge number to look up

SandMark version 2.0

Mon Jun 17 12:30:47 MST 2002