All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cc.common.mybatis.Pageable Maven / Gradle / Ivy

There is a newer version: 2020.07.21.1
Show newest version
package com.cc.common.mybatis;

import com.cc.common.exception.BadUserInputException;
import com.cc.common.exception.BasedException;

import java.util.HashMap;
import java.util.Map;

public class Pageable {
    private static final int LIMIT = 150;
    private int limit;
    private int offset;

    public Pageable() {
    }

    public Pageable(int limit, int offset) throws BasedException {
        Map errors = new HashMap<>();

        if (offset < 0) {
            errors.put("offset", "invalid user input");
        }
        if (limit > LIMIT) {
            errors.put("limit", String.format("invalid user input limit > %d", LIMIT));
        }
        if (!errors.isEmpty()) {
            throw new BadUserInputException(errors);
        }


        this.limit = limit;
        this.offset = offset;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) throws BasedException {
        if (limit > LIMIT) {
            Map error = Map.of("limit", String.format("invalid user input limit > %d", LIMIT));
            throw new BadUserInputException(error);
        }

        this.limit = limit;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) throws BasedException {
        if (offset < 0) {
            throw new BadUserInputException(Map.of("offset", "invalid user input"));
        }

        this.offset = offset;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy