Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package model.account;
- /**
- * Implementation of Account Interface.
- *
- */
- public final class ABCAccountImpl implements Account {
- private final String username;
- private String nickname;
- private String password;
- private int bestScore;
- private Settings settings;
- private ABCAccountImpl(final String username, final String nickname, final String password, final int bestScore, final Settings settings) {
- if (username == null || password == null) {
- throw new IllegalArgumentException();
- }
- this.username = username;
- this.nickname = nickname;
- this.password = password;
- this.bestScore = bestScore;
- this.settings = settings;
- }
- /**
- * Create a simple Account.
- * @param username the account username
- * @param password the account password
- * @return the Account
- */
- public static Account createSimpleAccount(final String username, final String password) {
- return new ABCAccountImpl(username, username, password, 0, Settings.DEFAULT);
- }
- /**
- * Create an Account with nickname.
- * @param username the account username
- * @param password the account password
- * @param nickname the account nickname
- * @return the Account
- */
- public static Account createAccountWithNickname(final String username, final String password, final String nickname) {
- if (nickname == null) {
- throw new IllegalArgumentException();
- }
- if (nickname.equals("")) {
- return new ABCAccountImpl(username, username, password, 0, Settings.DEFAULT);
- } else {
- return new ABCAccountImpl(username, nickname, password, 0, Settings.DEFAULT);
- }
- }
- /**
- * Create a complete Account.
- * @param username the account username
- * @param password the account password
- * @param nickname the account nickname
- * @param bestScore the account topScores
- * @param settings the account settings
- * @return the Account
- */
- public static Account createCompleteAccount(final String username, final String password, final String nickname, final int bestScore, final Settings settings) {
- if (nickname == null || bestScore < 0) {
- throw new IllegalArgumentException();
- }
- return new ABCAccountImpl(username, nickname, password, bestScore, settings);
- }
- /**
- * {@inheritDoc}
- */
- public String getUsername() {
- return this.username;
- }
- /**
- * {@inheritDoc}
- */
- public String getNickname() {
- return this.nickname;
- }
- /**
- * {@inheritDoc}
- */
- public String getPassword() {
- return this.password;
- }
- /**
- * {@inheritDoc}
- */
- public int getBestScore() {
- return this.bestScore;
- }
- /**
- * {@inheritDoc}
- */
- public Settings getSettings() {
- return settings;
- }
- /**
- * {@inheritDoc}
- */
- public void setNickname(final String nickname) {
- if (nickname == null) {
- throw new IllegalArgumentException();
- }
- this.nickname = nickname;
- }
- /**
- * {@inheritDoc}
- */
- public void setPassword(final String password) {
- if (password == null) {
- throw new IllegalArgumentException();
- }
- this.password = password;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public void setBestScore(final int bestScore) {
- if (bestScore < 0 || bestScore < this.bestScore) {
- throw new IllegalArgumentException();
- }
- this.bestScore = bestScore;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public void setSettings(final Settings settings) {
- if (settings == null) {
- throw new IllegalArgumentException();
- }
- this.settings = settings;
- }
- /**
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((username == null) ? 0 : username.hashCode());
- return result;
- }
- /**
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof ABCAccountImpl)) {
- return false;
- }
- final ABCAccountImpl other = (ABCAccountImpl) obj;
- if (username == null) {
- if (other.username != null) {
- return false;
- }
- } else if (!username.equals(other.username)) {
- return false;
- }
- return true;
- }
- /**
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "AccountImpl [username=" + username + ", nickname=" + nickname + ", password=" + password + "]";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement