vehicles-api/src/main/java/com/udacity/vehicles/service/CarService.java
public Car save(Car car) {
    if (car.getId() != null) {
      return repository.findById(car.getId())
              .map(carToBeUpdated -> {
                carToBeUpdated.setDetails(car.getDetails());
                carToBeUpdated.setLocation(car.getLocation());
                carToBeUpdated.setCondition(car.getCondition());
                return repository.save(carToBeUpdated);
              }).orElseThrow(CarNotFoundException::new);
    }

    return repository.save(car);
  }
/**
   * Either creates or updates a vehicle, based on prior existence of car
   *
   * @param car A car object, which can be either new or existing
   * @return the new/updated car is stored in the repository
   */
Either creates or updates a vehicle, based on prior existence of car
@param car A car object, which can be either new or existing
@return the new/updated car is stored in the repository
Either creates or updates a vehicle based on prior existence of car @param car A car object which can be either new or existing @return the new / updated car is stored in the repository
public Car save(Car car) {
    if (car.getId() != null) {
      return repository.findById(car.getId())
              .map(carToBeUpdated -> {
                carToBeUpdated.setDetails(car.getDetails());
                carToBeUpdated.setLocation(car.getLocation());
                carToBeUpdated.setCondition(car.getCondition());
                return repository.save(carToBeUpdated);
              }).orElseThrow(CarNotFoundException::new);
    }
    return repository.save(car);
  }
public Car save ( Car car ) { if ( car . getId ( ) != null ) { return repository . findById ( car . getId ( ) ) . map ( carToBeUpdated -> { carToBeUpdated . setDetails ( car . getDetails ( ) ) ; carToBeUpdated . setLocation ( car . getLocation ( ) ) ; carToBeUpdated . setCondition ( car . getCondition ( ) ) ; return repository . save ( carToBeUpdated ) ; } ) . orElseThrow ( CarNotFoundException :: new ) ; } return repository . save ( car ) ; }
Either creates or updates a vehicle, based on prior existence of car
 @param car A car object, which can be either new or existing
 @return the new/updated car is stored in the repository
Either creates or updates a vehicle based on prior existence of car @param car A car object which can be either new or existing @return the new / updated car is stored in the repository