Version Contorl Javacaup
جمعه, ۱۶ آبان ۱۳۹۹، ۰۱:۲۲ ق.ظ
package ir.javacup.vc; import java.util.*; import java.util.Map.Entry; public class VersionControl { private final Project project; private List <Project> history=new ArrayList<Project>(); public VersionControl(Project project) { this.project = project; } public Project takeSnapshot() { Project photo=new Project(project.getName(),project.getVersion()); for(Entry<String, StringBuilder> e:project.getSourceCodes().entrySet()) { photo.getSourceCodes().put(e.getKey(), new StringBuilder(e.getValue())); } history.add(photo); return photo; } public void goBack() { if(history.isEmpty()==false) { Project hey=history.get(history.size()-1); project.getSourceCodes().clear(); for(Entry<String, StringBuilder> e:hey.getSourceCodes().entrySet()) { project.getSourceCodes().put(e.getKey(), new StringBuilder(e.getValue())); } project.setName(hey.getName()); project.setVersion(hey.getVersion()); history.remove(history.size()-1); } } }
Project rms = new Project("Report Management System", 1); rms.getSourceCodes().put("A", new StringBuilder("public class Aaaaaaaa")); rms.getSourceCodes().put("B", new StringBuilder("public class B")); rms.getSourceCodes().put("C", new StringBuilder("finecccccc")); VersionControl git = new VersionControl(rms); Project snapshot = git.takeSnapshot(); rms.setName("RMS"); rms.setVersion(2); rms.getSourceCodes().get("A").append(" bbbb"); git.goBack(); private Map<String,StringBuilder> sourceCodes; sourceCodes = new HashMap<>();
۹۹/۰۸/۱۶