本文整理匯總了Java中com.rits.cloning.Cloner類的典型用法代碼示例。如果您正苦於以下問題:Java Cloner類的具體用法?Java Cloner怎麽用?Java Cloner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Cloner類屬於com.rits.cloning包,在下文中一共展示了Cloner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import com.rits.cloning.Cloner; //導入依賴的package包/類
public void run() throws OutOfMemoryError {
int numberOfColumns = this.numberOfColumns;
DifferenceSets[] differenceSetsModulo = this.differenceSets.allModulo(this.numberOfColumns);
for (int rhsIndex = 0; rhsIndex < numberOfColumns; rhsIndex++) {
DifferenceSets orig = differenceSetsModulo[rhsIndex];
Cloner cloner = new Cloner();
DifferenceSets uncovered = cloner.deepClone(orig);
if (orig.isEmpty()) {
ColumnCollection lhs = new ColumnCollection(this.numberOfColumns);
for (Integer lhsIndex : lhs.setCopy(rhsIndex).complement().getSetBits()) {
this.minimalDependencies.addRHSColumn(lhs.setCopy(lhsIndex), rhsIndex);
}
}
else if (!orig.containsEmptySet()) {
PartialOrder currentOrder = new PartialOrder(orig);
Path path = new Path(numberOfColumns);
findCovers(rhsIndex, orig, uncovered, path, currentOrder);
}
}
}
示例2: createCloner
import com.rits.cloning.Cloner; //導入依賴的package包/類
private Cloner createCloner() {
Cloner cloner = new Cloner() {
@SuppressWarnings("unchecked")
@Override
protected <T> T cloneInternal(T o, Map<Object, Object> clones) throws IllegalAccessException {
if (isHibernateInitialized(o)) {
Object underlyingObject = unproxy(o);
return (T) super.cloneInternal(underlyingObject, clones);
} else {
// Proxy not initialized, we keep the ref.
return o;
}
}
};
cloner.registerImmutable(Date.class);
return cloner;
}
示例3: addGram
import com.rits.cloning.Cloner; //導入依賴的package包/類
/**
* Adds a Gram in the Gram Container, merging grams with the same
* identifier. If the gram is already present, the method updates it adding
* the new occurrence. Annotations of the new gram are <b>not</b> merged
* into the old gram. This is because it's good practice to annotate grams
* only when they've <b>all</b> been added into the blackboard.
*
* @param unit the concept unit where the gram appears
* @param newGram the gram to add
*/
public void addGram(DocumentComponent unit, Gram newGram) {
Map<String, Gram> grams = generalNGramsContainer.get(newGram.getType());
if (grams == null) {
grams = new HashMap<>();
}
Gram gram = grams.get(newGram.getIdentifier());
// Deep clone the object instead of referencing the found one.
// this way, we're free to modify it by adding annotations without
// modifying the old object.
if (gram == null) {
Gram cloned = (new Cloner()).deepClone(newGram);
grams.put(cloned.getIdentifier(), cloned);
gram = cloned;
} else {
// add the surface of the new gram
gram.addSurfaces(newGram.getSurfaces(), newGram.getTokenLists());
}
gram.addAppaerance(unit);
unit.addGram(gram);
generalNGramsContainer.put(newGram.getType(), grams);
}
示例4: EntityScheme
import com.rits.cloning.Cloner; //導入依賴的package包/類
private EntityScheme (Entity entity, Cloner cloner, CloningPolicy cloningPolicy) {
fillBag.clear();
entity.getComponents(fillBag);
components = new Array<>(fillBag.size());
for (Component component : fillBag) {
if (component == null) continue;
if (component.getClass().isAnnotationPresent(Transient.class)) continue;
if (cloningPolicy == CloningPolicy.SKIP_INVISIBLE && component instanceof Invisible) continue;
if (component instanceof VisUUID) schemeUUID = ((VisUUID) component).getUUID();
if (component instanceof UsesProtoComponent) {
components.add(((UsesProtoComponent) component).toProtoComponent());
} else {
components.add(component);
}
}
if (schemeUUID == null) throw new IllegalStateException("Missing VisUUID component in Entity");
if (cloner != null) {
components = cloner.deepClone(components);
}
}
示例5: newCloner
import com.rits.cloning.Cloner; //導入依賴的package包/類
public static Cloner newCloner() {
Cloner cloner = new Cloner();
//Implement custom cloning for INDArrays (default can have problems with off-heap and pointers)
//Sadly: the cloner library does NOT support interfaces here, hence we need to use the actual classes
//cloner.registerFastCloner(INDArray.class, new INDArrayFastCloner()); //Does not work due to interface
IFastCloner fc = new INDArrayFastCloner();
cloner.registerFastCloner(Nd4j.getBackend().getNDArrayClass(), fc);
cloner.registerFastCloner(Nd4j.getBackend().getComplexNDArrayClass(), fc);
//Same thing with DataBuffers: off heap -> cloner library chokes on them, but need to know the concrete
// buffer classes, not just the interface
IFastCloner fc2 = new DataBufferFastCloner();
DataBufferFactory d = Nd4j.getDataBufferFactory();
doReg(cloner, fc2, d.intBufferClass());
doReg(cloner, fc2, d.longBufferClass());
doReg(cloner, fc2, d.halfBufferClass());
doReg(cloner, fc2, d.floatBufferClass());
doReg(cloner, fc2, d.doubleBufferClass());
doReg(cloner, fc2, CompressedDataBuffer.class);
return cloner;
}
示例6: setUp
import com.rits.cloning.Cloner; //導入依賴的package包/類
@Before
public void setUp() {
goCache = new StubGoCache(new TestTransactionSynchronizationManager());
sqlMapClientTemplate = mock(SqlMapClientTemplate.class);
stageSqlMapDao = new StageSqlMapDao(mock(JobInstanceSqlMapDao.class), new Cache(true, false, false), mock(TransactionTemplate.class), mock(SqlMapClient.class), goCache,
mock(TransactionSynchronizationManager.class), mock(SystemEnvironment.class), null);
stageSqlMapDao.setSqlMapClientTemplate(sqlMapClientTemplate);
cloner = mock(Cloner.class);
ReflectionUtil.setField(stageSqlMapDao, "cloner", cloner);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return invocationOnMock.getArguments()[0];
}
}).when(cloner).deepClone(anyObject());
}
示例7: shouldGetEditablePartOfEnvironmentConfig
import com.rits.cloning.Cloner; //導入依賴的package包/類
@Test
public void shouldGetEditablePartOfEnvironmentConfig() throws Exception {
String uat = "uat";
BasicEnvironmentConfig local = new BasicEnvironmentConfig(new CaseInsensitiveString("uat"));
local.addEnvironmentVariable("user", "admin");
BasicEnvironmentConfig remote = new BasicEnvironmentConfig(new CaseInsensitiveString("uat"));
remote.addEnvironmentVariable("foo", "bar");
MergeEnvironmentConfig merged = new MergeEnvironmentConfig(local, remote);
EnvironmentsConfig environments = new EnvironmentsConfig();
environments.add(merged);
environmentConfigService.sync(environments);
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
BasicEnvironmentConfig env = (BasicEnvironmentConfig) environmentConfigService.named(uat).getLocal();
cruiseConfig.addEnvironment(env);
BasicEnvironmentConfig expectedToEdit = new Cloner().deepClone(env);
when(mockGoConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
assertThat(environmentConfigService.getEnvironmentForEdit(uat), is(expectedToEdit));
}
示例8: shouldReturnAllTheLocalEnvironments
import com.rits.cloning.Cloner; //導入依賴的package包/類
@Test
public void shouldReturnAllTheLocalEnvironments() throws Exception {
String uat = "uat";
BasicEnvironmentConfig local = new BasicEnvironmentConfig(new CaseInsensitiveString("uat"));
local.addEnvironmentVariable("user", "admin");
BasicEnvironmentConfig remote = new BasicEnvironmentConfig(new CaseInsensitiveString("uat"));
remote.addEnvironmentVariable("foo", "bar");
MergeEnvironmentConfig merged = new MergeEnvironmentConfig(local, remote);
EnvironmentsConfig environments = new EnvironmentsConfig();
environments.add(merged);
environmentConfigService.sync(environments);
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
BasicEnvironmentConfig env = (BasicEnvironmentConfig) environmentConfigService.named(uat).getLocal();
cruiseConfig.addEnvironment(env);
List<BasicEnvironmentConfig> expectedToEdit = Arrays.asList(new Cloner().deepClone(env));
when(mockGoConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
assertThat(environmentConfigService.getAllLocalEnvironments(), is(expectedToEdit));
}
示例9: update
import com.rits.cloning.Cloner; //導入依賴的package包/類
@Override
public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
if (newPart != null && fingerprint != null) {
cruiseConfig.getPartials().remove(findMatchingPartial(cruiseConfig, fingerprint));
cruiseConfig.getPartials().add(new Cloner().deepClone(newPart));
for (PartialConfig partial : cruiseConfig.getPartials()) {
for (EnvironmentConfig environmentConfig : partial.getEnvironments()) {
if (!cruiseConfig.getEnvironments().hasEnvironmentNamed(environmentConfig.name())) {
cruiseConfig.addEnvironment(new BasicEnvironmentConfig(environmentConfig.name()));
}
}
for (PipelineConfigs pipelineConfigs : partial.getGroups()) {
if (!cruiseConfig.getGroups().hasGroup(pipelineConfigs.getGroup())) {
cruiseConfig.getGroups().add(new BasicPipelineConfigs(pipelineConfigs.getGroup(), new Authorization()));
}
}
}
}
return cruiseConfig;
}
示例10: fullConfigSaveThread
import com.rits.cloning.Cloner; //導入依賴的package包/類
private Thread fullConfigSaveThread(final int counter) throws InterruptedException {
return createThread(new Runnable() {
@Override
public void run() {
try {
CruiseConfig cruiseConfig = cachedGoConfig.loadForEditing();
CruiseConfig cruiseConfig1 = new Cloner().deepClone(cruiseConfig);
cruiseConfig1.addEnvironment(UUID.randomUUID().toString());
goConfigDao.updateFullConfig(new FullConfigUpdateCommand(cruiseConfig1, cruiseConfig.getMd5()));
} catch (Exception e) {
e.printStackTrace();
}
}
}, "full-config-save-thread" + counter);
}
示例11: shouldReturnTheLatestConfigAsResultWhenThereIsAnMd5Conflict
import com.rits.cloning.Cloner; //導入依賴的package包/類
@Test
public void shouldReturnTheLatestConfigAsResultWhenThereIsAnMd5Conflict() {
configHelper.addPipeline("pipeline", "stage");
String md5 = goConfigService.getConfigForEditing().getMd5();
goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("secondStage"), md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("thirdStage"), md5, Username.ANONYMOUS, result);
assertFailedResult(result, "Save failed. Configuration file has been modified by someone else.");
CruiseConfig expectedConfig = goConfigService.getConfigForEditing();
CruiseConfig modifiedConfig = new Cloner().deepClone(expectedConfig);
ReflectionUtil.setField(modifiedConfig, "md5", expectedConfig.getMd5());
PipelineConfig expected = modifiedConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline"));
expected.addStageWithoutValidityAssertion(StageConfigMother.custom("thirdStage", "job"));
PipelineConfig actual = (PipelineConfig) response.getNode();
assertThat(response.configAfterUpdate(), is(expectedConfig));
assertThat(response.getCruiseConfig(), is(modifiedConfig));
assertThat(actual, is(expected));
assertFailedResult(result, "Save failed. Configuration file has been modified by someone else.");
}
示例12: shouldCancelBuildsForDeletedStagesWhenPipelineConfigChanges
import com.rits.cloning.Cloner; //導入依賴的package包/類
@Test
public void shouldCancelBuildsForDeletedStagesWhenPipelineConfigChanges() throws Exception {
buildAssignmentService.initialize();
fixture.createPipelineWithFirstStageScheduled();
buildAssignmentService.onTimer();
PipelineConfig pipelineConfig = new Cloner().deepClone(configHelper.getCachedGoConfig().currentConfig().getPipelineConfigByName(new CaseInsensitiveString(fixture.pipelineName)));
String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig);
String md5 = CachedDigestUtils.md5Hex(xml);
StageConfig devStage = pipelineConfig.findBy(new CaseInsensitiveString(fixture.devStage));
pipelineConfig.remove(devStage);
pipelineConfigService.updatePipelineConfig(loserUser, pipelineConfig, md5, new HttpLocalizedOperationResult());
Pipeline pipeline = pipelineDao.mostRecentPipeline(fixture.pipelineName);
JobInstance job = pipeline.getFirstStage().getJobInstances().first();
assertThat(job.getState(), is(JobState.Completed));
assertThat(job.getResult(), is(JobResult.Cancelled));
}
示例13: shouldCancelBuildsForDeletedJobsWhenPipelineConfigChanges
import com.rits.cloning.Cloner; //導入依賴的package包/類
@Test
public void shouldCancelBuildsForDeletedJobsWhenPipelineConfigChanges() throws Exception {
buildAssignmentService.initialize();
fixture = new PipelineWithTwoStages(materialRepository, transactionTemplate, temporaryFolder).usingTwoJobs();
fixture.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp();
fixture.createPipelineWithFirstStageScheduled();
buildAssignmentService.onTimer();
PipelineConfig pipelineConfig = new Cloner().deepClone(configHelper.getCachedGoConfig().currentConfig().getPipelineConfigByName(new CaseInsensitiveString(fixture.pipelineName)));
String xml = new MagicalGoConfigXmlWriter(configCache, registry).toXmlPartial(pipelineConfig);
String md5 = CachedDigestUtils.md5Hex(xml);
StageConfig devStage = pipelineConfig.findBy(new CaseInsensitiveString(fixture.devStage));
devStage.getJobs().remove(devStage.jobConfigByConfigName(new CaseInsensitiveString(fixture.JOB_FOR_DEV_STAGE)));
pipelineConfigService.updatePipelineConfig(loserUser, pipelineConfig, md5, new HttpLocalizedOperationResult());
Pipeline pipeline = pipelineDao.mostRecentPipeline(fixture.pipelineName);
JobInstance deletedJob = pipeline.getFirstStage().getJobInstances().getByName(fixture.JOB_FOR_DEV_STAGE);
assertThat(deletedJob.getState(), is(JobState.Completed));
assertThat(deletedJob.getResult(), is(JobResult.Cancelled));
JobInstance retainedJob = pipeline.getFirstStage().getJobInstances().getByName(fixture.DEV_STAGE_SECOND_JOB);
assertThat(retainedJob.getState(), is(JobState.Scheduled));
assertThat(retainedJob.getResult(), is(JobResult.Unknown));
}
示例14: shouldErrorOutOnUpdateConfigWithValidPartials_WithMainConfigBreakingPartials
import com.rits.cloning.Cloner; //導入依賴的package包/類
@Test
public void shouldErrorOutOnUpdateConfigWithValidPartials_WithMainConfigBreakingPartials() throws GitAPIException, IOException {
setupExternalConfigRepoWithDependencyMaterialOnPipelineInMainXml("upstream", "downstream");
String gitShaBeforeSave = configRepository.getCurrentRevCommit().getName();
CruiseConfig originalConfig = cachedGoConfig.loadForEditing();
CruiseConfig editedConfig = new Cloner().deepClone(originalConfig);
editedConfig.getGroups().remove(editedConfig.findGroup("default"));
try {
cachedGoConfig.writeFullConfigWithLock(new FullConfigUpdateCommand(editedConfig, goConfigService.configFileMd5()));
fail("Expected the test to fail");
} catch (Exception e) {
String gitShaAfterSave = configRepository.getCurrentRevCommit().getName();
String configXmlFromConfigFolder = FileUtils.readFileToString(new File(goConfigDao.fileLocation()), UTF_8);
assertThat(cachedGoConfig.loadForEditing(), is(originalConfig));
assertEquals(gitShaBeforeSave, gitShaAfterSave);
assertThat(cachedGoConfig.loadForEditing().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
assertThat(cachedGoConfig.currentConfig().getMd5(), is(configRepository.getCurrentRevision().getMd5()));
assertThat(configXmlFromConfigFolder, is(configRepository.getCurrentRevision().getContent()));
RepoConfigOrigin origin = (RepoConfigOrigin) cachedGoPartials.lastValidPartials().get(0).getOrigin();
assertThat(origin.getRevision(), is("r1"));
}
}
示例15: shouldHandlePipelinesWithTemplates
import com.rits.cloning.Cloner; //導入依賴的package包/類
@Test
public void shouldHandlePipelinesWithTemplates() {
CruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
cruiseConfig.getTemplates().add(
new PipelineTemplateConfig(new CaseInsensitiveString("template-1"), new StageConfig(new CaseInsensitiveString("invalid stage name"), new JobConfigs(new JobConfig("job-1"))
)));
PipelineConfig pipelineWithTemplate = new PipelineConfig(new CaseInsensitiveString("pipeline-with-template"), MaterialConfigsMother.defaultMaterialConfigs());
pipelineWithTemplate.setTemplateName(new CaseInsensitiveString("template-1"));
cruiseConfig.getGroups().get(0).add(pipelineWithTemplate);
CruiseConfig rawCruiseConfig = new Cloner().deepClone(cruiseConfig);
MagicalGoConfigXmlLoader.validate(cruiseConfig);
cruiseConfig.copyErrorsTo(rawCruiseConfig);
assertThat(rawCruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template")).errors().isEmpty(), is(true));
assertThat(cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template")).getStage(new CaseInsensitiveString("invalid stage name")).errors().isEmpty(), is(false));
assertThat(rawCruiseConfig.getTemplateByName(new CaseInsensitiveString("template-1")).errors().isEmpty(), is(true));
}