Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private static final Pattern NEXT_PAGE_URL_PATTERN = Pattern.compile("/page/(\\d+)$");

    public static String constructNextPageBookSearchUrl(String currentBookSearchUrl, int currentPage) {
        final Matcher matcher = NEXT_PAGE_URL_PATTERN.matcher(currentBookSearchUrl);
        if (matcher.find()) {
            currentPage = Integer.parseInt(matcher.group(1));
            currentPage++;

            String cleanedBookSearchUrl = currentBookSearchUrl.replaceAll("(\\d+)$", "");
            return cleanedBookSearchUrl + currentPage;
        } else {
            currentPage++;
            return currentBookSearchUrl + "/page/" + currentPage;
        }
    }
}