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