io.permazen.IndexConverter 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.index.Index;
/**
* Converts {@link Index}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 IndexConverter extends Converter, Index> {
private final Converter valueConverter;
private final Converter targetConverter;
IndexConverter(Converter valueConverter, Converter targetConverter) {
Preconditions.checkArgument(valueConverter != null, "null valueConverter");
Preconditions.checkArgument(targetConverter != null, "null targetConverter");
this.valueConverter = valueConverter;
this.targetConverter = targetConverter;
}
@Override
protected Index doForward(Index index) {
if (index == null)
return null;
return new ConvertedIndex(index, this.valueConverter.reverse(), this.targetConverter.reverse());
}
@Override
protected Index doBackward(Index index) {
if (index == null)
return null;
return new ConvertedIndex<>(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 IndexConverter, ?, ?, ?> that = (IndexConverter, ?, ?, ?>)obj;
return this.valueConverter.equals(that.valueConverter) && this.targetConverter.equals(that.targetConverter);
}
@Override
public int hashCode() {
return 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