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

com.github.lontime.extjobrunr.beans.PageBean Maven / Gradle / Ivy

package com.github.lontime.extjobrunr.beans;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.github.lontime.extbeans.BeanHelper;
import org.jobrunr.jobs.Job;
import org.jobrunr.jobs.RecurringJob;
import org.jobrunr.storage.Page;
import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.MetaProperty;
import org.joda.beans.Property;
import org.joda.beans.gen.BeanDefinition;
import org.joda.beans.gen.PropertyDefinition;
import org.joda.beans.impl.direct.DirectBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;

@BeanDefinition
public class PageBean implements Bean {
    @PropertyDefinition
    private Long total;

    @PropertyDefinition
    private Long offset;

    @PropertyDefinition
    private Integer limit;

    @PropertyDefinition
    private List> items;

    @PropertyDefinition
    private Integer currentPage;

    @PropertyDefinition
    private Integer totalPages;

    @PropertyDefinition
    private Boolean hasPrevious;

    @PropertyDefinition
    private Boolean hasNext;

    public PageBean() {
    }

    public PageBean(Page page) {
        this.total = page.getTotal();
        this.offset = page.getOffset();
        this.limit = page.getLimit();
        final List items = page.getItems();
        final List> beans = new ArrayList<>(items.size());
        for (int i = 0; i < items.size(); i++) {
            final Object o = items.get(i);
            if (o instanceof Job) {
                beans.add(BeanHelper.beanToMap(new JobBean((Job) o)));
            } else if (o instanceof RecurringJob) {
                beans.add(BeanHelper.beanToMap(new RecurringJobBean((RecurringJob) o)));
            }
        }
        this.items = beans;
        this.currentPage = page.getCurrentPage();
        this.totalPages = page.getTotalPages();
        this.hasPrevious = page.hasPrevious();
        this.hasNext = page.hasNext();
    }
    //------------------------- AUTOGENERATED START -------------------------
    /**
     * The meta-bean for {@code PageBean}.
     * @return the meta-bean, not null
     */
    public static PageBean.Meta meta() {
        return PageBean.Meta.INSTANCE;
    }

    static {
        MetaBean.register(PageBean.Meta.INSTANCE);
    }

    @Override
    public PageBean.Meta metaBean() {
        return PageBean.Meta.INSTANCE;
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the total.
     * @return the value of the property
     */
    public Long getTotal() {
        return total;
    }

    /**
     * Sets the total.
     * @param total  the new value of the property
     */
    public void setTotal(Long total) {
        this.total = total;
    }

    /**
     * Gets the the {@code total} property.
     * @return the property, not null
     */
    public final Property total() {
        return metaBean().total().createProperty(this);
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the offset.
     * @return the value of the property
     */
    public Long getOffset() {
        return offset;
    }

    /**
     * Sets the offset.
     * @param offset  the new value of the property
     */
    public void setOffset(Long offset) {
        this.offset = offset;
    }

    /**
     * Gets the the {@code offset} property.
     * @return the property, not null
     */
    public final Property offset() {
        return metaBean().offset().createProperty(this);
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the limit.
     * @return the value of the property
     */
    public Integer getLimit() {
        return limit;
    }

    /**
     * Sets the limit.
     * @param limit  the new value of the property
     */
    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    /**
     * Gets the the {@code limit} property.
     * @return the property, not null
     */
    public final Property limit() {
        return metaBean().limit().createProperty(this);
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the items.
     * @return the value of the property
     */
    public List> getItems() {
        return items;
    }

    /**
     * Sets the items.
     * @param items  the new value of the property
     */
    public void setItems(List> items) {
        this.items = items;
    }

    /**
     * Gets the the {@code items} property.
     * @return the property, not null
     */
    public final Property>> items() {
        return metaBean().items().createProperty(this);
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the currentPage.
     * @return the value of the property
     */
    public Integer getCurrentPage() {
        return currentPage;
    }

    /**
     * Sets the currentPage.
     * @param currentPage  the new value of the property
     */
    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    /**
     * Gets the the {@code currentPage} property.
     * @return the property, not null
     */
    public final Property currentPage() {
        return metaBean().currentPage().createProperty(this);
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the totalPages.
     * @return the value of the property
     */
    public Integer getTotalPages() {
        return totalPages;
    }

    /**
     * Sets the totalPages.
     * @param totalPages  the new value of the property
     */
    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }

    /**
     * Gets the the {@code totalPages} property.
     * @return the property, not null
     */
    public final Property totalPages() {
        return metaBean().totalPages().createProperty(this);
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the hasPrevious.
     * @return the value of the property
     */
    public Boolean getHasPrevious() {
        return hasPrevious;
    }

    /**
     * Sets the hasPrevious.
     * @param hasPrevious  the new value of the property
     */
    public void setHasPrevious(Boolean hasPrevious) {
        this.hasPrevious = hasPrevious;
    }

    /**
     * Gets the the {@code hasPrevious} property.
     * @return the property, not null
     */
    public final Property hasPrevious() {
        return metaBean().hasPrevious().createProperty(this);
    }

    //-----------------------------------------------------------------------
    /**
     * Gets the hasNext.
     * @return the value of the property
     */
    public Boolean getHasNext() {
        return hasNext;
    }

    /**
     * Sets the hasNext.
     * @param hasNext  the new value of the property
     */
    public void setHasNext(Boolean hasNext) {
        this.hasNext = hasNext;
    }

    /**
     * Gets the the {@code hasNext} property.
     * @return the property, not null
     */
    public final Property hasNext() {
        return metaBean().hasNext().createProperty(this);
    }

    //-----------------------------------------------------------------------
    @Override
    public PageBean clone() {
        return JodaBeanUtils.cloneAlways(this);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj != null && obj.getClass() == this.getClass()) {
            PageBean other = (PageBean) obj;
            return JodaBeanUtils.equal(getTotal(), other.getTotal()) &&
                    JodaBeanUtils.equal(getOffset(), other.getOffset()) &&
                    JodaBeanUtils.equal(getLimit(), other.getLimit()) &&
                    JodaBeanUtils.equal(getItems(), other.getItems()) &&
                    JodaBeanUtils.equal(getCurrentPage(), other.getCurrentPage()) &&
                    JodaBeanUtils.equal(getTotalPages(), other.getTotalPages()) &&
                    JodaBeanUtils.equal(getHasPrevious(), other.getHasPrevious()) &&
                    JodaBeanUtils.equal(getHasNext(), other.getHasNext());
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = getClass().hashCode();
        hash = hash * 31 + JodaBeanUtils.hashCode(getTotal());
        hash = hash * 31 + JodaBeanUtils.hashCode(getOffset());
        hash = hash * 31 + JodaBeanUtils.hashCode(getLimit());
        hash = hash * 31 + JodaBeanUtils.hashCode(getItems());
        hash = hash * 31 + JodaBeanUtils.hashCode(getCurrentPage());
        hash = hash * 31 + JodaBeanUtils.hashCode(getTotalPages());
        hash = hash * 31 + JodaBeanUtils.hashCode(getHasPrevious());
        hash = hash * 31 + JodaBeanUtils.hashCode(getHasNext());
        return hash;
    }

    @Override
    public String toString() {
        StringBuilder buf = new StringBuilder(288);
        buf.append("PageBean{");
        int len = buf.length();
        toString(buf);
        if (buf.length() > len) {
            buf.setLength(buf.length() - 2);
        }
        buf.append('}');
        return buf.toString();
    }

    protected void toString(StringBuilder buf) {
        buf.append("total").append('=').append(JodaBeanUtils.toString(getTotal())).append(',').append(' ');
        buf.append("offset").append('=').append(JodaBeanUtils.toString(getOffset())).append(',').append(' ');
        buf.append("limit").append('=').append(JodaBeanUtils.toString(getLimit())).append(',').append(' ');
        buf.append("items").append('=').append(JodaBeanUtils.toString(getItems())).append(',').append(' ');
        buf.append("currentPage").append('=').append(JodaBeanUtils.toString(getCurrentPage())).append(',').append(' ');
        buf.append("totalPages").append('=').append(JodaBeanUtils.toString(getTotalPages())).append(',').append(' ');
        buf.append("hasPrevious").append('=').append(JodaBeanUtils.toString(getHasPrevious())).append(',').append(' ');
        buf.append("hasNext").append('=').append(JodaBeanUtils.toString(getHasNext())).append(',').append(' ');
    }

    //-----------------------------------------------------------------------
    /**
     * The meta-bean for {@code PageBean}.
     */
    public static class Meta extends DirectMetaBean {
        /**
         * The singleton instance of the meta-bean.
         */
        static final Meta INSTANCE = new Meta();

        /**
         * The meta-property for the {@code total} property.
         */
        private final MetaProperty total = DirectMetaProperty.ofReadWrite(
                this, "total", PageBean.class, Long.class);
        /**
         * The meta-property for the {@code offset} property.
         */
        private final MetaProperty offset = DirectMetaProperty.ofReadWrite(
                this, "offset", PageBean.class, Long.class);
        /**
         * The meta-property for the {@code limit} property.
         */
        private final MetaProperty limit = DirectMetaProperty.ofReadWrite(
                this, "limit", PageBean.class, Integer.class);
        /**
         * The meta-property for the {@code items} property.
         */
        @SuppressWarnings({"unchecked", "rawtypes" })
        private final MetaProperty>> items = DirectMetaProperty.ofReadWrite(
                this, "items", PageBean.class, (Class) List.class);
        /**
         * The meta-property for the {@code currentPage} property.
         */
        private final MetaProperty currentPage = DirectMetaProperty.ofReadWrite(
                this, "currentPage", PageBean.class, Integer.class);
        /**
         * The meta-property for the {@code totalPages} property.
         */
        private final MetaProperty totalPages = DirectMetaProperty.ofReadWrite(
                this, "totalPages", PageBean.class, Integer.class);
        /**
         * The meta-property for the {@code hasPrevious} property.
         */
        private final MetaProperty hasPrevious = DirectMetaProperty.ofReadWrite(
                this, "hasPrevious", PageBean.class, Boolean.class);
        /**
         * The meta-property for the {@code hasNext} property.
         */
        private final MetaProperty hasNext = DirectMetaProperty.ofReadWrite(
                this, "hasNext", PageBean.class, Boolean.class);
        /**
         * The meta-properties.
         */
        private final Map> metaPropertyMap$ = new DirectMetaPropertyMap(
                this, null,
                "total",
                "offset",
                "limit",
                "items",
                "currentPage",
                "totalPages",
                "hasPrevious",
                "hasNext");

        /**
         * Restricted constructor.
         */
        protected Meta() {
        }

        @Override
        protected MetaProperty metaPropertyGet(String propertyName) {
            switch (propertyName.hashCode()) {
                case 110549828:  // total
                    return total;
                case -1019779949:  // offset
                    return offset;
                case 102976443:  // limit
                    return limit;
                case 100526016:  // items
                    return items;
                case 601108392:  // currentPage
                    return currentPage;
                case -719810848:  // totalPages
                    return totalPages;
                case 1600681905:  // hasPrevious
                    return hasPrevious;
                case 696759469:  // hasNext
                    return hasNext;
            }
            return super.metaPropertyGet(propertyName);
        }

        @Override
        public BeanBuilder builder() {
            return new DirectBeanBuilder<>(new PageBean());
        }

        @Override
        public Class beanType() {
            return PageBean.class;
        }

        @Override
        public Map> metaPropertyMap() {
            return metaPropertyMap$;
        }

        //-----------------------------------------------------------------------
        /**
         * The meta-property for the {@code total} property.
         * @return the meta-property, not null
         */
        public final MetaProperty total() {
            return total;
        }

        /**
         * The meta-property for the {@code offset} property.
         * @return the meta-property, not null
         */
        public final MetaProperty offset() {
            return offset;
        }

        /**
         * The meta-property for the {@code limit} property.
         * @return the meta-property, not null
         */
        public final MetaProperty limit() {
            return limit;
        }

        /**
         * The meta-property for the {@code items} property.
         * @return the meta-property, not null
         */
        public final MetaProperty>> items() {
            return items;
        }

        /**
         * The meta-property for the {@code currentPage} property.
         * @return the meta-property, not null
         */
        public final MetaProperty currentPage() {
            return currentPage;
        }

        /**
         * The meta-property for the {@code totalPages} property.
         * @return the meta-property, not null
         */
        public final MetaProperty totalPages() {
            return totalPages;
        }

        /**
         * The meta-property for the {@code hasPrevious} property.
         * @return the meta-property, not null
         */
        public final MetaProperty hasPrevious() {
            return hasPrevious;
        }

        /**
         * The meta-property for the {@code hasNext} property.
         * @return the meta-property, not null
         */
        public final MetaProperty hasNext() {
            return hasNext;
        }

        //-----------------------------------------------------------------------
        @Override
        protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
            switch (propertyName.hashCode()) {
                case 110549828:  // total
                    return ((PageBean) bean).getTotal();
                case -1019779949:  // offset
                    return ((PageBean) bean).getOffset();
                case 102976443:  // limit
                    return ((PageBean) bean).getLimit();
                case 100526016:  // items
                    return ((PageBean) bean).getItems();
                case 601108392:  // currentPage
                    return ((PageBean) bean).getCurrentPage();
                case -719810848:  // totalPages
                    return ((PageBean) bean).getTotalPages();
                case 1600681905:  // hasPrevious
                    return ((PageBean) bean).getHasPrevious();
                case 696759469:  // hasNext
                    return ((PageBean) bean).getHasNext();
            }
            return super.propertyGet(bean, propertyName, quiet);
        }

        @SuppressWarnings("unchecked")
        @Override
        protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
            switch (propertyName.hashCode()) {
                case 110549828:  // total
                    ((PageBean) bean).setTotal((Long) newValue);
                    return;
                case -1019779949:  // offset
                    ((PageBean) bean).setOffset((Long) newValue);
                    return;
                case 102976443:  // limit
                    ((PageBean) bean).setLimit((Integer) newValue);
                    return;
                case 100526016:  // items
                    ((PageBean) bean).setItems((List>) newValue);
                    return;
                case 601108392:  // currentPage
                    ((PageBean) bean).setCurrentPage((Integer) newValue);
                    return;
                case -719810848:  // totalPages
                    ((PageBean) bean).setTotalPages((Integer) newValue);
                    return;
                case 1600681905:  // hasPrevious
                    ((PageBean) bean).setHasPrevious((Boolean) newValue);
                    return;
                case 696759469:  // hasNext
                    ((PageBean) bean).setHasNext((Boolean) newValue);
                    return;
            }
            super.propertySet(bean, propertyName, newValue, quiet);
        }

    }

    //-------------------------- AUTOGENERATED END --------------------------
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy