add CompatibilityManager
and a bitte of Checker and Configuration
This commit is contained in:
@@ -5,15 +5,24 @@ import fr.istic.nplouzeau.cartaylor.api.PartType;
|
||||
|
||||
|
||||
public class CompatibilityChecker implements fr.istic.nplouzeau.cartaylor.api.CompatibilityChecker {
|
||||
|
||||
|
||||
private Set<PartType> incompatibilities;
|
||||
private Set<PartType> requirements;
|
||||
|
||||
public CompatibilityChecker(Set<PartType> incompatibilities, Set<PartType> requirements){
|
||||
this.requirements=requirements;
|
||||
this.incompatibilities=incompatibilities;
|
||||
}
|
||||
@Override
|
||||
public Set<PartType> getIncompatibilities(PartType reference){
|
||||
return Set.of();
|
||||
/*TODO*/
|
||||
return this.incompatibilities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference){
|
||||
return Set.of();
|
||||
/*TODO*/
|
||||
return this.requirements;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +1,138 @@
|
||||
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>> incompatibilites;
|
||||
private HashMap<PartType, Set<PartType>> requirements;
|
||||
|
||||
public CompatibilityManager() {
|
||||
this.requirements= new HashMap<>();
|
||||
this.incompatibilites = 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");
|
||||
}
|
||||
|
||||
Set<PartType> incompa = this.getIncompatibilities(reference);
|
||||
Set<PartType> require = this.getRequirements(reference);
|
||||
|
||||
if(incompa== null){
|
||||
incompa= new HashSet<PartType>(target);
|
||||
this.incompatibilites.put(reference,incompa);
|
||||
}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= new HashSet<PartType>(target);
|
||||
this.incompatibilites.put(reference,require);
|
||||
}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 Set.of();
|
||||
return this.incompatibilites.get(reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PartType> getRequirements(PartType reference) {
|
||||
return Set.of();
|
||||
return this.requirements.get(reference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,15 @@ import fr.istic.nplouzeau.cartaylor.api.PartType;
|
||||
import java.util.Set;
|
||||
|
||||
public class Configuration implements fr.istic.nplouzeau.cartaylor.api.Configuration {
|
||||
private Set<PartType> partTypes;
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return false;
|
||||
if ( this.isComplete()){
|
||||
/*TODO*/
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,7 +30,7 @@ public class Configuration implements fr.istic.nplouzeau.cartaylor.api.Configura
|
||||
|
||||
@Override
|
||||
public void selectPart(PartType chosenPart) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user