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

io.permazen.Index3Converter Maven / Gradle / Ivy

There is a newer version: 5.1.0
Show 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.Index3;

/**
 * Converts {@link Index3}es.
 *
 * @param  first value type of converted indexes
 * @param  second value type of converted indexes
 * @param  third value type of converted indexes
 * @param  target type of converted indexes
 * @param  first value type of unconverted (wrapped) indexes
 * @param  second value type of unconverted (wrapped) indexes
 * @param  third value type of unconverted (wrapped) indexes
 * @param  target type of unconverted (wrapped) indexes
 */
class Index3Converter extends Converter, Index3> {

    private final Converter value1Converter;
    private final Converter value2Converter;
    private final Converter value3Converter;
    private final Converter targetConverter;

    Index3Converter(Converter value1Converter, Converter value2Converter,
      Converter value3Converter, Converter targetConverter) {
        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.value1Converter = value1Converter;
        this.value2Converter = value2Converter;
        this.value3Converter = value3Converter;
        this.targetConverter = targetConverter;
    }

    @Override
    protected Index3 doForward(Index3 index) {
        if (index == null)
            return null;
        return new ConvertedIndex3(index,
          this.value1Converter.reverse(), this.value2Converter.reverse(),
          this.value3Converter.reverse(), this.targetConverter.reverse());
    }

    @Override
    protected Index3 doBackward(Index3 index) {
        if (index == null)
            return null;
        return new ConvertedIndex3<>(index,
          this.value1Converter, this.value2Converter, this.value3Converter, this.targetConverter);
    }

// Object

    @Override
    public boolean equals(Object obj) {
        if (obj == this)
            return true;
        if (obj == null || obj.getClass() != this.getClass())
            return false;
        final Index3Converter that = (Index3Converter)obj;
        return this.value1Converter.equals(that.value1Converter)
          && this.value2Converter.equals(that.value2Converter)
          && this.value3Converter.equals(that.value3Converter)
          && this.targetConverter.equals(that.targetConverter);
    }

    @Override
    public int hashCode() {
        return this.value1Converter.hashCode()
          ^ this.value2Converter.hashCode()
          ^ this.value3Converter.hashCode()
          ^ this.targetConverter.hashCode();
    }

    @Override
    public String toString() {
        return this.getClass().getSimpleName()
          + "[value1Converter=" + this.value1Converter
          + ",value2Converter=" + this.value2Converter
          + ",value3Converter=" + this.value3Converter
          + ",targetConverter=" + this.targetConverter
          + "]";
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy