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

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

Introduction

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

Prototype

public static Object clone(Serializable 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.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayloadTest.java

@Test
public void testSerialization() {
    ServerConfigurationPayload expected = new ServerConfigurationPayload(
            Arrays.asList(new ServerInfo("1", true), new ServerInfo("2", false)));
    ServerConfigurationPayload cloned = (ServerConfigurationPayload) SerializationUtils.clone(expected);

    assertEquals("getServerConfig", expected.getServerConfig(), cloned.getServerConfig());
    assertEquals("isMigrated", false, cloned.isMigrated());
}

From source file:org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntryTest.java

@Test
public void testSerialization() {
    SimpleReplicatedLogEntry expected = new SimpleReplicatedLogEntry(0, 1,
            new MockRaftActorContext.MockPayload("A"));
    SimpleReplicatedLogEntry cloned = (SimpleReplicatedLogEntry) SerializationUtils.clone(expected);

    assertEquals("getTerm", expected.getTerm(), cloned.getTerm());
    assertEquals("getIndex", expected.getIndex(), cloned.getIndex());
    assertEquals("getData", expected.getData(), cloned.getData());
}

From source file:org.opendaylight.controller.cluster.raft.persisted.SnapshotTest.java

private static void testSerialization(final byte[] state, final List<ReplicatedLogEntry> unapplied) {
    long lastIndex = 6;
    long lastTerm = 2;
    long lastAppliedIndex = 5;
    long lastAppliedTerm = 1;
    long electionTerm = 3;
    String electionVotedFor = "member-1";
    ServerConfigurationPayload serverConfig = new ServerConfigurationPayload(
            Arrays.asList(new ServerInfo("1", true), new ServerInfo("2", false)));

    Snapshot expected = Snapshot.create(ByteState.of(state), unapplied, lastIndex, lastTerm, lastAppliedIndex,
            lastAppliedTerm, electionTerm, electionVotedFor, serverConfig);
    Snapshot cloned = (Snapshot) SerializationUtils.clone(expected);

    assertEquals("lastIndex", expected.getLastIndex(), cloned.getLastIndex());
    assertEquals("lastTerm", expected.getLastTerm(), cloned.getLastTerm());
    assertEquals("lastAppliedIndex", expected.getLastAppliedIndex(), cloned.getLastAppliedIndex());
    assertEquals("lastAppliedTerm", expected.getLastAppliedTerm(), cloned.getLastAppliedTerm());
    assertEquals("unAppliedEntries", expected.getUnAppliedEntries(), cloned.getUnAppliedEntries());
    assertEquals("electionTerm", expected.getElectionTerm(), cloned.getElectionTerm());
    assertEquals("electionVotedFor", expected.getElectionVotedFor(), cloned.getElectionVotedFor());
    assertEquals("state", expected.getState(), cloned.getState());
    assertEquals("serverConfig", expected.getServerConfiguration().getServerConfig(),
            cloned.getServerConfiguration().getServerConfig());
}

From source file:org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTermTest.java

@Test
public void testSerialization() {
    UpdateElectionTerm expected = new UpdateElectionTerm(5, "leader");
    UpdateElectionTerm cloned = (UpdateElectionTerm) SerializationUtils.clone(expected);

    assertEquals("getCurrentTerm", expected.getCurrentTerm(), cloned.getCurrentTerm());
    assertEquals("getVotedFor", expected.getVotedFor(), cloned.getVotedFor());
    assertEquals("isMigrated", false, cloned.isMigrated());
}

From source file:org.opendaylight.controller.cluster.raft.ServerConfigurationPayloadTest.java

@Test
public void testSerialization() {
    ServerConfigurationPayload expected = new ServerConfigurationPayload(
            Arrays.asList(new ServerConfigurationPayload.ServerInfo("1", true),
                    new ServerConfigurationPayload.ServerInfo("2", false)));
    org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload cloned = (org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload) SerializationUtils
            .clone(expected);//from  w  ww.  j av a 2s .com

    assertEquals("getServerConfig",
            ImmutableSet.of(new org.opendaylight.controller.cluster.raft.persisted.ServerInfo("1", true),
                    new org.opendaylight.controller.cluster.raft.persisted.ServerInfo("2", false)),
            ImmutableSet.copyOf(cloned.getServerConfig()));
    assertEquals("isMigrated", true, cloned.isMigrated());
}

From source file:org.opendaylight.controller.remote.rpc.messages.ExecuteRpcTest.java

@Test
public void testSerialization() {
    ExecuteRpc expected = ExecuteRpc.from(AbstractRpcTest.TEST_RPC_ID,
            AbstractRpcTest.makeRPCInput("serialization-test"));

    ExecuteRpc actual = (ExecuteRpc) SerializationUtils.clone(expected);

    assertEquals("getRpc", expected.getRpc(), actual.getRpc());
    assertEquals("getInputNormalizedNode", expected.getInputNormalizedNode(), actual.getInputNormalizedNode());
}

From source file:org.opendaylight.controller.remote.rpc.messages.RpcResponseTest.java

@Test
public void testSerialization() {
    RpcResponse expected = new RpcResponse(AbstractRpcTest.makeRPCOutput("serialization-test"));

    RpcResponse actual = (RpcResponse) SerializationUtils.clone(expected);

    assertEquals("getResultNormalizedNode", expected.getResultNormalizedNode(),
            actual.getResultNormalizedNode());
}

From source file:org.openehr.adl.flattener.OntologyFlattener.java

@SuppressWarnings("unchecked")
private <T extends Serializable> T clone(T from) {
    return (T) SerializationUtils.clone(from);
}

From source file:org.openehr.adl.util.AdlUtils.java

/**
 * Creates a clone using java serialization
 *
 * @param from Object to be cloned/*from  w  ww .j  av  a  2s .c  o  m*/
 * @param <T>  type of the cloned object
 * @return Clone of the object
 */
@SuppressWarnings("unchecked")
public static <T extends Serializable> T makeClone(T from) {
    return (T) SerializationUtils.clone(from);
}

From source file:org.openlegacy.designtime.mains.DesignTimeExecuterImpl.java

@Override
public void generateScreenEntityResources(String entityName,
        GenerateScreenModelRequest generateScreenModelRequest) {

    File packageDir = new File(generateScreenModelRequest.getSourceDirectory(),
            generateScreenModelRequest.getPackageDirectory());
    File screenResourcesDir = new File(packageDir, entityName + "-resources");
    if (!screenResourcesDir.exists()) {
        screenResourcesDir.mkdir();/* w w w .j ava  2s .  c om*/
    }

    ApplicationContext projectApplicationContext = getOrCreateApplicationContext(
            generateScreenModelRequest.getProjectPath());

    TerminalSnapshotImageRenderer imageRenderer = projectApplicationContext
            .getBean(TerminalSnapshotImageRenderer.class);
    TerminalSnapshotTextRenderer textRenderer = projectApplicationContext
            .getBean(TerminalSnapshotTextRenderer.class);
    DefaultTerminalSnapshotXmlRenderer xmlRenderer = projectApplicationContext
            .getBean(DefaultTerminalSnapshotXmlRenderer.class);

    TerminalSnapshot snapshot = (TerminalSnapshot) SerializationUtils
            .clone(generateScreenModelRequest.getTerminalSnapshots()[0]);

    if (generateScreenModelRequest.isGenerateSnapshotText()) {
        // generate txt file with screen content
        generateResource(snapshot, entityName, screenResourcesDir, textRenderer, true);
    }
    if (generateScreenModelRequest.isGenerateSnapshotImage()) {
        // generate jpg file with screen image
        generateResource(snapshot, entityName, screenResourcesDir, imageRenderer, true);
    }

    if (generateScreenModelRequest.isGenerateSnapshotXml()) {
        // generate xml file with screen XML for testing purposes
        generateResource(snapshot, entityName, screenResourcesDir, xmlRenderer, true);
    }
}