Java tutorial
/******************************************************************************* * Educational Online Test Delivery System * Copyright (c) 2013 American Institutes for Research * * Distributed under the AIR Open Source License, Version 1.0 * See accompanying file AIR-License-1_0.txt or at * http://www.smarterapp.org/documents/American_Institutes_for_Research_Open_Source_Software_License.pdf ******************************************************************************/ package org.opentestsystem.shared.mna.client.domain; import java.io.Serializable; import javax.xml.bind.annotation.XmlTransient; import org.apache.commons.lang.StringUtils; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** * Encapsulates the alternate key of server, node, and component. * These are generally required to have values. All these fields must be trimmed and * lowercased for consistency. */ @JsonIgnoreProperties(ignoreUnknown = true) public class MAAlternateKey implements Serializable { /** svUID. */ private static final long serialVersionUID = -7151827701965299677L; private static final int STRING_BUILDER_SIZE = 50; private String server; private String node; private String component; public MAAlternateKey() { // nothing to do } /** * This constructor will automatically trim and lowercase the values passed in. * * @param inServer * @param inNode * @param inComponent */ public MAAlternateKey(final String inServer, final String inNode, final String inComponent) { this.server = cleanValue(inServer); this.node = cleanValue(inNode); this.component = cleanValue(inComponent); } public String getServer() { return server; } public void setServer(final String inServer) { this.server = cleanValue(inServer); } public String getNode() { return node; } public void setNode(final String inNode) { this.node = cleanValue(inNode); } public String getComponent() { return component; } public void setComponent(final String inComponent) { this.component = cleanValue(inComponent); } @Override public String toString() { StringBuilder sbuilder = new StringBuilder(STRING_BUILDER_SIZE); sbuilder.append("MAAlternateKey: { server: "); sbuilder.append(server); sbuilder.append(", node: "); sbuilder.append(node); sbuilder.append(", component: "); sbuilder.append(component); sbuilder.append('}'); return sbuilder.toString(); } /** * Cleans the input by trimming spaces from the ends of the string * and also lowercasing for consistency. * * @param input * @return */ private String cleanValue(final String input) { String rvalue = ""; // NOPMD if (input != null) { rvalue = StringUtils.lowerCase(StringUtils.trim(input)); } return rvalue; } /** * Generates the name string used as an identifier for Hyperic, also used as a cache key * * @return */ @XmlTransient public String getHypericName() { return component + "-" + server + "-" + node; } }