MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / deepCopy

Method deepCopy

JSAT/test/jsat/TestTools.java:55–80  ·  view source on GitHub ↗

Creates a deep copy of the given object via serialization. @param The class of the object @param orig the object to make a copy of @return a copy of the object via serialization

(O orig)

Source from the content-addressed store, hash-verified

53 * @return a copy of the object via serialization
54 */
55 public static <O extends Object> O deepCopy(O orig)
56 {
57 Object obj = null;
58 try
59 {
60 ByteArrayOutputStream bos = new ByteArrayOutputStream();
61 ObjectOutputStream out = new ObjectOutputStream(bos);
62 out.writeObject(orig);
63 out.flush();
64 out.close();
65
66 ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
67 obj = in.readObject();
68 }
69 catch (IOException e)
70 {
71 e.printStackTrace();
72 throw new RuntimeException("Object couldn't be copied", e);
73 }
74 catch (ClassNotFoundException e)
75 {
76 e.printStackTrace();
77 throw new RuntimeException("Object couldn't be copied", e);
78 }
79 return (O) obj;
80 }
81
82 /**
83 * Evaluates a given clustering by assuming that the true cluster label is in the first categorical feature. Checks to make sure that each cluster is pure in the label

Callers 4

testCloneMethod · 0.95
testCloneMethod · 0.95

Calls 1

closeMethod · 0.80

Tested by

no test coverage detected