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

org.jsimpledb.ConvertedIndex4 Maven / Gradle / Ivy

The newest version!

/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package org.jsimpledb;

import com.google.common.base.Converter;
import com.google.common.base.Preconditions;

import java.util.NavigableMap;
import java.util.NavigableSet;

import org.jsimpledb.index.Index;
import org.jsimpledb.index.Index2;
import org.jsimpledb.index.Index3;
import org.jsimpledb.index.Index4;
import org.jsimpledb.tuple.Tuple2;
import org.jsimpledb.tuple.Tuple3;
import org.jsimpledb.tuple.Tuple4;
import org.jsimpledb.tuple.Tuple5;
import org.jsimpledb.util.ConvertedNavigableMap;
import org.jsimpledb.util.ConvertedNavigableSet;

/**
 * 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, Index> asMapOfIndex() {
        return new ConvertedNavigableMap, Index, Tuple3, Index>(
          this.index.asMapOfIndex(),
          new Tuple3Converter(this.value1Converter, this.value2Converter, this.value3Converter),
          new IndexConverter(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 Index asIndex() {
        return new ConvertedIndex<>(this.index.asIndex(), this.value1Converter, this.value2Converter);
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy