package gitlet; import java.io.File; import java.io.Serializable; import java.util.LinkedHashMap; import java.util.LinkedHashSet; /** This class keeps track of the staging in * Gitlet. Two main features it tracks are what * needs to be added and removed in the next commit. * @author Ethan Ikegami */ public class Staging implements Serializable { /** Initializes an instance given a Staging FILE. If the * parameter is null or the FILE does not exist, initializes new * Hashes, else gets Hashes from the given FILE. */ public Staging(File file) { if (file == null || !file.exists()) { _currentStage = new LinkedHashMap<>(); _removalStage = new LinkedHashSet<>(); } else { Staging stage = Utils.readObject(file, Staging.class); _currentStage = stage.getCurrentStage(); _removalStage = stage.getRemovalStage(); } } /** Adds CONTENT to the stage. */ public void add(Blob content) { _currentStage.put(content.getFileName(), Utils.serialize(content)); } /** Removes FILENAME from the stage. */ public void removeFrom(String fileName) { _currentStage.remove(fileName); } /** Adds FILENAME to the removal stage. */ public void addRemove(String fileName) { _removalStage.add(fileName); } /** Removes FILENAME from the removal stage. */ public void removeFromRemoval(String fileName) { _removalStage.remove(fileName); } /** Returns the current Add stage. */ public LinkedHashMap<String, byte[]> getCurrentStage() { return _currentStage; } /** Returns the current Remove stage. */ public LinkedHashSet<String> getRemovalStage() { return _removalStage; } /** The Add stage. */ private LinkedHashMap<String, byte[]> _currentStage; /** The Remove stage. */ private LinkedHashSet<String> _removalStage; }