本文整理匯總了Java中net.razorvine.pickle.objects.ClassDict類的典型用法代碼示例。如果您正苦於以下問題:Java ClassDict類的具體用法?Java ClassDict怎麽用?Java ClassDict使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClassDict類屬於net.razorvine.pickle.objects包,在下文中一共展示了ClassDict類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testUnpickleCustomClassAsClassDict
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
@Test
public void testUnpickleCustomClassAsClassDict() throws IOException {
byte[] pickled = new byte[] {
(byte)128, 2, 99, 95, 95, 109, 97, 105, 110, 95, 95, 10, 67, 117, 115, 115, 115, 115, 115, 115,
97, 122, 122, 10, 113, 0, 41, (byte)129, 113, 1, 125, 113, 2, 40, 85, 3, 97, 103, 101, 113, 3,
75, 34, 85, 6, 118, 97, 108, 117, 101, 115, 113, 4, 93, 113, 5, 40, 75, 1, 75, 2, 75, 3,
101, 85, 4, 110, 97, 109, 101, 113, 6, 85, 5, 72, 97, 114, 114, 121, 113, 7, 117, 98, 46};
PyroSerializer ser = new PickleSerializer();
ClassDict cd = (ClassDict) ser.deserializeData(pickled);
assertEquals("__main__.Cussssssazz", cd.get("__class__"));
assertEquals("Harry", cd.get("name"));
assertEquals(34, cd.get("age"));
ArrayList<Object> expected = new ArrayList<Object>() {{
add(1);
add(2);
add(3);
}};
assertEquals(expected, cd.get("values"));
}
示例2: newObject
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
public ClassDict newObject(){
Class<? extends ClassDict> clazz = getClazz();
if(clazz == null){
throw new RuntimeException();
}
try {
try {
Constructor<? extends ClassDict> namedConstructor = clazz.getConstructor(String.class, String.class);
return namedConstructor.newInstance(getModule(), getName());
} catch(NoSuchMethodException nsme){
return clazz.newInstance();
}
} catch(IllegalAccessException | InstantiationException | InvocationTargetException e){
throw new RuntimeException(e);
}
}
示例3: formatClass
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
static
public String formatClass(Object object){
if(object == null){
return null;
} // End if
if(object instanceof ClassDict){
ClassDict dict = (ClassDict)object;
return "Python class " + getName(dict);
}
Class<?> clazz = object.getClass();
return "Java class " + clazz.getName();
}
示例4: construct
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
@Override
public ClassDict construct(Object[] args){
if(args.length != 0){
throw new PickleException(Arrays.deepToString(args));
}
return newObject();
}
示例5: getName
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
static
public String getName(ClassDict dict){
String clazz = (String)dict.get("__class__");
if(clazz == null){
throw new IllegalArgumentException();
}
return clazz;
}
示例6: getSimpleName
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
static
public String getSimpleName(ClassDict dict){
String name = getName(dict);
int dot = name.lastIndexOf('.');
if(dot > -1){
return name.substring(dot + 1);
}
return name;
}
示例7: testINST
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
@Test
public void testINST() throws PickleException, IOException {
//INST = b'i' # build & push class instance
ClassDict result = (ClassDict) U("(i__main__\nThing\n(dS'value'\nI32\nsb.");
assertEquals("__main__.Thing", result.getClassName());
assertEquals(32, result.get("value"));
}
示例8: testOBJ
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
@Test
public void testOBJ() throws PickleException, IOException {
//OBJ = b'o' # build & push class instance
ClassDict result = (ClassDict)U("\u0080\u0002(c__main__\nThing\no}U\u0005valueK sb.");
assertEquals("__main__.Thing", result.getClassName());
assertEquals(32, result.get("value"));
}
示例9: ObjectConstructor
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
public ObjectConstructor(String module, String name, Class<? extends ClassDict> clazz){
setModule(module);
setName(name);
setClazz(clazz);
}
示例10: getClazz
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
public Class<? extends ClassDict> getClazz(){
return this.clazz;
}
示例11: setClazz
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
private void setClazz(Class<? extends ClassDict> clazz){
this.clazz = clazz;
}
示例12: isObject
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
static
private boolean isObject(ClassDict dict){
return ("__builtin__.object").equals(dict.get("__class__"));
}
示例13: formatMember
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
static
public String formatMember(ClassDict dict, String name){
String clazz = (String)dict.get("__class__");
return (clazz + "." + name);
}
示例14: formatProxyExample
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
static
public String formatProxyExample(Class<? extends ClassDict> proxyClazz, ClassDict dict){
return (proxyClazz.getSimpleName() + "(" + ClassDictUtil.getSimpleName(dict) + "(...))");
}
示例15: toString
import net.razorvine.pickle.objects.ClassDict; //導入依賴的package包/類
static
public String toString(ClassDict dict){
StringBuffer sb = new StringBuffer();
sb.append("\n{\n");
String sep = "";
List<? extends Map.Entry<String, ?>> entries = new ArrayList<>(dict.entrySet());
Comparator<Map.Entry<String, ?>> comparator = new Comparator<Map.Entry<String, ?>>(){
@Override
public int compare(Map.Entry<String, ?> left, Map.Entry<String, ?> right){
return (left.getKey()).compareToIgnoreCase(right.getKey());
}
};
Collections.sort(entries, comparator);
for(Map.Entry<String, ?> entry : entries){
sb.append(sep);
sep = "\n";
String key = entry.getKey();
Object value = entry.getValue();
sb.append("\t" + key + "=" + value + (" // " + (value != null ? (value.getClass()).getName() : "N/A")));
}
sb.append("\n}\n");
return sb.toString();
}