com.nec.harvest.bean.mapping.PurchaseBean.java Source code

Java tutorial

Introduction

Here is the source code for com.nec.harvest.bean.mapping.PurchaseBean.java

Source

/*
 * Copyright(C) 2014
 * NEC Corporation All rights reserved.
 * 
 * No permission to use, copy, modify and distribute this software
 * and its documentation for any purpose is granted.
 * This software is provided under applicable license agreement only.
 */
package com.nec.harvest.bean.mapping;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import com.nec.harvest.util.StringUtil;

public class PurchaseBean extends EntityBean implements Comparable<PurchaseBean> {

    private static final long serialVersionUID = -4305233936704283812L;

    private String srsCode;
    private String srsName;
    private String srsNameR;
    private String ctgCode;
    private String ctgName;
    private String ctgNameR;
    private String wakuNum;
    private Integer updNo;
    private Date srDate;
    private long kingaku;
    private String gnrKbn1;

    public PurchaseBean() {
        //
    }

    public PurchaseBean(String srsCode, String srsName, String srsNameR, String ctgCode, String ctgName,
            String ctgNameR, String wakuNum, Integer updNo, Date srDate, long kingaku, String gnrKbn1) {
        super();
        this.srsCode = srsCode;
        this.srsName = srsName;
        this.srsNameR = srsNameR;
        this.ctgCode = ctgCode;
        this.ctgName = ctgName;
        this.ctgNameR = ctgNameR;
        this.wakuNum = wakuNum;
        this.updNo = updNo;
        this.srDate = srDate;
        this.kingaku = kingaku;
        this.gnrKbn1 = gnrKbn1;
    }

    private long bigDecimalToDouble(BigDecimal decimal) {
        if (decimal == null) {
            return 0;
        }
        return decimal.longValue();
    }

    public String getSrsCode() {
        return srsCode;
    }

    public void setSrsCode(String srsCode) {
        this.srsCode = StringUtil.value(srsCode);
    }

    public String getSrsName() {
        return srsName;
    }

    public void setSrsName(String srsName) {
        this.srsName = StringUtil.value(srsName);
    }

    public String getSrsNameR() {
        return srsNameR;
    }

    public void setSrsNameR(String srsNameR) {
        this.srsNameR = StringUtil.value(srsNameR);
    }

    public String getCtgCode() {
        return ctgCode;
    }

    public void setCtgCode(String ctgCode) {
        this.ctgCode = StringUtil.value(ctgCode);
    }

    public String getCtgName() {
        return ctgName;
    }

    public void setCtgName(String ctgName) {
        this.ctgName = StringUtil.value(ctgName);
    }

    public String getCtgNameR() {
        return ctgNameR;
    }

    public void setCtgNameR(String ctgNameR) {
        this.ctgNameR = StringUtil.value(ctgNameR);
    }

    public String getWakuNum() {
        return wakuNum;
    }

    public void setWakuNum(String wakuNum) {
        this.wakuNum = StringUtil.value(wakuNum);
    }

    public Date getSrDate() {
        return srDate;
    }

    public void setSrDate(Date srDate) {
        this.srDate = srDate;
    }

    public long getKingaku() {
        return kingaku;
    }

    public void setKingaku(BigDecimal kingaku) {
        this.kingaku = bigDecimalToDouble(kingaku);
    }

    public String getGnrKbn1() {
        return gnrKbn1;
    }

    public void setGnrKbn1(String gnrKbn1) {
        this.gnrKbn1 = StringUtil.value(gnrKbn1);
    }

    public Integer getUpdNo() {
        return updNo;
    }

    public void setUpdNo(Integer updNo) {
        this.updNo = updNo;
    }

    @Override
    public int compareTo(PurchaseBean purchaseBean) {
        int compareVal = getSrDate().compareTo(purchaseBean.getSrDate());
        if (compareVal < 0) {
            return -1;
        } else if (compareVal > 0) {
            return 1;
        }
        return 0;
    }

    /**
     * Filter a collection by type (any type)
     * 
     * @param collection
     * @param filter
     * @return
     */
    public static List<PurchaseBean> filter(Collection<PurchaseBean> collection, FilterType filterType,
            String filter) {
        if (CollectionUtils.isEmpty(collection)) {
            return (List<PurchaseBean>) collection;
        }

        if (StringUtils.isEmpty(filter)) {
            return (List<PurchaseBean>) collection;
        }

        Iterator<PurchaseBean> itr = collection.iterator();
        while (itr.hasNext()) {
            PurchaseBean obj = itr.next();
            String filterTypeValue = null;
            if (filterType.getValue() == 1) {
                filterTypeValue = obj.getCtgCode();
            } else if (filterType.getValue() == 2) {
                filterTypeValue = obj.getSrsCode();
            } else if (filterType.getValue() == 3) {
                filterTypeValue = obj.getWakuNum();
            }

            if (!filter.equals(filterTypeValue)) {
                itr.remove();
            }
        }
        return (List<PurchaseBean>) collection;
    }

    /**
     * Filter Enum types
     * 
     * @author sondn
     *
     */
    public enum FilterType {
        FILTER_CTG_CODE(1), FILTER_SRC_CODE(2), FILTER_WAKU_NUM(3);

        private int value;

        // Constructor
        private FilterType(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

    }
}