107 lines
3.2 KiB
Java
107 lines
3.2 KiB
Java
package src.fr.impl;
|
|
|
|
import src.fr.api.Category;
|
|
import src.fr.api.PartType;
|
|
import src.fr.api.CompatibilityManager;
|
|
import src.fr.api.Configuration;
|
|
import src.fr.api.Part;
|
|
|
|
import java.util.Optional;
|
|
import java.util.Set;
|
|
|
|
public class ConfigurationImpl implements Configuration {
|
|
private Set<Part> selectedParts;
|
|
private CompatibilityManager compatibilityManager;
|
|
private static int NB_CATEGORY = 4;
|
|
|
|
|
|
@Override
|
|
public boolean isValid() {
|
|
if (this.isComplete()){
|
|
for(Part pt: selectedParts){
|
|
//Verifier Requirements
|
|
for(PartType require : compatibilityManager.getRequirements(pt.getType())){
|
|
//if(!selectedParts.contains(require)) return false;
|
|
//IN V2, instead of verify if it's in selectedParts,
|
|
//we will compare its type and selectedParts
|
|
//boolean no_error = true;
|
|
|
|
for(Part selectPart : selectedParts){
|
|
if (selectPart.getType().equals(require)){
|
|
return false;
|
|
//no_error= true;
|
|
//break;
|
|
}
|
|
}
|
|
|
|
}
|
|
//Verifier Incompabilities
|
|
for(PartType incompa : compatibilityManager.getIncompatibilities(pt.getType())){
|
|
for (Part selectPart : selectedParts){
|
|
if(selectPart.getType().equals(incompa)){
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
public boolean isComplete() {
|
|
if(selectedParts.size()==NB_CATEGORY){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public Set<Part> getSelectedParts() {
|
|
return selectedParts;
|
|
}
|
|
|
|
@Override
|
|
public void selectPart(PartType chosenPart) {
|
|
Category cat_chosenPart = chosenPart.getCategory();
|
|
|
|
//Vérifier s'il y a des pièces dans la même catégorie, si oui return
|
|
for(Part pt: selectedParts){
|
|
if(pt.getCategory().equals(cat_chosenPart)){
|
|
System.out.println("Il y a une pièce dans la même catégorie dans la configuration");
|
|
return;
|
|
}
|
|
}
|
|
selectedParts.add( ((PartTypeImpl)chosenPart).newInstance() );
|
|
}
|
|
|
|
@Override
|
|
public Optional<Part> getSelectionForCategory(Category category) {
|
|
for( Part pt: selectedParts){
|
|
if(pt.getCategory().equals(category)){
|
|
return Optional.of(pt);
|
|
}
|
|
}
|
|
return Optional.empty();
|
|
}
|
|
|
|
@Override
|
|
public void unselectPartType(Category categoryToClear) {
|
|
for( Part pt: selectedParts){
|
|
if(pt.getCategory().equals(categoryToClear)){
|
|
selectedParts.remove(pt);
|
|
}
|
|
}
|
|
System.out.println("Il n'y a pas des pièces dans cette catégorie");
|
|
|
|
}
|
|
|
|
@Override
|
|
public void clear() {
|
|
this.selectedParts.clear();;
|
|
}
|
|
}
|