jist.swans.misc
Class Mapper

java.lang.Object
  extended by jist.swans.misc.Mapper

public final class Mapper
extends java.lang.Object

Encodes a one-to-one mapping. Used, for example, to dynamically assign port numbers consistently, but in a smaller index range, in order to reduce array sizes.

Since:
SWANS1.0

Field Summary
static int MAP_INVALID
          Invalid mapping constant.
 
Constructor Summary
Mapper(int max)
          Create a mapping with a given index cap.
Mapper(int[] values)
          Create a sealed mapping of the provided values.
 
Method Summary
 int getLimit()
          Return limit of the range of this mapping.
 int getMap(int i)
          Return element in the range of the mapping.
 int getMapR(int j)
          Return element in the domain of the mapping.
 int mapToNext(int i)
          Define a mapping.
 void seal()
          Seal the current mapping; prevent further changes.
 int testMapToNext(int i)
          Define a mapping if one does not already exist.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAP_INVALID

public static final int MAP_INVALID
Invalid mapping constant.

See Also:
Constant Field Values
Constructor Detail

Mapper

public Mapper(int max)
Create a mapping with a given index cap.

Parameters:
max - map indices should be non-negative and less than max.

Mapper

public Mapper(int[] values)
Create a sealed mapping of the provided values.

Parameters:
values - array of domain values to map.
Method Detail

seal

public void seal()
Seal the current mapping; prevent further changes.


mapToNext

public int mapToNext(int i)
Define a mapping. Map i onto one more than the highest value in the range of the mapping.

Parameters:
i - integer in the domain of mapping
Returns:
selected value in the range of the mapping

testMapToNext

public int testMapToNext(int i)
Define a mapping if one does not already exist. Map i onto one more than the highest value in the range of the mapping, unless it is already mapped.

Parameters:
i - integer in the domain of mapping
Returns:
new or corresponding integer in the range of the mapping

getMap

public int getMap(int i)
Return element in the range of the mapping.

Parameters:
i - integer in the domain of the mapping
Returns:
corresponding integer in the range of the mapping

getMapR

public int getMapR(int j)
Return element in the domain of the mapping.

Parameters:
j - integer in the range of the mapping
Returns:
corresponding integer in the domain of the mapping

getLimit

public int getLimit()
Return limit of the range of this mapping.

Returns:
range limit of mapping