All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.constretto.model.CArray Maven / Gradle / Ivy

The newest version!
package org.constretto.model;

import org.apache.commons.lang.StringUtils;

import java.util.*;

/**
 * @author Kaare Nilsen
 */
public class CArray extends CValue {
    private final List data;

    public CArray(final List data) {

        if (data == null) {
            throw new NullPointerException("The \"data\" argument can not be null");
        }
        this.data = Arrays.asList(data.toArray(new CValue[]{}));
    }

    public List data() {
        return data == null ? Collections.emptyList() : Collections.unmodifiableList(data);
    }

    @Override
    public Set referencedKeys() {
        Set referencedKeys = new HashSet();
        for (CValue value : data) {
            if (value != null) {
                referencedKeys.addAll(value.referencedKeys());
            }
        }
        return referencedKeys;
    }

    @Override
    public void replace(String key, String resolvedValue) {
        for (CValue value : data) {
            if (value != null) {
                value.replace(key, resolvedValue);
            }
        }
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final CArray cArray = (CArray) o;

        if (data != null ? !data.equals(cArray.data) : cArray.data != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return data != null ? data.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "[" + StringUtils.join(data, ',') + "]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy