reorginazise

This commit is contained in:
Minh VU
2024-10-18 17:11:29 +02:00
parent 51fd5e6e07
commit f97509496e
14 changed files with 0 additions and 4 deletions

9
src/fr/api/Category.java Normal file
View File

@@ -0,0 +1,9 @@
package fr.istic.nplouzeau.cartaylor.api;
/**
* @author plouzeau
* <p>
* A public type to organize part types in categories
*/
public interface Category {
String getName();
}

View File

@@ -0,0 +1,6 @@
package fr.istic.nplouzeau.cartaylor.api;
import java.util.Set;
public interface CompatibilityChecker {
Set<PartType> getIncompatibilities(PartType reference);
Set<PartType> getRequirements(PartType reference);
}

View File

@@ -0,0 +1,8 @@
package fr.istic.nplouzeau.cartaylor.api;
import java.util.Set;
public interface CompatibilityManager extends CompatibilityChecker {
void addIncompatibilities(PartType reference,Set<PartType> target);
void removeIncompatibility(PartType reference, PartType target);
void addRequirements(PartType reference, Set<PartType> target);
void removeRequirement(PartType reference, PartType target);
}

View File

@@ -0,0 +1,11 @@
package fr.istic.nplouzeau.cartaylor.api;
import java.util.Set;
public interface Configuration {
boolean isValid();
boolean isComplete();
Set<PartType> getSelectedParts();
void selectPart(PartType chosenPart);
PartType getSelectionForCategory(Category category);
void unselectPartType(Category categoryToClear);
void clear();
}

View File

@@ -0,0 +1,8 @@
package fr.istic.nplouzeau.cartaylor.api;
import java.util.Set;
public interface Configurator {
Set<Category> getCategories();
Set<PartType> getVariants(Category category);
Configuration getConfiguration();
CompatibilityChecker getCompatibilityChecker();
}

5
src/fr/api/PartType.java Normal file
View File

@@ -0,0 +1,5 @@
package fr.istic.nplouzeau.cartaylor.api;
public interface PartType {
String getName();
Category getCategory();
}

13
src/fr/impl/Category.java Normal file
View File

@@ -0,0 +1,13 @@
package src;
public class Category implements fr.istic.nplouzeau.cartaylor.api.Category {
private String name;
public Category(String name){
this.name= name;
}
public String getName(){
return this.name;
}
}

View File

@@ -0,0 +1,29 @@
package src;
import java.util.HashMap;
import java.util.Set;
import fr.istic.nplouzeau.cartaylor.api.PartType;
public class CompatibilityChecker implements fr.istic.nplouzeau.cartaylor.api.CompatibilityChecker {
private HashMap<PartType, Set<PartType>> incompatibilities;
private HashMap<PartType, Set<PartType>> requirements;
public CompatibilityChecker( HashMap<PartType, Set<PartType>> incompatibilities, HashMap<PartType, Set<PartType>> requirements){
this.incompatibilities=incompatibilities;
this.requirements= requirements;
}
@Override
public Set<PartType> getIncompatibilities(PartType reference) {
return this.incompatibilities.get(reference);
}
@Override
public Set<PartType> getRequirements(PartType reference) {
return this.requirements.get(reference);
}
}

View 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);
}
}

View File

@@ -0,0 +1,87 @@
package src;
import fr.istic.nplouzeau.cartaylor.api.Category;
import fr.istic.nplouzeau.cartaylor.api.PartType;
import java.util.Set;
public class Configuration implements fr.istic.nplouzeau.cartaylor.api.Configuration {
private Set<PartType> selectedParts;
private CompatibilityManager compatibilityManager;
private static int NB_CATEGORY = 4;
@Override
public boolean isValid() {
if (this.isComplete()){
for(PartType pt: selectedParts){
//Verifier Requirements
for(PartType require : compatibilityManager.getRequirements(pt)){
if(!selectedParts.contains(require)) return false;
}
//Verifier Incompabilities
for(PartType incompa : compatibilityManager.getIncompatibilities(pt)){
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<PartType> 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");
return;
}
}
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();;
}
}

View File

@@ -0,0 +1,48 @@
package src;
import fr.istic.nplouzeau.cartaylor.api.Category;
import fr.istic.nplouzeau.cartaylor.api.CompatibilityChecker;
import fr.istic.nplouzeau.cartaylor.api.Configuration;
import fr.istic.nplouzeau.cartaylor.api.PartType;
import java.util.HashSet;
import java.util.Set;
public class Configurator implements fr.istic.nplouzeau.cartaylor.api.Configurator {
private Set<Category> categories;
private Set<PartType> partTypes;
private Configuration configuration;
private CompatibilityChecker compatibilityChecker;
public Configurator (Set<Category> cat, Set<PartType> pt, Configuration config) {
this.categories= cat;
this.partTypes=pt;
this.configuration=config;
}
@Override
public Set<Category> getCategories() {
return this.categories;
}
@Override
public Set<PartType> getVariants(Category category) {
Set<PartType>a = new HashSet<PartType>();
for(PartType x : partTypes){
if (x.getCategory()==category){
a.add(x);
}
}
return a;
}
@Override
public Configuration getConfiguration() {
return this.configuration;
}
@Override
public CompatibilityChecker getCompatibilityChecker() {
return this.compatibilityChecker;
}
}

19
src/fr/impl/PartType.java Normal file
View File

@@ -0,0 +1,19 @@
package src;
public class PartType implements fr.istic.nplouzeau.cartaylor.api.PartType {
private String name;
private Category category;
public PartType(String name, Category category ) {
this.name = name;
this.category = category;
}
public String getName(){
return this.name;
}
public Category getCategory(){
return this.category;
}
}

89
src/fr/test/test.java Normal file
View File

@@ -0,0 +1,89 @@
package tests;
import src.*;
import java.util.Set;
import java.util.HashSet;
import static org.junit.Assert.*;
import org.junit.Test;
public class test {
public static void main(String[] args){
Category Engine = new Category("Engine");
Category Transmission = new Category("Transmission");
Category Exterior= new Category("Exterior");
Category Interior= new Category("Interior");
//PartType
PartType EG100= new PartType("EG100", Engine);
PartType EG133= new PartType("EG133", Engine);
PartType EG210= new PartType("EG210", Engine);
PartType ED110= new PartType("ED110", Engine);
PartType ED180= new PartType("ED180", Engine);
PartType EH120= new PartType("EH120", Engine);
PartType TM5= new PartType("TM5", Transmission);
PartType TM6= new PartType("TM6", Transmission);
PartType TA5= new PartType("TA5", Transmission);
PartType TS6= new PartType("TS6", Transmission);
PartType TSF7= new PartType("TSF7", Transmission);
PartType TC120= new PartType("TC120", Transmission);
PartType XC= new PartType("XC", Exterior);
PartType XM= new PartType("XM", Exterior);
PartType XS= new PartType("XS", Exterior);
PartType IN= new PartType("IN", Interior);
PartType IH= new PartType("IH", Interior);
PartType IS= new PartType("IS", Interior);
CompatibilityManager cm = new CompatibilityManager();
Set<PartType> EH120Requirement = new HashSet<PartType>();
EH120Requirement.add(TC120);
Set<PartType> TA5Incompatibilities = new HashSet<PartType>();
TA5Incompatibilities.add(TA5);
Set<PartType> TSF7Incompatibilities = new HashSet<PartType>();
TSF7Incompatibilities.add(EG100);
TSF7Incompatibilities.add(EG133);
TSF7Incompatibilities.add(ED110);
Set<PartType> TC120Requirement = new HashSet<PartType>();
TC120Requirement.add(EH120);
Set<PartType> XCIncompatibilities = new HashSet<PartType>();
XCIncompatibilities.add(EG210);
Set<PartType> XMIncompatibilities = new HashSet<PartType>();
XMIncompatibilities.add(EG100);
Set<PartType> XSIncompatibilities = new HashSet<PartType>();
XSIncompatibilities.add(EG100);
Set<PartType> XSRequirement = new HashSet<PartType>();
XSRequirement.add(IS);
Set<PartType> ISIncompatibilities = new HashSet<PartType>();
ISIncompatibilities.add(EG100);
ISIncompatibilities.add(TM5);
Set<PartType> ISRequirement = new HashSet<PartType>();
ISRequirement.add(XS);
cm.addRequirements(EH120, (HashSet<PartType>) EH120Requirement);
}
@Test
public void test(){
assertTrue(true);
}
@Test
public void test2(){
assertEquals(1,1); //very Important test
}
}