Java Reference
In-Depth Information
seats.put(seat.getId(), seat);
}
@Lock(READ)
public Collection<Seat> getSeats() {
return
Collections.unmodifiableCollection( seats.values() );
}
@Lock(READ)
public int getSeatPrice(int seatId) throws
NoSuchSeatException {
return getSeat(seatId).getPrice();
}
@Lock(WRITE)
public void buyTicket(int seatId) throws
SeatBookedException, NoSuchSeatException {
final Seat seat = getSeat(seatId);
if (seat.isBooked()) {
throw new SeatBookedException("Seat " + seatId
+ " already booked!");
}
addSeat(seat.getBookedSeat());
}
@Lock(READ)
private Seat getSeat(int seatId) throws
NoSuchSeatException {
final Seat seat = cache.get(seatId);
if (seat == null) {
throw new NoSuchSeatException("Seat " + seatId
+ " does not exist!");
}
return seat;
}
}
Search WWH ::




Custom Search