Android URL Create buildQueries(String baseQuery, List datesByQueryIndex)

Here you can find the source of buildQueries(String baseQuery, List datesByQueryIndex)

Description

build Queries

License

Open Source License

Declaration

static Map<String, String> buildQueries(String baseQuery,
            List<Date> datesByQueryIndex) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w. ja  va  2 s . c om*/
 * Copyright (c) 2010-2012 Mark Allen.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.util.Date;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Main {
    private static final long SECONDS_IN_DAY = 60 * 60 * 24;

    static Map<String, String> buildQueries(String baseQuery,
            List<Date> datesByQueryIndex) {
        Map<String, String> fqlByQueryIndex = new LinkedHashMap<String, String>();
        for (int queryIndex = 0; queryIndex < datesByQueryIndex.size(); queryIndex++) {
            Date d = datesByQueryIndex.get(queryIndex);
            String query = baseQuery + convertToUnixTimeOneDayLater(d);
            fqlByQueryIndex.put(String.valueOf(queryIndex), query);
        }
        return fqlByQueryIndex;
    }

    /**
     * Converts into a "unix time", which means convert into the number of seconds (NOT milliseconds) from the Epoch fit
     * for the Facebook Query Language. Notice that if you want data for September 15th then you need to present to
     * Facebook the NEXT DAY, ie. the upper exclusive limit of your date range. So beyond all the sliding to midnight code
     * you see in {@link #convertToMidnightInPacificTimeZone(Date)}, we need to go further and slide this input date
     * forward one day.
     * 
     * In retrospect, this should have been implemented via the Facebook end_time_date() function.
     * 
     * @param date
     *          The date to convert.
     * @return Unix time representation of the given {@code date}.
     */
    static long convertToUnixTimeOneDayLater(Date date) {
        long time = date.getTime() / 1000L;
        // note we cannot use a Daylight sensitive Calendar here since that would
        // adjust the time incorrectly over the DST junction
        time += SECONDS_IN_DAY;
        return time;
    }
}

Related

  1. generateQueryJson(Map params)
  2. generateQueryString(Map params)
  3. mapToQueryString( HashMap queryString)
  4. buildEmailUri(String email, String subject, CharSequence body)
  5. url(String baseUrl, String relativePath)
  6. url(String baseUrl, String relativePath)
  7. createUrl(final String rootUrl, final String indivisualHost, final String featurePath, final int index, List pairs)