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)
| 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 |
no test coverage detected