io.permazen.ListConverter 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.util.ConvertedList;
import java.util.List;
/**
* Converts {@link List}s into {@link ConvertedList}s using the provided element {@link Converter}.
*
* @param element type of the converted sets
* @param element type of the unconverted (wrapped) sets
*/
class ListConverter extends Converter, List> {
private final Converter elementConverter;
ListConverter(Converter elementConverter) {
Preconditions.checkArgument(elementConverter != null, "null elementConverter");
this.elementConverter = elementConverter;
}
@Override
protected List doForward(List set) {
if (set == null)
return null;
return new ConvertedList(set, this.elementConverter.reverse());
}
@Override
protected List doBackward(List set) {
if (set == null)
return null;
return new ConvertedList<>(set, this.elementConverter);
}
// Object
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (obj == null || obj.getClass() != this.getClass())
return false;
final ListConverter, ?> that = (ListConverter, ?>)obj;
return this.elementConverter.equals(that.elementConverter);
}
@Override
public int hashCode() {
return this.elementConverter.hashCode();
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "[elementConverter=" + this.elementConverter + "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy