com.sfs.beans.UserPreferencesBean.java Source code

Java tutorial

Introduction

Here is the source code for com.sfs.beans.UserPreferencesBean.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.beans;

import java.util.HashMap;

import org.apache.commons.lang.StringUtils;

/**
 * The Class UserPreferencesBean.
 *
 * @author David Harrison 6th September 2004 - modified 4th June 2007
 */
public class UserPreferencesBean implements java.io.Serializable {

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

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

    /** The options. */
    private HashMap<String, String> options;

    /**
     * Sets the dN.
     *
     * @param dnVal the new dN
     */
    public final void setDN(final String dnVal) {
        this.dn = dnVal;
    }

    /**
     * Gets the dN.
     *
     * @return the dN
     */
    public final String getDN() {
        return this.dn;
    }

    /**
     * Reset options.
     */
    public final void resetOptions() {
        this.options = new HashMap<String, String>();
    }

    /**
     * Gets the option.
     *
     * @param index the index
     *
     * @return the option
     */
    public final String getOption(final String index) {
        String strOption = "";
        if (this.options == null) {
            this.options = new HashMap<String, String>();
        }
        if (this.options.containsKey(index)) {
            strOption = this.options.get(index);
        }
        return strOption;
    }

    /**
     * Gets the user preference option as a boolean.
     *
     * @param index the index
     * @return the bl option
     */
    public final boolean getBlOption(final String index) {
        boolean option = false;

        if (StringUtils.equalsIgnoreCase(this.getOption(index), "true")) {
            option = true;
        }
        return option;
    }

    /**
     * Gets the options.
     *
     * @return the options
     */
    public final HashMap<String, String> getOptions() {
        if (this.options != null) {
            return this.options;
        } else {
            return new HashMap<String, String>();
        }
    }

    /**
     * Checks for option.
     *
     * @param index the index
     *
     * @return true, if successful
     */
    public final boolean hasOption(final String index) {
        if (this.options != null) {
            return this.options.containsKey(index);
        }
        return false;
    }

    /**
     * Removes the option.
     *
     * @param index the index
     */
    public final void removeOption(final String index) {
        if (this.options != null && this.options.containsKey(index)) {
            this.options.remove(index);
        }
    }

    /**
     * Sets the option.
     *
     * @param index the index
     * @param value the value
     */
    public final void setOption(final String index, final String value) {
        if (this.options == null) {
            this.options = new HashMap<String, String>();
        }
        if (index != null && index.compareTo("") != 0 && value != null) {
            this.options.put(index, value);
        }
    }
}