com.sfs.whichdoctor.beans.GroupBean.java Source code

Java tutorial

Introduction

Here is the source code for com.sfs.whichdoctor.beans.GroupBean.java

Source

/*******************************************************************************
 * Copyright (c) 2009 David Harrison.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl-3.0.html
 *
 * Contributors:
 *     David Harrison - initial API and implementation
 ******************************************************************************/
package com.sfs.whichdoctor.beans;

import java.util.Collection;
import java.util.TreeMap;
import java.util.ArrayList;

import org.apache.commons.lang.StringUtils;

/**
 * The Class GroupBean.
 *
 * @author David Harrison 30th May 2003
 */
public class GroupBean extends WhichDoctorCoreBean {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /** The name. */
    private String name;

    /** The type. */
    private String type;

    /** The item count. */
    private int itemCount;

    /** The cast vote count. */
    private int castVoteCount;

    /** The eligible vote count. */
    private int eligibleVoteCount;

    /** The year holds the year of the election (only valid for elections). */
    private int year;

    /** The colour. */
    private String colour;

    /** The weighting. */
    private int weighting;

    /** The group dn. */
    private String groupDN;

    /** The permission. */
    private String permission;

    /** The items. */
    private TreeMap<String, ItemBean> items = new TreeMap<String, ItemBean>();

    /** The votes cast. */
    private TreeMap<Integer, VoteBean> votesCast = new TreeMap<Integer, VoteBean>();

    /** The candidates. */
    private Collection<CandidateBean> candidates = new ArrayList<CandidateBean>();

    /**
     * Sets the name.
     *
     * @param nameVal the new name
     */
    public final void setName(final String nameVal) {
        this.name = nameVal;
    }

    /**
     * Gets the name.
     *
     * @return the name
     */
    public final String getName() {
        if (this.name == null) {
            this.name = "";
        }
        return this.name;
    }

    /**
     * Sets the type.
     *
     * @param typeVal the new type
     */
    public final void setType(final String typeVal) {
        this.type = typeVal;
    }

    /**
     * Gets the type.
     *
     * @return the type
     */
    public final String getType() {
        return this.type;
    }

    /**
     * Gets the election group.
     *
     * @return the election group
     */
    public final boolean getElectionGroup() {
        boolean displayYear = false;
        if (getType() != null) {
            if (getType().compareToIgnoreCase("Election") == 0) {
                displayYear = true;
            }
        }
        return displayYear;
    }

    /**
     * Sets the year.
     *
     * @param yearVal the new year
     */
    public final void setYear(final int yearVal) {
        this.year = yearVal;
    }

    /**
     * Gets the year.
     *
     * @return the year
     */
    public final int getYear() {
        return this.year;
    }

    /**
     * Gets the year as string.
     *
     * @return the year as string
     */
    public final String getYearAsString() {
        String strYear = "";
        if (this.year > 0) {
            strYear = String.valueOf(this.year);
        }
        return strYear;
    }

    /**
     * Sets the colour.
     *
     * @param colourVal the new colour
     */
    public final void setColour(final String colourVal) {
        this.colour = colourVal;
    }

    /**
     * Gets the colour.
     *
     * @return the colour
     */
    public final String getColour() {
        if (this.colour == null) {
            this.colour = "";
        }
        if (this.colour.compareTo("") == 0) {
            this.colour = "#FFFFFF";
        }
        return this.colour;
    }

    /**
     * Sets the weighting.
     *
     * @param weightingVal the new weighting
     */
    public final void setWeighting(final int weightingVal) {
        this.weighting = weightingVal;
    }

    /**
     * Gets the weighting.
     *
     * @return the weighting
     */
    public final int getWeighting() {
        return this.weighting;
    }

    /**
     * Sets the item count.
     *
     * @param itemCountVal the new item count
     */
    public final void setItemCount(final int itemCountVal) {
        this.itemCount = itemCountVal;
    }

    /**
     * Gets the item count.
     *
     * @return the item count
     */
    public final int getItemCount() {
        int intItemCount = this.itemCount;

        if (this.items != null) {
            if (this.items.size() > 0) {
                intItemCount = this.items.size();
            }
        }
        return intItemCount;
    }

    /**
     * Sets the permission.
     *
     * @param permissionVal the new permission
     */
    public final void setPermission(final String permissionVal) {
        this.permission = permissionVal;
    }

    /**
     * Gets the permission.
     *
     * @return the permission
     */
    public final String getPermission() {
        return this.permission;
    }

    /**
     * Sets the group dn.
     *
     * @param groupDNVal the new group dn
     */
    public final void setGroupDN(final String groupDNVal) {
        this.groupDN = groupDNVal;
    }

    /**
     * Gets the group dn.
     *
     * @return the group dn
     */
    public final String getGroupDN() {
        if (StringUtils.isBlank(this.groupDN) || StringUtils.equalsIgnoreCase(this.groupDN, "null")) {
            this.groupDN = "";
        }
        return this.groupDN;
    }

    /**
     * Sets the items.
     *
     * @param itemsVal the items
     */
    public final void setItems(final TreeMap<String, ItemBean> itemsVal) {
        this.items = itemsVal;
    }

    /**
     * Gets the items.
     *
     * @return the items
     */
    public final TreeMap<String, ItemBean> getItems() {
        if (this.items == null) {
            this.items = new TreeMap<String, ItemBean>();
        }
        return this.items;
    }

    /**
     * Sets the votes cast.
     *
     * @param votesCastVal the votes cast
     */
    public final void setVotesCast(final TreeMap<Integer, VoteBean> votesCastVal) {
        this.votesCast = votesCastVal;
    }

    /**
     * Gets the votes cast.
     *
     * @return the votes cast
     */
    public final TreeMap<Integer, VoteBean> getVotesCast() {
        if (this.votesCast == null) {
            this.votesCast = new TreeMap<Integer, VoteBean>();
        }
        return this.votesCast;
    }

    /**
     * Sets the cast vote count.
     *
     * @param castVoteCountVal the new cast vote count
     */
    public final void setCastVoteCount(final int castVoteCountVal) {
        this.castVoteCount = castVoteCountVal;
    }

    /**
     * Gets the cast vote count.
     *
     * @return the cast vote count
     */
    public final int getCastVoteCount() {
        return this.castVoteCount;
    }

    /**
     * Sets the eligible vote count.
     *
     * @param eligibleVoteCountVal the new eligible vote count
     */
    public final void setEligibleVoteCount(final int eligibleVoteCountVal) {
        this.eligibleVoteCount = eligibleVoteCountVal;
    }

    /**
     * Gets the eligible vote count.
     *
     * @return the eligible vote count
     */
    public final int getEligibleVoteCount() {
        return this.eligibleVoteCount;
    }

    /**
     * Gets the outstanding vote count.
     *
     * @return the outstanding vote count
     */
    public final int getOutstandingVoteCount() {
        return this.eligibleVoteCount - this.castVoteCount;
    }

    /**
     * Sets the candidates.
     *
     * @param candidatesVal the new candidates
     */
    public final void setCandidates(final Collection<CandidateBean> candidatesVal) {
        this.candidates = candidatesVal;
    }

    /**
     * Gets the candidates.
     *
     * @return the candidates
     */
    public final Collection<CandidateBean> getCandidates() {
        if (this.candidates == null) {
            this.candidates = new ArrayList<CandidateBean>();
        }
        return this.candidates;
    }

    /**
     * Gets the order index.
     *
     * @return the order index
     */
    public final String getOrderIndex() {
        return this.getName() + "_" + this.getGUID();
    }
}