From 7b2be1a7aeef76a2d2453c58751fe27011ffcb62 Mon Sep 17 00:00:00 2001 From: Maiero Date: Mon, 26 Aug 2019 17:35:55 +0200 Subject: [PATCH] Added equals and hashcode methods in Password API. Signed-off-by: Maiero --- .../eclipse/kura/configuration/Password.java | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/configuration/Password.java b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/configuration/Password.java index 9d1aea91362..21837f2b50d 100644 --- a/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/configuration/Password.java +++ b/kura/org.eclipse.kura.api/src/main/java/org/eclipse/kura/configuration/Password.java @@ -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 @@ -11,6 +11,8 @@ *******************************************************************************/ package org.eclipse.kura.configuration; +import java.util.Arrays; + import org.osgi.annotation.versioning.ProviderType; /** @@ -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; } + }