Maybe the incompatible will be useful
This commit is contained in:
@@ -2,27 +2,26 @@ package src.fr.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import src.fr.api.PartType;
|
||||
import src.fr.api.CompatibilityManager;
|
||||
|
||||
|
||||
public class CompatibilityCheckerImpl implements src.fr.api.CompatibilityChecker {
|
||||
private CompatibilityManager compatibilityManager;
|
||||
|
||||
private HashMap<PartType, Set<PartType>> incompatibilities;
|
||||
private HashMap<PartType, Set<PartType>> requirements;
|
||||
|
||||
public CompatibilityCheckerImpl( HashMap<PartType, Set<PartType>> incompatibilities, HashMap<PartType, Set<PartType>> requirements){
|
||||
this.incompatibilities=incompatibilities;
|
||||
this.requirements= requirements;
|
||||
public CompatibilityCheckerImpl( CompatibilityManager compatibilityManager){
|
||||
this.compatibilityManager=compatibilityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getIncompatibilities(PartType reference) {
|
||||
return this.incompatibilities.get(reference);
|
||||
return this.compatibilityManager.getIncompatibilities(reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference) {
|
||||
return this.requirements.get(reference);
|
||||
return this.compatibilityManager.getRequirements(reference);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Objects;
|
||||
@@ -128,48 +129,54 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
|
||||
}
|
||||
}
|
||||
|
||||
// A - incompatible B + B require C => A incompatbile C
|
||||
// This is B require C
|
||||
protected Set<PartType> getIncompability_middle(PartType reference){
|
||||
return this.requirements.getOrDefault(reference, new HashSet<PartType>());
|
||||
// A -> B -> C -> A, D -> B
|
||||
//bool verify requirement (1) or incompatible (0)
|
||||
private void Femeture_Transivite(PartType reference, Set<PartType> result, Set<PartType> visited, boolean bool){
|
||||
//Condition de quitter la boucle
|
||||
if(visited.contains(reference)){
|
||||
return;
|
||||
}else {
|
||||
visited.add(reference);
|
||||
}
|
||||
|
||||
Set<PartType> list = null;
|
||||
if(bool==true){ // requirement
|
||||
//Get all requirement of A (in example is B)
|
||||
list = this.requirements.get(reference);
|
||||
}else{ //incompatible
|
||||
list = this.incompatibilities.get(reference);
|
||||
}
|
||||
|
||||
if(list != null){ // list = {B}
|
||||
for(PartType pt: list){
|
||||
if(!result.contains(pt)){
|
||||
result.add(pt);
|
||||
}
|
||||
Femeture_Transivite(pt,result,visited,bool);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void check_All_Catalog(PartType reference, Set<PartType> result, boolean bool){
|
||||
if(bool){ //
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getIncompatibilities(PartType reference) {
|
||||
// Il faut verifier ref est existé dans Hashmap
|
||||
//return this.incompatibilities.get(reference);
|
||||
Set<PartType> result = new HashSet<>();
|
||||
Femeture_Transivite(reference, result,new HashSet<>(),false);
|
||||
return result;
|
||||
}
|
||||
|
||||
//A incompatible B
|
||||
Set<PartType> parts = this.incompatibilities.getOrDefault(reference, new HashSet<PartType>());
|
||||
|
||||
// A incompatible C
|
||||
//Get all incomptability with transivity
|
||||
if (parts != null){
|
||||
for( PartType p: parts){
|
||||
parts.addAll(this.getIncompability_middle(p));
|
||||
}
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
|
||||
//Same but B incompatible C
|
||||
protected Set<PartType> getRequirement_middle(PartType reference){
|
||||
return this.incompatibilities.getOrDefault(reference, new HashSet<PartType>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference) {
|
||||
Set<PartType> parts = this.requirements.getOrDefault(reference, new HashSet<PartType>());
|
||||
|
||||
// A incompatible C
|
||||
//Get all incomptability with transivity
|
||||
if (parts != null){
|
||||
for( PartType p: parts){
|
||||
parts.addAll(this.getRequirement_middle(p));
|
||||
}
|
||||
}
|
||||
return parts;
|
||||
Set<PartType> result = new HashSet<>();
|
||||
Femeture_Transivite(reference, result,new HashSet<>(),true);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user