Proterty color Interior + prix pour les Part
This commit is contained in:
@@ -2,6 +2,7 @@ package src.fr.impl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@@ -16,9 +17,11 @@ import src.fr.api.PartType;
|
||||
public class PartImpl implements Part {
|
||||
|
||||
private PartType type;
|
||||
private int price;
|
||||
|
||||
public PartImpl(PartType type){
|
||||
public PartImpl(PartType type, int price){
|
||||
this.type = type;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
private class Property {
|
||||
@@ -80,4 +83,8 @@ public class PartImpl implements Part {
|
||||
public PartType getType(){
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public int getPrice(){
|
||||
return this.price;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,18 @@
|
||||
package src.fr.impl.Parts;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test.None;
|
||||
|
||||
import src.fr.impl.CategoryImpl;
|
||||
import src.fr.impl.PartImpl;
|
||||
import src.fr.impl.PartTypeImpl;
|
||||
|
||||
public class Engine extends PartImpl {
|
||||
public Engine(String name, CategoryImpl category){
|
||||
super(new PartTypeImpl(name,Engine.class, category));
|
||||
|
||||
|
||||
//init_prix();
|
||||
//this.addProperty("prix", () -> Integer.toString(getPrix()), null, getPropertyNames());
|
||||
}
|
||||
|
||||
private HashMap<String,Integer> table_prix;
|
||||
|
||||
private void init_prix(){
|
||||
table_prix.put("EG100",100);
|
||||
}
|
||||
|
||||
public int getPrix(){
|
||||
return table_prix.get(this.getName());
|
||||
public Engine(String name, CategoryImpl category, int price){
|
||||
super(new PartTypeImpl(name,Engine.class, category),price);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,46 @@
|
||||
package src.fr.impl.Parts;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import src.fr.impl.CategoryImpl;
|
||||
import src.fr.impl.PartImpl;
|
||||
import src.fr.impl.PartTypeImpl;
|
||||
|
||||
public class Exterior extends PartImpl {
|
||||
public Exterior(String name, CategoryImpl category){
|
||||
super(new PartTypeImpl(name,Engine.class, category));
|
||||
public class Exterior extends PartImpl {
|
||||
|
||||
private static final Set<String> colorSet;
|
||||
static {
|
||||
colorSet = new HashSet<>();
|
||||
colorSet.add("white");
|
||||
colorSet.add("green");
|
||||
colorSet.add("red");
|
||||
colorSet.add("blue");
|
||||
colorSet.add("green");
|
||||
colorSet.add("gray");
|
||||
}
|
||||
|
||||
|
||||
public Exterior(String name, CategoryImpl category, int price){
|
||||
super(new PartTypeImpl(name,Engine.class, category),price);
|
||||
|
||||
Set<String> l = new HashSet<String>();
|
||||
l.add("red");
|
||||
this.addProperty("color", () -> getColor(), p -> setColor(p), colorSet);
|
||||
}
|
||||
|
||||
|
||||
public String getColor(){
|
||||
String result = "white";
|
||||
Optional<String> color = this.getProperty("color");
|
||||
if(color.isPresent()){
|
||||
result = color.get();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setColor(String newColor){
|
||||
this.setProperty("color",newColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import src.fr.impl.PartImpl;
|
||||
import src.fr.impl.PartTypeImpl;
|
||||
|
||||
public class Interior extends PartImpl {
|
||||
public Interior(String name, CategoryImpl category){
|
||||
super(new PartTypeImpl(name,Engine.class, category));
|
||||
public Interior(String name, CategoryImpl category, int price){
|
||||
super(new PartTypeImpl(name,Engine.class, category), price);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import src.fr.impl.PartImpl;
|
||||
import src.fr.impl.PartTypeImpl;
|
||||
|
||||
public class Transmission extends PartImpl {
|
||||
public Transmission(String name, CategoryImpl category){
|
||||
super(new PartTypeImpl(name,Engine.class, category));
|
||||
public Transmission(String name, CategoryImpl category, int price){
|
||||
super(new PartTypeImpl(name,Engine.class, category),price);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,28 +23,28 @@ public class test {
|
||||
|
||||
|
||||
PartType EG100PartType = new PartTypeImpl("EG100",Engine.class,engine);
|
||||
|
||||
Engine EG100 = new Engine("EG100",engine,3000);
|
||||
Engine EG133 = new Engine("EG133",engine,8000);
|
||||
Engine EG210= new Engine("EG210", engine,15000);
|
||||
Engine ED110= new Engine("ED110", engine,2000);
|
||||
Engine ED180= new Engine("ED180", engine,4000);
|
||||
Engine EH120= new Engine("EH120", engine,15000);
|
||||
|
||||
Engine EG100 = new Engine("EG100",engine);
|
||||
Engine EG133 = new Engine("EG133",engine);
|
||||
Engine EG210= new Engine("EG210", engine);
|
||||
Engine ED110= new Engine("ED110", engine);
|
||||
Engine ED180= new Engine("ED180", engine);
|
||||
Engine EH120= new Engine("EH120", engine);
|
||||
Transmission TM5= new Transmission("TM5", transmission,2000);
|
||||
Transmission TM6= new Transmission("TM6", transmission,4000);
|
||||
Transmission TA5= new Transmission("TA5", transmission,7000);
|
||||
Transmission TS6= new Transmission("TS6", transmission,10000);
|
||||
Transmission TSF7= new Transmission("TSF7", transmission,15000);
|
||||
Transmission TC120= new Transmission("TC120", transmission,1000);
|
||||
|
||||
Transmission TM5= new Transmission("TM5", transmission);
|
||||
Transmission TM6= new Transmission("TM6", transmission);
|
||||
Transmission TA5= new Transmission("TA5", transmission);
|
||||
Transmission TS6= new Transmission("TS6", transmission);
|
||||
Transmission TSF7= new Transmission("TSF7", transmission);
|
||||
Transmission TC120= new Transmission("TC120", transmission);
|
||||
Exterior XC= new Exterior("XC", exterior,0);
|
||||
Exterior XM= new Exterior("XM", exterior,1000);
|
||||
Exterior XS= new Exterior("XS", exterior,10000);
|
||||
|
||||
Exterior XC= new Exterior("XC", exterior);
|
||||
Exterior XM= new Exterior("XM", exterior);
|
||||
Exterior XS= new Exterior("XS", exterior);
|
||||
|
||||
Interior IN= new Interior("IN", interior);
|
||||
Interior IH= new Interior("IH", interior);
|
||||
Interior IS= new Interior("IS", interior);
|
||||
Interior IN= new Interior("IN", interior,0);
|
||||
Interior IH= new Interior("IH", interior,800);
|
||||
Interior IS= new Interior("IS", interior,2500);
|
||||
|
||||
|
||||
|
||||
@@ -52,8 +52,6 @@ public class test {
|
||||
CompatibilityManager cm = new CompatibilityManagerImpl();
|
||||
@Before
|
||||
public void init(){
|
||||
|
||||
|
||||
Set<PartType> EH120Requirement = new HashSet<PartType>();
|
||||
EH120Requirement.add(TC120.getType());
|
||||
|
||||
@@ -96,7 +94,10 @@ public class test {
|
||||
cm.addIncompatibilities(IS.getType(), ISIncompatibilities);
|
||||
cm.addRequirements(IS.getType(), ISRequirement);
|
||||
|
||||
|
||||
|
||||
|
||||
//EG100.setProperty("prix","5€");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user