public PlaceRequest toPlaceRequest(String placeToken) throws TokenFormatException {
return unescapedToPlaceRequest(URL.decodeQueryString(placeToken));
}
private PlaceRequest unescapedToPlaceRequest(String unescapedPlaceToken) throws TokenFormatException {
PlaceRequest req = null;
int split = unescapedPlaceToken.indexOf(paramSeparator);
if (split == 0) {
throw new TokenFormatException("Place history token is missing.");
} else if (split == -1) {
req = new PlaceRequest(unescapedPlaceToken);
} else if (split >= 0) {
req = new PlaceRequest(unescapedPlaceToken.substring(0, split));
String paramsChunk = unescapedPlaceToken.substring(split + 1);
String[] paramTokens = paramsChunk.split(paramSeparator);
for (String paramToken : paramTokens) {
if (paramToken.isEmpty()) {
throw new TokenFormatException("Bad parameter: Successive parameters require a single '" + paramSeparator + "' between them.");
}
String[] param = splitParamToken(paramToken);
String key = paramValueUnescape(param[0]);
String value = paramValueUnescape(param[1]);
req = req.with(key, value);
}
}
return req;
}