Test all verified
Nice tester ( Thibaut )
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package src.fr.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Objects;
|
||||
import src.fr.api.PartType;
|
||||
|
||||
public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager {
|
||||
@@ -9,18 +11,23 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
|
||||
private HashMap<PartType, Set<PartType>> incompatibilities;
|
||||
private HashMap<PartType, Set<PartType>> requirements;
|
||||
|
||||
public CompatibilityManagerImpl() {
|
||||
this.incompatibilities = new HashMap<>();
|
||||
this.requirements = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addIncompatibilities(PartType reference, Set<PartType> target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
Objects.requireNonNull(reference);
|
||||
Objects.requireNonNull(target);
|
||||
|
||||
|
||||
Set<PartType> incompa = this.getIncompatibilities(reference);
|
||||
Set<PartType> require = this.getRequirements(reference);
|
||||
|
||||
if(incompa== null){
|
||||
incompa=target;
|
||||
if(incompa.isEmpty()){
|
||||
incompatibilities.put(reference, target);
|
||||
}else {
|
||||
for(PartType x: target){
|
||||
if (incompa.contains(x)){
|
||||
@@ -45,12 +52,11 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
|
||||
@Override
|
||||
public void removeIncompatibility(PartType reference, PartType target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
Objects.requireNonNull(reference);
|
||||
Objects.requireNonNull(target);
|
||||
|
||||
Set<PartType> incompa = this.getIncompatibilities(reference);
|
||||
if(incompa==null){
|
||||
if(incompa.isEmpty()){
|
||||
System.out.println("No part incompatible");
|
||||
}else{
|
||||
if(incompa.contains(target)){
|
||||
@@ -66,14 +72,13 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
|
||||
@Override
|
||||
public void addRequirements(PartType reference, Set<PartType> target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
Objects.requireNonNull(reference);
|
||||
Objects.requireNonNull(target);
|
||||
|
||||
Set<PartType> incompa = this.getIncompatibilities(reference);
|
||||
Set<PartType> require = this.getRequirements(reference);
|
||||
if(require== null){
|
||||
require= target;
|
||||
if(require.isEmpty()){
|
||||
requirements.put(reference, target);
|
||||
}else {
|
||||
for(PartType x: target){
|
||||
if (require.contains(x)){
|
||||
@@ -99,12 +104,11 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
|
||||
@Override
|
||||
public void removeRequirement(PartType reference, PartType target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
Objects.requireNonNull(reference);
|
||||
Objects.requireNonNull(target);
|
||||
|
||||
Set<PartType> require = this.getRequirements(reference);
|
||||
if(require ==null){
|
||||
if(require.isEmpty()){
|
||||
System.out.println("No part compatible");
|
||||
}else{
|
||||
if(require.contains(target)){
|
||||
@@ -119,12 +123,15 @@ public class CompatibilityManagerImpl implements src.fr.api.CompatibilityManager
|
||||
|
||||
@Override
|
||||
public Set<PartType> getIncompatibilities(PartType reference) {
|
||||
return this.incompatibilities.get(reference);
|
||||
// Il faut verifier ref est existé dans Hashmap
|
||||
//return this.incompatibilities.get(reference);
|
||||
return this.incompatibilities.getOrDefault(reference, new HashSet<PartType>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference) {
|
||||
return this.requirements.get(reference);
|
||||
//return this.requirements.get(reference);
|
||||
return this.requirements.getOrDefault(reference, new HashSet<PartType>());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class test {
|
||||
EH120Requirement.add(TC120);
|
||||
|
||||
Set<PartType> TA5Incompatibilities = new HashSet<PartType>();
|
||||
TA5Incompatibilities.add(TA5);
|
||||
TA5Incompatibilities.add(EG100);
|
||||
|
||||
Set<PartType> TSF7Incompatibilities = new HashSet<PartType>();
|
||||
TSF7Incompatibilities.add(EG100);
|
||||
@@ -80,7 +80,7 @@ public class test {
|
||||
ISRequirement.add(XS);
|
||||
|
||||
cm.addRequirements(EH120, EH120Requirement);
|
||||
cm.addRequirements(TA5, TA5Incompatibilities);
|
||||
cm.addIncompatibilities(TA5, TA5Incompatibilities);
|
||||
cm.addIncompatibilities(TSF7, TSF7Incompatibilities);
|
||||
cm.addRequirements(TC120, TC120Requirement);
|
||||
cm.addIncompatibilities(XC, XCIncompatibilities);
|
||||
|
||||
Reference in New Issue
Block a user