Project Report: fawkez

Packagesummary org.jcoderz.commons.connector

org.jcoderz.commons.connector.UserPassword

LineHitsNoteSource
1  /*
2   * $Id: UserPassword.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.connector;
34  
35  /**
36   * Provides UserName and Password.
37   *
38   */
39 (1)public final class UserPassword
40  {
41     /** A UserPassword instance with a null userName and null password. */
42100    public static final UserPassword EMPTY_USER_PASSWORD = new UserPassword ();
43  
44     private final String mUser;
45     private final String mPassword;
46     private final int mHashCode;
47  
48     private UserPassword (UserPassword up)
490    {
500       mHashCode = up.mHashCode;
510       mUser = up.mUser;
520       mPassword = up.mPassword;
530    }
54  
55     private UserPassword ()
56     {
57100       this(null, null);
58100    }
59  
60     private UserPassword (String user, String password)
61100    {
62100       mUser = user;
63100       mPassword = password;
64100       mHashCode = new StringBuffer(UserPassword.class.getName()).append(mUser)
65              .append(mPassword).toString().hashCode();
66100    }
67  
68     /**
69      * Constructs a new UserPassword instance containing exactly the same user
70      * and password as the <code>up</code> instance provides.
71      *
72      * @param up The UserPassword instance to be cloned.
73      *
74      * @return a new UserPassword instance containing the same user and
75      *    password as the <code>up</code> instance provides.
76      */
77     public static UserPassword fromUserPassword (UserPassword up)
78     {
79        final UserPassword result;
80100       if (EMPTY_USER_PASSWORD.equals(up))
81        {
82100          result = EMPTY_USER_PASSWORD;
83        }
84        else
85        {
860          result = new UserPassword(up);
87        }
88  
89100       return result;
90     }
91  
92     /**
93      * Returns a new UserPassword instance wrapping the given <code>user</code>
94      * and <code>password</code>.
95      *
96      * @param user UserName
97      * @param password Password
98      *
99      * @return a new UserPassword instance wrapping the given <code>user</code>
100      *    and <code>password</code>.
101      */
102     public static UserPassword fromUserPassword (final String user,
103           final String password)
104     {
105        final UserPassword result;
106100       if (user == null && password == null)
107        {
108100          result = EMPTY_USER_PASSWORD;
109        }
110        else
111        {
112100          result = new UserPassword(user, password);
113        }
114  
115100       return result;
116     }
117  
118  
119     /**
120      * @return Returns the Password.
121      */
122     public String getPassword ()
123     {
1240       return mPassword;
125     }
126     /**
127      * @return Returns the User.
128      */
129     public String getUserName ()
130     {
131100       return mUser;
132     }
133  
134     /**
135      * Returns true if the UserPassword instance <code>up</code> contains a null
136      * UserName and null Password.
137      *
138      * @param up UserPassword to be checked.
139      *
140      * @return true if the UserPassword instance <code>up</code> contains a null
141      * UserName and null Password; otherwise false.
142      */
143     public static boolean isEmpty (UserPassword up)
144     {
145100       return UserPassword.EMPTY_USER_PASSWORD.equals(up);
146     }
147  
148     /** {@inheritDoc} */
149     public boolean equals (Object other)
150     {
151100       boolean result = false;
152100       if (this == other)
153        {
154100          result = true;
155        }
156100       else if (other != null)
157        {
158100          if (mHashCode == other.hashCode() && other instanceof UserPassword)
159           {
160100             final UserPassword up = (UserPassword) other;
16180             result = isStringsEquals(mUser, up.mUser)
162                    && isStringsEquals(mPassword, up.mPassword);
163           }
164        }
165  
166100       return result;
167     }
168  
169     /** {@inheritDoc} */
170     public int hashCode ()
171     {
172100       return mHashCode;
173     }
174  
175     private static boolean isStringsEquals (final String a, final String b)
176     {
177100       boolean equals = false;
178100       if (a == null && b == null)
179        {
180100          equals = true;
181        }
182100       else if (a != null && a.equals(b))
183        {
184100          equals = true;
185        }
186100       return equals;
187     }
188  
189     /** {@inheritDoc} */
190     public String toString ()
191     {
192100       return new StringBuffer("<UserPassword user: '").append(mUser)
193           .append("', password: 'xxx'>").toString();
194     }
195  }

Findings in this File

c (1) 39 : 0 Type Javadoc comment is missing an @author tag.