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.stanza_content_encryption.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.Objects; 023import org.jivesoftware.smack.util.XmlStringBuilder; 024 025import org.jxmpp.jid.Jid; 026 027public abstract class JidAffixElement implements NamedElement, AffixElement { 028 029 public static final String ATTR_JID = "jid"; 030 031 private final Jid jid; 032 033 public JidAffixElement(Jid jid) { 034 this.jid = Objects.requireNonNull(jid, "Value of 'jid' MUST NOT be null."); 035 } 036 037 public Jid getJid() { 038 return jid; 039 } 040 041 @Override 042 public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) { 043 return new XmlStringBuilder(this) 044 .attribute(ATTR_JID, getJid()) 045 .closeEmptyElement(); 046 } 047 048 @Override 049 public final boolean equals(Object obj) { 050 return EqualsUtil.equals(this, obj, (e, o) -> e.append(getJid(), o.getJid()).append(getElementName(), o.getElementName())); 051 } 052 053 @Override 054 public final int hashCode() { 055 return (getElementName() + getJid().toString()).hashCode(); 056 } 057}