Exemplo n.º 1
0
 public void modifyCar(int id, int price, String name, int model, String color) {
   Car temp = (Car) cars.get(id);
   temp.setPrice(price);
   temp.setName(name);
   temp.setModel(model);
   temp.setColor(color);
   cars.set(id, temp);
 }
Exemplo n.º 2
0
 // Create a new car location or add cars to an existing location.
 // Note: if price <= 0 and the car location already exists, it maintains
 // its current price.
 @Override
 public boolean addCars(int id, String location, int numCars, int carPrice) {
   Trace.info(
       "RM::addCars(" + id + ", " + location + ", " + numCars + ", $" + carPrice + ") called.");
   synchronized (syncLock) {
     Car curObj = (Car) readData(id, Car.getKey(location));
     if (curObj == null) {
       // Doesn't exist; add it.
       Car newObj = new Car(location, numCars, carPrice);
       writeData(id, newObj.getKey(), newObj);
       Trace.info(
           "RM::addCars(" + id + ", " + location + ", " + numCars + ", $" + carPrice + ") OK.");
     } else {
       // Add count to existing object and update price.
       curObj.setCount(curObj.getCount() + numCars);
       if (carPrice > 0) {
         curObj.setPrice(carPrice);
       }
       writeData(id, curObj.getKey(), curObj);
       Trace.info(
           "RM::addCars("
               + id
               + ", "
               + location
               + ", "
               + numCars
               + ", $"
               + carPrice
               + ") OK: "
               + "cars = "
               + curObj.getCount()
               + ", price = $"
               + carPrice);
     }
     return (true);
   }
 }