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

com.addc.commons.slp.StringAttributeValue Maven / Gradle / Ivy

Go to download

The addc-slp library supplies client classes for registering objects with a Service Location Protocol Daemon and for looking theses objects up later.

There is a newer version: 2.6
Show newest version
package com.addc.commons.slp;

/**
 * The StringAttributeValue supplies an attribute value containing a UTF-8
 * string wghich cannot contain the characters '\\n', '\\r', '\\t', '_' or '*'
 */
public class StringAttributeValue implements AttributeValue {
    private final String value;

    /**
     * Create a new AttributeValue
     * 
     * @param value
     *            The String value
     */
    public StringAttributeValue(String value) {
        super();
        if (SLPAttributeHelper.getInstance().containsBadTag(value)) {
            throw new IllegalArgumentException("Value cannot contain bad tags ('\\n', '\\r', '\\t', '_', '*')");
        }
        this.value= value;
    }

    @Override
    public String getValue() {
        return value;
    }

    @Override
    public String getClassName() {
        return String.class.getSimpleName();
    }

    @Override
    public String getEscapedString() {
        return SLPAttributeHelper.getInstance().escapeString(value);
    }

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

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof StringAttributeValue)) {
            return false;
        }
        StringAttributeValue other= (StringAttributeValue) obj;
        if (!value.equals(other.value)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return value;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy