001 /*
002 * $Id: AddeAccount.java,v 1.11 2012/02/19 17:35:48 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2012
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 *
012 * All Rights Reserved
013 *
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.
016 *
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 *
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
025 * GNU Lesser Public License for more details.
026 *
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program. If not, see http://www.gnu.org/licenses.
029 */
030
031 package edu.wisc.ssec.mcidasv.servermanager;
032
033 /**
034 * Simplistic representation of ADDE accounting information. This is an
035 * immutable class.
036 */
037 public class AddeAccount {
038
039 /** Username to hand off to the server. */
040 private final String username;
041
042 /** Project number (currently not limited to a numeric value). */
043 private final String project;
044
045 /**
046 * Builds a new ADDE account object.
047 *
048 * @param user Username to store. Cannot be {@code null}.
049 * @param proj Project number to store. Cannot be {@code null}.
050 *
051 * @throws NullPointerException if {@code user} or {@code proj} is
052 * {@code null}.
053 */
054 public AddeAccount(final String user, final String proj) {
055 if (user == null) {
056 throw new NullPointerException();
057 }
058 if (proj == null) {
059 throw new NullPointerException();
060 }
061 username = user;
062 project = proj;
063 }
064
065 /**
066 * Get the username associated with this account.
067 *
068 * @return {@link #username}
069 */
070 public String getUsername() {
071 return username;
072 }
073
074 /**
075 * Get the project number associated with this account.
076 *
077 * @return {@link #project}
078 */
079 public String getProject() {
080 return project;
081 }
082
083 /**
084 * Determines whether or not a given object is equivalent to this ADDE
085 * account. Currently the username and project number <b>are</b> case
086 * sensitive, though this is likely to change.
087 *
088 * @param obj Object to test against.
089 *
090 * @return Whether or not {@code obj} is equivalent to this ADDE account.
091 */
092 @Override public boolean equals(Object obj) {
093 if (this == obj) {
094 return true;
095 }
096 if (obj == null) {
097 return false;
098 }
099 if (!(obj instanceof AddeAccount)) {
100 return false;
101 }
102 AddeAccount other = (AddeAccount) obj;
103 if (project == null) {
104 if (other.project != null) {
105 return false;
106 }
107 } else if (!project.equals(other.project)) {
108 return false;
109 }
110 if (username == null) {
111 if (other.username != null) {
112 return false;
113 }
114 } else if (!username.equals(other.username)) {
115 return false;
116 }
117 return true;
118 }
119
120 /**
121 * Computes the hashcode of this ADDE account using the hashcodes of
122 * {@link #username} and {@link #project}.
123 *
124 * @return A hash code value for this object.
125 */
126 @Override public int hashCode() {
127 final int prime = 31;
128 int result = 1;
129 result = prime * result + ((project == null) ? 0 : project.hashCode());
130 result = prime * result
131 + ((username == null) ? 0 : username.hashCode());
132 return result;
133 }
134
135 /**
136 * Returns a string representation of this account. The formatting of
137 * this string is subject to change, but currently looks like:<br/>
138 * <pre>[AddeAccount@HASHCODE: username=..., project=...]</pre>
139 *
140 * @return {@link String} representation of this ADDE account.
141 */
142 public String toString() {
143 return String.format("[AddeAccount@%x: username=%s, project=%s]", hashCode(), username, project);
144 }
145
146 /**
147 * Returns a {@literal "human-friendly"} representation of this accounting
148 * object. Currently looks like {@code USER / PROJ}.
149 *
150 * @return Friendly accounting detail {@code String}.
151 */
152 public String friendlyString() {
153 return username+" / "+project;
154 }
155 }