Android Open Source - ean-android Reservation






From Project

Back to project page ean-android.

License

The source code is released under:

Copyright (c) 2013, Expedia Affiliate Network All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that redistributions of sour...

If you think the Android project ean-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (c) 2013, Expedia Affiliate Network
 * All rights reserved.//  ww w  .j  a va  2 s  .  c  om
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that redistributions of source code
 * retain the above copyright notice, these conditions, and the following
 * disclaimer. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation are those
 * of the authors and should not be interpreted as representing official policies, 
 * either expressed or implied, of the Expedia Affiliate Network or Expedia Inc.
 */

package com.ean.mobile.hotel;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.json.JSONArray;
import org.json.JSONObject;

import com.ean.mobile.Address;

/**
 * Holds the response from a booking response. Together with an itinerary, represents all information knowable
 * about a particular reservation.
 * Built from the <a href="http://developer.ean.com/docs/read/hotels/version_3/book_reservation/Response_Format">
 *     HotelRoomReservationResponse</a> documentation, as well as experimental results with test bookings.
 */
public final class Reservation implements Comparable<Reservation> {

    /**
     * The formatter used for paring DateTime objects from returned api date fields.
     */
    private static final DateTimeFormatter API_DATE_PARSER = DateTimeFormat.forPattern("MM/dd/YYYY");

    /**
     * EAN's unique ID for the reservation. Used along with the booking confirmation number for any communication
     * that EAN or your own customer service department makes with the customer.
     * Ensure both values are clearly provided to the customer.
     */
    public final long itineraryId;

    /**
     * Confirmation number(s) for the booking, one per room booked.
     * Generated by the Expedia Collect reservation database or from the specific Hotel
     * Collect system used to make the booking.
     * Used along with the itinerary ID for any communication that EAN or your own customer service
     * department makes with the customer. Ensure both values are clearly provided to the customer.
     */
    public final List<Long> confirmationNumbers;

    /**
     * Indicates if the hotel itself confirmed the reservation as it was processed.
     * Always returns as true for Expedia Collect.
     * <br />
     * For Hotel Collect , when returned as false, indicates the property has not yet
     * returned a confirmation number for the reservation.
     * The reservation will likely return with a PS status.
     * <br />
     * In these cases, an EAN agent will monitor the booking until it is fully confirmed.
     * The confirmation email will advise the customer that a confirmation number will be
     * forwarded by an agent as soon as the property provides it.
     */
    public final boolean processedWithConfirmation;

    /**
     * Any error text that may have been generated during the booking process
     * in addition to the contents of the EanWSError common element.
     *
     * Will be null in the case that an error did not occur.
     */
    public final String errorText;

    /**
     * Any information received from the hotel at the time of booking. May be null.
     */
    public final String hotelReplyText;

    /**
     * The supplier used to actually make the booking.
     */
    public final SupplierType supplierType;

    /**
     * Indicates the status of the reservation in the supplier system at the time of booking.
     * Anticipate appropriate customer messaging for all non-confirmed values.
     */
    public final ConfirmationStatus reservationStatusCode;

    /**
     * Indicator for a prevented duplicate booking,
     * used in conjunction with the affiliateConfirmationId request parameter.
     * Returns as true along with the existing successful itinerary
     * if the same confirmation value is sent more than once.
     */
    public final boolean existingItinerary;

    /**
     * Check-in instructions for the hotel.
     */
    public final String checkInInstructions;

    /**
     * The date of check-in.
     */
    public final LocalDate arrivalDate;

    /**
     * The date of check-out.
     */
    public final LocalDate departureDate;

    /**
     * The name of the hotel that this reservation is for.
     */
    public final String hotelName;

    /**
     * The address of the hotel.
     */
    public final Address hotelAddress;

    /**
     * A short description of the room booked.
     */
    public final String roomDescription;

    /**
     * Whether or not this booking is refundable. If the booking is successful and this is set to true,
     * then the amount charged is final and cannot be refunded. Applies only to Expedia Collect.
     */
    public final boolean nonRefundable;

    /**
     * Confirms how many guests are guaranteed for the room booked.
     *
     * If original guest count is lower than this number for a Hotel Collect property,
     * make discrepancy very clear to the customer as extra person charges are likely
     * to be charged by the property at this point.
     */
    public final int rateOccupancyPerRoom;

    /**
     * Cancellation policy for the property. Display required.
     */
    public final CancellationPolicy cancellationPolicy;

    /**
     * The list of rate informations associated with this reservation.
     */
    public final List<Rate> rateInformations;

    /**
     * The cached hashCode for this object.
     */
    private final int hashCache;

    /**
     * Constructs a reservation object from an appropriately structured JSONObject.
     * @param object The appropriately structured JSONObject.
     */
    public Reservation(final JSONObject object) {
        final List<Long> localConfirmationNumbers;
        if (object.optJSONArray("confirmationNumbers") != null) {
            final JSONArray confirmationNumbersJson = object.optJSONArray("confirmationNumbers");
            localConfirmationNumbers = new ArrayList<Long>(confirmationNumbersJson.length());
            for (int i = 0; i < confirmationNumbersJson.length(); i++) {
                localConfirmationNumbers.add(confirmationNumbersJson.optLong(i));
            }
        } else {
            localConfirmationNumbers = Collections.singletonList(object.optLong("confirmationNumbers"));
        }

        this.itineraryId = object.optLong("itineraryId");
        this.confirmationNumbers = Collections.unmodifiableList(localConfirmationNumbers);
        this.processedWithConfirmation = object.optBoolean("processedWithConfirmation");
        this.errorText = object.optString("errorText");
        this.hotelReplyText = object.optString("hotelReplyText");
        this.supplierType = SupplierType.getByCode(object.optString("supplierType"));
        this.reservationStatusCode = ConfirmationStatus.fromString(object.optString("reservationStatusCode"));
        this.existingItinerary = object.optBoolean("existingItinerary");
        this.checkInInstructions = object.optString("checkInInstructions");
        this.arrivalDate = API_DATE_PARSER.parseLocalDate(object.optString("arrivalDate"));
        this.departureDate = API_DATE_PARSER.parseLocalDate(object.optString("departureDate"));
        this.hotelName = object.optString("hotelName");
        final String addressLine1 = object.optString("hotelAddress");
        final String city = object.optString("hotelCity");
        final String stateProvinceCode = object.optString("hotelStateProvinceCode");
        final String countryCode = object.optString("hotelCountryCode");
        final String postalCode = object.optString("hotelPostalCode");
        this.hotelAddress = new Address(Arrays.asList(addressLine1), city, stateProvinceCode, countryCode, postalCode);
        this.roomDescription = object.optString("roomDescription");
        this.nonRefundable = object.optBoolean("nonRefundable");
        this.rateOccupancyPerRoom = object.optInt("rateOccupancyPerRoom");
        this.cancellationPolicy = new CancellationPolicy(object, this.arrivalDate);
        this.rateInformations = Collections.unmodifiableList(Rate.parseFromRateInformations(object));

        final int prime = 31;
        int localHash = new Long(itineraryId).hashCode();
        for (Long confirmationNumber : confirmationNumbers) {
            localHash += prime * confirmationNumber.hashCode();
        }
        this.hashCache = localHash;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(final Object o) {
        return o instanceof Reservation && o.hashCode() == this.hashCode();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return hashCache;
    }

    /**
     * {@inheritDoc}
     *
     * When used as the comparison for Collections.sort or a sorted collection, reservations with later arrival dates
     * will come first.
     */
    @Override
    public int compareTo(final Reservation reservation) {
        return reservation.arrivalDate.compareTo(arrivalDate);
    }
}




Java Source Code List

android.text.Html.java
android.text.Spanned.java
android.util.Log.java
com.ean.mobile.Address.java
com.ean.mobile.Constants.java
com.ean.mobile.CustomerAddress.java
com.ean.mobile.Destination.java
com.ean.mobile.Individual.java
com.ean.mobile.LatLongAddress.java
com.ean.mobile.Name.java
com.ean.mobile.activity.BookingSummary.java
com.ean.mobile.activity.HotelInformation.java
com.ean.mobile.activity.HotelList.java
com.ean.mobile.activity.ReservationDisplay.java
com.ean.mobile.activity.StartupSearch.java
com.ean.mobile.activity.package-info.java
com.ean.mobile.app.HotelImageDrawableMap.java
com.ean.mobile.app.HotelImageDrawable.java
com.ean.mobile.app.ImageFetcher.java
com.ean.mobile.app.SampleApp.java
com.ean.mobile.app.SampleConstants.java
com.ean.mobile.app.StarRating.java
com.ean.mobile.app.package-info.java
com.ean.mobile.exception.CommonParameterValidationException.java
com.ean.mobile.exception.DataValidationException.java
com.ean.mobile.exception.EanWsError.java
com.ean.mobile.exception.UriCreationException.java
com.ean.mobile.exception.UrlRedirectionException.java
com.ean.mobile.exception.package-info.java
com.ean.mobile.hotel.CancellationPolicy.java
com.ean.mobile.hotel.Cancellation.java
com.ean.mobile.hotel.ConfirmationStatus.java
com.ean.mobile.hotel.HotelImageTuple.java
com.ean.mobile.hotel.HotelInformation.java
com.ean.mobile.hotel.HotelList.java
com.ean.mobile.hotel.HotelRoom.java
com.ean.mobile.hotel.Hotel.java
com.ean.mobile.hotel.Itinerary.java
com.ean.mobile.hotel.NightlyRate.java
com.ean.mobile.hotel.Rate.java
com.ean.mobile.hotel.ReservationRoom.java
com.ean.mobile.hotel.Reservation.java
com.ean.mobile.hotel.RoomOccupancy.java
com.ean.mobile.hotel.SupplierType.java
com.ean.mobile.hotel.request.BookingRequest.java
com.ean.mobile.hotel.request.CancellationRequest.java
com.ean.mobile.hotel.request.InformationRequest.java
com.ean.mobile.hotel.request.ItineraryRequest.java
com.ean.mobile.hotel.request.ListRequest.java
com.ean.mobile.hotel.request.RoomAvailabilityRequest.java
com.ean.mobile.hotel.request.package-info.java
com.ean.mobile.hotel.package-info.java
com.ean.mobile.request.CommonParameters.java
com.ean.mobile.request.DestinationRequest.java
com.ean.mobile.request.RequestProcessor.java
com.ean.mobile.request.Request.java
com.ean.mobile.request.package-info.java
com.ean.mobile.task.ImageDrawableLoaderTask.java
com.ean.mobile.task.SuggestionFactory.java
com.ean.mobile.task.package-info.java
com.ean.mobile.package-info.java