class GroupChainGenerator {

	public GroupChain getGroupChainFor(Collection<Class<?>> groups) {
		if ( groups == null || groups.size() == 0 ) {
			throw new IllegalArgumentException( "At least one groups has to be specified." );
		}

		for ( Class<?> clazz : groups ) {
			if ( !clazz.isInterface() ) {
				throw new ValidationException( "A groups has to be an interface. " + clazz.getName() + " is not." );
			}
		}

		GroupChain chain = new GroupChain();
		for ( Class<?> clazz : groups ) {
			if ( clazz.getAnnotation( GroupSequence.class ) == null ) {
				Group group = new Group( clazz );
				chain.insertGroup( group );
				insertInheritedGroups( clazz, chain );
			}
			else {
				insertSequence( clazz, chain );
			}
		}

		return chain;
	}

}