001/* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2016 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 029package edu.wisc.ssec.mcidasv.servermanager; 030 031import static java.util.Objects.requireNonNull; 032 033/** 034 * Simplistic representation of ADDE accounting information. This is an 035 * immutable class. 036 */ 037public 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 username = requireNonNull(user, "user cannot be null"); 056 project = requireNonNull(proj, "proj cannot be null"); 057 } 058 059 /** 060 * Get the username associated with this account. 061 * 062 * @return {@link #username} 063 */ 064 public String getUsername() { 065 return username; 066 } 067 068 /** 069 * Get the project number associated with this account. 070 * 071 * @return {@link #project} 072 */ 073 public String getProject() { 074 return project; 075 } 076 077 /** 078 * Determines whether or not a given object is equivalent to this ADDE 079 * account. Currently the username and project number <b>are</b> case 080 * sensitive, though this is likely to change. 081 * 082 * @param obj Object to test against. 083 * 084 * @return Whether or not {@code obj} is equivalent to this ADDE account. 085 */ 086 @Override public boolean equals(Object obj) { 087 if (this == obj) { 088 return true; 089 } 090 if (obj == null) { 091 return false; 092 } 093 if (!(obj instanceof AddeAccount)) { 094 return false; 095 } 096 AddeAccount other = (AddeAccount) obj; 097 if (!project.equals(other.project)) { 098 return false; 099 } 100 if (!username.equals(other.username)) { 101 return false; 102 } 103 return true; 104 } 105 106 /** 107 * Computes the hashcode of this ADDE account using the hashcodes of 108 * {@link #username} and {@link #project}. 109 * 110 * @return A hash code value for this object. 111 */ 112 @Override public int hashCode() { 113 final int prime = 31; 114 int result = 1; 115 result = prime * result + project.hashCode(); 116 result = prime * result + username.hashCode(); 117 return result; 118 } 119 120 /** 121 * Returns a string representation of this account. 122 * 123 * The formatting of this string is subject to change, but currently looks 124 * like {@code [AddeAccount@HASHCODE: username=..., project=...]}. 125 * 126 * @return {@link String} representation of this ADDE account. 127 */ 128 public String toString() { 129 return String.format("[AddeAccount@%x: username=%s, project=%s]", hashCode(), username, project); 130 } 131 132 /** 133 * Returns a {@literal "human-friendly"} representation of this accounting 134 * object. Currently looks like {@code USER / PROJ}. 135 * 136 * @return Friendly accounting detail {@code String}. 137 */ 138 public String friendlyString() { 139 return username+" / "+project; 140 } 141}