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.omnaest.utils.table.TableTest.java

@Test
public void testSerializationJavaSerializable() {
    Table<String> table = this.filledTableWithTitles(4, 5);
    Table<String> clone = SerializationUtils.clone(table);
    assertTrue(table.equalsInContent(clone));
    assertTrue(table.equalsInContentAndMetaData(clone));

    //System.out.println( clone );
}

From source file:org.omnaest.utils.time.DurationCaptureTest.java

@Test
public void testObjectSerialization() throws InterruptedException {
    DurationCapture durationCapture = new DurationCapture().startTimeMeasurement();
    DurationCapture cloneObject = SerializationUtils.clone(durationCapture);
    Thread.sleep(10);/*from   w  ww . j  ava 2  s  . c om*/
    final long durationInMilliseconds = cloneObject.stopTimeMeasurement().getDurationInMilliseconds();
    //System.out.println( durationInMilliseconds );
    //System.out.println( durationCapture );
    assertTrue(durationInMilliseconds > 0);
}

From source file:org.onexus.website.api.pages.PageConfig.java

public PageStatus newStatus() {

    PageStatus status = getDefaultStatus();

    if (status != null) {
        status = SerializationUtils.clone(status);
    } else {//from   ww w . jav a 2s .co m
        status = createEmptyStatus();
    }

    status.setId(getId());
    status.setConfig(this);

    // Add widget status
    List<WidgetConfig> widgets = getWidgets();
    List<WidgetStatus> statuses = new ArrayList<WidgetStatus>(widgets.size());
    for (WidgetConfig widgetConfig : getWidgets()) {
        statuses.add(widgetConfig.newStatus());
    }
    status.setWidgetStatuses(statuses);

    return status;
}

From source file:org.onexus.website.api.WebsiteConfig.java

public WebsiteStatus newStatus() {

    WebsiteStatus status = getDefaultStatus();

    if (status != null) {
        status = SerializationUtils.clone(status);
    } else {/*  w ww  .j a  va2s  .c  om*/
        status = createEmptyStatus();
    }

    status.setConfig(this);

    // Add page status
    if (getPages() != null) {
        List<PageStatus> pageStatuses = new ArrayList<PageStatus>();
        for (PageConfig page : getPages()) {
            page.setWebsiteConfig(this);
            pageStatuses.add(page.newStatus());
        }
        status.setPageStatuses(pageStatuses);
    }

    return status;
}

From source file:org.onexus.website.api.widgets.WidgetConfig.java

public WidgetStatus newStatus() {

    WidgetStatus status = getDefaultStatus();

    if (status != null) {
        status = SerializationUtils.clone(status);
    } else {//from w  w w .  ja  v  a2s .  c  o  m
        status = createEmptyStatus();
    }

    status.setId(getId());
    status.setConfig(this);

    return status;
}

From source file:org.opendaylight.controller.cluster.datastore.DataTreeCandidatePayloadTest.java

@Test
public void testPayloadSerDes() throws IOException {
    final DataTreeCandidatePayload payload = DataTreeCandidatePayload.create(candidate);
    assertCandidateEquals(candidate, SerializationUtils.clone(payload).getCandidate());
}

From source file:org.opendaylight.controller.cluster.datastore.persisted.AbortTransactionPayloadTest.java

@Test
public void testPayloadSerDes() throws IOException {
    final AbortTransactionPayload template = AbortTransactionPayload.create(nextTransactionId());
    final AbortTransactionPayload cloned = SerializationUtils.clone(template);
    assertEquals(template.getIdentifier(), cloned.getIdentifier());
}

From source file:org.opendaylight.controller.cluster.datastore.persisted.AbstractIdentifiablePayloadTest.java

@Test
public void testSerialization() {
    final T object = object();
    final T cloned = SerializationUtils.clone(object);
    Assert.assertEquals(object.getIdentifier(), cloned.getIdentifier());
}

From source file:org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayloadTest.java

@Test
public void testPayloadSerDes() throws IOException {
    final CommitTransactionPayload payload = CommitTransactionPayload.create(nextTransactionId(), candidate);
    assertCandidateEquals(candidate, SerializationUtils.clone(payload).getCandidate().getValue());
}

From source file:org.opendaylight.controller.md.sal.common.api.clustering.EntityTest.java

@Test
public void testSerialization() {
    Entity entity = new Entity(ENTITY_TYPE1, YANGID1);

    Entity clone = SerializationUtils.clone(entity);

    assertEquals("getType", entity.getType(), clone.getType());
    assertEquals("getId", entity.getId(), clone.getId());
}