mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 05:52:06 +01:00
Add copy constructor to Message and Presence
and also implement Cloneable and add clone() methods.
This commit is contained in:
parent
bc3bbb5bb4
commit
e9dd3e2fa6
2 changed files with 62 additions and 2 deletions
|
@ -50,7 +50,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
*
|
*
|
||||||
* @author Matt Tucker
|
* @author Matt Tucker
|
||||||
*/
|
*/
|
||||||
public final class Message extends Stanza {
|
public final class Message extends Stanza implements Cloneable {
|
||||||
|
|
||||||
public static final String ELEMENT = "message";
|
public static final String ELEMENT = "message";
|
||||||
public static final String BODY = "body";
|
public static final String BODY = "body";
|
||||||
|
@ -98,6 +98,23 @@ public final class Message extends Stanza {
|
||||||
setBody(body);
|
setBody(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy constructor.
|
||||||
|
* <p>
|
||||||
|
* This does not perform a deep clone, as extension elements are shared between the new and old
|
||||||
|
* instance.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param other
|
||||||
|
*/
|
||||||
|
public Message(Message other) {
|
||||||
|
super(other);
|
||||||
|
this.type = other.type;
|
||||||
|
this.thread = other.thread;
|
||||||
|
this.subjects.addAll(other.subjects);
|
||||||
|
this.bodies.addAll(other.bodies);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of the message. If no type has been set this method will return {@link
|
* Returns the type of the message. If no type has been set this method will return {@link
|
||||||
* org.jivesoftware.smack.packet.Message.Type#normal}.
|
* org.jivesoftware.smack.packet.Message.Type#normal}.
|
||||||
|
@ -445,6 +462,19 @@ public final class Message extends Stanza {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and returns a copy of this message stanza.
|
||||||
|
* <p>
|
||||||
|
* This does not perform a deep clone, as extension elements are shared between the new and old
|
||||||
|
* instance.
|
||||||
|
* </p>
|
||||||
|
* @return a clone of this message.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Message clone() {
|
||||||
|
return new Message(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a message subject, its language and the content of the subject.
|
* Represents a message subject, its language and the content of the subject.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -55,7 +55,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
*
|
*
|
||||||
* @author Matt Tucker
|
* @author Matt Tucker
|
||||||
*/
|
*/
|
||||||
public final class Presence extends Stanza {
|
public final class Presence extends Stanza implements Cloneable {
|
||||||
|
|
||||||
public static final String ELEMENT = "presence";
|
public static final String ELEMENT = "presence";
|
||||||
|
|
||||||
|
@ -88,6 +88,23 @@ public final class Presence extends Stanza {
|
||||||
setMode(mode);
|
setMode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy constructor.
|
||||||
|
* <p>
|
||||||
|
* This does not perform a deep clone, as extension elements are shared between the new and old
|
||||||
|
* instance.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param other
|
||||||
|
*/
|
||||||
|
public Presence(Presence other) {
|
||||||
|
super(other);
|
||||||
|
this.type = other.type;
|
||||||
|
this.status = other.status;
|
||||||
|
this.priority = other.priority;
|
||||||
|
this.mode = other.mode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the {@link Type presence type} is available (online) and
|
* Returns true if the {@link Type presence type} is available (online) and
|
||||||
* false if the user is unavailable (offline), or if this is a presence packet
|
* false if the user is unavailable (offline), or if this is a presence packet
|
||||||
|
@ -228,6 +245,19 @@ public final class Presence extends Stanza {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and returns a copy of this presence stanza.
|
||||||
|
* <p>
|
||||||
|
* This does not perform a deep clone, as extension elements are shared between the new and old
|
||||||
|
* instance.
|
||||||
|
* </p>
|
||||||
|
* @return a clone of this presence.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Presence clone() {
|
||||||
|
return new Presence(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An enum to represent the presence type. Note that presence type is often confused
|
* An enum to represent the presence type. Note that presence type is often confused
|
||||||
* with presence mode. Generally, if a user is signed in to a server, they have a presence
|
* with presence mode. Generally, if a user is signed in to a server, they have a presence
|
||||||
|
|
Loading…
Reference in a new issue