All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.permazen.NavigableSetConverter Maven / Gradle / Ivy

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.util.ConvertedNavigableSet;

import java.util.NavigableSet;

/**
 * Converts {@link NavigableSet}s into {@link ConvertedNavigableSet}s using the provided element {@link Converter}.
 *
 * @param  element type of the converted sets
 * @param  element type of the unconverted (wrapped) sets
 */
class NavigableSetConverter extends Converter, NavigableSet> {

    private final Converter elementConverter;

    NavigableSetConverter(Converter elementConverter) {
        Preconditions.checkArgument(elementConverter != null, "null elementConverter");
        this.elementConverter = elementConverter;
    }

    @Override
    protected NavigableSet doForward(NavigableSet set) {
        if (set == null)
            return null;
        return new ConvertedNavigableSet(set, this.elementConverter.reverse());
    }

    @Override
    protected NavigableSet doBackward(NavigableSet set) {
        if (set == null)
            return null;
        return new ConvertedNavigableSet<>(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 NavigableSetConverter that = (NavigableSetConverter)obj;
        return this.elementConverter.equals(that.elementConverter);
    }

    @Override
    public int hashCode() {
        return this.getClass().hashCode() ^ this.elementConverter.hashCode();
    }

    @Override
    public String toString() {
        return this.getClass().getSimpleName() + "[elementConverter=" + this.elementConverter + "]";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy