List of usage examples for org.apache.commons.lang3 SerializationUtils clone
public static <T extends Serializable> T clone(final T 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:com.link_intersystems.lang.reflect.SerializableConstructorTest.java
@Test public void noSuchMethodOnSerialization() throws Throwable { Constructor<ConstructorSerializationTestClass> constructor = ConstructorSerializationTestClass.class .getDeclaredConstructor(String.class); final SerializableConstructor serializableConstructor = new NoSuchMethodSerializableConstructor( constructor);// w w w . j a va 2s . c o m Assertion.assertCause(NoSuchMethodException.class, new Callable<Object>() { public Object call() throws Exception { return SerializationUtils.clone(serializableConstructor); } }); }
From source file:com.link_intersystems.lang.reflect.Package2Test.java
@Test public void serializable() { Package2 package2 = Package2.get(Package2Test.class.getPackage()); Package2 clone = (Package2) SerializationUtils.clone(package2); assertEquals(package2, clone); }
From source file:de.upb.timok.run.DataGenerator.java
private void run() throws IOException, InterruptedException { // parse timed sequences final List<TimedSequence> trainingTimedSequences = TimedSequence.parseTimedSequences(dataString, true, false);// ww w . j a v a 2 s . c om final TauPTA pta = new TauPTA(trainingTimedSequences); @SuppressWarnings("unused") final TimedSequence s1 = pta.sampleSequence(); @SuppressWarnings("unused") final TimedSequence s2 = pta.sampleSequence(); // logger.info("{}", s1); // logger.info("{}", s2); // pta.toGraphvizFile(Paths.get("pta.gv"), false); // IoUtils.xmlSerialize(pta, Paths.get("pta.xml")); // logger.info("{}", pta.getStates(0)); // logger.info("{}", pta.getStates(1)); // logger.info("{}", pta.getStates(2)); // logger.info("{}", pta.getStates(3)); // logger.info("{}", pta.getStates(4)); final TauPTA anomaly1 = SerializationUtils.clone(pta); anomaly1.setAnomalyType(AnomalyInsertionType.TYPE_ONE); for (int i = 0; i < 1000; i++) { anomaly1.sampleSequence(); } final TauPTA anomaly2 = SerializationUtils.clone(pta); anomaly2.setAnomalyType(AnomalyInsertionType.TYPE_TWO); final TauPTA anomaly3 = SerializationUtils.clone(pta); anomaly3.setAnomalyType(AnomalyInsertionType.TYPE_THREE); final TauPTA anomaly4 = SerializationUtils.clone(pta); anomaly4.setAnomalyType(AnomalyInsertionType.TYPE_FOUR); // TODO for smac change the input format s.t. it contains unlabeled train and labeled test set // also create type 5: sequence stops // insert final state probabilities in states that do not have final state probabilities }
From source file:eu.stratosphere.api.common.operators.util.UserCodeObjectWrapper.java
@SuppressWarnings("unchecked") @Override// www .j av a2 s . c o m public T getUserCodeObject() { // return a clone because some code retrieves this and runs configure() on it before // the job is actually run. This way we can always hand out a pristine copy. Serializable ser = (Serializable) userCodeObject; T cloned = (T) SerializationUtils.clone(ser); return cloned; }
From source file:com.swiftwayz.service.driver.DriverServiceIntTest.java
@Test public void should_update_driver() { long id = 1L; Driver savedDriver = driverService.findOne(id); String oldFirstName = savedDriver.getFirstName(); Driver driver = SerializationUtils.clone(savedDriver); String driverName = "DriverName"; driver.setFirstName(driverName);//from ww w .j av a 2 s.com Driver updateDriver = driverService.updateDriver(driver); assertThat(updateDriver).isNotNull(); assertThat(updateDriver.getFirstName()).isNotEqualTo(oldFirstName); assertThat(updateDriver.getFirstName()).isEqualTo(driverName); }
From source file:com.music.scheduled.PieceDigestSendingJob.java
@Scheduled(cron = "0 0 9 ? * 1,4") @Transactional(readOnly = true)/* www .jav a 2 s . c o m*/ public void sendPieceDigestEmails() { logger.info("Sending email digests started"); DateTime now = new DateTime(); DateTime minusTwoDays = now.minusDays(2); List<Piece> pieces = pieceDao.getPiecesInRange(minusTwoDays, now); Collections.shuffle(pieces); final List<Piece> includedPieces = new ArrayList<>(pieces.subList(0, Math.min(pieces.size(), 3))); if (includedPieces.isEmpty()) { return; } // for now - using the same data for all users. TODO send personalized selection final EmailDetails baseDetails = new EmailDetails(); baseDetails.setMessageTemplate("digest.vm"); baseDetails.setSubject("Computoser-generated tracks digest for you"); Map<String, Object> model = Maps.newHashMap(); baseDetails.setMessageTemplateModel(model); baseDetails.setFrom(from); baseDetails.setHtml(true); userDao.performBatched(User.class, 100, new PageableOperation<User>() { @Override public void execute() { for (User user : getData()) { if (user.isReceiveDailyDigest() && StringUtils.isNotBlank(user.getEmail())) { EmailDetails email = SerializationUtils.clone(baseDetails); email.setTo(user.getEmail()); email.setCurrentUser(user); String hmac = SecurityUtils.hmac(user.getEmail(), hmacKey); email.getMessageTemplateModel().put("pieces", includedPieces); email.getMessageTemplateModel().put("hmac", hmac); // needed due to SES restrictions try { Thread.sleep(500); } catch (InterruptedException e) { throw new IllegalStateException(e); } emailService.send(email); } } } }); }
From source file:com.twosigma.beaker.chart.Graphics.java
@Override public Object clone() throws CloneNotSupportedException { return SerializationUtils.clone(this); }
From source file:com.mirth.connect.connectors.file.FileReceiver.java
@Override public void onDeploy() throws ConnectorTaskException { this.connectorProperties = (FileReceiverProperties) SerializationUtils.clone(getConnectorProperties()); if (connectorProperties.isBinary() && isProcessBatch()) { throw new ConnectorTaskException("Batch processing is not supported for binary data."); }// w w w. ja v a 2 s.c o m this.charsetEncoding = CharsetUtils.getEncoding(connectorProperties.getCharsetEncoding(), System.getProperty("ca.uhn.hl7v2.llp.charset")); // Load the default configuration String configurationClass = configurationController.getProperty(connectorProperties.getProtocol(), "fileConfigurationClass"); try { configuration = (FileConfiguration) Class.forName(configurationClass).newInstance(); } catch (Exception e) { logger.trace("could not find custom configuration class, using default"); configuration = new DefaultFileConfiguration(); } try { configuration.configureConnectorDeploy(this, connectorProperties); } catch (Exception e) { throw new ConnectorTaskException(e); } this.moveToDirectory = connectorProperties.getMoveToDirectory(); this.moveToFileName = connectorProperties.getMoveToFileName(); this.errorMoveToDirectory = connectorProperties.getErrorMoveToDirectory(); this.errorMoveToFileName = connectorProperties.getErrorMoveToFileName(); fileSizeMinimum = NumberUtils.toLong(connectorProperties.getFileSizeMinimum(), 0); fileSizeMaximum = NumberUtils.toLong(connectorProperties.getFileSizeMaximum(), 0); eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getSourceName(), ConnectionStatusEventType.IDLE)); }
From source file:it.uniroma2.sag.kelp.data.representation.tree.TreeRepresentation.java
@Override public TreeRepresentation clone() { return SerializationUtils.clone(this); }
From source file:com.openthinks.webscheduler.model.task.ITaskRef.java
public default Object clone() { return SerializationUtils.clone(this); }