it.unimo.dbgroup.momis.tools
Class DistanceMap

java.lang.Object
  extended byit.unimo.dbgroup.momis.tools.DistanceMap
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DistanceMapSymmetrical

public class DistanceMap
extends java.lang.Object
implements java.io.Serializable

Asymmetric Index container for Distance objects.
This class has been designed to handle Distances between objects and provides several ways to retrieve distances.
In this implementation distances are considered asymmetrically. This means that d(a,b, 10) could be different from (b,a, 20);
This choice allows handling of directed graphs.

Author:
Alberto Corni, July 2000
See Also:
Serialized Form

Field Summary
private  java.util.HashMap _dstMap
          Index on the second element of the distance.
private  java.util.HashMap _srcMap
          Index on the first element of the distance.
 
Constructor Summary
DistanceMap()
          Indexes a set of Distance objects.
DistanceMap(Distance[] distances)
          Indexes a set of Distance objects.
DistanceMap(DistanceMap oldMap)
          Clonation method.
DistanceMap(DistanceMap oldMap, java.util.Set preserve)
          Clonation method with filter.
 
Method Summary
 void delete(Distance distance)
          Given a Distance object, looks for equivalent all Distance object (same src and dst objects) and removes them from the indexing structure.
 void delete(java.lang.Object src, java.lang.Object dst)
          Removes from the indexing structure all distances from the given src and the given dst.
 Distance get(java.lang.Object src, java.lang.Object dst)
          Given source and destination object returns the Distance object between them .
 java.util.Set getAllDistances()
          Return a set containing ALL distances stored in this data-structure
 java.util.Set getEndingIn(java.lang.Object src)
          Given an object returns all distances ending in it.
 java.util.Set getRelatedTo(java.lang.Object src)
          All distances that contains the Given object.
 java.util.Set getSetOfDestinationElements()
          Retuns a set of object that appears at least once as DESTINATION object.
 java.util.Set getSetOfDistances()
          Retuns all stored distances as a set.
 java.util.Set getSetOfElements()
          Retuns a set of object that appears at least once in this indexing data structure as SOURCE or as DESTINATION.
 java.util.Set getSetOfSourceElements()
          Retuns a set of object that appears at least once as SOURCE object.
 java.util.Set getStartingFrom(java.lang.Object src)
          Given an object returns all distances starting from it.
static void main(java.lang.String[] args)
          Routine used to test the class.
 void put(Distance distance)
          Add a distance object in the indexing structure.
If a distance between the given elements already exists, it is substituted whith the new object.
protected  void putArray(java.lang.Object[] distances)
          Indexes an array of Distance objects.
protected  void putArrayRestricted(java.lang.Object[] distances, java.util.Set preserve)
          Indexes an array of Distance objects with filter on nodes.
 java.lang.String toString()
          String representation.
 java.lang.String toStringTable()
          String representation.
Produces a tabular output
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_srcMap

private java.util.HashMap _srcMap
Index on the first element of the distance.


_dstMap

private java.util.HashMap _dstMap
Index on the second element of the distance.

Constructor Detail

DistanceMap

public DistanceMap()
Indexes a set of Distance objects.


DistanceMap

public DistanceMap(Distance[] distances)
Indexes a set of Distance objects.

Parameters:
distances - Distance instance to be indexed.

DistanceMap

public DistanceMap(DistanceMap oldMap)
Clonation method.


DistanceMap

public DistanceMap(DistanceMap oldMap,
                   java.util.Set preserve)
Clonation method with filter.
The new DistanceMap will contain only the element specified in the preserve set.

Parameters:
oldMap - the DistanceMap to copy from.
preserve - the list of element to preserve.
Method Detail

putArray

protected void putArray(java.lang.Object[] distances)
Indexes an array of Distance objects.

Parameters:
distances - array of Distance instance to be indexed.

putArrayRestricted

protected void putArrayRestricted(java.lang.Object[] distances,
                                  java.util.Set preserve)
Indexes an array of Distance objects with filter on nodes.
Will be copied only the distances between the element specified in the preserve set.
In the preserve set must be specified a list of node element (source or destination for the distances). This method will copy only the relation specific of the subgraph given by the intesection between the nodes of the preserve set and the nodes present in the DistanceMap to clone.

Parameters:
distances - distances to insert.
preserve - the list of element to preserve.

getAllDistances

public java.util.Set getAllDistances()
Return a set containing ALL distances stored in this data-structure


put

public void put(Distance distance)
Add a distance object in the indexing structure.
If a distance between the given elements already exists, it is substituted whith the new object.

Parameters:
distance - The distance element to add to this indexing structure

get

public Distance get(java.lang.Object src,
                    java.lang.Object dst)
Given source and destination object returns the Distance object between them .

Returns:
the Distance object between the source and destination objects (remind this class is directional), null if such distance is not present.

getStartingFrom

public java.util.Set getStartingFrom(java.lang.Object src)
Given an object returns all distances starting from it.

Returns:
a set of Distance object starting form the given object. null if no Distance object start from the given obj.

getEndingIn

public java.util.Set getEndingIn(java.lang.Object src)
Given an object returns all distances ending in it.

Returns:
a set of Distance object ending in the given object. null if no Distance object ends in the given obj.

getRelatedTo

public java.util.Set getRelatedTo(java.lang.Object src)
All distances that contains the Given object.

Returns:
null if the object does not appears in any distance obj.

delete

public void delete(Distance distance)
Given a Distance object, looks for equivalent all Distance object (same src and dst objects) and removes them from the indexing structure.

Parameters:
distance - The distance element to be removed from this tructure.

delete

public void delete(java.lang.Object src,
                   java.lang.Object dst)
Removes from the indexing structure all distances from the given src and the given dst.


getSetOfElements

public java.util.Set getSetOfElements()
Retuns a set of object that appears at least once in this indexing data structure as SOURCE or as DESTINATION.


getSetOfSourceElements

public java.util.Set getSetOfSourceElements()
Retuns a set of object that appears at least once as SOURCE object.


getSetOfDestinationElements

public java.util.Set getSetOfDestinationElements()
Retuns a set of object that appears at least once as DESTINATION object.


getSetOfDistances

public java.util.Set getSetOfDistances()
Retuns all stored distances as a set.


toString

public java.lang.String toString()
String representation.


toStringTable

public java.lang.String toStringTable()
String representation.
Produces a tabular output


main

public static void main(java.lang.String[] args)
Routine used to test the class.

Tests the tools.



Universita' di Modena e Reggio Emilia