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

io.permazen.util.MapEntryConverter Maven / Gradle / Ivy

The newest version!

/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package io.permazen.util;

import com.google.common.base.Converter;

import java.util.Map;

/**
 * Converts {@link Map.Entry}s.
 *
 * @param  key type of this map
 * @param  value type of this map
 * @param  key type of wrapped map
 * @param  value type of wrapped map
 */
class MapEntryConverter extends Converter, Map.Entry> {

    private final Converter keyConverter;
    private final Converter valueConverter;

    MapEntryConverter(Converter keyConverter, Converter valueConverter) {
        this.keyConverter = keyConverter;
        this.valueConverter = valueConverter;
    }

    @Override
    protected Map.Entry doForward(Map.Entry entry) {
        if (entry == null)
            return null;
        return new ConvertedMapEntry(this.keyConverter.reverse(), this.valueConverter.reverse(), entry);
    }

    @Override
    protected Map.Entry doBackward(Map.Entry wentry) {
        if (wentry == null)
            return null;
        return new ConvertedMapEntry<>(this.keyConverter, this.valueConverter, wentry);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy