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:stroom.entity.server.util.CloneUtil.java
@SuppressWarnings("unchecked") public static <T extends Serializable> T deepClone(final T clone) { return (T) SerializationUtils.clone(clone); }
From source file:uk.ac.diamond.scisoft.analysis.io.ADSCImageTest.java
@Test public void testSerializability() throws Exception { DataHolder loader = new ADSCImageLoader(TestFileFolder + testfile1).loadFile(); Dataset data;/* ww w .ja v a 2 s .c o m*/ IDiffractionMetadata md, cmd; data = loader.getDataset(0); md = (IDiffractionMetadata) data.getMetadata(); // test cloning cmd = md.clone(); Assert.assertEquals("Metadata", md.getDiffractionCrystalEnvironment(), cmd.getDiffractionCrystalEnvironment()); Assert.assertEquals("Metadata", md.getDetector2DProperties(), cmd.getDetector2DProperties()); // test cloning serialization cmd = (IDiffractionMetadata) SerializationUtils.clone(md); Assert.assertEquals("Metadata", md.getDiffractionCrystalEnvironment(), cmd.getDiffractionCrystalEnvironment()); Assert.assertEquals("Metadata", md.getDetector2DProperties(), cmd.getDetector2DProperties()); }
From source file:uk.ac.ebi.interpro.scan.model.Hmmer2MatchTest.java
/** * Tests the equivalent() method works as expected *//*from w w w.ja v a 2 s . c om*/ @Test public void testMatchEquals() { Hmmer2Match original = new Hmmer2Match(new Signature("PF02310", "B12-binding"), 0.035, 3.7e-9, new HashSet<Hmmer2Match.Hmmer2Location>(Arrays.asList(new Hmmer2Match.Hmmer2Location(3, 107, 3.0, 3.7e-9, 1, 104, HmmBounds.N_TERMINAL_COMPLETE)))); Hmmer2Match copy = (Hmmer2Match) SerializationUtils.clone(original); assertEquals("Original should equal itself", original, original); assertEquals("Original and copy should be equal", original, copy); @SuppressWarnings("unchecked") Set<Hmmer2Match.Hmmer2Location> locationsCopy = (Set<Hmmer2Match.Hmmer2Location>) SerializationUtils .clone(new HashSet<Hmmer2Match.Hmmer2Location>(original.getLocations())); Hmmer2Match badCopy = new Hmmer2Match(new Signature("1", "A"), 1, 2, locationsCopy); assertFalse("Original and copy should not be equal", original.equals(badCopy)); // Test sets Set<Match> originalSet = new HashSet<Match>(); Set<Match> copySet = new HashSet<Match>(); originalSet.add(original); copySet.add(copy); assertEquals("Original set should equal itself", originalSet, originalSet); assertEquals("Original and copy sets should be equal", originalSet, copySet); }
From source file:uk.ac.ebi.interpro.scan.model.Hmmer2MatchTest.java
/** * Tests the equivalent() method works as expected *///from ww w . ja v a 2 s. c o m @Test public void testLocationEquals() { HmmerLocation original = new Hmmer2Match.Hmmer2Location(3, 107, 3.0, 3.7e-9, 1, 104, HmmBounds.N_TERMINAL_COMPLETE); HmmerLocation copy = (HmmerLocation) SerializationUtils.clone(original); assertEquals("Original should equal itself", original, original); assertEquals("Original and copy should be equal", original, copy); copy = new Hmmer2Match.Hmmer2Location(1, 2, 3, 4, 5, 6, HmmBounds.COMPLETE); assertFalse("Original and copy should not be equal", original.equals(copy)); }
From source file:uk.ac.ebi.interpro.scan.model.Hmmer3MatchTest.java
/** * Tests the equivalent() method works as expected *//*from w w w.java2 s . c o m*/ @Test public void testMatchEquals() { Hmmer3Match original = originalMatch; Hmmer3Match copy = (Hmmer3Match) SerializationUtils.clone(original); assertEquals("Original should equal itself", original, original); assertEquals("Original and copy should be equal", original, copy); @SuppressWarnings("unchecked") Set<Hmmer3Match.Hmmer3Location> locationsCopy = (Set<Hmmer3Match.Hmmer3Location>) SerializationUtils .clone(new HashSet<Hmmer3Match.Hmmer3Location>(original.getLocations())); Hmmer3Match badCopy = new Hmmer3Match(new Signature("1", "A"), 1, 2, locationsCopy); assertFalse("Original and copy should not be equal", original.equals(badCopy)); // Test sets Set<Match> originalSet = new HashSet<Match>(); Set<Match> copySet = new HashSet<Match>(); originalSet.add(original); copySet.add(copy); assertEquals("Original set should equal itself", originalSet, originalSet); assertEquals("Original and copy sets should be equal", originalSet, copySet); }
From source file:uk.ac.ebi.interpro.scan.model.Hmmer3MatchTest.java
/** * Tests the equivalent() method works as expected *///from w w w .j a v a 2 s. co m @Test public void testLocationEquals() { HmmerLocation original = originalLocation; HmmerLocation copy = (HmmerLocation) SerializationUtils.clone(original); assertEquals("Original should equal itself", original, original); assertEquals("Original and copy should be equal", original, copy); copy = new Hmmer3Match.Hmmer3Location(1, 2, 3, 4, 5, 6, HmmBounds.COMPLETE, 7, 8); assertFalse("Original and copy should not be equal", original.equals(copy)); }
From source file:uk.ac.ebi.interpro.scan.model.NucleicAcidMatchesHolderTest.java
@Test public void testEquals() throws IOException, ParseException { // Original// ww w . j a va2 s. co m NucleicAcidMatchesHolder original = getPfamObject(); // Copy NucleicAcidMatchesHolder copy = (NucleicAcidMatchesHolder) SerializationUtils.clone(original); // Should be equal assertEquals("Original and copy should be equal", original, copy); // Print if (LOGGER.isDebugEnabled()) { LOGGER.debug(original.toString()); LOGGER.debug(super.marshal(original)); } }
From source file:uk.ac.ebi.interpro.scan.model.NucleotideSequenceTest.java
@Test public void testEquals() throws IOException, ParseException { // Original/*from ww w . j a v a2s . c om*/ NucleotideSequence original = getPfamObject(); // Copy NucleotideSequence copy = (NucleotideSequence) 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.PhobiusMatchTest.java
/** * Tests the equivalent() method works as expected *///from w ww . j av a2s . c o m @Test public void testMatchEquals() { PhobiusMatch original = new PhobiusMatch( new Signature("SIGNAL_PEPTIDE_N_REGION", "Signal peptide N-region"), new HashSet<PhobiusMatch.PhobiusLocation>(Arrays.asList(new PhobiusMatch.PhobiusLocation(3, 107)))); PhobiusMatch copy = (PhobiusMatch) SerializationUtils.clone(original); assertEquals("Original should equal itself", original, original); assertEquals("Original and copy should be equal", original, copy); assertFalse("Original and copy should not be equal", original.equals(new PhobiusMatch(new Signature("NON_CYTOPLASMIC_DOMAIN", "Non cytoplasmic domain"), new HashSet<PhobiusMatch.PhobiusLocation>( Arrays.asList(new PhobiusMatch.PhobiusLocation(3, 107)))))); // Test sets Set<Match> originalSet = new HashSet<Match>(); Set<Match> copySet = new HashSet<Match>(); originalSet.add(original); copySet.add(copy); assertEquals("Original set should equal itself", originalSet, originalSet); assertEquals("Original and copy sets should be equal", originalSet, copySet); }
From source file:uk.ac.ebi.interpro.scan.model.PhobiusMatchTest.java
/** * Tests the equivalent() method works as expected *//*from w w w .j ava 2 s. co m*/ @Test public void testLocationEquals() { PhobiusMatch.PhobiusLocation original = new PhobiusMatch.PhobiusLocation(3, 107); PhobiusMatch.PhobiusLocation copy = (PhobiusMatch.PhobiusLocation) SerializationUtils.clone(original); assertEquals("Original should equal itself", original, original); assertEquals("Original and copy should be equal", original, copy); assertFalse("Original and copy should not be equal", original.equals(new PhobiusMatch.PhobiusLocation(1, 2))); }