package de.clemensloos.folder_sync;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

/**
 * The global SyncConfig contains one or more targets. One instance is usually
 * represented by one config file.
 */
public class SyncConfig {

	private boolean compareSize = false;
	private boolean compareChecksum = false;

	private FilenameFilter filenameFilter;

	private List<Target> targetList = new ArrayList<>();

	public boolean isCompareSize() {
		return compareSize;
	}

	public void setCompareSize(boolean compareSize) {
		this.compareSize = compareSize;
	}

	public boolean isCompareChecksum() {
		return compareChecksum;
	}

	public void setCompareChecksum(boolean compareChecksum) {
		this.compareChecksum = compareChecksum;
	}

	public List<Target> getTargetList() {
		return targetList;
	}

	public void setTargetList(List<Target> targetList) {
		this.targetList = targetList;
	}

	public void addTarget(Target target) {
		this.targetList.add(target);
	}

	public void setFilter(String[] filenameFilterString, String[] pathFilterString, String[] extensionFilterString) {
		this.filenameFilter = new MyFilenameFilter(filenameFilterString, pathFilterString, extensionFilterString);
	}

	public FilenameFilter getFilenameFilter() {
		return this.filenameFilter;
	}

	private class MyFilenameFilter implements FilenameFilter {

		private String[] filenameFilterString;
		private String[] pathFilterString;
		private String[] extensionFilterString;

		public MyFilenameFilter(String[] filenameFilterString, String[] pathFilterString, String[] extensionFilterString) {
			this.filenameFilterString = filenameFilterString;
			this.pathFilterString = pathFilterString;
			this.extensionFilterString = extensionFilterString;
		}

		@Override
		public boolean accept(File dir, String name) {
			for (String s : filenameFilterString) {
				if (name.equals(s)) {
					return false;
				}
			}
			for (String s : pathFilterString) {
				if ((dir.getAbsolutePath() + Sync.SLASH + name).contains(s)) {
					return false;
				}
			}
			for (String s : extensionFilterString) {
				if (name.contains(".") && name.substring(name.lastIndexOf(".") + 1).equalsIgnoreCase(s)) {
					return false;
				}
			}
			return true;
		}

	}

}

@@ -1884,24 +1884,40 @@
 ) %7B%0A%09%09%09%09if (
+!s.isEmpty() && 
 name.equals(
@@ -1914,32 +1914,32 @@
 me.equals(s)) %7B%0A
-
 %09%09%09%09%09return fals
@@ -1999,16 +1999,32 @@
 %09%09%09%09if (
+!s.isEmpty() && 
 (dir.get
@@ -2148,24 +2148,24 @@
 ring) %7B%0A
-
 %09%09%09%09if (
 name.con
@@ -2156,16 +2156,31 @@
 %09%09%09%09if (
+!s.isEmpty() &&
 name.con

Fix empty filter issue.