io.permazen.Tuple3Converter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of permazen-main Show documentation
Show all versions of permazen-main Show documentation
Permazen classes that map Java model classes onto the core API.
/*
* 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.tuple.Tuple3;
/**
* Converts {@link Tuple3}s.
*
* @param first converted value
* @param second converted value
* @param third converted value
* @param first wrapped value
* @param second wrapped value
* @param third wrapped value
*/
class Tuple3Converter extends Converter, Tuple3> {
private final Converter value1Converter;
private final Converter value2Converter;
private final Converter value3Converter;
Tuple3Converter(Converter value1Converter, Converter value2Converter, Converter value3Converter) {
Preconditions.checkArgument(value1Converter != null, "null value1Converter");
Preconditions.checkArgument(value2Converter != null, "null value2Converter");
Preconditions.checkArgument(value3Converter != null, "null value3Converter");
this.value1Converter = value1Converter;
this.value2Converter = value2Converter;
this.value3Converter = value3Converter;
}
@Override
protected Tuple3 doForward(Tuple3 tuple) {
if (tuple == null)
return null;
return new Tuple3(
this.value1Converter.convert(tuple.getValue1()),
this.value2Converter.convert(tuple.getValue2()),
this.value3Converter.convert(tuple.getValue3()));
}
@Override
protected Tuple3 doBackward(Tuple3 tuple) {
if (tuple == null)
return null;
return new Tuple3(
this.value1Converter.reverse().convert(tuple.getValue1()),
this.value2Converter.reverse().convert(tuple.getValue2()),
this.value3Converter.reverse().convert(tuple.getValue3()));
}
// Object
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null || obj.getClass() != this.getClass())
return false;
final Tuple3Converter, ?, ?, ?, ?, ?> that = (Tuple3Converter, ?, ?, ?, ?, ?>)obj;
return this.value1Converter.equals(that.value1Converter)
&& this.value2Converter.equals(that.value2Converter)
&& this.value3Converter.equals(that.value3Converter);
}
@Override
public int hashCode() {
return this.value1Converter.hashCode()
^ this.value2Converter.hashCode()
^ this.value3Converter.hashCode();
}
@Override
public String toString() {
return this.getClass().getSimpleName()
+ "[value1Converter=" + this.value1Converter
+ ",value2Converter=" + this.value2Converter
+ ",value3Converter=" + this.value3Converter
+ "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy