org.eigenbase.util.mapping
Class Mappings.PartialFunctionImpl

java.lang.Object
  extended by org.eigenbase.util.mapping.Mappings.AbstractMapping
      extended by org.eigenbase.util.mapping.Mappings.PartialFunctionImpl
All Implemented Interfaces:
Iterable<IntPair>, Mapping, Mappings.FunctionMapping, Mappings.SourceMapping, Mappings.TargetMapping
Enclosing class:
Mappings

private static class Mappings.PartialFunctionImpl
extends Mappings.AbstractMapping
implements Mappings.TargetMapping

Implementation of Mapping where a source can have at most one target, and a target can have any number of sources. The source count must be finite, but the target count may be infinite.

The implementation uses an array for the forward-mapping, but does not store the backward mapping.


Field Summary
private  MappingType mappingType
           
private  int sourceCount
           
private  int targetCount
           
private  int[] targets
           
 
Constructor Summary
Mappings.PartialFunctionImpl(int sourceCount, int targetCount, MappingType mappingType)
           
 
Method Summary
 MappingType getMappingType()
           
 int getSourceCount()
          Returns the number of sources.
 int getTargetCount()
          Returns the number of targets.
 int getTargetOpt(int source)
          Returns the target that a source maps to, or -1 if it is not mapped.
 Mapping inverse()
           
 Iterator<IntPair> iterator()
          Returns an iterator over the elements in this mapping.
 void set(int source, int target)
           
 void setAll(Mapping mapping)
           
 
Methods inherited from class org.eigenbase.util.mapping.Mappings.AbstractMapping
getSource, getSourceOpt, getTarget, isIdentity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eigenbase.util.mapping.Mappings.TargetMapping
getSourceOpt, getTarget
 

Field Detail

sourceCount

private final int sourceCount

targetCount

private final int targetCount

mappingType

private final MappingType mappingType

targets

private final int[] targets
Constructor Detail

Mappings.PartialFunctionImpl

public Mappings.PartialFunctionImpl(int sourceCount,
                                    int targetCount,
                                    MappingType mappingType)
Method Detail

getSourceCount

public int getSourceCount()
Description copied from interface: Mapping
Returns the number of sources. Valid sources will be in the range 0 .. sourceCount.

Specified by:
getSourceCount in interface Mapping
Specified by:
getSourceCount in interface Mappings.FunctionMapping
Specified by:
getSourceCount in interface Mappings.SourceMapping
Specified by:
getSourceCount in interface Mappings.TargetMapping
Overrides:
getSourceCount in class Mappings.AbstractMapping

getTargetCount

public int getTargetCount()
Description copied from interface: Mapping
Returns the number of targets. Valid targets will be in the range 0 .. targetCount.

Specified by:
getTargetCount in interface Mapping
Specified by:
getTargetCount in interface Mappings.SourceMapping
Specified by:
getTargetCount in interface Mappings.TargetMapping
Overrides:
getTargetCount in class Mappings.AbstractMapping

iterator

public Iterator<IntPair> iterator()
Description copied from interface: Mapping
Returns an iterator over the elements in this mapping.

This method is optional; implementations may throw UnsupportedOperationException.

Specified by:
iterator in interface Iterable<IntPair>
Specified by:
iterator in interface Mapping

getMappingType

public MappingType getMappingType()
Specified by:
getMappingType in interface Mapping
Specified by:
getMappingType in interface Mappings.FunctionMapping
Specified by:
getMappingType in interface Mappings.SourceMapping
Specified by:
getMappingType in interface Mappings.TargetMapping

inverse

public Mapping inverse()
Specified by:
inverse in interface Mappings.SourceMapping
Specified by:
inverse in interface Mappings.TargetMapping

set

public void set(int source,
                int target)
Specified by:
set in interface Mappings.TargetMapping
Overrides:
set in class Mappings.AbstractMapping

setAll

public void setAll(Mapping mapping)

getTargetOpt

public int getTargetOpt(int source)
Description copied from interface: Mappings.FunctionMapping
Returns the target that a source maps to, or -1 if it is not mapped.

Specified by:
getTargetOpt in interface Mappings.FunctionMapping
Specified by:
getTargetOpt in interface Mappings.SourceMapping
Specified by:
getTargetOpt in interface Mappings.TargetMapping
Overrides:
getTargetOpt in class Mappings.AbstractMapping