correction get et set de Property
This commit is contained in:
@@ -21,26 +21,22 @@ public class Exterior extends PartImpl {
|
|||||||
colorSet.add("gray");
|
colorSet.add("gray");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String color;
|
||||||
|
|
||||||
public Exterior(String name, CategoryImpl category, int price){
|
public Exterior(String name, CategoryImpl category, int price){
|
||||||
super(new PartTypeImpl(name,Engine.class, category),price);
|
super(new PartTypeImpl(name,Engine.class, category),price);
|
||||||
|
|
||||||
Set<String> l = new HashSet<String>();
|
Set<String> l = new HashSet<String>();
|
||||||
l.add("red");
|
l.add("red");
|
||||||
this.addProperty("color", () -> getColor(), p -> setColor(p), colorSet);
|
this.addProperty("color", () -> getColor(), c -> setColor(c), colorSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getColor(){
|
public String getColor(){
|
||||||
String result = "white";
|
return this.color;
|
||||||
Optional<String> color = this.getProperty("color");
|
|
||||||
if(color.isPresent()){
|
|
||||||
result = color.get();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(String newColor){
|
public void setColor(String newColor){
|
||||||
this.setProperty("color",newColor);
|
this.color = newColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,8 +221,8 @@ public class test {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_PropertyInteriorColor(){
|
public void test_PropertyInteriorColor(){
|
||||||
XS.setColor("red");
|
XS.setProperty("color","red");
|
||||||
assertTrue(XS.getColor()=="red");
|
assertTrue(XS.getProperty("color").get()=="red");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user