From 3f9ca68134961841103c07ffd0bef638ad74718b Mon Sep 17 00:00:00 2001
From: Florian Schmaus
Date: Sun, 14 Jun 2020 17:38:51 +0200
Subject: [PATCH] Delete TypedCloneable
---
.../jivesoftware/smack/packet/Message.java | 17 ++++++++--
.../smack/packet/MessageOrPresence.java | 8 ++++-
.../jivesoftware/smack/packet/Presence.java | 20 +++++++++--
.../org/jivesoftware/smack/util/MultiMap.java | 4 +--
.../smack/util/TypedCloneable.java | 34 -------------------
.../smackx/disco/ServiceDiscoveryManager.java | 3 +-
.../smackx/disco/packet/DiscoverInfo.java | 18 +++++-----
.../smackx/muc/MucEnterConfiguration.java | 12 ++++---
.../org/jivesoftware/smack/roster/Roster.java | 12 +++----
9 files changed, 67 insertions(+), 61 deletions(-)
delete mode 100644 smack-core/src/main/java/org/jivesoftware/smack/util/TypedCloneable.java
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
index c424e339e..a85f7c5b6 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java
@@ -22,11 +22,11 @@ import java.util.Locale;
import javax.xml.namespace.QName;
+import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.util.EqualsUtil;
import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils;
-import org.jivesoftware.smack.util.TypedCloneable;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jxmpp.jid.Jid;
@@ -58,7 +58,7 @@ import org.jxmpp.stringprep.XmppStringprepException;
* @author Matt Tucker
*/
public final class Message extends MessageOrPresence
- implements MessageView, TypedCloneable {
+ implements MessageView {
public static final String ELEMENT = "message";
public static final String BODY = "body";
@@ -371,6 +371,16 @@ public final class Message extends MessageOrPresence
return StanzaBuilder.buildMessageFrom(this, getStanzaId());
}
+ @Override
+ public MessageBuilder asBuilder(String id) {
+ return StanzaBuilder.buildMessageFrom(this, id);
+ }
+
+ @Override
+ public MessageBuilder asBuilder(XMPPConnection connection) {
+ return connection.getStanzaFactory().buildMessageStanzaFrom(this);
+ }
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -409,7 +419,10 @@ public final class Message extends MessageOrPresence
* instance.
*
* @return a clone of this message.
+ * @deprecated use {@link #asBuilder()} instead.
*/
+ // TODO: Remove in Smack 4.5.
+ @Deprecated
@Override
public Message clone() {
return new Message(this);
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/MessageOrPresence.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/MessageOrPresence.java
index c885e941c..f48b794a0 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/packet/MessageOrPresence.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/MessageOrPresence.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2019 Florian Schmaus
+ * Copyright 2019-2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
*/
package org.jivesoftware.smack.packet;
+import org.jivesoftware.smack.XMPPConnection;
+
public abstract class MessageOrPresence> extends Stanza {
@Deprecated
@@ -33,4 +35,8 @@ public abstract class MessageOrPresence
- implements PresenceView, TypedCloneable {
+ implements PresenceView {
public static final String ELEMENT = "presence";
@@ -282,6 +282,16 @@ public final class Presence extends MessageOrPresence
return StanzaBuilder.buildPresenceFrom(this, getStanzaId());
}
+ @Override
+ public PresenceBuilder asBuilder(String id) {
+ return StanzaBuilder.buildPresenceFrom(this, id);
+ }
+
+ @Override
+ public PresenceBuilder asBuilder(XMPPConnection connection) {
+ return connection.getStanzaFactory().buildPresenceStanzaFrom(this);
+ }
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -343,7 +353,10 @@ public final class Presence extends MessageOrPresence
* instance.
*
* @return a clone of this presence.
+ * @deprecated use {@link #asBuilder()} instead.
*/
+ // TODO: Remove in Smack 4.5.
+ @Deprecated
@Override
public Presence clone() {
return new Presence(this);
@@ -354,7 +367,10 @@ public final class Presence extends MessageOrPresence
*
* @return a "clone" of this presence with a different stanza ID.
* @since 4.1.2
+ * @deprecated use {@link #asBuilder(XMPPConnection)} or {@link #asBuilder(String)}instead.
*/
+ // TODO: Remove in Smack 4.5.
+ @Deprecated
public Presence cloneWithNewId() {
Presence clone = clone();
clone.setNewStanzaId();
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/MultiMap.java b/smack-core/src/main/java/org/jivesoftware/smack/util/MultiMap.java
index daa3241a8..f7dcad596 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/MultiMap.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/MultiMap.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright © 2015-2019 Florian Schmaus
+ * Copyright © 2015-2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ import java.util.Set;
* @param the type of the keys the map uses.
* @param the type of the values the map uses.
*/
-public class MultiMap implements TypedCloneable> {
+public class MultiMap {
/**
* The constant value {@value}.
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/TypedCloneable.java b/smack-core/src/main/java/org/jivesoftware/smack/util/TypedCloneable.java
deleted file mode 100644
index 0a2121845..000000000
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/TypedCloneable.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- *
- * Copyright 2015 Florian Schmaus
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jivesoftware.smack.util;
-
-/**
- * An extended version of {@link java.lang.Cloneable}, which defines a generic {@link #clone()}
- * method.
- *
- * @param the type returned by {@link #clone()}.
- */
-public interface TypedCloneable extends Cloneable {
-
- /**
- * Clone this instance.
- *
- * @return a cloned version of this instance.
- */
- T clone();
-
-}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java
index 61103d2ee..312b559b5 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java
@@ -962,8 +962,9 @@ public final class ServiceDiscoveryManager extends Manager {
// to respect ConnectionConfiguration.isSendPresence()
final Presence presenceSend = this.presenceSend;
if (connection.isAuthenticated() && presenceSend != null) {
+ Presence presence = presenceSend.asBuilder(connection).build();
try {
- connection.sendStanza(presenceSend.cloneWithNewId());
+ connection.sendStanza(presence);
}
catch (InterruptedException | NotConnectedException e) {
LOGGER.log(Level.WARNING, "Could could not update presence with caps info", e);
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java
index 7de48f1be..b4d3f7554 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/packet/DiscoverInfo.java
@@ -30,7 +30,6 @@ import org.jivesoftware.smack.packet.IqData;
import org.jivesoftware.smack.util.EqualsUtil;
import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smack.util.StringUtils;
-import org.jivesoftware.smack.util.TypedCloneable;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jxmpp.util.XmppStringUtils;
@@ -44,7 +43,7 @@ import org.jxmpp.util.XmppStringUtils;
*
* @author Gaston Dombiak
*/
-public class DiscoverInfo extends IQ implements DiscoverInfoView, TypedCloneable {
+public class DiscoverInfo extends IQ implements DiscoverInfoView {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = "http://jabber.org/protocol/disco#info";
@@ -303,7 +302,13 @@ public class DiscoverInfo extends IQ implements DiscoverInfoView, TypedCloneable
return new DiscoverInfoBuilder(this, stanzaId);
}
- // TODO: Deprecate in favor of asBuilder().
+ /**
+ * Deprecated, do not use.
+ *
+ * @deprecated use {@link #asBuilder(String)} instead.
+ */
+ // TODO: Remove in Smack 4.5.
+ @Deprecated
@Override
public DiscoverInfo clone() {
return new DiscoverInfo(this);
@@ -516,7 +521,7 @@ public class DiscoverInfo extends IQ implements DiscoverInfoView, TypedCloneable
* as well as specific feature types of interest, if any (e.g., for the purpose of feature
* negotiation).
*/
- public static final class Feature implements TypedCloneable {
+ public static final class Feature {
private final String variable;
@@ -566,11 +571,6 @@ public class DiscoverInfo extends IQ implements DiscoverInfoView, TypedCloneable
return variable.hashCode();
}
- @Override
- public Feature clone() {
- return new Feature(this);
- }
-
@Override
public String toString() {
return toXML().toString();
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucEnterConfiguration.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucEnterConfiguration.java
index de2b6606e..8a6b4b2fd 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucEnterConfiguration.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MucEnterConfiguration.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2015-2016 Florian Schmaus
+ * Copyright 2015-2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,15 +60,17 @@ public final class MucEnterConfiguration {
since = builder.since;
timeout = builder.timeout;
+ final PresenceBuilder joinPresenceBuilder;
if (builder.joinPresence == null) {
- joinPresence = builder.joinPresenceBuilder.ofType(Presence.Type.available).build();
+ joinPresenceBuilder = builder.joinPresenceBuilder.ofType(Presence.Type.available);
}
else {
- joinPresence = builder.joinPresence.clone();
+ joinPresenceBuilder = builder.joinPresence.asBuilder();
}
// Indicate the the client supports MUC
- joinPresence.addExtension(new MUCInitialPresence(password, maxChars, maxStanzas, seconds,
+ joinPresenceBuilder.addExtension(new MUCInitialPresence(password, maxChars, maxStanzas, seconds,
since));
+ joinPresence = joinPresenceBuilder.build();
}
Presence getJoinPresence(MultiUserChat multiUserChat) {
@@ -92,6 +94,8 @@ public final class MucEnterConfiguration {
private long timeout;
private final PresenceBuilder joinPresenceBuilder;
+
+ // TODO: Remove in Smack 4.5.
private Presence joinPresence;
Builder(Resourcepart nickname, XMPPConnection connection) {
diff --git a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java
index dd05ac97b..02ee0d7e1 100644
--- a/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java
+++ b/smack-im/src/main/java/org/jivesoftware/smack/roster/Roster.java
@@ -1047,7 +1047,7 @@ public final class Roster extends Manager {
}
if (presence == null) {
if (unavailable != null) {
- return unavailable.clone();
+ return unavailable;
}
else {
presence = synthesizeUnvailablePresence(jid);
@@ -1055,7 +1055,7 @@ public final class Roster extends Manager {
}
}
else {
- return presence.clone();
+ return presence;
}
}
}
@@ -1084,7 +1084,7 @@ public final class Roster extends Manager {
return presence;
}
else {
- return presence.clone();
+ return presence;
}
}
}
@@ -1107,7 +1107,7 @@ public final class Roster extends Manager {
} else {
res = new ArrayList<>(userPresences.values().size());
for (Presence presence : userPresences.values()) {
- res.add(presence.clone());
+ res.add(presence);
}
}
return res;
@@ -1156,7 +1156,7 @@ public final class Roster extends Manager {
Presence unavailable = null;
for (Presence presence : userPresences.values()) {
if (presence.isAvailable()) {
- answer.add(presence.clone());
+ answer.add(presence);
}
else {
unavailable = presence;
@@ -1166,7 +1166,7 @@ public final class Roster extends Manager {
res = answer;
}
else if (unavailable != null) {
- res = Arrays.asList(unavailable.clone());
+ res = Arrays.asList(unavailable);
}
else {
Presence presence = synthesizeUnvailablePresence(jid);