
com.redislabs.mesclun.search.output.AggregateResultOutput Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mesclun Show documentation
Show all versions of mesclun Show documentation
Java client for Redis Labs module
The newest version!
package com.redislabs.mesclun.search.output;
import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.output.CommandOutput;
import java.nio.ByteBuffer;
import java.util.*;
public class AggregateResultOutput extends CommandOutput> {
private final List array;
private boolean initialized;
private K key;
private int count;
public AggregateResultOutput(RedisCodec codec) {
super(codec, Collections.emptyMap());
this.array = new ArrayList<>();
}
@Override
public void set(ByteBuffer bytes) {
if (key == null) {
key = (bytes == null) ? null : codec.decodeKey(bytes);
return;
}
V value = (bytes == null) ? null : codec.decodeValue(bytes);
if (count > 0) {
array.add(value);
if (array.size() == count) {
output.put(key, new ArrayList<>(array));
key = null;
array.clear();
count = 0;
}
} else {
output.put(key, value);
key = null;
}
}
@Override
@SuppressWarnings("unchecked")
public void set(long integer) {
if (key == null) {
key = (K) Long.valueOf(integer);
return;
}
V value = (V) Long.valueOf(integer);
output.put(key, value);
key = null;
}
@Override
public void multi(int count) {
if (initialized) {
if (key != null) {
this.count = count;
}
} else {
output = new LinkedHashMap<>(count / 2, 1);
initialized = true;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy