io.activej.ot.repository.OTRepository Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of activej-ot Show documentation
Show all versions of activej-ot Show documentation
Implementation of operational transformation technology. Allows building collaborative software systems.
/*
* Copyright (C) 2020 ActiveJ LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.activej.ot.repository;
import io.activej.async.function.AsyncSupplier;
import io.activej.ot.OTCommit;
import io.activej.ot.OTCommitFactory;
import io.activej.promise.Promise;
import io.activej.promise.Promises;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.stream.IntStream;
import static java.util.Collections.singleton;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.*;
public interface OTRepository extends OTCommitFactory {
Promise push(Collection> commits);
default Promise push(OTCommit commit) {
return push(singletonList(commit));
}
Promise updateHeads(Set newHeads, Set excludedHeads);
default Promise pushAndUpdateHead(OTCommit commit) {
return push(commit)
.then(() -> updateHeads(singleton(commit.getId()), commit.getParentIds()));
}
default Promise pushAndUpdateHeads(Collection> commits) {
Set parents = commits.stream()
.flatMap(commit -> commit.getParentIds().stream())
.collect(toSet());
Set heads = commits.stream()
.map(OTCommit::getId)
.filter(commit -> !parents.contains(commit)).collect(toSet());
return push(commits)
.then(() -> updateHeads(heads, parents));
}
default @NotNull Promise getLevel(@NotNull K commitId) {
return loadCommit(commitId)
.map(OTCommit::getLevel);
}
default @NotNull Promise
© 2015 - 2024 Weber Informatics LLC | Privacy Policy