001/**
002 *
003 * Copyright 2020 Paul Schaub
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.urldata.element;
018
019import org.jivesoftware.smack.packet.NamedElement;
020import org.jivesoftware.smack.packet.XmlEnvironment;
021import org.jivesoftware.smack.util.EqualsUtil;
022import org.jivesoftware.smack.util.HashCode;
023import org.jivesoftware.smack.util.XmlStringBuilder;
024
025public class DescElement implements NamedElement {
026
027    public static final String ELEMENT = "desc";
028
029    private final String desc;
030
031    public DescElement(String desc) {
032        this.desc = desc;
033    }
034
035    public String getDesc() {
036        return desc;
037    }
038
039    @Override
040    public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
041        return new XmlStringBuilder(this)
042                .rightAngleBracket()
043                .append(getDesc())
044                .closeElement(this);
045    }
046
047    @Override
048    public String getElementName() {
049        return ELEMENT;
050    }
051
052    @Override
053    public int hashCode() {
054        return HashCode.builder()
055                .append(getElementName())
056                .append(getDesc())
057                .build();
058    }
059
060    @Override
061    public boolean equals(Object obj) {
062        return EqualsUtil.equals(this, obj, (equalsBuilder, other) ->
063                equalsBuilder
064                        .append(getElementName(), other.getElementName())
065                        .append(getDesc(), other.getDesc()));
066    }
067}