/*
 * Copyright 2015 Lukas Tenbrink
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package ivorius.ivtoolkit.maze.components;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by lukas on 30.09.15.
 */
public class MazePredicateMany<M extends MazeComponent<C>, C> implements MazePredicate<M, C>
{
    private final List<MazePredicate<M, C>> predicates = new ArrayList<>();

    public MazePredicateMany(List<MazePredicate<M, C>> predicates)
    {
        this.predicates.addAll(predicates);
    }

    @SafeVarargs
    public MazePredicateMany(MazePredicate<M, C>... predicates)
    {
        Collections.addAll(this.predicates, predicates);
    }

    @Override
    public boolean canPlace(final MorphingMazeComponent<C> maze, final ShiftedMazeComponent<M, C> component)
    {
        return Iterables.all(predicates, new Predicate<MazePredicate<M, C>>()
        {
            @Override
            public boolean apply(MazePredicate<M, C> p)
            {
                return p.canPlace(maze, component);
            }
        });
    }

    @Override
    public void willPlace(MorphingMazeComponent<C> maze, ShiftedMazeComponent<M, C> component)
    {
        for (MazePredicate<M, C> predicate : predicates)
            predicate.willPlace(maze, component);
    }

    @Override
    public void didUnplace(MorphingMazeComponent<C> maze, ShiftedMazeComponent<M, C> component)
    {

    }

    @Override
    public boolean isDirtyConnection(final MazeRoom dest, final MazeRoom source, final C c)
    {
        return Iterables.all(predicates, new Predicate<MazePredicate<M, C>>()
        {
            @Override
            public boolean apply(MazePredicate<M, C> p)
            {
                return p.isDirtyConnection(dest, source, c);
            }
        });
    }
}

@@ -976,14 +976,13 @@
    p
-rivate
+ublic
  fin
@@ -1043,16 +1043,60 @@
 t%3C%3E();%0A%0A
+    public MazePredicateMany()%0A    %7B%0A    %7D%0A%0A
     publ
@@ -2101,16 +2101,123 @@
 )%0A    %7B%0A
+        for (MazePredicate%3CM, C%3E predicate : predicates)%0A            predicate.didUnplace(maze, component);
 %0A    %7D%0A%0A

Make MazePredicateMany great again.