Java tutorial
/******************************************************************************* * 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.ArrayList; import java.util.Collection; import java.util.HashMap; import org.apache.commons.lang.StringUtils; /** * The Class BuilderBean. * * @author David Harrison 10th June 2005 */ public class BuilderBean implements java.io.Serializable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; /** The builder id. */ private int builderId; /** The parameters. */ private HashMap<String, String> parameters; /** The ordering. */ private Collection<String> ordering = new ArrayList<String>(); /** The sections. */ private HashMap<String, BuilderBean> sections; /** The section order. */ private Collection<String> sectionOrder = new ArrayList<String>(); /** * Sets the parameter. * * @param parameter the parameter * @param value the value */ public final void setParameter(final String parameter, final boolean value) { if (value) { setValue(parameter, "true"); } else { setValue(parameter, "false"); } } /** * Sets the parameter. * * @param parameter the parameter * @param value the value */ public final void setParameter(final String parameter, final String value) { setValue(parameter, value); } /** * Gets the boolean. * * @param parameter the parameter * * @return the boolean */ public final boolean getBoolean(final String parameter) { boolean value = false; if (this.parameters != null) { if (this.parameters.containsKey(parameter)) { String stringValue = (String) this.parameters.get(parameter); if (StringUtils.equals(stringValue, "true")) { value = true; } } else { // Check to see if LOAD_ALL flag is set to true, if so return // true and exit if (this.parameters.containsKey("LOAD_ALL")) { String stringValue = (String) this.parameters.get("LOAD_ALL"); if (StringUtils.equals(stringValue, "true")) { value = true; } } } } return value; } /** * Gets the string. * * @param parameter the parameter * * @return the string */ public final String getString(final String parameter) { String value = ""; if (this.parameters != null) { if (this.parameters.containsKey(parameter)) { String stringValue = (String) this.parameters.get(parameter); if (StringUtils.isNotBlank(stringValue)) { value = stringValue; } } } return value; } /** * Gets the builder id. * * @return the builder id */ public final int getBuilderId() { return this.builderId; } /** * Sets the builder id. * * @param builderIdVal the new builder id */ public final void setBuilderId(final int builderIdVal) { this.builderId = builderIdVal; } /** * Gets the order. * * @return the order */ public final Collection<String> getOrder() { if (this.ordering == null) { this.ordering = new ArrayList<String>(); } return this.ordering; } /** * Gets the sections. * * @return the sections */ public final HashMap<String, BuilderBean> getSections() { if (this.sections == null) { this.sections = new HashMap<String, BuilderBean>(); } return this.sections; } /** * Adds the section. * * @param name the name * @param details the details */ public final void addSection(final String name, final BuilderBean details) { if (this.sections == null) { this.sections = new HashMap<String, BuilderBean>(); this.sectionOrder = new ArrayList<String>(); } this.sections.put(name, details); this.sectionOrder.add(name); } /** * Gets the section. * * @param name the name * * @return the section */ public final BuilderBean getSection(final String name) { if (this.sections != null) { if (this.sections.containsKey(name)) { return (BuilderBean) this.sections.get(name); } } return null; } /** * Gets the section order. * * @return the section order */ public final Collection<String> getSectionOrder() { if (this.sectionOrder == null) { this.sectionOrder = new ArrayList<String>(); } return this.sectionOrder; } /** * Sets the value. * * @param parameter the parameter * @param value the value */ private void setValue(final String parameter, final String value) { if (parameter != null) { if (parameter.compareTo("") != 0) { if (value != null) { if (this.parameters == null) { this.parameters = new HashMap<String, String>(); } if (this.ordering == null) { this.ordering = new ArrayList<String>(); } this.parameters.put(parameter, value); this.ordering.add(parameter); } } } } }