001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.devtools.filewatch;
018
019import java.io.File;
020import java.util.Collections;
021import java.util.Iterator;
022import java.util.Set;
023
024/**
025 * A collections of files from a specific source folder that have changed.
026 *
027 * @author Phillip Webb
028 * @since 1.3.0
029 * @see FileChangeListener
030 * @see ChangedFiles
031 */
032public final class ChangedFiles implements Iterable<ChangedFile> {
033
034        private final File sourceFolder;
035
036        private final Set<ChangedFile> files;
037
038        public ChangedFiles(File sourceFolder, Set<ChangedFile> files) {
039                this.sourceFolder = sourceFolder;
040                this.files = Collections.unmodifiableSet(files);
041        }
042
043        /**
044         * The source folder being watched.
045         * @return the source folder
046         */
047        public File getSourceFolder() {
048                return this.sourceFolder;
049        }
050
051        @Override
052        public Iterator<ChangedFile> iterator() {
053                return getFiles().iterator();
054        }
055
056        /**
057         * The files that have been changed.
058         * @return the changed files
059         */
060        public Set<ChangedFile> getFiles() {
061                return this.files;
062        }
063
064        @Override
065        public boolean equals(Object obj) {
066                if (obj == null) {
067                        return false;
068                }
069                if (obj == this) {
070                        return true;
071                }
072                if (obj instanceof ChangedFiles) {
073                        ChangedFiles other = (ChangedFiles) obj;
074                        return this.sourceFolder.equals(other.sourceFolder)
075                                        && this.files.equals(other.files);
076                }
077                return super.equals(obj);
078        }
079
080        @Override
081        public int hashCode() {
082                return this.files.hashCode();
083        }
084
085        @Override
086        public String toString() {
087                return this.sourceFolder + " " + this.files;
088        }
089
090}