mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 20:12:07 +01:00
Deduplicate code ChatMarkersElements
by introducing ChatMarkerExtensionWithId.
This commit is contained in:
parent
36bfa060a5
commit
0778485243
1 changed files with 37 additions and 69 deletions
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Fernando Ramirez
|
||||
* Copyright © 2016 Fernando Ramirez, 2018 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -76,24 +76,10 @@ public class ChatMarkersElements {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Received extension class.
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public static class ReceivedExtension implements ExtensionElement {
|
||||
protected abstract static class ChatMarkerExtensionWithId implements ExtensionElement {
|
||||
protected final String id;
|
||||
|
||||
/**
|
||||
* received element.
|
||||
*/
|
||||
public static final String ELEMENT = ChatMarkersState.received.toString();
|
||||
|
||||
private final String id;
|
||||
|
||||
public ReceivedExtension(String id) {
|
||||
protected ChatMarkerExtensionWithId(String id) {
|
||||
this.id = StringUtils.requireNotNullNorEmpty(id, "Message ID must not be null");
|
||||
}
|
||||
|
||||
|
@ -102,10 +88,38 @@ public class ChatMarkersElements {
|
|||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
public final String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final XmlStringBuilder toXML(String enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.attribute("id", id);
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Received extension class.
|
||||
*
|
||||
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
|
||||
* Markers</a>
|
||||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public static class ReceivedExtension extends ChatMarkerExtensionWithId {
|
||||
|
||||
/**
|
||||
* received element.
|
||||
*/
|
||||
public static final String ELEMENT = ChatMarkersState.received.toString();
|
||||
|
||||
public ReceivedExtension(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getElementName() {
|
||||
return ELEMENT;
|
||||
|
@ -116,14 +130,6 @@ public class ChatMarkersElements {
|
|||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML(String enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.attribute("id", id);
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
|
||||
public static ReceivedExtension from(Message message) {
|
||||
return (ReceivedExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
|
@ -137,26 +143,15 @@ public class ChatMarkersElements {
|
|||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public static class DisplayedExtension implements ExtensionElement {
|
||||
public static class DisplayedExtension extends ChatMarkerExtensionWithId {
|
||||
|
||||
/**
|
||||
* displayed element.
|
||||
*/
|
||||
public static final String ELEMENT = ChatMarkersState.displayed.toString();
|
||||
|
||||
private final String id;
|
||||
|
||||
public DisplayedExtension(String id) {
|
||||
this.id = StringUtils.requireNotNullNorEmpty(id, "Message ID must not be null");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -169,14 +164,6 @@ public class ChatMarkersElements {
|
|||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML(String enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.attribute("id", id);
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
|
||||
public static DisplayedExtension from(Message message) {
|
||||
return (DisplayedExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
|
@ -190,26 +177,15 @@ public class ChatMarkersElements {
|
|||
* @author Fernando Ramirez
|
||||
*
|
||||
*/
|
||||
public static class AcknowledgedExtension implements ExtensionElement {
|
||||
public static class AcknowledgedExtension extends ChatMarkerExtensionWithId {
|
||||
|
||||
/**
|
||||
* acknowledged element.
|
||||
*/
|
||||
public static final String ELEMENT = ChatMarkersState.acknowledged.toString();
|
||||
|
||||
private final String id;
|
||||
|
||||
public AcknowledgedExtension(String id) {
|
||||
this.id = StringUtils.requireNotNullNorEmpty(id, "Message id must not be null");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -222,14 +198,6 @@ public class ChatMarkersElements {
|
|||
return NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence toXML(String enclosingNamespace) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||
xml.attribute("id", id);
|
||||
xml.closeEmptyElement();
|
||||
return xml;
|
||||
}
|
||||
|
||||
public static AcknowledgedExtension from(Message message) {
|
||||
return (AcknowledgedExtension) message.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue