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