redis.clients.jedis.BuilderFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jedis Show documentation
Show all versions of jedis Show documentation
A java client for github.com/antirez/redis, a fork of github.com/xetorthio/jedis
The newest version!
package redis.clients.jedis;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import redis.clients.util.JedisByteHashMap;
import redis.clients.util.SafeEncoder;
public final class BuilderFactory {
public static final Builder DOUBLE = new Builder() {
@Override
public Double build(Object data) {
String string = STRING.build(data);
if (string == null) return null;
try {
return Double.valueOf(string);
} catch (NumberFormatException e) {
if (string.equals("inf") || string.equals("+inf")) return Double.POSITIVE_INFINITY;
if (string.equals("-inf")) return Double.NEGATIVE_INFINITY;
throw e;
}
}
@Override
public String toString() {
return "double";
}
};
public static final Builder BOOLEAN = new Builder() {
@Override
public Boolean build(Object data) {
return ((Long) data) == 1;
}
@Override
public String toString() {
return "boolean";
}
};
public static final Builder BYTE_ARRAY = new Builder() {
@Override
public byte[] build(Object data) {
return ((byte[]) data); // deleted == 1
}
@Override
public String toString() {
return "byte[]";
}
};
public static final Builder LONG = new Builder() {
@Override
public Long build(Object data) {
return (Long) data;
}
@Override
public String toString() {
return "long";
}
};
public static final Builder STRING = new Builder() {
@Override
public String build(Object data) {
return data == null ? null : SafeEncoder.encode((byte[]) data);
}
@Override
public String toString() {
return "string";
}
};
public static final Builder> STRING_LIST = new Builder>() {
@Override
@SuppressWarnings("unchecked")
public List build(Object data) {
if (null == data) {
return null;
}
List l = (List) data;
final ArrayList result = new ArrayList(l.size());
for (final byte[] barray : l) {
if (barray == null) {
result.add(null);
} else {
result.add(SafeEncoder.encode(barray));
}
}
return result;
}
@Override
public String toString() {
return "List";
}
};
public static final Builder