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 java.util.HashSet; import java.util.Set; public class ConfigurationImpl implements Configuration { private Set selectedParts = new HashSet (); private CompatibilityManager compatibilityManager; private static int NB_CATEGORY = 4; public ConfigurationImpl(CompatibilityManager cm){ this.compatibilityManager=cm; } @Override public boolean isValid() { if (this.isComplete()){ for(PartType pt: selectedParts){ System.out.println(pt.getName()); //Verifier Requirements for(PartType require : compatibilityManager.getRequirements(pt)){ System.out.println("\t"+require.getName()); if(!selectedParts.contains(require)) return false; } //Verifier Incompabilities for(PartType incompa : compatibilityManager.getIncompatibilities(pt)){ System.out.println("\t"+incompa.getName()); if(selectedParts.contains(incompa)) return false; } } return true; }else{ return false; } } @Override public boolean isComplete() { if(selectedParts.size()==NB_CATEGORY){ return true; } return false; } @Override public Set 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( PartType 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"); selectedParts.remove(pt); break; } } selectedParts.add(chosenPart); } @Override public PartType getSelectionForCategory(Category category) { for( PartType pt: selectedParts){ if(pt.getCategory().equals(category)){ return pt; } } return null; } @Override public void unselectPartType(Category categoryToClear) { for( PartType 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();; } }