correction get et set de Property

This commit is contained in:
trochas
2024-12-04 17:18:27 +01:00
parent e68e2771ed
commit f9c6059067
2 changed files with 6 additions and 10 deletions

View File

@@ -21,26 +21,22 @@ public class Exterior extends PartImpl {
colorSet.add("gray");
}
private String color;
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);
this.addProperty("color", () -> getColor(), c -> setColor(c), colorSet);
}
public String getColor(){
String result = "white";
Optional<String> color = this.getProperty("color");
if(color.isPresent()){
result = color.get();
}
return result;
return this.color;
}
public void setColor(String newColor){
this.setProperty("color",newColor);
this.color = newColor;
}
}

View File

@@ -221,8 +221,8 @@ public class test {
@Test
public void test_PropertyInteriorColor(){
XS.setColor("red");
assertTrue(XS.getColor()=="red");
XS.setProperty("color","red");
assertTrue(XS.getProperty("color").get()=="red");
}