Package com.tap5.hotelbooking.data

Source Code of com.tap5.hotelbooking.data.UserWorkspace

package com.tap5.hotelbooking.data;

import java.util.ArrayList;
import java.util.List;

import com.tap5.hotelbooking.entities.Booking;
import com.tap5.hotelbooking.entities.Hotel;
import com.tap5.hotelbooking.entities.User;

/**
* Use this object to store user's booking. It also provides all the method to handle booking in
* progress for the current user. This object is stored in session when the user starts to book an
* hotel.
*
* @author karesti
*/
public class UserWorkspace
{
    private Booking current;

    private List<Booking> notConfirmed = new ArrayList<Booking>();

    public List<Booking> getNotConfirmed()
    {
        return notConfirmed;
    }

    public Booking getCurrent()
    {
        return current;
    }

    public void startBooking(Hotel hotel, User user)
    {
        Booking booking = new Booking(hotel, user, 1, 1);
        this.current = booking;
        notConfirmed.add(booking);
    }

    private void removeCurrentBooking(Booking booking)
    {
        notConfirmed.remove(booking);
        this.current = null;
    }

    public Booking restoreBooking(Long bookId)
    {
        Booking restoredBooking = null;

        for (Booking booking : notConfirmed)
        {
            if (bookId.equals(booking.getHotel().getId()))
            {
                restoredBooking = booking;
                break;
            }
        }

        this.current = restoredBooking;

        return restoredBooking;
    }

    public void cancelCurrentBooking(Booking booking)
    {
        removeCurrentBooking(booking);
    }

    public void confirmCurrentBooking(Booking booking)
    {
        removeCurrentBooking(booking);
    }

}
TOP

Related Classes of com.tap5.hotelbooking.data.UserWorkspace

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.