All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.permazen.ConvertedIndex4 Maven / Gradle / Ivy

The newest version!

/*
 * 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.Index1;
import io.permazen.index.Index2;
import io.permazen.index.Index3;
import io.permazen.index.Index4;
import io.permazen.tuple.Tuple2;
import io.permazen.tuple.Tuple3;
import io.permazen.tuple.Tuple4;
import io.permazen.tuple.Tuple5;
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 Index4}s.
 *
 * @param  first value type of this index
 * @param  second value type of this index
 * @param  third value type of this index
 * @param  fourth 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  fourth value type of wrapped index
 * @param  target type of wrapped index
 */
class ConvertedIndex4 implements Index4 {

    private final Index4 index;
    private final Converter value1Converter;
    private final Converter value2Converter;
    private final Converter value3Converter;
    private final Converter value4Converter;
    private final Converter targetConverter;

    ConvertedIndex4(Index4 index, Converter value1Converter,
      Converter value2Converter, Converter value3Converter, Converter value4Converter,
      Converter targetConverter) {
        Preconditions.checkArgument(value1Converter != null, "null value1Converter");
        Preconditions.checkArgument(value2Converter != null, "null value2Converter");
        Preconditions.checkArgument(value3Converter != null, "null value3Converter");
        Preconditions.checkArgument(value4Converter != null, "null value4Converter");
        Preconditions.checkArgument(targetConverter != null, "null targetConverter");
        this.index = index;
        this.value1Converter = value1Converter;
        this.value2Converter = value2Converter;
        this.value3Converter = value3Converter;
        this.value4Converter = value4Converter;
        this.targetConverter = targetConverter;
    }

    @Override
    public NavigableSet> asSet() {
        return new ConvertedNavigableSet, Tuple5>(
          this.index.asSet(),
          new Tuple5Converter(this.value1Converter,
            this.value2Converter, this.value3Converter, this.value4Converter, this.targetConverter));
    }

    @Override
    public NavigableMap, NavigableSet> asMap() {
        return new ConvertedNavigableMap, NavigableSet, Tuple4, NavigableSet>(
          this.index.asMap(),
          new Tuple4Converter(this.value1Converter,
            this.value2Converter, this.value3Converter, this.value4Converter),
            new NavigableSetConverter(this.targetConverter));
    }

    @Override
    public NavigableMap, Index1> asMapOfIndex1() {
        return new ConvertedNavigableMap, Index1, Tuple3, Index1>(
          this.index.asMapOfIndex1(),
          new Tuple3Converter(this.value1Converter, this.value2Converter, this.value3Converter),
          new Index1Converter(this.value4Converter, this.targetConverter));
    }

    @Override
    public NavigableMap, Index2> asMapOfIndex2() {
        return new ConvertedNavigableMap, Index2, Tuple2, Index2>(
          this.index.asMapOfIndex2(),
          new Tuple2Converter(this.value1Converter, this.value2Converter),
          new Index2Converter(this.value3Converter, this.value4Converter, this.targetConverter));
    }

    @Override
    public NavigableMap> asMapOfIndex3() {
        return new ConvertedNavigableMap, WV1, Index3>(
          this.index.asMapOfIndex3(),
          this.value1Converter,
          new Index3Converter(this.value2Converter,
            this.value3Converter, this.value4Converter, this.targetConverter));
    }

    @Override
    public Index3 asIndex3() {
        return new ConvertedIndex3<>(this.index.asIndex3(),
          this.value1Converter, this.value2Converter, this.value3Converter, this.value4Converter);
    }

    @Override
    public Index2 asIndex2() {
        return new ConvertedIndex2<>(this.index.asIndex2(),
          this.value1Converter, this.value2Converter, this.value3Converter);
    }

    @Override
    public Index1 asIndex1() {
        return new ConvertedIndex1<>(this.index.asIndex1(), this.value1Converter, this.value2Converter);
    }

    @Override
    public Index4 withValue1Bounds(Bounds bounds) {
        return this.convert(this.index.withValue1Bounds(ConvertedIndex1.convert(bounds, this.value1Converter)));
    }

    @Override
    public Index4 withValue2Bounds(Bounds bounds) {
        return this.convert(this.index.withValue2Bounds(ConvertedIndex1.convert(bounds, this.value2Converter)));
    }

    @Override
    public Index4 withValue3Bounds(Bounds bounds) {
        return this.convert(this.index.withValue3Bounds(ConvertedIndex1.convert(bounds, this.value3Converter)));
    }

    @Override
    public Index4 withValue4Bounds(Bounds bounds) {
        return this.convert(this.index.withValue4Bounds(ConvertedIndex1.convert(bounds, this.value4Converter)));
    }

    @Override
    public Index4 withTargetBounds(Bounds bounds) {
        return this.convert(this.index.withTargetBounds(ConvertedIndex1.convert(bounds, this.targetConverter)));
    }

    private Index4 convert(Index4 boundedIndex) {
        return boundedIndex == this.index ? this :
          new ConvertedIndex4(boundedIndex,
           this.value1Converter, this.value2Converter, this.value3Converter, this.value4Converter, this.targetConverter);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy