// Path: src/main/java/uk/ac/ic/wlgitbridge/data/filestore/RawFile.java
// public abstract class RawFile {
// 
//     public abstract String getPath();
// 
//     public abstract byte[] getContents();
// 
//     public abstract long size();
// 
//     public final void writeToDisk(File directory) throws IOException {
//         File file = new File(directory, getPath());
//         file.getParentFile().mkdirs();
//         file.createNewFile();
//         OutputStream out = new FileOutputStream(file);
//         out.write(getContents());
//         out.close();
//         Log.info("Wrote file: {}", file.getAbsolutePath());
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (!(obj instanceof RawFile)) {
//             return false;
//         }
//         RawFile that = (RawFile) obj;
//         return getPath().equals(that.getPath())
//                 && Arrays.equals(getContents(), that.getContents());
//     }
// 
// }


import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory;
import uk.ac.ic.wlgitbridge.util.Util;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
package uk.ac.ic.wlgitbridge.data;



/**
 * Created by Winston on 16/11/14.
 */
public class CandidateSnapshot implements AutoCloseable {

    private final String projectName;
    private final int currentVersion;
    private final List<ServletFile> files;
    private final List<String> deleted;
    private File attsDirectory;

    public CandidateSnapshot(
            String projectName,
            int currentVersion,
            RawDirectory directoryContents,
            RawDirectory oldDirectoryContents
    ) {
        this.projectName = projectName;
        this.currentVersion = currentVersion;
        files = diff(directoryContents, oldDirectoryContents);
        deleted = deleted(directoryContents, oldDirectoryContents);
    }

    private List<ServletFile> diff(
            RawDirectory directoryContents,
            RawDirectory oldDirectoryContents
    ) {
        List<ServletFile> files = new LinkedList<ServletFile>();
// Path: src/main/java/uk/ac/ic/wlgitbridge/data/filestore/RawFile.java
// public abstract class RawFile {
// 
//     public abstract String getPath();
// 
//     public abstract byte[] getContents();
// 
//     public abstract long size();
// 
//     public final void writeToDisk(File directory) throws IOException {
//         File file = new File(directory, getPath());
//         file.getParentFile().mkdirs();
//         file.createNewFile();
//         OutputStream out = new FileOutputStream(file);
//         out.write(getContents());
//         out.close();
//         Log.info("Wrote file: {}", file.getAbsolutePath());
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (!(obj instanceof RawFile)) {
//             return false;
//         }
//         RawFile that = (RawFile) obj;
//         return getPath().equals(that.getPath())
//                 && Arrays.equals(getContents(), that.getContents());
//     }
// 
// }


// Path: src/main/java/uk/ac/ic/wlgitbridge/data/CandidateSnapshot.java
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
import uk.ac.ic.wlgitbridge.data.filestore.RawDirectory;
import uk.ac.ic.wlgitbridge.util.Util;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

package uk.ac.ic.wlgitbridge.data;



/**
 * Created by Winston on 16/11/14.
 */
public class CandidateSnapshot implements AutoCloseable {

    private final String projectName;
    private final int currentVersion;
    private final List<ServletFile> files;
    private final List<String> deleted;
    private File attsDirectory;

    public CandidateSnapshot(
            String projectName,
            int currentVersion,
            RawDirectory directoryContents,
            RawDirectory oldDirectoryContents
    ) {
        this.projectName = projectName;
        this.currentVersion = currentVersion;
        files = diff(directoryContents, oldDirectoryContents);
        deleted = deleted(directoryContents, oldDirectoryContents);
    }

    private List<ServletFile> diff(
            RawDirectory directoryContents,
            RawDirectory oldDirectoryContents
    ) {
        List<ServletFile> files = new LinkedList<ServletFile>();
        Map<String, RawFile> fileTable = directoryContents.getFileTable();