Skip to content

Commit

Permalink
Added equals and hashcode methods in Password API.
Browse files Browse the repository at this point in the history
Signed-off-by: Maiero <matteo.maiero@eurotech.com>
  • Loading branch information
MMaiero committed Aug 26, 2019
1 parent 18a0dd5 commit 7b2be1a
Showing 1 changed file with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2016 Eurotech and/or its affiliates
* Copyright (c) 2011, 2019 Eurotech and/or its affiliates
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -11,6 +11,8 @@
*******************************************************************************/
package org.eclipse.kura.configuration;

import java.util.Arrays;

import org.osgi.annotation.versioning.ProviderType;

/**
Expand All @@ -19,26 +21,53 @@
@ProviderType
public class Password {

private char[] m_password;
private char[] value;

public Password(String password) {
super();
if (password != null) {
this.m_password = password.toCharArray();
this.value = password.toCharArray();
}
}

public Password(char[] password) {
super();
this.m_password = password;
this.value = password;
}

public char[] getPassword() {
return this.m_password;
return this.value;
}

@Override
public String toString() {
return new String(this.m_password);
return new String(this.value);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(this.value);
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Password other = (Password) obj;
if (!Arrays.equals(this.value, other.value)) {
return false;
}
return true;
}

}

0 comments on commit 7b2be1a

Please sign in to comment.