/*
 * Copyright 2014 the original author or authors.
 *
 * 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 org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts;

import org.gradle.api.Action;
import org.gradle.api.artifacts.ModuleIdentifier;
import org.gradle.api.internal.artifacts.ivyservice.resolveengine.ComponentResolutionState;

class PotentialConflictFactory {

    static PotentialConflict potentialConflict(final ConflictContainer<ModuleIdentifier, ? extends ComponentResolutionState>.Conflict conflict) {
        return new PotentialConflict() {
            public boolean conflictExists() {
                return conflict != null;
            }

            public void withParticipatingModules(Action<ModuleIdentifier> action) {
                assert conflictExists();
                for (ModuleIdentifier participant : conflict.participants) {
                    action.execute(participant);
                }
            }
        };
    }
}
@@ -868,16 +868,39 @@
 State;%0A%0A
+import java.util.Set;%0A%0A
 class Po
@@ -925,16 +925,92 @@
 tory %7B%0A%0A
+    private static final PotentialConflict NO_CONFLICT = new NoConflict();%0A%0A
     stat
@@ -1159,95 +1159,213 @@
     
-return new PotentialConflict() %7B
+if (conflict == null) %7B%0A            return NO_CONFLICT;%0A        %7D%0A        return new HasConflict(conflict.participants);
 %0A    
+%7D%0A%0A
     
-    public boolean conflictExists()
+private static class HasConflict implements PotentialConflict
  %7B%0A
+%0A
         
     
@@ -1364,39 +1364,169 @@
     
-        return conflict != null
+private final Set%3CModuleIdentifier%3E participants;%0A%0A        private HasConflict(Set%3CModuleIdentifier%3E participants) %7B%0A            this.participants = participants
 ;%0A  
@@ -1531,27 +1531,37 @@
         
+%7D%0A%0A
     
-%7D%0A%0A
     
+@Override%0A
         
@@ -1648,110 +1648,186 @@
     
-    assert conflictExists();%0A                for (ModuleIdentifier participant : conflict.participan
+for (ModuleIdentifier participant : participants) %7B%0A                action.execute(participant);%0A            %7D%0A        %7D%0A%0A        @Override%0A        public boolean conflictExis
 ts
+(
 ) %7B%0A
@@ -1842,44 +1842,202 @@
     
-        action.execute(participant);
+return true;%0A        %7D%0A    %7D%0A%0A    private static class NoConflict implements PotentialConflict %7B%0A        @Override%0A        public void withParticipatingModules(Action%3CModuleIdentifier%3E action) %7B
 %0A   
@@ -2037,32 +2037,35 @@
 ) %7B%0A        
+%7D%0A%0A
         
 %7D%0A          
@@ -2056,23 +2056,85 @@
     
-%7D%0A            %7D
+@Override%0A        public boolean conflictExists() %7B%0A            return false;
 %0A   
@@ -2143,13 +2143,12 @@
    %7D
-;
 %0A    %7D%0A%7D
@@ -2147,8 +2147,9 @@
 %0A    %7D%0A%7D
+%0A

Use subtypes for conflicts