Commits

synthomat  committed 91873c2

ProductConverter ausgebessert

  • Participants
  • Parent commits f6aca29

Comments (0)

Files changed (2)

File src/hs/Product.java

 
 	@Override
 	public void stepQuantityDown(int amount) {
-		
 		if (this.quantity >= amount)
 			this.quantity -= amount;
 		else

File src/strategies/XStreamConverters/ProductConverter.java

 
 	public void marshal(Object value, HierarchicalStreamWriter writer,
 			MarshallingContext context) {
+		 
 		Product product = (Product) value;
+
+		// ID-Attribut hinzufügen
 		writer.addAttribute("id", product.getIdAsString());
+		
+		// NODES
 		writer.startNode("name");
-		writer.setValue(product.getName());
+			writer.setValue(product.getName());
 		writer.endNode();
 		writer.startNode("preis");
-		writer.setValue(Double.toString(product.getPrice()));
+			writer.setValue(product.getPriceAsString());
 		writer.endNode();
 		writer.startNode("quantity");
-		writer.setValue(Integer.toString(product.getQuantity()));
+			writer.setValue(Integer.toString(product.getQuantity()));
 		writer.endNode();
 	}
 
 	public Object unmarshal(HierarchicalStreamReader reader,
 			UnmarshallingContext context) {
 		Product product = new Product();
+		
+		// Attribut auslesen
 		product.setId(new Integer(reader.getAttribute("id")));
+		
+		// NODES
 		reader.moveDown();
-		product.setName(reader.getValue());
+			product.setName(reader.getValue());
 		reader.moveUp();
 		reader.moveDown();
-		product.setPrice(new Double(reader.getValue()));
+			product.setPrice(new Double(reader.getValue()));
 		reader.moveUp();
 		reader.moveDown();
-		product.setQuantity(new Integer(reader.getValue()));
+			product.setQuantity(new Integer(reader.getValue()));
 		reader.moveUp();
 
 		return product;
 	}
-
 }