Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to apply diffs #213

Open
Kira-Cesonia opened this issue Jun 26, 2020 · 0 comments
Open

How to apply diffs #213

Kira-Cesonia opened this issue Jun 26, 2020 · 0 comments

Comments

@Kira-Cesonia
Copy link

Kira-Cesonia commented Jun 26, 2020

My use case is that I want to store diffs and the original object in a database, and then at a later date restore different versions of the object using the diffs.

For that, I am looking for a functionality that lets me apply the diffs to the base object, like this:

	@Test
	void applyDiffDeltaShouldCorrectlyApplyDeltaToCity() {
		GameCharacter sylvia = GameCharacters.sylvia();
		GameCharacter sylviaEdited = GameCharacters.sylviaEdited();
		
		DiffNode characterDelta
			= objectDiffer.compare(sylvia, sylviaEdited);
		GameCharacter sylviaWithAppliedDelta
			= DeltaApplier.applyDelta(sylvia, characterDelta);
		
		assertEquals(sylviaEdited.getName(), sylviaWithAppliedDelta.getName());
	}

	public static <T> T applyDelta(T baseObject, DiffNode diff) {
		//This won't work, but it would be cool if it did:
		T updatedObject = baseObject + diff;
		return updatedObject ;
	}

This feels like something that java-object-diff should be able to do. However, all the examples in the documentation appear to require both the start and the end version of a document, in addition to the diffs.

So, how can I make this work? How can I create the end document just from the start document and one (or more) diffs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant