public abstract class Mappings extends Object
MappingType,
Mapping,
Permutation| Modifier and Type | Class and Description |
|---|---|
static class |
Mappings.AbstractMapping
Abstract implementation of
Mapping. |
static interface |
Mappings.CoreMapping
Core interface of all mappings.
|
static class |
Mappings.FiniteAbstractMapping
Abstract implementation of mapping where both source and target
domains are finite.
|
static interface |
Mappings.FunctionMapping
Mapping where every source has a target.
|
static class |
Mappings.IdentityMapping
The identity mapping, of a given size, or infinite.
|
static class |
Mappings.NoElementException
Thrown when a mapping is expected to return one element but returns none.
|
static class |
Mappings.OverridingSourceMapping
Source mapping that returns the same result as a parent
Mappings.SourceMapping except for specific overriding elements. |
static class |
Mappings.OverridingTargetMapping
Target mapping that returns the same result as a parent
Mappings.TargetMapping except for specific overriding elements. |
static class |
Mappings.PartialMapping
A mapping where a source has at most one target, and every target has at
most one source.
|
static interface |
Mappings.SourceMapping
Mapping suitable for sourcing columns.
|
static interface |
Mappings.TargetMapping
Mapping suitable for mapping columns to a target.
|
static class |
Mappings.TooManyElementsException
Thrown when a mapping is expected to return one element but returns
several.
|
| Modifier and Type | Method and Description |
|---|---|
static Mappings.TargetMapping |
append(Mappings.TargetMapping mapping0,
Mappings.TargetMapping mapping1)
Creates a mapping by appending two mappings.
|
static BitSet |
apply(Mapping mapping,
BitSet bitSet)
Applies a mapping to a BitSet.
|
static ImmutableBitSet |
apply(Mapping mapping,
ImmutableBitSet bitSet)
Applies a mapping to an
ImmutableBitSet. |
static <T> List<T> |
apply(Mapping mapping,
List<T> list)
Applies a mapping to a list.
|
static int |
apply(Mappings.TargetMapping mapping,
int i)
Applies a mapping to an optional integer, returning an optional
result.
|
static com.google.common.collect.ImmutableList<ImmutableBitSet> |
apply2(Mapping mapping,
Iterable<ImmutableBitSet> bitSets)
Applies a mapping to a collection of
ImmutableBitSets. |
static List<Integer> |
apply2(Mapping mapping,
List<Integer> list) |
static <T> List<T> |
apply3(Mapping mapping,
List<T> list)
Creates a view of a list, permuting according to a mapping.
|
static List<Integer> |
asList(Mappings.TargetMapping mapping)
Returns a mapping as a list such that
list.get(source) is
mapping.getTarget(source) and list.size() is
mapping.getSourceCount(). |
static List<Integer> |
asListNonNull(Mappings.TargetMapping mapping)
Returns a mapping as a list such that
list.get(source) is
mapping.getTarget(source) and list.size() is
mapping.getSourceCount(). |
static Mapping |
bijection(List<Integer> targets)
Creates a bijection.
|
static Mapping |
bijection(Map<Integer,Integer> targets)
Creates a bijection.
|
static Mapping |
create(MappingType mappingType,
int sourceCount,
int targetCount)
Creates a mapping with required properties.
|
static Mappings.IdentityMapping |
createIdentity(int fieldCount)
Creates the identity mapping.
|
static Mappings.TargetMapping |
createShiftMapping(int sourceCount,
int... ints)
Creates a mapping that consists of a set of contiguous ranges.
|
static Mapping |
divide(Mapping mapping1,
Mapping mapping2)
Divides one mapping by another.
|
static Iterable<IntPair> |
invert(Iterable<IntPair> pairs)
|
static Iterator<IntPair> |
invert(Iterator<IntPair> pairs)
|
static Mapping |
invert(Mapping mapping)
Converts a mapping to its inverse.
|
static boolean |
isIdentity(List<Integer> list,
int count)
Returns whether a list of integers is the identity mapping
[0, ..., n - 1].
|
static boolean |
isIdentity(Mappings.TargetMapping mapping)
Returns whether a mapping is the identity.
|
static boolean |
keepsOrdering(Mappings.TargetMapping mapping)
Returns whether a mapping keeps order.
|
static Mappings.TargetMapping |
merge(Mappings.TargetMapping mapping0,
Mappings.TargetMapping mapping1)
Creates a mapping by merging two mappings.
|
static Mapping |
multiply(Mapping mapping1,
Mapping mapping2)
Multiplies one mapping by another.
|
static Mappings.TargetMapping |
offset(Mappings.TargetMapping mapping,
int offset,
int sourceCount)
Returns a mapping that shifts a given mapping's source and target by a
given offset.
|
static Mappings.TargetMapping |
offsetSource(Mappings.TargetMapping mapping,
int offset)
Returns a mapping that shifts a given mapping's source by a given
offset, incrementing the number of sources by the minimum possible.
|
static Mappings.TargetMapping |
offsetSource(Mappings.TargetMapping mapping,
int offset,
int sourceCount)
Returns a mapping that shifts a given mapping's source by a given
offset.
|
static Mappings.TargetMapping |
offsetTarget(Mappings.TargetMapping mapping,
int offset)
Returns a mapping that shifts a given mapping's target by a given
offset, incrementing the number of targets by the minimum possible.
|
static Mappings.TargetMapping |
offsetTarget(Mappings.TargetMapping mapping,
int offset,
int targetCount)
Returns a mapping that shifts a given mapping's target by a given
offset.
|
static <T> List<T> |
permute(List<T> list,
Mappings.TargetMapping mapping)
Creates a view of a list, permuting according to a target mapping.
|
static Mapping |
source(List<Integer> targets,
int targetCount) |
static Mappings.TargetMapping |
target(IntFunction<? extends Integer> function,
int sourceCount,
int targetCount) |
static Mapping |
target(Iterable<IntPair> pairs,
int sourceCount,
int targetCount) |
static Mapping |
target(List<Integer> sources,
int sourceCount) |
static Mappings.TargetMapping |
target(Map<Integer,Integer> map,
int sourceCount,
int targetCount)
Converts a
Map of integers to a Mappings.TargetMapping. |
public static Mapping create(MappingType mappingType, int sourceCount, int targetCount)
public static Mappings.IdentityMapping createIdentity(int fieldCount)
For example, createIdentity(2) returns the mapping
{0:0, 1:1, 2:2}.
fieldCount - Number of sources/targetspublic static Mapping divide(Mapping mapping1, Mapping mapping2)
divide(A, B) returns a mapping C such that B . C (the mapping
B followed by the mapping C) is equivalent to A.
mapping1 - First mappingmapping2 - Second mappingpublic static Mapping multiply(Mapping mapping1, Mapping mapping2)
multiply(A, B) returns a mapping C such that A . B (the mapping
A followed by the mapping B) is equivalent to C.
mapping1 - First mappingmapping2 - Second mappingpublic static BitSet apply(Mapping mapping, BitSet bitSet)
If the mapping does not affect the bit set, returns the original. Never changes the original.
mapping - MappingbitSet - Bit setpublic static ImmutableBitSet apply(Mapping mapping, ImmutableBitSet bitSet)
ImmutableBitSet.
If the mapping does not affect the bit set, returns the original. Never changes the original.
mapping - MappingbitSet - Bit setpublic static com.google.common.collect.ImmutableList<ImmutableBitSet> apply2(Mapping mapping, Iterable<ImmutableBitSet> bitSets)
ImmutableBitSets.mapping - MappingbitSets - Collection of bit setspublic static <T> List<T> apply(Mapping mapping, List<T> list)
T - Element typemapping - Mappinglist - Listpublic static <T> List<T> apply3(Mapping mapping, List<T> list)
T - Element typemapping - Mappinglist - Listpublic static <T> List<T> permute(List<T> list, Mappings.TargetMapping mapping)
T - Element typemapping - Mappinglist - List@CheckReturnValue public static List<Integer> asList(Mappings.TargetMapping mapping)
list.get(source) is
mapping.getTarget(source) and list.size() is
mapping.getSourceCount().
Converse of target(List, int)
asListNonNull(TargetMapping)@CheckReturnValue public static List<Integer> asListNonNull(Mappings.TargetMapping mapping)
list.get(source) is
mapping.getTarget(source) and list.size() is
mapping.getSourceCount().
The resulting list never contains null elements
Converse of target(List, int)
asList(TargetMapping)public static Mappings.TargetMapping target(Map<Integer,Integer> map, int sourceCount, int targetCount)
Map of integers to a Mappings.TargetMapping.public static Mappings.TargetMapping target(IntFunction<? extends Integer> function, int sourceCount, int targetCount)
public static Mapping bijection(List<Integer> targets)
Throws if sources and targets are not one to one.
public static Mapping bijection(Map<Integer,Integer> targets)
Throws if sources and targets are not one to one.
public static boolean isIdentity(Mappings.TargetMapping mapping)
public static boolean keepsOrdering(Mappings.TargetMapping mapping)
For example, {0:0, 1:1} and {0:1, 1:1} keeps order, and {0:1, 1:0} breaks the initial order.
public static Mappings.TargetMapping createShiftMapping(int sourceCount, int... ints)
For example,
createShiftMapping(60,
100, 0, 3,
200, 50, 5);
creates
| Source | Target |
|---|---|
| 0 | 100 |
| 1 | 101 |
| 2 | 102 |
| 3 | -1 |
| ... | -1 |
| 50 | 200 |
| 51 | 201 |
| 52 | 202 |
| 53 | 203 |
| 54 | 204 |
| 55 | -1 |
| ... | -1 |
| 59 | -1 |
sourceCount - Maximum value of sourceints - Collection of ranges, each
(target, source, count)public static Mappings.TargetMapping append(Mappings.TargetMapping mapping0, Mappings.TargetMapping mapping1)
Sources and targets of the second mapping are shifted to the right.
For example,
append({0:0, 1:1}, {0:0, 1:1, 2:2}) yields
{0:0, 1:1, 2:2, 3:3, 4:4}.public static Mappings.TargetMapping merge(Mappings.TargetMapping mapping0, Mappings.TargetMapping mapping1)
Unlike append(org.apache.calcite.util.mapping.Mappings.TargetMapping, org.apache.calcite.util.mapping.Mappings.TargetMapping), sources and targets are not shifted.
For example, merge({0:0, 1:1}, {2:2, 3:3, 4:4}) yields
{0:0, 1:1, 2:2, 3:3, 4:4}.
merge({0:0, 1:1}, {1:2, 2:3}) throws, because there are
two entries with source=1.
public static Mappings.TargetMapping offsetSource(Mappings.TargetMapping mapping, int offset)
mapping - Input mappingoffset - Offset to be applied to each sourcepublic static Mappings.TargetMapping offsetSource(Mappings.TargetMapping mapping, int offset, int sourceCount)
For example, given mapping with sourceCount=2, targetCount=8,
and (source, target) entries {[0: 5], [1: 7]}, offsetSource(mapping, 3)
returns a mapping with sourceCount=5, targetCount=8,
and (source, target) entries {[3: 5], [4: 7]}.
mapping - Input mappingoffset - Offset to be applied to each sourcesourceCount - New source count; must be at least mapping's
source count plus offsetpublic static Mappings.TargetMapping offsetTarget(Mappings.TargetMapping mapping, int offset)
mapping - Input mappingoffset - Offset to be applied to each targetpublic static Mappings.TargetMapping offsetTarget(Mappings.TargetMapping mapping, int offset, int targetCount)
For example, given mapping with sourceCount=2, targetCount=8,
and (source, target) entries {[0: 5], [1: 7]}, offsetTarget(mapping, 3)
returns a mapping with sourceCount=2, targetCount=11,
and (source, target) entries {[0: 8], [1: 10]}.
mapping - Input mappingoffset - Offset to be applied to each targettargetCount - New target count; must be at least mapping's
target count plus offsetpublic static Mappings.TargetMapping offset(Mappings.TargetMapping mapping, int offset, int sourceCount)
For example, given mapping with sourceCount=2, targetCount=8,
and (source, target) entries {[0: 5], [1: 7]}, offsetSource(mapping, 3)
returns a mapping with sourceCount=5, targetCount=8,
and (source, target) entries {[3: 8], [4: 10]}.
mapping - Input mappingoffset - Offset to be applied to each sourcesourceCount - New source count; must be at least mapping's
source count plus offsetpublic static boolean isIdentity(List<Integer> list, int count)
public static int apply(Mappings.TargetMapping mapping, int i)
Copyright © 2012-2022 Apache Software Foundation. All Rights Reserved.