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

nl.vpro.domain.media.search.Pager Maven / Gradle / Ivy

Go to download

The basic domain classes for 'media', the core of POMS. Also, the 'update' XML bindings for it. It also contains some closely related domain classes like the enum to contain NICAM kijkwijzer settings.

There is a newer version: 8.3.1
Show newest version
/*
 * Copyright (C) 2010 Licensed under the Apache License, Version 2.0
 * VPRO The Netherlands
 */
package nl.vpro.domain.media.search;

import lombok.Data;
import lombok.ToString;

import org.checkerframework.checker.nullness.qual.Nullable;
import jakarta.validation.constraints.NotNull;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlTransient;


import org.checkerframework.checker.nullness.qual.Nullable;

@XmlTransient
@ToString
@Data
public abstract class Pager {

    public enum Direction {
        ASC,
        DESC
    }

    @XmlElement(required = false)
    @NotNull
    private Long offset = 0L;

    @XmlElement(required = false)
    @Nullable
    private Integer max = null;

    @XmlTransient
    private S sort;

    @XmlElement
    private Direction order = Direction.ASC;

    protected Pager(long offset, Integer max, S sort, Direction order) {
        if (order == null) {
            order = Direction.ASC;
        }
        if(offset < 0 || (max != null && max < 0)) {
            throw new IllegalArgumentException(String.format("Must supply valid arguments, got offset: %1$s, max: %d$s %2$s, sort: %3$s, order: %4$s", offset, max, sort, order));
        }

        this.offset = offset;
        this.max = max;
        this.sort = sort;
        this.order = order;

    }


    public String getSortField() {
        return getSort().name();
    }

    public boolean hasOffset() {
        return offset != null && offset != 0;
    }

    /**
     * @since 7.11
     */
    public Integer getOffsetAsInteger() {
        return offset == null ? null : offset.intValue();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy