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

org.jsimpledb.ConvertedIndex Maven / Gradle / Ivy


/*
 * 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.tuple.Tuple2;
import org.jsimpledb.util.ConvertedNavigableMap;
import org.jsimpledb.util.ConvertedNavigableSet;

/**
 * Converter for {@link Index}es.
 *
 * @param  value type of this index
 * @param  target type of this index
 * @param  value type of wrapped index
 * @param  target type of wrapped index
 */
class ConvertedIndex implements Index {

    private final Index index;
    private final Converter valueConverter;
    private final Converter targetConverter;

    ConvertedIndex(Index index, Converter valueConverter, Converter targetConverter) {
        Preconditions.checkArgument(index != null, "null index");
        Preconditions.checkArgument(valueConverter != null, "null valueConverter");
        Preconditions.checkArgument(targetConverter != null, "null targetConverter");
        this.index = index;
        this.valueConverter = valueConverter;
        this.targetConverter = targetConverter;
    }

    @Override
    public NavigableSet> asSet() {
        return new ConvertedNavigableSet, Tuple2>(this.index.asSet(),
          new Tuple2Converter(this.valueConverter, this.targetConverter));
    }

    @Override
    public NavigableMap> asMap() {
        return new ConvertedNavigableMap, WV, NavigableSet>(this.index.asMap(),
          this.valueConverter, new NavigableSetConverter(this.targetConverter));
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy