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

org.zodiac.fastorm.rdb.codec.CompositeValueCodec Maven / Gradle / Ivy

The newest version!
package org.zodiac.fastorm.rdb.codec;

import java.util.LinkedList;

import org.zodiac.fastorm.core.Decoder;
import org.zodiac.fastorm.core.Encoder;
import org.zodiac.fastorm.core.ValueCodec;

public class CompositeValueCodec implements ValueCodec {

    private LinkedList encoders = new LinkedList<>();
    private LinkedList decoders = new LinkedList<>();

    public CompositeValueCodec() {
        super();
    }

    public CompositeValueCodec addEncoder(Encoder encoder){
        encoders.add(encoder);
        return this;
    }

    public CompositeValueCodec addDecoder(Decoder encoder){
        decoders.add(encoder);
        return this;
    }

    public CompositeValueCodec addEncoderFirst(Encoder encoder){
        encoders.addFirst(encoder);
        return this;
    }

    public CompositeValueCodec addDecoderFirst(Decoder encoder){
        decoders.addFirst(encoder);
        return this;
    }

    @Override
    public Object encode(Object value) {
        for (Encoder codec : encoders) {
            value = codec.encode(value);
        }
        return value;
    }

    @Override
    public Object decode(Object data) {
        for (Decoder codec : decoders) {
            data = codec.decode(data);
        }
        return data;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy