001/*
002 * Syncany, www.syncany.org
003 * Copyright (C) 2011-2016 Philipp C. Heckel <philipp.heckel@gmail.com> 
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package org.syncany.operations;
019
020import java.util.TreeSet;
021
022import org.simpleframework.xml.ElementList;
023
024/**
025 * A change set represents the result of a comparison of two file trees, either 
026 * by comparing a local file tree with the local database, or by comparing the remote
027 * database with the local database.
028 * 
029 * <p>It contains several lists, indicating new, changed, deleted and unchanged files.
030 * File paths are stored relative to the root Syncany directory.
031 * 
032 * @author Philipp C. Heckel (philipp.heckel@gmail.com)
033 */
034public class ChangeSet {
035        @ElementList(name = "changedFiles", entry = "file", required = false)
036        private TreeSet<String> changedFiles;  
037
038        @ElementList(name = "newFiles", entry = "file", required = false)
039        private TreeSet<String> newFiles;
040        
041        @ElementList(name = "deletedFiles", entry = "file", required = false)
042        private TreeSet<String> deletedFiles;
043        
044        @ElementList(name = "unchangedFiles", entry = "file", required = false)
045        private TreeSet<String> unchangedFiles;
046        
047        public ChangeSet() {
048                changedFiles = new TreeSet<String>();
049                newFiles = new TreeSet<String>();
050                deletedFiles = new TreeSet<String>();
051                unchangedFiles = new TreeSet<String>();
052        }
053        
054        /**
055         * Returns <code>true</code> if files have been added, changed or
056         * deleted by checking the size of {@link #getNewFiles()}, {@link #getChangedFiles()}
057         * and {@link #getDeletedFiles()}.
058         */
059        public boolean hasChanges() {
060                return changedFiles.size() > 0 
061                        || newFiles.size() > 0
062                        || deletedFiles.size() > 0;
063        }
064        
065        // TODO [low] This is ugly. Use unmutable lists.
066        public TreeSet<String> getChangedFiles() {
067                return changedFiles;
068        }
069        
070        public TreeSet<String> getNewFiles() {
071                return newFiles;
072        }
073        
074        public TreeSet<String> getDeletedFiles() {
075                return deletedFiles;
076        }       
077        
078        public TreeSet<String> getUnchangedFiles() {
079                return unchangedFiles;
080        }
081}