io.permazen.ConvertedIndex3 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of permazen-main Show documentation
Show all versions of permazen-main Show documentation
Permazen classes that map Java model classes onto the core API.
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package io.permazen;
import com.google.common.base.Converter;
import com.google.common.base.Preconditions;
import io.permazen.index.Index;
import io.permazen.index.Index2;
import io.permazen.index.Index3;
import io.permazen.tuple.Tuple2;
import io.permazen.tuple.Tuple3;
import io.permazen.tuple.Tuple4;
import io.permazen.util.Bounds;
import io.permazen.util.ConvertedNavigableMap;
import io.permazen.util.ConvertedNavigableSet;
import java.util.NavigableMap;
import java.util.NavigableSet;
/**
* Converter for {@link Index3}s.
*
* @param first value type of this index
* @param second value type of this index
* @param third value type of this index
* @param target type of this index
* @param first value type of wrapped index
* @param second value type of wrapped index
* @param third value type of wrapped index
* @param target type of wrapped index
*/
class ConvertedIndex3 implements Index3 {
private final Index3 index;
private final Converter value1Converter;
private final Converter value2Converter;
private final Converter value3Converter;
private final Converter targetConverter;
ConvertedIndex3(Index3 index, Converter value1Converter,
Converter value2Converter, Converter value3Converter, Converter targetConverter) {
Preconditions.checkArgument(index != null, "null index");
Preconditions.checkArgument(value1Converter != null, "null value1Converter");
Preconditions.checkArgument(value2Converter != null, "null value2Converter");
Preconditions.checkArgument(value3Converter != null, "null value3Converter");
Preconditions.checkArgument(targetConverter != null, "null targetConverter");
this.index = index;
this.value1Converter = value1Converter;
this.value2Converter = value2Converter;
this.value3Converter = value3Converter;
this.targetConverter = targetConverter;
}
@Override
public NavigableSet> asSet() {
return new ConvertedNavigableSet, Tuple4>(
this.index.asSet(),
new Tuple4Converter(this.value1Converter,
this.value2Converter, this.value3Converter, this.targetConverter));
}
@Override
public NavigableMap, NavigableSet> asMap() {
return new ConvertedNavigableMap, NavigableSet, Tuple3, NavigableSet>(
this.index.asMap(),
new Tuple3Converter(this.value1Converter, this.value2Converter, this.value3Converter),
new NavigableSetConverter(this.targetConverter));
}
@Override
public NavigableMap, Index> asMapOfIndex() {
return new ConvertedNavigableMap, Index, Tuple2, Index>(
this.index.asMapOfIndex(),
new Tuple2Converter(this.value1Converter, this.value2Converter),
new IndexConverter(this.value3Converter, this.targetConverter));
}
@Override
public NavigableMap> asMapOfIndex2() {
return new ConvertedNavigableMap, WV1, Index2>(
this.index.asMapOfIndex2(),
this.value1Converter,
new Index2Converter(this.value2Converter, this.value3Converter, this.targetConverter));
}
@Override
public Index2 asIndex2() {
return new ConvertedIndex2<>(this.index.asIndex2(),
this.value1Converter, this.value2Converter, this.value3Converter);
}
@Override
public Index asIndex() {
return new ConvertedIndex<>(this.index.asIndex(), this.value1Converter, this.value2Converter);
}
@Override
public Index3 withValue1Bounds(Bounds bounds) {
return this.convert(this.index.withValue1Bounds(ConvertedIndex.convert(bounds, this.value1Converter)));
}
@Override
public Index3 withValue2Bounds(Bounds bounds) {
return this.convert(this.index.withValue2Bounds(ConvertedIndex.convert(bounds, this.value2Converter)));
}
@Override
public Index3 withValue3Bounds(Bounds bounds) {
return this.convert(this.index.withValue3Bounds(ConvertedIndex.convert(bounds, this.value3Converter)));
}
@Override
public Index3 withTargetBounds(Bounds bounds) {
return this.convert(this.index.withTargetBounds(ConvertedIndex.convert(bounds, this.targetConverter)));
}
private Index3 convert(Index3 boundedIndex) {
return boundedIndex == this.index ? this :
new ConvertedIndex3(boundedIndex,
this.value1Converter, this.value2Converter, this.value3Converter, this.targetConverter);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy