1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-21 22:02:06 +01:00

Delete TypedCloneable

This commit is contained in:
Florian Schmaus 2020-06-14 17:38:51 +02:00
parent 18c2c37ad0
commit 3f9ca68134
9 changed files with 67 additions and 61 deletions

View file

@ -22,11 +22,11 @@ import java.util.Locale;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.util.EqualsUtil; import org.jivesoftware.smack.util.EqualsUtil;
import org.jivesoftware.smack.util.HashCode; import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.TypedCloneable;
import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
@ -58,7 +58,7 @@ import org.jxmpp.stringprep.XmppStringprepException;
* @author Matt Tucker * @author Matt Tucker
*/ */
public final class Message extends MessageOrPresence<MessageBuilder> public final class Message extends MessageOrPresence<MessageBuilder>
implements MessageView, TypedCloneable<Message> { implements MessageView {
public static final String ELEMENT = "message"; public static final String ELEMENT = "message";
public static final String BODY = "body"; public static final String BODY = "body";
@ -371,6 +371,16 @@ public final class Message extends MessageOrPresence<MessageBuilder>
return StanzaBuilder.buildMessageFrom(this, getStanzaId()); 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 @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -409,7 +419,10 @@ public final class Message extends MessageOrPresence<MessageBuilder>
* instance. * instance.
* </p> * </p>
* @return a clone of this message. * @return a clone of this message.
* @deprecated use {@link #asBuilder()} instead.
*/ */
// TODO: Remove in Smack 4.5.
@Deprecated
@Override @Override
public Message clone() { public Message clone() {
return new Message(this); return new Message(this);

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2019 Florian Schmaus * Copyright 2019-2020 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
*/ */
package org.jivesoftware.smack.packet; package org.jivesoftware.smack.packet;
import org.jivesoftware.smack.XMPPConnection;
public abstract class MessageOrPresence<MPB extends MessageOrPresenceBuilder<?, ?>> extends Stanza { public abstract class MessageOrPresence<MPB extends MessageOrPresenceBuilder<?, ?>> extends Stanza {
@Deprecated @Deprecated
@ -33,4 +35,8 @@ public abstract class MessageOrPresence<MPB extends MessageOrPresenceBuilder<?,
public abstract MPB asBuilder(); public abstract MPB asBuilder();
public abstract MPB asBuilder(String id);
public abstract MPB asBuilder(XMPPConnection connection);
} }

View file

@ -20,9 +20,9 @@ package org.jivesoftware.smack.packet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.TypedCloneable;
import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
@ -61,7 +61,7 @@ import org.jxmpp.jid.Jid;
* @author Matt Tucker * @author Matt Tucker
*/ */
public final class Presence extends MessageOrPresence<PresenceBuilder> public final class Presence extends MessageOrPresence<PresenceBuilder>
implements PresenceView, TypedCloneable<Presence> { implements PresenceView {
public static final String ELEMENT = "presence"; public static final String ELEMENT = "presence";
@ -282,6 +282,16 @@ public final class Presence extends MessageOrPresence<PresenceBuilder>
return StanzaBuilder.buildPresenceFrom(this, getStanzaId()); 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 @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -343,7 +353,10 @@ public final class Presence extends MessageOrPresence<PresenceBuilder>
* instance. * instance.
* </p> * </p>
* @return a clone of this presence. * @return a clone of this presence.
* @deprecated use {@link #asBuilder()} instead.
*/ */
// TODO: Remove in Smack 4.5.
@Deprecated
@Override @Override
public Presence clone() { public Presence clone() {
return new Presence(this); return new Presence(this);
@ -354,7 +367,10 @@ public final class Presence extends MessageOrPresence<PresenceBuilder>
* *
* @return a "clone" of this presence with a different stanza ID. * @return a "clone" of this presence with a different stanza ID.
* @since 4.1.2 * @since 4.1.2
* @deprecated use {@link #asBuilder(XMPPConnection)} or {@link #asBuilder(String)}instead.
*/ */
// TODO: Remove in Smack 4.5.
@Deprecated
public Presence cloneWithNewId() { public Presence cloneWithNewId() {
Presence clone = clone(); Presence clone = clone();
clone.setNewStanzaId(); clone.setNewStanzaId();

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright © 2015-2019 Florian Schmaus * Copyright © 2015-2020 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,7 +34,7 @@ import java.util.Set;
* @param <K> the type of the keys the map uses. * @param <K> the type of the keys the map uses.
* @param <V> the type of the values the map uses. * @param <V> the type of the values the map uses.
*/ */
public class MultiMap<K, V> implements TypedCloneable<MultiMap<K, V>> { public class MultiMap<K, V> {
/** /**
* The constant value {@value}. * The constant value {@value}.

View file

@ -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 <T> the type returned by {@link #clone()}.
*/
public interface TypedCloneable<T> extends Cloneable {
/**
* Clone this instance.
*
* @return a cloned version of this instance.
*/
T clone();
}

View file

@ -962,8 +962,9 @@ public final class ServiceDiscoveryManager extends Manager {
// to respect ConnectionConfiguration.isSendPresence() // to respect ConnectionConfiguration.isSendPresence()
final Presence presenceSend = this.presenceSend; final Presence presenceSend = this.presenceSend;
if (connection.isAuthenticated() && presenceSend != null) { if (connection.isAuthenticated() && presenceSend != null) {
Presence presence = presenceSend.asBuilder(connection).build();
try { try {
connection.sendStanza(presenceSend.cloneWithNewId()); connection.sendStanza(presence);
} }
catch (InterruptedException | NotConnectedException e) { catch (InterruptedException | NotConnectedException e) {
LOGGER.log(Level.WARNING, "Could could not update presence with caps info", e); LOGGER.log(Level.WARNING, "Could could not update presence with caps info", e);

View file

@ -30,7 +30,6 @@ import org.jivesoftware.smack.packet.IqData;
import org.jivesoftware.smack.util.EqualsUtil; import org.jivesoftware.smack.util.EqualsUtil;
import org.jivesoftware.smack.util.HashCode; import org.jivesoftware.smack.util.HashCode;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.TypedCloneable;
import org.jivesoftware.smack.util.XmlStringBuilder; import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jxmpp.util.XmppStringUtils; import org.jxmpp.util.XmppStringUtils;
@ -44,7 +43,7 @@ import org.jxmpp.util.XmppStringUtils;
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class DiscoverInfo extends IQ implements DiscoverInfoView, TypedCloneable<DiscoverInfo> { public class DiscoverInfo extends IQ implements DiscoverInfoView {
public static final String ELEMENT = QUERY_ELEMENT; public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = "http://jabber.org/protocol/disco#info"; 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); 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 @Override
public DiscoverInfo clone() { public DiscoverInfo clone() {
return new DiscoverInfo(this); 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 * as well as specific feature types of interest, if any (e.g., for the purpose of feature
* negotiation). * negotiation).
*/ */
public static final class Feature implements TypedCloneable<Feature> { public static final class Feature {
private final String variable; private final String variable;
@ -566,11 +571,6 @@ public class DiscoverInfo extends IQ implements DiscoverInfoView, TypedCloneable
return variable.hashCode(); return variable.hashCode();
} }
@Override
public Feature clone() {
return new Feature(this);
}
@Override @Override
public String toString() { public String toString() {
return toXML().toString(); return toXML().toString();

View file

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2015-2016 Florian Schmaus * Copyright 2015-2020 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; since = builder.since;
timeout = builder.timeout; timeout = builder.timeout;
final PresenceBuilder joinPresenceBuilder;
if (builder.joinPresence == null) { if (builder.joinPresence == null) {
joinPresence = builder.joinPresenceBuilder.ofType(Presence.Type.available).build(); joinPresenceBuilder = builder.joinPresenceBuilder.ofType(Presence.Type.available);
} }
else { else {
joinPresence = builder.joinPresence.clone(); joinPresenceBuilder = builder.joinPresence.asBuilder();
} }
// Indicate the the client supports MUC // Indicate the the client supports MUC
joinPresence.addExtension(new MUCInitialPresence(password, maxChars, maxStanzas, seconds, joinPresenceBuilder.addExtension(new MUCInitialPresence(password, maxChars, maxStanzas, seconds,
since)); since));
joinPresence = joinPresenceBuilder.build();
} }
Presence getJoinPresence(MultiUserChat multiUserChat) { Presence getJoinPresence(MultiUserChat multiUserChat) {
@ -92,6 +94,8 @@ public final class MucEnterConfiguration {
private long timeout; private long timeout;
private final PresenceBuilder joinPresenceBuilder; private final PresenceBuilder joinPresenceBuilder;
// TODO: Remove in Smack 4.5.
private Presence joinPresence; private Presence joinPresence;
Builder(Resourcepart nickname, XMPPConnection connection) { Builder(Resourcepart nickname, XMPPConnection connection) {

View file

@ -1047,7 +1047,7 @@ public final class Roster extends Manager {
} }
if (presence == null) { if (presence == null) {
if (unavailable != null) { if (unavailable != null) {
return unavailable.clone(); return unavailable;
} }
else { else {
presence = synthesizeUnvailablePresence(jid); presence = synthesizeUnvailablePresence(jid);
@ -1055,7 +1055,7 @@ public final class Roster extends Manager {
} }
} }
else { else {
return presence.clone(); return presence;
} }
} }
} }
@ -1084,7 +1084,7 @@ public final class Roster extends Manager {
return presence; return presence;
} }
else { else {
return presence.clone(); return presence;
} }
} }
} }
@ -1107,7 +1107,7 @@ public final class Roster extends Manager {
} else { } else {
res = new ArrayList<>(userPresences.values().size()); res = new ArrayList<>(userPresences.values().size());
for (Presence presence : userPresences.values()) { for (Presence presence : userPresences.values()) {
res.add(presence.clone()); res.add(presence);
} }
} }
return res; return res;
@ -1156,7 +1156,7 @@ public final class Roster extends Manager {
Presence unavailable = null; Presence unavailable = null;
for (Presence presence : userPresences.values()) { for (Presence presence : userPresences.values()) {
if (presence.isAvailable()) { if (presence.isAvailable()) {
answer.add(presence.clone()); answer.add(presence);
} }
else { else {
unavailable = presence; unavailable = presence;
@ -1166,7 +1166,7 @@ public final class Roster extends Manager {
res = answer; res = answer;
} }
else if (unavailable != null) { else if (unavailable != null) {
res = Arrays.asList(unavailable.clone()); res = Arrays.asList(unavailable);
} }
else { else {
Presence presence = synthesizeUnvailablePresence(jid); Presence presence = synthesizeUnvailablePresence(jid);