com.logicbus.redis.util.BuilderFactory Maven / Gradle / Ivy
package com.logicbus.redis.util;
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;
public class BuilderFactory {
public static final Builder DOUBLE = new Builder() {
public Double build(Object data,Double t) {
String asString = STRING.build(data,null);
return asString == null ? null : Double.valueOf(asString);
}
public String toString() {
return "double";
}
};
public static final Builder BOOLEAN = new Builder() {
public Boolean build(Object data,Boolean t) {
return ((Long) data) == 1;
}
public String toString() {
return "boolean";
}
};
public static final Builder BYTE_ARRAY = new Builder() {
public byte[] build(Object data,byte [] t) {
return ((byte[]) data); // deleted == 1
}
public String toString() {
return "byte[]";
}
};
public static final Builder LONG = new Builder() {
public Long build(Object data,Long t) {
return (Long) data;
}
public String toString() {
return "long";
}
};
public static final Builder STRING = new Builder() {
public String build(Object data,String t) {
return data == null ? null : SafeEncoder.encode((byte[]) data);
}
public String toString() {
return "string";
}
};
public static final Builder> STRING_LIST = new Builder>() {
@SuppressWarnings("unchecked")
public List build(Object data,List t) {
if (null == data) {
return null;
}
List l = (List) data;
final List result = (t == null) ? new ArrayList(l.size()) : t;
for (final byte[] barray : l) {
if (barray == null) {
result.add(null);
} else {
result.add(SafeEncoder.encode(barray));
}
}
return result;
}
public String toString() {
return "List";
}
};
public static final Builder