All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cdc.applic.dictionaries.edit.sync.EnRepositorySync Maven / Gradle / Ivy

The newest version!
package cdc.applic.dictionaries.edit.sync;

import java.util.List;

import cdc.applic.dictionaries.edit.EnRepository;
import cdc.applic.dictionaries.edit.checks.EnRepositoryChecker;
import cdc.applic.dictionaries.impl.RepositoryImpl;
import cdc.issues.Issue;
import cdc.issues.io.SnapshotData;

/**
 * Class in charge of synchronizing a computation repository with an editable repository.
 * 

* The editable repository can be modified as necessary.
* The computed repository is updated and kept synchronized with the editable one. */ public final class EnRepositorySync { /** The editable repository. */ private final EnRepository enRepository = EnRepository.builder().build(); /** The editable repository checker. */ private final EnRepositoryChecker checker; /** serial number of the last update event of the editable repository. */ private long lastEventSerial = -1L; /** The computed repository. */ private RepositoryImpl repositoryImpl = null; // TODO map from id to issues // TODO maps to / from edition elements / computation elements private EnRepositorySync(Builder builder) { this.checker = new EnRepositoryChecker(builder.projectName, builder.snapshotName, enRepository); } /** * @return The edition repository, than can be modified as necessary. */ public EnRepository getEnRepository() { return enRepository; } /** * @return The computation repository, that should NOT directly be modified. */ public RepositoryImpl getRepository() { update(); return repositoryImpl; } /** * @return The snapshot data generated by checks. */ public SnapshotData getSnapshotData() { update(); return checker.getManager(); } /** * @return The collected issues related to the editable repository. */ public List getIssues() { return checker.getManager().getIssuesCollector().getIssues(); } /** * @return {@code true} if the computed repository needs to be updated. */ public boolean needsUpdate() { return enRepository.getEventSerial() != lastEventSerial; } /** * Check the edition repository and update the computation repository, if necessary. *

* Edition repository changes are tracked. */ public void update() { if (needsUpdate()) { // Currently, adopt a brute force approach for checks and update checker.getManager().getIssuesCollector().clear(); checker.check(); updateInt(); lastEventSerial = enRepository.getEventSerial(); } } private void updateInt() { repositoryImpl = new RepositoryImpl(); // TODO } public static Builder builder() { return new Builder(); } public static final class Builder { private String projectName = null; private String snapshotName = null; private Builder() { } public Builder projectName(String projectName) { this.projectName = projectName; return this; } public Builder snapshotName(String snapshotName) { this.snapshotName = snapshotName; return this; } public EnRepositorySync build() { return new EnRepositorySync(this); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy