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

org.jsimpledb.Tuple4Converter 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 org.jsimpledb.tuple.Tuple4;

/**
 * Converts {@link Tuple4}s.
 *
 * @param  first converted value
 * @param  second converted value
 * @param  third converted value
 * @param  fouth converted value
 * @param  first wrapped value
 * @param  second wrapped value
 * @param  third wrapped value
 * @param  fourth wrapped value
 */
class Tuple4Converter extends Converter, Tuple4> {

    private final Converter value1Converter;
    private final Converter value2Converter;
    private final Converter value3Converter;
    private final Converter value4Converter;

    Tuple4Converter(Converter value1Converter, Converter value2Converter,
      Converter value3Converter, Converter value4Converter) {
        Preconditions.checkArgument(value1Converter != null, "null value1Converter");
        Preconditions.checkArgument(value2Converter != null, "null value2Converter");
        Preconditions.checkArgument(value3Converter != null, "null value3Converter");
        Preconditions.checkArgument(value4Converter != null, "null value4Converter");
        this.value1Converter = value1Converter;
        this.value2Converter = value2Converter;
        this.value3Converter = value3Converter;
        this.value4Converter = value4Converter;
    }

    @Override
    protected Tuple4 doForward(Tuple4 tuple) {
        if (tuple == null)
            return null;
        return new Tuple4(
          this.value1Converter.convert(tuple.getValue1()),
          this.value2Converter.convert(tuple.getValue2()),
          this.value3Converter.convert(tuple.getValue3()),
          this.value4Converter.convert(tuple.getValue4()));
    }

    @Override
    protected Tuple4 doBackward(Tuple4 tuple) {
        if (tuple == null)
            return null;
        return new Tuple4(
          this.value1Converter.reverse().convert(tuple.getValue1()),
          this.value2Converter.reverse().convert(tuple.getValue2()),
          this.value3Converter.reverse().convert(tuple.getValue3()),
          this.value4Converter.reverse().convert(tuple.getValue4()));
    }

// Object

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

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

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





© 2015 - 2024 Weber Informatics LLC | Privacy Policy