org.jsimpledb.Tuple5Converter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsimpledb-main Show documentation
Show all versions of jsimpledb-main Show documentation
JSimpleDB classes that map Java model classes onto the core API.
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.Tuple5;
/**
* Converts {@link Tuple5}s.
*
* @param first converted value
* @param second converted value
* @param third converted value
* @param fouth converted value
* @param fifth converted value
* @param first wrapped value
* @param second wrapped value
* @param third wrapped value
* @param fourth wrapped value
* @param fifth wrapped value
*/
class Tuple5Converter
extends Converter, Tuple5> {
private final Converter value1Converter;
private final Converter value2Converter;
private final Converter value3Converter;
private final Converter value4Converter;
private final Converter value5Converter;
Tuple5Converter(Converter value1Converter, Converter value2Converter,
Converter value3Converter, Converter value4Converter, Converter value5Converter) {
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(value5Converter != null, "null value5Converter");
this.value1Converter = value1Converter;
this.value2Converter = value2Converter;
this.value3Converter = value3Converter;
this.value4Converter = value4Converter;
this.value5Converter = value5Converter;
}
@Override
protected Tuple5 doForward(Tuple5 tuple) {
if (tuple == null)
return null;
return new Tuple5(
this.value1Converter.convert(tuple.getValue1()),
this.value2Converter.convert(tuple.getValue2()),
this.value3Converter.convert(tuple.getValue3()),
this.value4Converter.convert(tuple.getValue4()),
this.value5Converter.convert(tuple.getValue5()));
}
@Override
protected Tuple5 doBackward(Tuple5 tuple) {
if (tuple == null)
return null;
return new Tuple5(
this.value1Converter.reverse().convert(tuple.getValue1()),
this.value2Converter.reverse().convert(tuple.getValue2()),
this.value3Converter.reverse().convert(tuple.getValue3()),
this.value4Converter.reverse().convert(tuple.getValue4()),
this.value5Converter.reverse().convert(tuple.getValue5()));
}
// Object
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null || obj.getClass() != this.getClass())
return false;
final Tuple5Converter, ?, ?, ?, ?, ?, ?, ?, ?, ?> that = (Tuple5Converter, ?, ?, ?, ?, ?, ?, ?, ?, ?>)obj;
return this.value1Converter.equals(that.value1Converter)
&& this.value2Converter.equals(that.value2Converter)
&& this.value3Converter.equals(that.value3Converter)
&& this.value4Converter.equals(that.value4Converter)
&& this.value5Converter.equals(that.value5Converter);
}
@Override
public int hashCode() {
return this.value1Converter.hashCode()
^ this.value2Converter.hashCode()
^ this.value3Converter.hashCode()
^ this.value4Converter.hashCode()
^ this.value5Converter.hashCode();
}
@Override
public String toString() {
return this.getClass().getSimpleName()
+ "[value1Converter=" + this.value1Converter
+ ",value2Converter=" + this.value2Converter
+ ",value3Converter=" + this.value3Converter
+ ",value4Converter=" + this.value4Converter
+ ",value5Converter=" + this.value5Converter
+ "]";
}
}