Java Code Examples for com.rits.cloning.Cloner#deepClone()

The following examples show how to use com.rits.cloning.Cloner#deepClone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastFDs.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
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 (int 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);
		}
	}
}
 
Example 2
Source File: Maps.java    From Java-Coding-Problems with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <K, V> HashMap<K, V> deepCopy(Map<K, V> map) {

    if (map == null) {
        return (HashMap) Collections.emptyMap();
    }

    Cloner cloner = new Cloner();
    HashMap<K, V> copy = (HashMap<K, V>) cloner.deepClone(map);

    return copy;
}
 
Example 3
Source File: Tane.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private CollectionSet<ColumnCollection> generateNextLevel(CollectionSet<ColumnCollection> currentLevel) {
	CollectionSet<ColumnCollection> nextLevel = new CollectionSet<>();
	
	Cloner cloner = new Cloner();
	AprioriGeneration<ColumnCollection> prefixBlockGenerator = new AprioriGeneration<>(cloner.deepClone(currentLevel));
	for (CollectionSet<ColumnCollection> k : prefixBlockGenerator.prefixBlocks()) {
		for (ColumnCollection y : k) {
			for (ColumnCollection z : k.tailSet(y)) {
				ColumnCollection x = y.orCopy(z);
				boolean xInNextLevel = true;
				for (int a : x.getSetBits()) {
					x.clear(a);
					if (!currentLevel.contains(x)) {
						xInNextLevel = false;
						break;
					}
					x.set(a);
				}
				if (xInNextLevel) {
					nextLevel.add(x);
					strippedPartitions.put(x, strippedProduct(strippedPartitions.get(y), strippedPartitions.get(z)));
				}
			}
		}
	}

	return nextLevel;
}
 
Example 4
Source File: BasicCruiseConfig.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Override
public CruiseConfig cloneForValidation() {
    Cloner cloner = new Cloner();
    BasicCruiseConfig configForValidation = cloner.deepClone(BasicCruiseConfig.this);
    // This needs to be done clear the cached fields else the cloned object will all get them.
    configForValidation.resetAllPipelineConfigsCache();
    return configForValidation;
}
 
Example 5
Source File: MergeCruiseConfigTest.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCollectPipelineNameConflictErrorsInTheChildren_InMergedConfig_WhenCloned() {
    //we need this case because cloning has proven to be problematic with complex object graph in merged config
    BasicCruiseConfig mainCruiseConfig = GoConfigMother.configWithPipelines("pipeline-1");
    PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipeline-1", "g2");
    partialConfig.setOrigin(new RepoConfigOrigin());
    CruiseConfig config = new BasicCruiseConfig(mainCruiseConfig, partialConfig);
    Cloner CLONER = new Cloner();
    CruiseConfig cloned = CLONER.deepClone(config);

    List<ConfigErrors> allErrors = cloned.validateAfterPreprocess();
    assertThat(allErrors.size(), is(2));
    assertThat(allErrors.get(0).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]"));
    assertThat(allErrors.get(1).on("name"), is("You have defined multiple pipelines named 'pipeline-1'. Pipeline names must be unique. Source(s): [http://some.git at 1234fed, cruise-config.xml]"));
}
 
Example 6
Source File: Reminders.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onItemDismiss(int position) {
    // snooze + save in undo + save details for pushbuttons
    final Reminder remind = reminders.get(position);
    final Cloner cloner = new Cloner();
    //cloner.setDumpClonedClasses(true);
    //cloner.dontClone(
    //       android.graphics.DashPathEffect.class);
    last_undo = cloner.deepClone(remind);
    if (SimpleItemTouchHelperCallback.last_swipe_direction == ItemTouchHelper.LEFT) {

        // swipe left
        snoozeReminder(remind, remind.last_snoozed_for > 0 ? remind.last_snoozed_for : default_snooze);

        last_swiped = remind;
        last_undo_pos = position;
        reminders.remove(position);
        notifyItemRemoved(position);
        cancelAlert();
        showSnoozeFloater();
    } else {
        // swipe right

        if (remind.repeating || !remind.isDue()) {
            remind.schedule_next();
            setFloaterText(remind.getTitle() + " " + xdrip.getAppContext().getString(R.string.next_in) + " " + JoH.niceTimeTill(remind.next_due));
        } else if (!remind.repeating) {
            setFloaterText(remind.getTitle() + " " + xdrip.getAppContext().getString(R.string.completed));
            remind.enabled = false;
            remind.save();
        }

        last_swiped = remind;
        last_undo_pos = position;
        reminders.remove(position);
        notifyItemRemoved(position);
        cancelAlert();
        showSnoozeFloater();
    }
    JoH.runOnUiThreadDelayed(new Runnable() {
        @Override
        public void run() {
            reinject(remind);
        }
    }, 500);
}
 
Example 7
Source File: Reminders.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onItemDismiss(int position) {
    // snooze + save in undo + save details for pushbuttons
    final Reminder remind = reminders.get(position);
    final Cloner cloner = new Cloner();
    //cloner.setDumpClonedClasses(true);
    //cloner.dontClone(
    //       android.graphics.DashPathEffect.class);
    last_undo = cloner.deepClone(remind);
    if (SimpleItemTouchHelperCallback.last_swipe_direction == ItemTouchHelper.LEFT) {

        // swipe left
        snoozeReminder(remind, remind.last_snoozed_for > 0 ? remind.last_snoozed_for : default_snooze);

        last_swiped = remind;
        last_undo_pos = position;
        reminders.remove(position);
        notifyItemRemoved(position);
        cancelAlert();
        showSnoozeFloater();
    } else {
        // swipe right

        if (remind.repeating || !remind.isDue()) {
            remind.schedule_next();
            setFloaterText(remind.getTitle() + " " + xdrip.getAppContext().getString(R.string.next_in) + " " + JoH.niceTimeTill(remind.next_due));
        } else if (!remind.repeating) {
            setFloaterText(remind.getTitle() + " " + xdrip.getAppContext().getString(R.string.completed));
            remind.enabled = false;
            remind.save();
        }

        last_swiped = remind;
        last_undo_pos = position;
        reminders.remove(position);
        notifyItemRemoved(position);
        cancelAlert();
        showSnoozeFloater();
    }
    JoH.runOnUiThreadDelayed(new Runnable() {
        @Override
        public void run() {
            reinject(remind);
        }
    }, 500);
}
 
Example 8
Source File: DifferentialFunction.java    From nd4j with Apache License 2.0 4 votes vote down vote up
/**
 * Duplicate this function
 * @return
 */
public  DifferentialFunction dup() {
    Cloner cloner = SameDiff.newCloner();
    return cloner.deepClone(this);
}
 
Example 9
Source File: ApplicationSettings.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
@Override
public ApplicationSettings clone() {
	Cloner cloner = new Cloner();
	cloner.nullInsteadOfClone();
	return cloner.deepClone(this);
}
 
Example 10
Source File: MyLangUtils.java    From spring-boot with Apache License 2.0 2 votes vote down vote up
/**
 * clone : 内存中完全独立的一个对象,和被 clone 对象相同,操作其中一个,对另外一个无影响
 * -
 * 被 clone 对象不需要实现 Cloneable 接口,可以任意克隆对象。
 * -
 * 利用 https://code.google.com/p/cloning/ 插件
 * This method makes a "deep clone" of any object it is given.
 *
 * @param object 被克隆对象
 * @return 完全独立的被克隆对象
 */
//org.apache.commons.lang3.SerializationUtils.clone() 只能深度克隆继承了 Serializable 接口的对象
public static <T> T deepClone(T object) {
    Cloner cloner = new Cloner();
    return cloner.deepClone(object);
}