package com.tzavellas.circuitbreaker.support;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

class ClassSet {
	
	private List<Class<?>> classes = new CopyOnWriteArrayList<Class<?>>();

	public void add(Class<?> c) {
		if (c == null) return;
		boolean toAdd = classes.isEmpty();
		for (Class<?> cls: classes)
			if (c.isAssignableFrom(cls)) {
				classes.remove(cls);
				toAdd = true;
			} else if (cls.isAssignableFrom(c)) {
				return;
			}
		
		if (toAdd) classes.add(c);
	}

	public void addAll(Collection<? extends Class<?>> classes) {
		if (classes == null) return;
		for (Class<?> c: classes) add(c);
	}
	
	public boolean contains(Class<?> c) {
		for (Class<?> cls: classes)
			if (cls.isAssignableFrom(c))
				return true;
		return false;
	}

	public boolean isEmpty() {
		return classes.isEmpty();
	}
	
	public int size() {
		return classes.size();
	}
	
	public void clear() {
		classes.clear();
	}

	public boolean remove(Class<?> c) {
		return classes.remove(c);
	}
}

@@ -295,45 +295,8 @@
 rn;%0A
-%09%09boolean toAdd = classes.isEmpty();%0A
 %09%09fo
@@ -313,32 +313,32 @@
 %3E cls: classes)%0A
+
 %09%09%09if (c.isAssig
@@ -384,26 +384,8 @@
 s);%0A
-%09%09%09%09toAdd = true;%0A
 %09%09%09%7D
@@ -442,24 +442,10 @@
 %09%09%7D%0A
+
 %09%09
-%0A%09%09if (toAdd) 
 clas

Simplify implementation