Scientific article describing the data structure: Link
Example usage
packageorg.treedoc;
importorg.junit.jupiter.api.Test;
importjava.util.List;
importstaticorg.assertj.core.api.Assertions.assertThat;
publicclassIntegrationTest {
privatestaticfinalStringUSER_1 = "user1";
privatestaticfinalStringUSER_2 = "user2";
privatestaticfinalStringUSER_3 = "user3";
privatefinalTreeDOC<Character, String> treeDOC = TreeDOC.create();
@Testvoidtest() {
// Document is initially emptyexpectContent(List.of());
// User 1 inserted first charactervaraPath = treeDOC.insertBetween(null, null, 'A', USER_1);
expectContent(List.of('A'));
// User 2 inserted second character before AvarbPath = treeDOC.insertBetween(null, aPath, 'B', USER_2);
expectContent(List.of('B', 'A'));
// Users 1 and 3 concurrently inserted characters between B and AvarcPath = treeDOC.insertBetween(bPath, aPath, 'C', USER_3);
vardPath = treeDOC.insertBetween(bPath, aPath, 'D', USER_1);
expectContent(List.of('B', 'D', 'C', 'A'));
// Users 1 and 3 concurrently inserted character between D and C, operations was executed in different ordervarePath = treeDOC.insertBetween(dPath, cPath, 'E', USER_1);
varfPath = treeDOC.insertBetween(dPath, cPath, 'F', USER_3);
// Since disambiguator of User 1 is lower than disambiguator of User 2 character E is inserted before FexpectContent(List.of('B', 'D', 'E', 'F', 'C', 'A'));
// User 2 deletes character F while User 3 inserts new character between F and CtreeDOC.delete(fPath);
vargPath = treeDOC.insertBetween(fPath, cPath, 'G', USER_2);
expectContent(List.of('B', 'D', 'E', 'G', 'C', 'A'));
}
privatevoidexpectContent(List<Character> expectedContent) {
assertThat(treeDOC.getAtoms()).isEqualTo(expectedContent);
}
}