/*
 * oxCore is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.persist.model;

import java.util.Arrays;

import org.gluu.util.ArrayHelper;
import org.gluu.util.StringHelper;

/**
 * LDAP Attribute
 *
 * @author Yuriy Movchan Date: 10.10.2010
 */
public class AttributeData {
    private final String name;
    private final Object[] values;
    private Boolean multiValued;

    public AttributeData(String name, Object[] values) {
    	this(name, values, null);
    }

    public AttributeData(String name, Object[] values, Boolean multiValued) {
        this.name = name;
        this.values = values;
        this.multiValued = multiValued;
    }

    public AttributeData(String name, Object value) {
        this.name = name;
        this.values = new Object[1];
        this.values[0] = value;
        this.multiValued = null;
    }

    public final String getName() {
        return name;
    }

    public final Object[] getValues() {
        return values;
    }

    public final String[] getStringValues() {
    	return StringHelper.toStringArray(this.values);
    }

    public Object getValue() {
        if ((this.values == null) || (this.values.length == 0)) {
            return null;
        }

        return this.values[0];
    }

	public void setMultiValued(Boolean multiValued) {
		this.multiValued = multiValued;
	}

	public Boolean getMultiValued() {
		return multiValued;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((multiValued == null) ? 0 : multiValued.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + Arrays.deepHashCode(values);
		return result;
	}

    @Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AttributeData other = (AttributeData) obj;
		if (multiValued == null) {
			if (other.multiValued != null)
				return false;
		} else if (!multiValued.equals(other.multiValued))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (!Arrays.deepEquals(values, other.values))
			return false;
		return true;
	}

    @Override
	public String toString() {
		return "AttributeData [name=" + name + ", values=" + Arrays.toString(values) + ", multiValued=" + multiValued + "]";
	}

}

@@ -2025,16 +2025,17 @@
 j;%0A%09%09if 
+(
 (multiVa
@@ -2039,25 +2039,25 @@
 iValued 
-=
+!
 = null) 
 %7B%0A%09%09%09if 
@@ -2040,39 +2040,34 @@
 Valued != null) 
-%7B%0A%09%09%09if
+&&
  (other.multiVal
@@ -2082,36 +2082,15 @@
 ull)
+) %7B
 %0A%09%09%09
-%09return false;%0A%09%09%7D else 
 if (
@@ -2128,24 +2128,25 @@
 Valued))%0A%09%09%09
+%09
 return false
@@ -2143,24 +2143,28 @@
 turn false;%0A
+%09%09%7D%0A
 %09%09if (name =

Check multivalued only if both bean has this value