public final class Contact extends java.lang.Object implements RosterItem, java.lang.Comparable<Contact>
A contact in the user’s roster.
The
<query/>
element inside a roster set contains one<item/>
child, and a roster result typically contains multiple<item/>
children. Each<item/>
element describes a unique “roster item” (sometimes also called a “contact”).
This class is immutable.
SubscriptionState.Subscription
Constructor and Description |
---|
Contact(Jid jid)
Creates a new contact associated with the given JID.
|
Contact(Jid jid,
java.lang.String name)
Creates a new contact associated with the given JID and name.
|
Contact(Jid jid,
java.lang.String name,
java.lang.Boolean isPending,
java.lang.Boolean approved,
SubscriptionState.Subscription subscription,
java.util.Collection<java.lang.String> groups)
Creates a new contact associated with the given JID, name and groups.
|
Contact(Jid jid,
java.lang.String name,
java.util.Collection<java.lang.String> groups)
Creates a new contact associated with the given JID, name and groups.
|
Contact(Jid jid,
java.lang.String name,
java.lang.String... groups)
Creates a new contact associated with the given JID, name and groups.
|
Contact(RosterItem rosterItem)
Creates a new contact from a roster item.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Contact o)
Compares two contacts with each other by first comparing their names, then their subscription states and eventually their pending states.
|
boolean |
equals(java.lang.Object o) |
java.util.List<java.lang.String> |
getGroups()
Gets the groups of the contact.
|
Jid |
getJid()
Gets the JID of the contact.
|
java.lang.String |
getName()
Gets the name of the contact.
|
SubscriptionState.Subscription |
getSubscription()
Gets the subscription attribute.
|
int |
hashCode() |
boolean |
isApproved()
Gets the subscription pre-approval status.
|
boolean |
isPending()
Deprecated.
Use
isPendingOut() |
boolean |
isPendingIn()
Roster items on the XMPP layer don’t have a notion of a “Pending In” subscription state, therefore this methods always returns false.
|
boolean |
isPendingOut()
Gets the pending state of the contact.
|
static Contact |
removeContact(Jid jid)
Creates a new contact to send to the server for removal.
|
java.lang.String |
toString() |
Contact |
withGroups(java.util.Collection<java.lang.String> groups)
Creates an identical contact with only the groups changed.
|
Contact |
withGroups(java.lang.String... groups)
Creates an identical contact with only the groups changed.
|
Contact |
withName(java.lang.String name)
Creates an identical contact with only the name changed.
|
Contact |
withoutGroups()
Creates an identical contact without groups.
|
Contact |
withoutName()
Creates an identical contact without name.
|
equals
public Contact(Jid jid)
Creates a new contact associated with the given JID.
jid
- The JID.public Contact(Jid jid, java.lang.String name)
Creates a new contact associated with the given JID and name.
jid
- The JID.name
- The name.public Contact(Jid jid, java.lang.String name, java.lang.String... groups)
Creates a new contact associated with the given JID, name and groups.
jid
- The JID.name
- The name.groups
- The groups for this contact.public Contact(Jid jid, java.lang.String name, java.util.Collection<java.lang.String> groups)
Creates a new contact associated with the given JID, name and groups.
jid
- The JID.name
- The name.groups
- The groups for this contact.public Contact(RosterItem rosterItem)
Creates a new contact from a roster item.
rosterItem
- The roster item.public Contact(Jid jid, java.lang.String name, java.lang.Boolean isPending, java.lang.Boolean approved, SubscriptionState.Subscription subscription, java.util.Collection<java.lang.String> groups)
Creates a new contact associated with the given JID, name and groups.
jid
- The JID.name
- The name.isPending
- Indicates, whether the contact’s subscription approval is pending.approved
- Indicates, whether the contact is pre-approved.subscription
- The subscription.groups
- The groups for this contact.public static Contact removeContact(Jid jid)
Creates a new contact to send to the server for removal.
jid
- Jid of the contact to be removed.SubscriptionState.Subscription.REMOVE
set.public Contact withName(java.lang.String name)
Creates an identical contact with only the name changed.
name
- The name.public Contact withoutName()
Creates an identical contact without name.
public Contact withGroups(java.util.Collection<java.lang.String> groups)
Creates an identical contact with only the groups changed.
groups
- the new groups.public Contact withGroups(java.lang.String... groups)
Creates an identical contact with only the groups changed.
groups
- the new groups.public Contact withoutGroups()
Creates an identical contact without groups.
public final Jid getJid()
Gets the JID of the contact.
getJid
in interface RosterItem
public final java.lang.String getName()
Gets the name of the contact.
The ‘name’ attribute of the
<item/>
element specifies the “handle” to be associated with the JID, as determined by the user (not the contact). Although the value of the ‘name’ attribute MAY have meaning to a human user, it is opaque to the server. However, the ‘name’ attribute MAY be used by the server for matching purposes within the context of various XMPP extensions (one possible comparison method is that described for XMPP resourceparts in [XMPP-ADDR]).It is OPTIONAL for a client to include the ‘name’ attribute when adding or updating a roster item.
getName
in interface RosterItem
public final SubscriptionState.Subscription getSubscription()
Gets the subscription attribute.
getSubscription
in interface SubscriptionState
@Deprecated public final boolean isPending()
isPendingOut()
Gets the pending state of the contact.
The ‘ask’ attribute of the
<item/>
element with a value of “subscribe” is used to signal various subscription sub-states that include a “Pending Out” aspect as described under Section 3.1.2.A server SHOULD include the ‘ask’ attribute to inform the client of “Pending Out” sub-states. A client MUST NOT include the ‘ask’ attribute in the roster sets it sends to the server, but instead MUST use presence stanzas of type “subscribe” and “unsubscribe” to manage such sub-states as described under Section 3.1.2.
public final boolean isPendingOut()
Gets the pending state of the contact.
The ‘ask’ attribute of the
<item/>
element with a value of “subscribe” is used to signal various subscription sub-states that include a “Pending Out” aspect as described under Section 3.1.2.A server SHOULD include the ‘ask’ attribute to inform the client of “Pending Out” sub-states. A client MUST NOT include the ‘ask’ attribute in the roster sets it sends to the server, but instead MUST use presence stanzas of type “subscribe” and “unsubscribe” to manage such sub-states as described under Section 3.1.2.
isPendingOut
in interface SubscriptionState
public final boolean isPendingIn()
Roster items on the XMPP layer don’t have a notion of a “Pending In” subscription state, therefore this methods always returns false. Pending-in subscription states are not represented in the user’s roster at all.
isPendingIn
in interface SubscriptionState
false
.public final boolean isApproved()
Gets the subscription pre-approval status.
The boolean ‘approved’ attribute with a value of “true” is used to signal subscription pre-approval as described under Section 3.4
isApproved
in interface RosterItem
public final java.util.List<java.lang.String> getGroups()
Gets the groups of the contact.
getGroups
in interface RosterItem
public final boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public final int hashCode()
hashCode
in class java.lang.Object
public final int compareTo(Contact o)
Compares two contacts with each other by first comparing their names, then their subscription states and eventually their pending states.
compareTo
in interface java.lang.Comparable<Contact>
o
- The other contact.public final java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2014–2019 XMPP.rocks. All rights reserved.