Example usage for org.apache.commons.lang3 SerializationUtils clone

List of usage examples for org.apache.commons.lang3 SerializationUtils clone

Introduction

In this page you can find the example usage for org.apache.commons.lang3 SerializationUtils clone.

Prototype

public static <T extends Serializable> T clone(final T object) 

Source Link

Document

Deep clone an Object using serialization.

This is many times slower than writing clone methods by hand on all objects in your object graph.

Usage

From source file:org.moeaframework.core.Solution.java

/**
 * Similar to {@link #copy()} except all attributes are also copied.  As a
 * result, this method tends to be significantly slower than {@code copy()}
 * if many large objects are stored as attributes.
 * //w w  w  .  j  av a 2 s .  co m
 * @return an independent copy of this solution
 */
public Solution deepCopy() {
    Solution copy = copy();

    for (Map.Entry<String, Serializable> entry : getAttributes().entrySet()) {
        copy.setAttribute(entry.getKey(), SerializationUtils.clone(entry.getValue()));
    }

    return copy;
}

From source file:org.mqnaas.core.impl.slicing.SliceAdministration.java

/**
 * Clones the <code>source</code> slice space. Up to 3D implemented.
 *///from   w ww  .  j a va 2 s  . co m
private Object cloneSliceData(Object source, int dimensions) {
    switch (dimensions) {
    case 1:
        return SerializationUtils.clone((boolean[]) source);
    case 2:
        return SerializationUtils.clone((boolean[][]) source);
    case 3:
        return SerializationUtils.clone((boolean[][][]) source);
    default:
        throw new RuntimeException("Only up to three dimensions implemented");
    }
}

From source file:org.nuxeo.ecm.core.api.TestDocumentModel.java

@Test
public void testDocumentLiveSerialization() throws Exception {
    DocumentModel doc = session.createDocumentModel("/", "doc", "File");
    doc = session.createDocument(doc);/*from ww  w.  ja  va2  s  . c  o m*/
    doc.getProperty("common:icon").setValue("prefetched");
    doc.getProperty("dublincore:language").setValue("not-prefetch");
    doc = session.saveDocument(doc);

    Assertions.assertThat(doc.getCoreSession()).isNotNull();

    doc = SerializationUtils.clone(doc);

    assertThat(doc.getCoreSession()).isNull();
    assertThat(doc.getName()).isEqualTo("doc");
    assertThat(doc.getProperty("common:icon").getValue(String.class)).isEqualTo("prefetched");
    assertThat(doc.getProperty("dublincore:language").getValue(String.class)).isEqualTo("not-prefetch");
}

From source file:org.nuxeo.ecm.core.api.TestDocumentModel.java

@Test
public void testDocumentDirtySerialization() throws Exception {
    DocumentModel doc = session.createDocumentModel("/", "doc", "File");
    doc = session.createDocument(doc);//from  ww w  .java  2s  .c  om
    doc.getProperty("common:size").setValue(10L);

    assertThat(doc.isDirty()).isTrue();

    doc = SerializationUtils.clone(doc);

    assertThat(doc.getCoreSession()).isNull();
    assertThat(doc.getProperty("common:size").getValue(Long.class)).isEqualTo(10L);
}

From source file:org.nuxeo.ecm.core.api.TestDocumentModel.java

@Test
public void testDocumentDeletedSerialization() throws Exception {
    DocumentModel doc = session.createDocumentModel("/", "doc", "File");
    doc = session.createDocument(doc);//w w  w .ja va2  s  .  c o  m
    doc.getProperty("dublincore:title").setValue("doc"); // prefetch
    doc.getProperty("common:size").setValue(10L); // not prefetch

    session.removeDocument(doc.getRef());

    assertThat(session.exists(doc.getRef())).isFalse();

    doc = SerializationUtils.clone(doc);

    assertThat(doc.getCoreSession()).isNull();
    assertThat(doc.getProperty("common:size").getValue(Long.class)).isEqualTo(10L);
    assertThat(doc.getProperty("dublincore:title").getValue(String.class)).isEqualTo("doc");
}

From source file:org.nuxeo.ecm.core.api.TestDocumentModel.java

@Test
public void testDetachedDocumentSerialization() throws Exception {
    DocumentModel doc = session.createDocumentModel("/", "doc", "File");
    doc = session.createDocument(doc);//from  ww w  .  java 2 s.c  om
    doc.getProperty("common:size").setValue(10L);
    doc.detach(false);

    assertThat(doc.getCoreSession()).isNull();

    doc = SerializationUtils.clone(doc);

    assertThat(doc.getCoreSession()).isNull();
    assertThat(doc.getName()).isEqualTo("doc");
    assertThat(doc.getProperty("common:size").getValue(Long.class)).isEqualTo(10L);
}

From source file:org.nuxeo.ecm.core.test.TestWorkQueuing.java

@Override
protected BlockingQueue<Runnable> newBlockingQueue(WorkQueueDescriptor workQueueDescriptor) {
    return new MemoryBlockingQueue(workQueueDescriptor.getCapacity()) {
        @Override/*from   w  w w  .  ja v  a  2  s.c o  m*/
        public void putElement(Runnable r) throws InterruptedException {
            super.putElement(clone(r));
        }

        Runnable clone(Runnable r) {
            Work original = WorkHolder.getWork(r);
            try {
                return new WorkHolder(SerializationUtils.clone(original));
            } catch (SerializationException cause) {
                throw new NuxeoException("Cannot serialize work of type " + original.getClass().getName());
            }
        }
    };
}

From source file:org.nuxeo.ecm.core.work.TestWorkQueuing.java

@Override
public MemoryBlockingQueue init(WorkQueueDescriptor config) {
    MemoryBlockingQueue queue = new MemoryBlockingQueue(config.id, this, config.getCapacity()) {
        @Override//  w  ww.jav a  2  s .  com
        public void putElement(Runnable r) throws InterruptedException {
            super.putElement(clone(r));
        }

        Runnable clone(Runnable r) {
            Work original = WorkHolder.getWork(r);
            try {
                return new WorkHolder(SerializationUtils.clone(original));
            } catch (SerializationException cause) {
                throw new NuxeoException("Cannot serialize work of type " + original.getClass().getName(),
                        cause);
            }
        }
    };
    super.allQueued.put(queue.queueId, queue);
    return queue;
}

From source file:org.omnaest.utils.beans.replicator.BeanReplicatorSimpleTest.java

@Test
public void testSerialization() {
    BeanReplicator<TestSimpleBeanFrom, TestSimpleBeanTo> beanReplicator = SerializationUtils
            .clone(this.beanReplicator);
    final TestSimpleBeanFrom simpleBean = newPreparedSimpleBean();
    final TestSimpleBeanTo clone = beanReplicator.clone(simpleBean);
    assertSimpleBean(simpleBean, clone);
}

From source file:org.omnaest.utils.beans.result.BeanPropertyAccessorTest.java

@Test
public void testReadResolve() throws Exception {
    BeanPropertyAccessor<TestBean> clone = SerializationUtils.clone(this.beanPropertyAccessorValue1);
    assertNotNull(clone.getBeanClass());
    assertNotNull(clone.getPropertyName());
    assertNotNull(clone.getField());//from ww w  . ja  v a 2  s. c o  m
    assertNotNull(clone.getMethodGetter());
    assertNotNull(clone.getMethodSetter());
}