package robots;

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public abstract class AbstractRule implements Rule {

	private String path;
	private boolean wildcardsAllowed;
	
	
	
	public AbstractRule(String path, boolean wildcardsAllowed) {
		
		this.path = path;
		this.wildcardsAllowed = wildcardsAllowed;
				
	}
	
	public String getPath() {
		return this.path;
	}
	
	
	public abstract Boolean isAllowed(String path);
	
	@Override
	public String toString() {
		
		return getClass().getName()+ " on "+ this.path;
	}
	
	protected boolean match(String query) {
		
		if(!wildcardsAllowed || (path.indexOf("*")== -1 && path.indexOf("$")== -1)){
		
			return query.startsWith(path);
			
		}
		
		
		String regExp = path;
		regExp = regExp.replace("/", "\\/");
		regExp = regExp.replace("*", ".*");
		
		
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(query);
		boolean r = m.find();

		return r;
		
	}

}

@@ -80,16 +80,84 @@
 ern;%0D%0A%0D%0A
+/**%0D%0A* @author Giuseppe Giorgi %3Cgiuseppe.giorgi1987@gmail.com%3E%0D%0A*/%0D%0A
 %0D%0Apublic

Update AbstractRule.java