io.permazen.Index2Converter 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.
The 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.Index2;
/**
* Converts {@link Index2}es.
*
* @param first value type of converted indexes
* @param second 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 target type of unconverted (wrapped) indexes
*/
class Index2Converter extends Converter, Index2> {
private final Converter value1Converter;
private final Converter value2Converter;
private final Converter targetConverter;
Index2Converter(Converter value1Converter, Converter value2Converter, Converter targetConverter) {
Preconditions.checkArgument(value1Converter != null, "null value1Converter");
Preconditions.checkArgument(value2Converter != null, "null value2Converter");
Preconditions.checkArgument(targetConverter != null, "null targetConverter");
this.value1Converter = value1Converter;
this.value2Converter = value2Converter;
this.targetConverter = targetConverter;
}
@Override
protected Index2 doForward(Index2 index) {
if (index == null)
return null;
return new ConvertedIndex2(index,
this.value1Converter.reverse(), this.value2Converter.reverse(), this.targetConverter.reverse());
}
@Override
protected Index2 doBackward(Index2 index) {
if (index == null)
return null;
return new ConvertedIndex2<>(index,
this.value1Converter, this.value2Converter, this.targetConverter);
}
// Object
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null || obj.getClass() != this.getClass())
return false;
final Index2Converter, ?, ?, ?, ?, ?> that = (Index2Converter, ?, ?, ?, ?, ?>)obj;
return this.value1Converter.equals(that.value1Converter)
&& this.value2Converter.equals(that.value2Converter)
&& this.targetConverter.equals(that.targetConverter);
}
@Override
public int hashCode() {
return this.getClass().hashCode()
^ this.value1Converter.hashCode()
^ this.value2Converter.hashCode()
^ this.targetConverter.hashCode();
}
@Override
public String toString() {
return this.getClass().getSimpleName()
+ "[value1Converter=" + this.value1Converter
+ ",value2Converter=" + this.value2Converter
+ ",targetConverter=" + this.targetConverter
+ "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy