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

com.lambdaworks.redis.output.ListMapOutput Maven / Gradle / Ivy

There is a newer version: 3.40.2
Show newest version
// Copyright (C) 2011 - Will Glozer.  All rights reserved.

package com.lambdaworks.redis.output;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lambdaworks.redis.codec.RedisCodec;
import com.lambdaworks.redis.protocol.CommandOutput;

public class ListMapOutput extends CommandOutput>> {
    private K key;
    private int index = 0;

    public ListMapOutput(RedisCodec codec) {
        super(codec, new ArrayList>());
    }

    @Override
    public void set(ByteBuffer bytes) {
        if (key == null) {
            key = codec.decodeMapKey(bytes);
            return;
        }

        V value = (bytes == null) ? null : codec.decodeMapValue(bytes);
        if (output.isEmpty()) {
            output.add(new HashMap());
        }
        Map map = output.get(index);
        if (map == null) {
            map = new HashMap();
            output.add(map);
        }
        if (map.get(key) != null) {
            index++;
            map = new HashMap();
            output.add(map);
        }
        map.put(key, value);
        key = null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy