@ken3013

Как Конвертировать код с java в php?

Для того что-бы организовать постраничный вывод, владелец API пишет пример на Java. В Java вообще не понимаю ничего, объясните как это понять и реализовать на php ??


This article explains how to add a paginating system for hotel list results using the cacheKey and cacheLocation parameters.

Instructions
Use a List or an Array to save the cacheKey and a List or an Array to save the cacheLocation.

For example, you have made the first list request, and you received the response for the first page, which also includes the cacheKey and cacheLocation for the second page.

Make two lists in which you will save the cacheKey and cacheLocation:

List cacheKeyList = new ArrayList();
cacheKeyList.add(cacheKey); // where cacheKey is being received in the Hotel List response and is used for requesting the next page

List cacheLocationList = new ArrayList();
cacheLocationList.add(cacheLocation); // where cacheLocation is being received in the Hotel List response and is used for requesting the next page

By using cacheKeyList[0] and cacheLocationList[0] in your next Hotel List request, you will receive the response for page 2.

Now, for every request that you do, the cache keys and cache locations for every page are being stored in your list, and for example, if you are at page 5 and you want to go at page 3, all you have to do is make a request using cacheKeyList[1] and cacheLocationList[1].

Also, the lists should be reinitialized after about 30 minutes, as the cacheKey and cacheLocation will expire.

In addition to the above example, you will have to shorten the list to the size of the current page you're on because once you use the cache key and the cache location for a previous page than the one you're on, the new cache key and cache location that you will receive for the next page will be different from the one you had for that next page. For example:

You are on page 5 and you saved the cacheKey and cacheLocation for page 6 in cacheKey[4] and cacheLocation[4]. You go to the previous page, which is page 4 using cacheKey[2] and cacheLocation[2]. You now have to delete all the records from the lists that are past [2] (3rd record in the list) before receiving the response of page 4. For example cacheKey[3] and cacheLocation[3] should not exist at this very moment. After this has been done, you will receive the response with page 4 of hotels and the cacheKey and cacheLocation for page 5, which will be added to cacheKey[3] and cacheLocation[3].

In order to get to the first page, you have to make the initial request, without the cacheKey and cacheLocation.

More information
Initial request without cacheKey and cacheLocation - used to request page 1 of hotels
cacheKey[0] , cacheLocation[0] - used to request page 2 of hotels
cacheKey[1] , cacheLocation[1] - used to request page 3 of hotels
cacheKey[2] , cacheLocation[2] - used to request page 4 of hotels

..............................................................................................................

cacheKey[n] , cacheLocation[n] - used to request page n+2 of hotels

Notice
Please note that the example provided is written in Java and depending on the developing language you are using, this may not work. This should be used as a reference and not copy/pasted in your application.
  • Вопрос задан
  • 2928 просмотров
Пригласить эксперта
Ответы на вопрос 2
@ken3013 Автор вопроса
cacheKey=-5d14faf0:14a06e0f8df:6c74&
cacheLocation=10.186.170.129:7300
Ответ написан
Комментировать
gbg
@gbg
Любые ответы на любые вопросы
Сервис в каждом ответе присылает новые cacheKey и cacheLocation, отправив которые ему в ответ в следующем запросе вы получите следующий элемент списка отелей.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
23 нояб. 2024, в 01:31
1000 руб./за проект
23 нояб. 2024, в 00:16
2000 руб./за проект
22 нояб. 2024, в 23:55
3000 руб./за проект