List of usage examples for org.apache.commons.lang SerializationUtils clone
public static Object clone(Serializable object)
Deep clone an Object
using serialization.
This is many times slower than writing clone methods by hand on all objects in your object graph.
From source file:uk.ac.ebi.interpro.scan.model.ProteinMatchesHolderTest.java
@Test public void testEquals() throws IOException, ParseException { // Original//w w w. j a va 2s .c o m ProteinMatchesHolder original = getPfamObject(); // Copy ProteinMatchesHolder copy = (ProteinMatchesHolder) SerializationUtils.clone(original); // Should be equal assertEquals("Original and copy should be equal", original, copy); // Print if (LOGGER.isDebugEnabled()) { LOGGER.debug(original); LOGGER.debug(super.marshal(original)); } }
From source file:uk.ac.ebi.interpro.scan.model.ProteinTest.java
/** * Tests the equivalent() method works as expected *//*w ww. j a va 2 s .c o m*/ @Test @Ignore public void testEquals() throws IOException { Protein original = new Protein(GOOD); Protein copy = (Protein) SerializationUtils.clone(original); // Original should equal itself assertEquals(original, original); // Original and copy should be equal assertEquals(original, copy); // Original and copy should not be equal ProteinXref ProteinXref = original.addCrossReference(new ProteinXref("A0A000_9ACTO")); assertFalse("Original and copy should not be equal", original.equals(copy)); // Original and copy should be equal again copy.addCrossReference((ProteinXref) SerializationUtils.clone(ProteinXref)); assertEquals(original, copy); // Try with locations Set<Hmmer2Match.Hmmer2Location> locations = new HashSet<Hmmer2Match.Hmmer2Location>(); locations.add(new Hmmer2Match.Hmmer2Location(3, 107, 3.0, 3.7e-9, 1, 104, HmmBounds.N_TERMINAL_COMPLETE)); Match match = original .addMatch(new Hmmer2Match(new Signature("PF02310", "B12-binding"), 0.035, 3.7e-9, locations)); assertFalse("Original and copy should not be equal", original.equals(copy)); copy.addMatch((Hmmer2Match) SerializationUtils.clone(match)); assertEquals(original, copy); // Print if (LOGGER.isDebugEnabled()) { LOGGER.debug(original); LOGGER.debug(super.marshal(original)); } }
From source file:uk.ac.ebi.interpro.scan.model.SignatureLibraryReleaseTest.java
@Test public void testEquals() throws ParseException { // Original/*from ww w .j av a2 s. c om*/ SignatureLibraryRelease original = getGene3dObject(); // Copy SignatureLibraryRelease copy = (SignatureLibraryRelease) SerializationUtils.clone(original); //TODO: Why is the signature library set to NULL? //copy.getSignatures().iterator().next().setSignatureLibraryRelease(null); // Should be equal assertEquals("Original and copy models should be equal", original.getSignatures().iterator().next().getModels(), copy.getSignatures().iterator().next().getModels()); assertEquals("Original and copy signatures should be equal", original.getSignatures(), copy.getSignatures()); assertEquals("Original and copy should be equal", original, copy); }
From source file:ws.prager.camel.consul.ConsulRegistry.java
public void put(String key, Object object) { // Substitute $ character in key key = key.replaceAll("\\$", "/"); // create session to avoid conflicts // (not sure if that is safe enough, again) SessionClient sessionClient = consul.sessionClient(); String sessionName = "session_" + UUID.randomUUID().toString(); SessionCreatedResponse response = sessionClient .createSession(ImmutableSession.builder().name(sessionName).build()); String sessionId = response.getId(); kvClient = consul.keyValueClient();/* w ww . j a v a 2 s . co m*/ String lockKey = "lock_" + key; kvClient.acquireLock(lockKey, sessionName, sessionId); // Allow only unique keys, last one wins if (lookupByName(key) != null) { remove(key); } Object clone = SerializationUtils.clone((Serializable) object); byte[] serializedObject = SerializationUtils.serialize((Serializable) clone); // pre-encode due native encoding issues byte[] preEncodedValue = Base64.encodeBase64(serializedObject); String value = new String(preEncodedValue); // store the actual class logger.debug("store value: " + value + " ,under key: " + key); kvClient.putValue(key, value); // store just as a bookmark logger.debug("store bookmark: " + 1 + " ,under key: " + object.getClass().getName().replaceAll("\\$", "/") + "/" + key); kvClient.putValue(object.getClass().getName().replaceAll("\\$", "/") + "/" + key, "1"); kvClient.releaseLock(lockKey, sessionId); }