reorginazise
This commit is contained in:
131
src/fr/impl/CompatibilityManager.java
Normal file
131
src/fr/impl/CompatibilityManager.java
Normal file
@@ -0,0 +1,131 @@
|
||||
package src;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import fr.istic.nplouzeau.cartaylor.api.PartType;
|
||||
|
||||
public class CompatibilityManager implements fr.istic.nplouzeau.cartaylor.api.CompatibilityManager {
|
||||
|
||||
private HashMap<PartType, Set<PartType>> incompatibilities;
|
||||
private HashMap<PartType, Set<PartType>> requirements;
|
||||
|
||||
@Override
|
||||
public void addIncompatibilities(PartType reference, Set<PartType> target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
|
||||
Set<PartType> incompa = this.getIncompatibilities(reference);
|
||||
Set<PartType> require = this.getRequirements(reference);
|
||||
|
||||
if(incompa== null){
|
||||
incompa=target;
|
||||
}else {
|
||||
for(PartType x: target){
|
||||
if (incompa.contains(x)){
|
||||
System.out.println("We have it already");
|
||||
}else {
|
||||
if(require.contains(x)){
|
||||
System.out.println("Cannot remove");
|
||||
}else{
|
||||
//Ajout ref à x
|
||||
incompa.add(x);
|
||||
System.out.println("Add "+reference.getName() +" incompatible with "+x.getName());
|
||||
|
||||
//Ajoute x à ref
|
||||
this.getIncompatibilities(x).add(reference);
|
||||
System.out.println("Add "+x.getName() +" incompatible with "+reference.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeIncompatibility(PartType reference, PartType target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
|
||||
Set<PartType> incompa = this.getIncompatibilities(reference);
|
||||
if(incompa==null){
|
||||
System.out.println("No part incompatible");
|
||||
}else{
|
||||
if(incompa.contains(target)){
|
||||
incompa.remove(target);
|
||||
//Remove target -> ref
|
||||
this.getIncompatibilities(target).remove(reference);
|
||||
}else {
|
||||
System.out.println("This part doesn't exist in incompatibilities list");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(PartType reference, Set<PartType> target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
|
||||
Set<PartType> incompa = this.getIncompatibilities(reference);
|
||||
Set<PartType> require = this.getRequirements(reference);
|
||||
if(require== null){
|
||||
require= target;
|
||||
}else {
|
||||
for(PartType x: target){
|
||||
if (require.contains(x)){
|
||||
System.out.println("We have it already");
|
||||
}else {
|
||||
if(incompa.contains(x)){
|
||||
System.out.println("Cannot remove");
|
||||
}else{
|
||||
//Ajout ref à x
|
||||
require.add(x);
|
||||
System.out.println("Add "+reference.getName() +" compatible with "+x.getName());
|
||||
|
||||
//Ajoute x à ref
|
||||
this.getRequirements(x).add(reference);
|
||||
System.out.println("Add "+x.getName() +" compatible with "+reference.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRequirement(PartType reference, PartType target){
|
||||
//Précondition
|
||||
if(reference == null || target == null ){
|
||||
throw new IllegalArgumentException("Ref or Target is null");
|
||||
}
|
||||
|
||||
Set<PartType> require = this.getRequirements(reference);
|
||||
if(require ==null){
|
||||
System.out.println("No part compatible");
|
||||
}else{
|
||||
if(require.contains(target)){
|
||||
require.remove(target);
|
||||
//Remove target -> ref
|
||||
this.getRequirements(target).remove(reference);
|
||||
}else {
|
||||
System.out.println("This part doesn't exist in compatibilities list");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getIncompatibilities(PartType reference) {
|
||||
return this.incompatibilities.get(reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference) {
|
||||
return this.requirements.get(reference);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user