removes unused code

This commit is contained in:
Tristan 2025-01-09 12:22:49 +01:00
parent fdf96193c5
commit 59dfa1fc88
24 changed files with 0 additions and 4478 deletions

View file

@ -1,34 +0,0 @@
/**
*
* Copyright © 2015-2016 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.jxmpp.jid;
/**
* An XMPP address (JID) which has no {@link org.jxmpp.jid.parts.Resourcepart}. Either
* {@link EntityBareJid} or {@link DomainBareJid}.
* <p>
* Examples:
* </p>
* <ul>
* <li><code>localpart@domain.part</code></li>
* <li><code>domain.part</code></li>
* </ul>
*
* @see Jid
*/
public interface BareJid extends Jid {
}

View file

@ -1,33 +0,0 @@
/**
*
* Copyright © 2014-2016 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.jxmpp.jid;
/**
* An XMPP address (JID) consisting of the domainpart. For example "xmpp.org".
* <p>
* Examples:
* </p>
* <ul>
* <li><code>xmpp.org</code></li>
* <li><code>example.net</code></li>
* </ul>
*
* @see Jid
*/
public interface DomainBareJid extends Jid, BareJid, DomainJid {
}

View file

@ -1,34 +0,0 @@
/**
*
* Copyright © 2014-2016 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.jxmpp.jid;
/**
* An XMPP address (JID) consisting of a domainpart and a resourcepart. For example
* "xmpp.org/resource".
* <p>
* Examples:
* </p>
* <ul>
* <li><code>domain.part/resource</code></li>
* <li><code>example.net/8c6def89</code></li>
* </ul>
*
* @see Jid
*/
public interface DomainFullJid extends Jid, FullJid, DomainJid {
}

View file

@ -1,34 +0,0 @@
/**
*
* Copyright © 2015-2016 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.jxmpp.jid;
/**
* An XMPP address (JID) which has no {@link org.jxmpp.jid.parts.Localpart}. Either
* {@link DomainBareJid} or {@link DomainFullJid}.
* <p>
* Examples:
* </p>
* <ul>
* <li><code>domain.part</code></li>
* <li><code>domain.part/resourcepart</code></li>
* </ul>
*
* @see Jid
*/
public interface DomainJid extends Jid {
}

View file

@ -1,34 +0,0 @@
/**
*
* Copyright © 2014-2016 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.jxmpp.jid;
/**
* An XMPP address (JID) consisting of a localpart and a domainpart. For example
* "user@xmpp.org".
* <p>
* Examples:
* </p>
* <ul>
* <li><code>localpart@domain.part</code></li>
* <li><code>user@example.net</code></li>
* </ul>
*
* @see Jid
*/
public interface EntityBareJid extends Jid, EntityJid, BareJid {
}

View file

@ -1,34 +0,0 @@
/**
*
* Copyright © 2014-2016 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.jxmpp.jid;
/**
* An XMPP address (JID) consisting of a localpart, domainpart and resourcepart. For example
* "user@xmpp.org/resource".
* <p>
* Examples:
* </p>
* <ul>
* <li><code>localpart@domain.part/resource</code></li>
* <li><code>juliet@xmpp.org/balcony</code></li>
* </ul>
*
* @see Jid
*/
public interface EntityFullJid extends Jid, FullJid, EntityJid {
}

View file

@ -1,56 +0,0 @@
/**
*
* Copyright © 2014-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.
* 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.jxmpp.jid;
import org.jxmpp.jid.parts.Localpart;
/**
* An XMPP address (JID) which has a {@link Localpart}. Either {@link EntityBareJid} or {@link EntityFullJid}.
* <p>
* Examples:
* </p>
* <ul>
* <li><code>localpart@domain.part</code></li>
* <li><code>localpart@domain.part/resourcepart</code></li>
* </ul>
*
* @see Jid
*/
public interface EntityJid extends Jid {
/**
* Return the {@link Localpart} of this JID.
*
* @return the localpart.
*/
Localpart getLocalpart();
/**
* Return the bare JID of this entity JID.
*
* @return the bare JID.
*/
EntityBareJid asEntityBareJid();
/**
* Return the bare JID string of this full JID.
*
* @return the bare JID string.
*/
String asEntityBareJidString();
}

View file

@ -1,42 +0,0 @@
/**
*
* Copyright © 2014-2016 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.jxmpp.jid;
import org.jxmpp.jid.parts.Resourcepart;
/**
* An XMPP address (JID) which has a {@link Resourcepart}. Either {@link EntityFullJid} or {@link DomainFullJid}.
* <p>
* Examples:
* </p>
* <ul>
* <li><code>localpart@domain.part/resourcepart</code></li>
* <li><code>domain.part/resourcepart</code></li>
* </ul>
*
* @see Jid
*/
public interface FullJid extends Jid {
/**
* Return the {@link Resourcepart} of this JID.
*
* @return the resourcepart.
*/
Resourcepart getResourcepart();
}

View file

@ -1,489 +0,0 @@
/**
*
* Copyright © 2014-2024 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.jxmpp.jid;
import java.io.Serializable;
import org.jxmpp.jid.parts.Domainpart;
import org.jxmpp.jid.parts.Localpart;
import org.jxmpp.jid.parts.Resourcepart;
/**
* An <b>XMPP address</b>, also known as JID (formerly for "Jabber Identifier"), which acts as globally unique address
* within the XMPP network.
* <p>
* JIDs are created from {@link String} or {@link CharSequence} with the {@link org.jxmpp.jid.impl.JidCreate} utility.
* </p>
*
* <pre>
* Jid jid = JidCreate.from("juliet@capulet.org/balcony");
* EntityBareJid bareJid = JidCreate.entityBareFrom("romeo@montague.net");
* </pre>
* <p>
* This is the super interface for all JID types, which are constructed from two dimensions: Bare/Full and
* Domain/Entity. Every JID consists at least of a {@link Domainpart}. Bare JID types do not come with a
* {@link Resourcepart}, full JID types always have a {@link Resourcepart}. Domain JID types do not possess a
* {@link Localpart}, whereas entity JID types always do.
* </p>
* <p>
* The following table shows a few examples of JID types.
* </p>
* <table>
* <caption>XMPP Address Types</caption>
* <tr>
* <td>Example</td>
* <td>Type</td>
* </tr>
* <tr>
* <td><code>example.org</code></td>
* <td>{@link DomainBareJid}</td>
* </tr>
* <tr>
* <td><code>example.org/resource</code></td>
* <td>{@link DomainFullJid}</td>
* </tr>
* <tr>
* <td><code>user@example.org</code></td>
* <td>{@link EntityBareJid}</td>
* </tr>
* <tr>
* <td><code>user@example.org/resource</code></td>
* <td>{@link EntityFullJid}</td>
* </tr>
* </table>
* <p>
* You can retrieve the escaped String representing the Jid with {@link #toString()} or the unescaped String of the JID
* with {@link #asUnescapedString()}.
* </p>
* <h2>URL Encoded JIDs</h2>
* <p>
* The URL encoded representation of a JID is ideal if a JID should be stored as part of a path name, e.g. as file name.
* You can retrieve this information using {@link #asUrlEncodedString()}. The JidCreate API provides methods to create
* JIDs from URL encoded Strings like {@link org.jxmpp.jid.impl.JidCreate#fromUrlEncoded(CharSequence)}.
* </p>
*
*
* @see <a href="http://xmpp.org/rfcs/rfc6120.html#arch-addresses">RFC 6120 (XMPP: Core) § 2.1 Global Addresses</a>
* @see <a href="http://xmpp.org/rfcs/rfc6122.html#addressing-fundamentals">RFC 6122 (XMPP: Address Format) § 2.1
* Fundamentals</a>
*/
public interface Jid extends Comparable<Jid>, CharSequence, Serializable {
/**
* Get the {@link Domainpart} of this Jid.
*
* @return the domainpart.
*/
Domainpart getDomain();
/**
* Returns the String representation of this JID.
*
* @return the String representation of this JID.
*/
@Override
String toString();
/**
* Return the <b>unescaped</b> String representation of this JID.
* <p>
* Since certain Unicode code points are disallowed in the localpart of a JID by the required stringprep profile,
* those need to get escaped when used in a real JID. The unescaped representation of the JID is only for
* presentation to a human user or for gatewaying to a non-XMPP system.
* </p>
* For example, if the users inputs {@code 'at&t guy@example.com'}, the escaped real JID created with
* {@link org.jxmpp.jid.impl.JidCreate} will be {@code 'at\26t\20guy@example.com'}, which is what
* {@link Jid#toString()} will return. But {@link Jid#asUnescapedString()} will return again
* {@code 'at&t guy@example.com'}.
*
* @return the unescaped String representation of this JID.
*/
String asUnescapedString();
/**
* Get the URL encoded version of this JID.
*
* @return the URL encoded version of this JID.
* @since 0.7.0
*/
String asUrlEncodedString();
/**
* Check if this is a {@link EntityBareJid} or {@link EntityFullJid}.
*
* @return true if this is an instance of BareJid or FullJid.
*/
boolean isEntityJid();
/**
* Check if this is an instance of {@link EntityBareJid}.
*
* @return true if this is an instance of EntityBareJid
*/
boolean isEntityBareJid();
/**
* Check if this is an instance of {@link EntityFullJid}.
*
* @return true if this is an instance of EntityFullJid
*/
boolean isEntityFullJid();
/**
* Check if this is an instance of {@link DomainBareJid}.
*
* @return true if this is an instance of DomainBareJid
*/
boolean isDomainBareJid();
/**
* Check if this is an instance of {@link DomainFullJid}.
*
* @return true if this is an instance of DomainFullJid
*/
boolean isDomainFullJid();
/**
* Check if this is an instance of {@link EntityBareJid} or {@link DomainBareJid}.
*
* @return true if this is an instance of BareJid or DomainBareJid
*/
boolean hasNoResource();
/**
* Check if this is a Jid with a {@link Resourcepart}.
*
* @return true if this Jid has a resourcepart.
*/
boolean hasResource();
/**
* Check if this is a Jid with a {@link Localpart}.
*
* @return true if this Jid has a localpart.
*/
boolean hasLocalpart();
/**
* Return a JID created by removing the Resourcepart from this JID.
*
* @return this Jid without a Resourcepart.
*/
BareJid asBareJid();
/**
* Convert this Jid to a {@link EntityBareJid} if possible.
*
* @return the corresponding {@link EntityBareJid} or null.
*/
EntityBareJid asEntityBareJidIfPossible();
/**
* Convert this Jid to a {@link EntityBareJid} or throw an {@code IllegalStateException} if this is not possible.
*
* @return the corresponding {@link EntityBareJid}.
*/
EntityBareJid asEntityBareJidOrThrow();
/**
* Convert this Jid to a {@link EntityFullJid} if possible.
*
* @return the corresponding {@link EntityFullJid} or null.
*/
EntityFullJid asEntityFullJidIfPossible();
/**
* Convert this Jid to a {@link EntityFullJid} or throw an {@code IllegalStateException} if this is not possible.
*
* @return the corresponding {@link EntityFullJid}.
*/
EntityFullJid asEntityFullJidOrThrow();
/**
* Convert this Jid to a {@link EntityJid} if possible.
*
* @return the corresponding {@link EntityJid} or null.
*/
EntityJid asEntityJidIfPossible();
/**
* Convert this Jid to a {@link EntityJid} or throw an {@code IllegalStateException} if this is not possible.
*
* @return the corresponding {@link EntityJid}.
*/
EntityJid asEntityJidOrThrow();
/**
* Convert this Jid to a {@link FullJid} if possible.
*
* @return the corresponding {@link FullJid} or null.
*/
FullJid asFullJidIfPossible();
/**
* Convert this Jid to a {@link FullJid} or throw an {@code IllegalStateException} if this is not possible.
*
* @return the corresponding {@link FullJid}.
*/
EntityFullJid asFullJidOrThrow();
/**
* Convert this Jid to a {@link DomainBareJid}.
* <p>
* Note that it is always possible to convert a Jid to a DomainBareJid, since every Jid has a domain part.
* </p>
*
* @return the corresponding DomainBareJid.
*/
DomainBareJid asDomainBareJid();
/**
* Convert this Jid to a {@link DomainFullJid} if possible.
*
* @return the corresponding DomainFullJid or null.
*/
DomainFullJid asDomainFullJidIfPossible();
/**
* Convert this Jid to a {@link DomainFullJid} or throw an {@code IllegalStateException} if this is not possible.
*
* @return the corresponding {@link DomainFullJid}.
*/
DomainFullJid asDomainFullJidOrThrow();
/**
* Get the resourcepart of this JID or null.
* <p>
* If the JID is of form {@code <localpart@domain.example/resource>} then this method returns 'resource'. If the JID no
* resourcepart, then <code>null</code> is returned.
* </p>
*
* @return the resource of this JID or null.
*/
Resourcepart getResourceOrNull();
/**
* Get the resourcepart of this JID or return the empty resourcepart.
* <p>
* If the JID is of form {@code <localpart@domain.example/resource>} then this method returns 'resource'. If the JID no
* resourcepart, then {@link org.jxmpp.jid.parts.Resourcepart#EMPTY} is returned.
* </p>
*
* @return the resource of this JID or the empty resourcepart.
*/
Resourcepart getResourceOrEmpty();
/**
* Get the resourcepart of this JID or throw an {@code IllegalStateException}.
* <p>
* If the JID is of form {@code <localpart@domain.example/resource>} then this method returns 'resource'. If the JID no
* resourcepart, then an {@code IllegalStateException} is thrown.
* </p>
*
* @return the resource of this JID.
*/
Resourcepart getResourceOrThrow();
/**
* Get the localpart of this JID or null.
* <p>
* If the JID is of form {@code <localpart@domain.example>} then this method returns 'localpart'. If the JID has no
* localpart, then <code>null</code> is returned.
* </p>
*
* @return the localpart of this JID or null.
*/
Localpart getLocalpartOrNull();
/**
* Get the localpart of this JID or throw an {@code IllegalStateException}.
* <p>
* If the JID is of form {@code <localpart@domain.example>} then this method returns 'localpart'. If the JID has no
* localpart, then <code>null</code> is returned.
* </p>
*
* @return the localpart of this JID.
*/
Localpart getLocalpartOrThrow();
/**
* Check if this JID is the parent of another JID. The <b>parent of</b> relation is defined, under the
* precondition that the JID parts (localpart, domainpart and resourcepart) are equal, as follows:
* <pre>
* | this JID (parentOf) | other JID | result |
* |---------------------+---------------------+--------|
* | dom.example | dom.example | true |
* | dom.example | dom.example/res | true |
* | dom.example | loc@dom.example | true |
* | dom.example | loc@dom.example/res | true |
* | dom.example/res | dom.exmple | false |
* | dom.example/res | dom.example/res | true |
* | dom.example/res | loc@dom.example | false |
* | dom.example/res | loc@dom.example/res | false |
* | loc@dom.example | dom.example | false |
* | loc@dom.example | dom.example/res | false |
* | loc@dom.example | loc@dom.example | true |
* | loc@dom.example | loc@dom.example/res | true |
* | loc@dom.example/res | dom.example | false |
* | loc@dom.example/res | dom.example/res | false |
* | loc@dom.example/res | loc@dom.example | false |
* | loc@dom.example/res | loc@dom.example/res | true |
* </pre>
*
* @param jid
* the other JID to compare with
* @return true if this JID is a parent of the given JID.
*/
boolean isParentOf(Jid jid);
/**
* See {@link #isParentOf(Jid)}.
*
* @param bareJid the bare JID.
* @return true if this JID is a parent of the given JID.
*/
boolean isParentOf(EntityBareJid bareJid);
/**
* See {@link #isParentOf(Jid)}.
*
* @param fullJid the full JID.
* @return true if this JID is a parent of the given JID.
*/
boolean isParentOf(EntityFullJid fullJid);
/**
* See {@link #isParentOf(Jid)}.
*
* @param domainBareJid the domain bare JID.
* @return true if this JID is a parent of the given JID.
*/
boolean isParentOf(DomainBareJid domainBareJid);
/**
* See {@link #isParentOf(Jid)}.
*
* @param domainFullJid the domain full JID.
* @return true if this JID is a parent of the given JID.
*/
boolean isParentOf(DomainFullJid domainFullJid);
/**
* Check if this JID is the strict parent of another JID. In other words, all parts of this JID must
* exist on the other JID, and match this JID's values. Furthermore, and this is what makes this
* method different from {@link #isParentOf(Jid)}, the other JID must have one additional part,
* that this JID does not have. The <b>parent of</b> relation is defined, under the
* precondition that the JID parts (localpart, domainpart and resourcepart) are equal, as follows:
* <pre>
* | this JID | other JID | result |
* |---------------------+---------------------+--------|
* | dom.example | dom.example | false | (different from isParentOf)
* | dom.example | dom.example/res | true |
* | dom.example | loc@dom.example | true |
* | dom.example | loc@dom.example/res | true |
* | dom.example/res | dom.exmple | false |
* | dom.example/res | dom.example/res | false | (different from isParentOf)
* | dom.example/res | loc@dom.example | false |
* | dom.example/res | loc@dom.example/res | false |
* | loc@dom.example | dom.example | false |
* | loc@dom.example | dom.example/res | false |
* | loc@dom.example | loc@dom.example | false | (different from isParentOf)
* | loc@dom.example | loc@dom.example/res | true |
* | loc@dom.example/res | dom.example | false |
* | loc@dom.example/res | dom.example/res | false |
* | loc@dom.example/res | loc@dom.example | false |
* | loc@dom.example/res | loc@dom.example/res | false | (different from isParentOf)
* </pre>
*
* @param jid
* the other JID to compare with
* @return true if this JID is a parent of the given JID.
*/
boolean isStrictParentOf(Jid jid);
/**
* See {@link #isParentOf(Jid)}.
*
* @param bareJid the bare JID.
* @return true if this JID is a parent of the given JID.
*/
boolean isStrictParentOf(EntityBareJid bareJid);
/**
* See {@link #isStrictParentOf(Jid)}.
*
* @param fullJid the full JID.
* @return true if this JID is a parent of the given JID.
*/
boolean isStrictParentOf(EntityFullJid fullJid);
/**
* See {@link #isStrictParentOf(Jid)}.
*
* @param domainBareJid the domain bare JID.
* @return true if this JID is a parent of the given JID.
*/
boolean isStrictParentOf(DomainBareJid domainBareJid);
/**
* See {@link #isStrictParentOf(Jid)}.
*
* @param domainFullJid the domain full JID.
* @return true if this JID is a parent of the given JID.
*/
boolean isStrictParentOf(DomainFullJid domainFullJid);
/**
* Return the downcasted instance of this Jid. This method is unsafe, make sure to check that this is actually of the type of are casting to.
*
* @param jidClass the class of JID to downcast too.
* @param <T> the Jid type to downcast to.
* @return the downcasted instanced of this
* @throws ClassCastException if this JID is not assignable to the type T.
*/
<T extends Jid> T downcast(Class<T> jidClass) throws ClassCastException;
/**
* Compares the given CharSequence with this JID. Returns true if {@code equals(charSequence.toString()} would
* return true.
*
* @param charSequence the CharSequence to compare this JID with.
* @return true if if {@code equals(charSequence.toString()} would return true.
* @see #equals(String)
*/
@SuppressWarnings("NonOverridingEquals")
boolean equals(CharSequence charSequence);
/**
* Compares the given String wit this JID.
* <p>
* Returns true if {@code toString().equals(string)}, that is if the String representation of this JID matches the given string.
* </p>
*
* @param string the String to compare this JID with.
* @return true if {@code toString().equals(string)}.
*/
@SuppressWarnings("NonOverridingEquals")
boolean equals(String string);
/**
* Returns the canonical String representation of this JID. See {@link String#intern} for details.
*
* @return the canonical String representation.
*/
String intern();
}

View file

@ -1,282 +0,0 @@
/**
*
* Copyright © 2014-2024 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.jxmpp.jid.impl;
import org.jxmpp.jid.EntityBareJid;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.DomainFullJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.parts.Localpart;
import org.jxmpp.jid.parts.Resourcepart;
public abstract class AbstractJid implements Jid {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Cache for the String representation of this JID.
*/
protected String cache;
@Override
public final boolean isEntityJid() {
return isEntityBareJid() || isEntityFullJid();
}
@Override
public final boolean isEntityBareJid() {
return this instanceof EntityBareJid;
}
@Override
public final boolean isEntityFullJid() {
return this instanceof EntityFullJid;
}
@Override
public final boolean isDomainBareJid() {
return this instanceof DomainBareJid;
}
@Override
public final boolean isDomainFullJid() {
return this instanceof DomainFullJid;
}
@Override
public abstract boolean hasNoResource();
@Override
public final boolean hasResource() {
return this instanceof FullJid;
}
@Override
public final boolean hasLocalpart() {
return this instanceof EntityJid;
}
@Override
public final <T extends Jid> T downcast(Class<T> jidClass) {
return jidClass.cast(this);
}
@Override
public int length() {
return toString().length();
}
@Override
public char charAt(int index) {
return toString().charAt(index);
}
@Override
public CharSequence subSequence(int start, int end) {
return toString().subSequence(start, end);
}
@Override
public final EntityBareJid asEntityBareJidOrThrow() {
EntityBareJid entityBareJid = asEntityBareJidIfPossible();
if (entityBareJid == null) throwIse("can not be converted to EntityBareJid");
return entityBareJid;
}
@Override
public EntityFullJid asEntityFullJidOrThrow() {
EntityFullJid entityFullJid = asEntityFullJidIfPossible();
if (entityFullJid == null) throwIse("can not be converted to EntityFullJid");
return entityFullJid;
}
@Override
public EntityJid asEntityJidOrThrow() {
EntityJid entityJid = asEntityJidIfPossible();
if (entityJid == null) throwIse("can not be converted to EntityJid");
return entityJid;
}
@Override
public EntityFullJid asFullJidOrThrow() {
EntityFullJid entityFullJid = asEntityFullJidIfPossible();
if (entityFullJid == null) throwIse("can not be converted to EntityBareJid");
return entityFullJid;
}
@Override
public DomainFullJid asDomainFullJidOrThrow() {
DomainFullJid domainFullJid = asDomainFullJidIfPossible();
if (domainFullJid == null) throwIse("can not be converted to DomainFullJid");
return domainFullJid;
}
@Override
public abstract Resourcepart getResourceOrNull();
@Override
public final Resourcepart getResourceOrEmpty() {
Resourcepart resourcepart = getResourceOrNull();
if (resourcepart == null) return Resourcepart.EMPTY;
return resourcepart;
}
@Override
public final Resourcepart getResourceOrThrow() {
Resourcepart resourcepart = getResourceOrNull();
if (resourcepart == null) throwIse("has no resourcepart");
return resourcepart;
}
@Override
public abstract Localpart getLocalpartOrNull();
@Override
public final Localpart getLocalpartOrThrow() {
Localpart localpart = getLocalpartOrNull();
if (localpart == null) throwIse("has no localpart");
return localpart;
}
@Override
public final boolean isParentOf(Jid jid) {
EntityFullJid fullJid = jid.asEntityFullJidIfPossible();
if (fullJid != null) {
return isParentOf(fullJid);
}
EntityBareJid bareJid = jid.asEntityBareJidIfPossible();
if (bareJid != null) {
return isParentOf(bareJid);
}
DomainFullJid domainFullJid = jid.asDomainFullJidIfPossible();
if (domainFullJid != null) {
return isParentOf(domainFullJid);
}
return isParentOf(jid.asDomainBareJid());
}
@Override
public final boolean isStrictParentOf(Jid jid) {
EntityFullJid fullJid = jid.asEntityFullJidIfPossible();
if (fullJid != null) {
return isStrictParentOf(fullJid);
}
EntityBareJid bareJid = jid.asEntityBareJidIfPossible();
if (bareJid != null) {
return isStrictParentOf(bareJid);
}
DomainFullJid domainFullJid = jid.asDomainFullJidIfPossible();
if (domainFullJid != null) {
return isStrictParentOf(domainFullJid);
}
return isStrictParentOf(jid.asDomainBareJid());
}
@Override
public final int hashCode() {
return toString().hashCode();
}
@Override
public final boolean equals(Object other) {
if (other == null) {
return false;
}
if (this == other) {
return true;
}
if (other instanceof CharSequence) {
return equals((CharSequence) other);
}
return false;
}
@SuppressWarnings("NonOverridingEquals")
@Override
public final boolean equals(CharSequence charSequence) {
if (charSequence == null) {
return false;
}
return equals(charSequence.toString());
}
@SuppressWarnings("NonOverridingEquals")
@Override
public final boolean equals(String string) {
return toString().equals(string);
}
@Override
public final int compareTo(Jid other) {
String otherString = other.toString();
String myString = toString();
return myString.compareTo(otherString);
}
/**
* The cache holding the internalized value of this part. This needs to be transient so that the
* cache is recreated once the data was de-serialized.
*/
private transient String internalizedCache;
@Override
public final String intern() {
if (internalizedCache == null) {
cache = internalizedCache = toString().intern();
}
return internalizedCache;
}
private transient String urlEncodedCache;
@Override
public final String asUrlEncodedString() {
if (urlEncodedCache == null) {
String string = toString();
try {
urlEncodedCache = URLEncoder.encode(string, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
}
return urlEncodedCache;
}
private void throwIse(String message) {
String exceptionMessage = "The JID '" + this + "' " + message;
throw new IllegalStateException(exceptionMessage);
}
static <O> O requireNonNull(O object, String message) {
if (object != null) {
return object;
}
throw new IllegalArgumentException(message);
}
}

View file

@ -1,173 +0,0 @@
/**
*
* Copyright © 2014-2024 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.jxmpp.jid.impl;
import org.jxmpp.JxmppContext;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.DomainFullJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.parts.Domainpart;
import org.jxmpp.jid.parts.Localpart;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
/**
* RFC6122 2.4 allows JIDs with only a domain and resource part.
* <p>
* Note that this implementation does not require an cache for the unescaped
* string, compared to {@link LocalDomainAndResourcepartJid}.
* </p>
*
*/
public final class DomainAndResourcepartJid extends AbstractJid implements DomainFullJid {
/**
*
*/
private static final long serialVersionUID = 1L;
private final DomainBareJid domainBareJid;
private final Resourcepart resource;
DomainAndResourcepartJid(String domain, String resource, JxmppContext context) throws XmppStringprepException {
this(new DomainpartJid(domain, context), Resourcepart.from(resource, context));
}
DomainAndResourcepartJid(DomainBareJid domainBareJid, Resourcepart resource) {
this.domainBareJid = requireNonNull(domainBareJid, "The DomainBareJid must not be null");
this.resource = requireNonNull(resource, "The Resource must not be null");
}
@Override
public String toString() {
if (cache != null) {
return cache;
}
cache = domainBareJid.toString() + '/' + resource;
return cache;
}
@Override
public DomainBareJid asDomainBareJid() {
return domainBareJid;
}
@Override
public boolean hasNoResource() {
return false;
}
@Override
public EntityBareJid asEntityBareJidIfPossible() {
return null;
}
@Override
public EntityFullJid asEntityFullJidIfPossible() {
return null;
}
@Override
public DomainFullJid asDomainFullJidIfPossible() {
return this;
}
@Override
public Resourcepart getResourceOrNull() {
return getResourcepart();
}
@Override
public boolean isParentOf(EntityBareJid bareJid) {
return false;
}
@Override
public boolean isParentOf(EntityFullJid fullJid) {
return false;
}
@Override
public boolean isParentOf(DomainBareJid domainBareJid) {
return false;
}
@Override
public boolean isParentOf(DomainFullJid domainFullJid) {
return domainBareJid.equals(domainFullJid.getDomain()) && resource.equals(domainFullJid.getResourcepart());
}
@Override
public boolean isStrictParentOf(EntityBareJid bareJid) {
return false;
}
@Override
public boolean isStrictParentOf(EntityFullJid fullJid) {
return false;
}
@Override
public boolean isStrictParentOf(DomainBareJid domainBareJid) {
return false;
}
@Override
public boolean isStrictParentOf(DomainFullJid domainFullJid) {
// A DomainFullJid can never be the strict parent of another DomainFullJid.
return false;
}
@Override
public Resourcepart getResourcepart() {
return resource;
}
@Override
public BareJid asBareJid() {
return asDomainBareJid();
}
@Override
public Domainpart getDomain() {
return domainBareJid.getDomain();
}
@Override
public String asUnescapedString() {
return toString();
}
@Override
public EntityJid asEntityJidIfPossible() {
return null;
}
@Override
public FullJid asFullJidIfPossible() {
return this;
}
@Override
public Localpart getLocalpartOrNull() {
return null;
}
}

View file

@ -1,162 +0,0 @@
/**
*
* Copyright © 2014-2024 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.jxmpp.jid.impl;
import org.jxmpp.JxmppContext;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.DomainFullJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.parts.Domainpart;
import org.jxmpp.jid.parts.Localpart;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
public final class DomainpartJid extends AbstractJid implements DomainBareJid {
/**
*
*/
private static final long serialVersionUID = 1L;
final Domainpart domain;
DomainpartJid(String domain, JxmppContext context) throws XmppStringprepException {
this(Domainpart.from(domain, context));
}
DomainpartJid(Domainpart domain) {
this.domain = requireNonNull(domain, "The Domainpart must not be null");
}
@Override
public Domainpart getDomain() {
return domain;
}
@Override
public String toString() {
// Prefer the cached version over the domain.toString() one, since the cached version may
// also be the internalized representation of the String. Which, e.g. provides benefits when
// comparing JIDs.
if (cache != null) {
return cache;
}
cache = domain.toString();
return cache;
}
@Override
public String asUnescapedString() {
// No un-escaping necessary for DomainpartJid
return toString();
}
@Override
public DomainBareJid asDomainBareJid() {
return this;
}
@Override
public boolean hasNoResource() {
return true;
}
@Override
public EntityBareJid asEntityBareJidIfPossible() {
return null;
}
@Override
public EntityFullJid asEntityFullJidIfPossible() {
return null;
}
@Override
public DomainFullJid asDomainFullJidIfPossible() {
return null;
}
@Override
public boolean isParentOf(EntityBareJid bareJid) {
return domain.equals(bareJid.getDomain());
}
@Override
public boolean isParentOf(EntityFullJid fullJid) {
return domain.equals(fullJid.getDomain());
}
@Override
public boolean isParentOf(DomainBareJid domainBareJid) {
return domain.equals(domainBareJid.getDomain());
}
@Override
public boolean isParentOf(DomainFullJid domainFullJid) {
return domain.equals(domainFullJid.getDomain());
}
@Override
public boolean isStrictParentOf(EntityBareJid bareJid) {
return isParentOf(bareJid);
}
@Override
public boolean isStrictParentOf(EntityFullJid fullJid) {
return isParentOf(fullJid);
}
@Override
public boolean isStrictParentOf(DomainBareJid domainBareJid) {
return false;
}
@Override
public boolean isStrictParentOf(DomainFullJid domainFullJid) {
return isParentOf(domainFullJid);
}
@Override
public BareJid asBareJid() {
return this;
}
@Override
public EntityJid asEntityJidIfPossible() {
return null;
}
@Override
public FullJid asFullJidIfPossible() {
return null;
}
@Override
public Resourcepart getResourceOrNull() {
return null;
}
@Override
public Localpart getLocalpartOrNull() {
return null;
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,182 +0,0 @@
/**
*
* Copyright © 2014-2024 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.jxmpp.jid.impl;
import org.jxmpp.JxmppContext;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.DomainFullJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.parts.Domainpart;
import org.jxmpp.jid.parts.Localpart;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
public final class LocalAndDomainpartJid extends AbstractJid implements EntityBareJid {
/**
*
*/
private static final long serialVersionUID = 1L;
private final DomainBareJid domainBareJid;
private final Localpart localpart;
private transient String unescapedCache;
LocalAndDomainpartJid(String localpart, String domain, JxmppContext context) throws XmppStringprepException {
domainBareJid = new DomainpartJid(domain, context);
this.localpart = Localpart.from(localpart, context);
}
LocalAndDomainpartJid(Localpart localpart, Domainpart domain) {
this.localpart = requireNonNull(localpart, "The Localpart must not be null");
this.domainBareJid = new DomainpartJid(domain);
}
@Override
public Localpart getLocalpart() {
return localpart;
}
@Override
public String toString() {
if (cache != null) {
return cache;
}
cache = getLocalpart().toString() + '@' + domainBareJid.toString();
return cache;
}
@Override
public String asUnescapedString() {
if (unescapedCache != null) {
return unescapedCache;
}
unescapedCache = getLocalpart().asUnescapedString() + '@' + domainBareJid.toString();
return unescapedCache;
}
@Override
public EntityBareJid asEntityBareJidIfPossible() {
return this;
}
@Override
public EntityFullJid asEntityFullJidIfPossible() {
return null;
}
@Override
public DomainFullJid asDomainFullJidIfPossible() {
return null;
}
@Override
public boolean isParentOf(EntityBareJid bareJid) {
return domainBareJid.equals(bareJid.getDomain()) && localpart.equals(bareJid.getLocalpart());
}
@Override
public boolean isParentOf(EntityFullJid fullJid) {
return isParentOf(fullJid.asBareJid());
}
@Override
public boolean isParentOf(DomainBareJid domainBareJid) {
return false;
}
@Override
public boolean isParentOf(DomainFullJid domainFullJid) {
return false;
}
@Override
public boolean isStrictParentOf(EntityBareJid bareJid) {
return false;
}
@Override
public boolean isStrictParentOf(EntityFullJid fullJid) {
return isParentOf(fullJid);
}
@Override
public boolean isStrictParentOf(DomainBareJid domainBareJid) {
return false;
}
@Override
public boolean isStrictParentOf(DomainFullJid domainFullJid) {
return false;
}
@Override
public DomainBareJid asDomainBareJid() {
return domainBareJid;
}
@Override
public Domainpart getDomain() {
return domainBareJid.getDomain();
}
@Override
public BareJid asBareJid() {
return this;
}
@Override
public boolean hasNoResource() {
return true;
}
@Override
public EntityJid asEntityJidIfPossible() {
return this;
}
@Override
public FullJid asFullJidIfPossible() {
return null;
}
@Override
public EntityBareJid asEntityBareJid() {
return this;
}
@Override
public Resourcepart getResourceOrNull() {
return null;
}
@Override
public Localpart getLocalpartOrNull() {
return getLocalpart();
}
@Override
public String asEntityBareJidString() {
return toString();
}
}

View file

@ -1,185 +0,0 @@
/**
*
* Copyright © 2014-2024 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.jxmpp.jid.impl;
import org.jxmpp.JxmppContext;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.DomainFullJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.FullJid;
import org.jxmpp.jid.parts.Domainpart;
import org.jxmpp.jid.parts.Localpart;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
public final class LocalDomainAndResourcepartJid extends AbstractJid implements EntityFullJid {
/**
*
*/
private static final long serialVersionUID = 1L;
private final EntityBareJid bareJid;
private final Resourcepart resource;
private String unescapedCache;
LocalDomainAndResourcepartJid(String localpart, String domain, String resource, JxmppContext context) throws XmppStringprepException {
this(new LocalAndDomainpartJid(localpart, domain, context), Resourcepart.from(resource, context));
}
LocalDomainAndResourcepartJid(EntityBareJid bareJid, Resourcepart resource) {
this.bareJid = requireNonNull(bareJid, "The EntityBareJid must not be null");
this.resource = requireNonNull(resource, "The Resourcepart must not be null");
}
@Override
public String toString() {
if (cache != null) {
return cache;
}
cache = bareJid.toString() + '/' + resource;
return cache;
}
@Override
public String asUnescapedString() {
if (unescapedCache != null) {
return unescapedCache;
}
unescapedCache = bareJid.asUnescapedString() + '/' + resource;
return unescapedCache;
}
@Override
public EntityBareJid asEntityBareJid() {
return bareJid;
}
@Override
public String asEntityBareJidString() {
return asEntityBareJid().toString();
}
@Override
public boolean hasNoResource() {
return false;
}
@Override
public EntityBareJid asEntityBareJidIfPossible() {
return asEntityBareJid();
}
@Override
public EntityFullJid asEntityFullJidIfPossible() {
return this;
}
@Override
public DomainFullJid asDomainFullJidIfPossible() {
return null;
}
@Override
public Localpart getLocalpartOrNull() {
return bareJid.getLocalpart();
}
@Override
public Resourcepart getResourceOrNull() {
return getResourcepart();
}
@Override
public boolean isParentOf(EntityBareJid bareJid) {
return false;
}
@Override
public boolean isParentOf(EntityFullJid fullJid) {
return this.equals(fullJid);
}
@Override
public boolean isParentOf(DomainBareJid domainBareJid) {
return false;
}
@Override
public boolean isParentOf(DomainFullJid domainFullJid) {
return false;
}
@Override
public boolean isStrictParentOf(EntityBareJid bareJid) {
return false;
}
@Override
public boolean isStrictParentOf(EntityFullJid fullJid) {
return false;
}
@Override
public boolean isStrictParentOf(DomainBareJid domainBareJid) {
return false;
}
@Override
public boolean isStrictParentOf(DomainFullJid domainFullJid) {
return false;
}
@Override
public DomainBareJid asDomainBareJid() {
return bareJid.asDomainBareJid();
}
@Override
public Resourcepart getResourcepart() {
return resource;
}
@Override
public BareJid asBareJid() {
return asEntityBareJid();
}
@Override
public Domainpart getDomain() {
return bareJid.getDomain();
}
@Override
public Localpart getLocalpart() {
return bareJid.getLocalpart();
}
@Override
public EntityJid asEntityJidIfPossible() {
return this;
}
@Override
public FullJid asFullJidIfPossible() {
return this;
}
}

View file

@ -1,21 +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.
*/
/**
* JXMPP's implementation of {@link org.jxmpp.jid.Jid} and it's subtypes.
*/
package org.jxmpp.jid.impl;

View file

@ -1,21 +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.
*/
/**
* Interfaces and classes for XMPP Addresses (JIDs).
*/
package org.jxmpp.jid;

View file

@ -1,108 +0,0 @@
/**
*
* Copyright © 2014-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.
* 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.jxmpp.jid.parts;
import org.jxmpp.JxmppContext;
import org.jxmpp.stringprep.XmppStringPrepUtil;
import org.jxmpp.stringprep.XmppStringprepException;
/**
* A <i>domainpart</i> of an XMPP address (JID).
* <p>
* You can create instances of this class from Strings using {@link #from(String)}.
* </p>
*
* @see <a href="http://xmpp.org/rfcs/rfc6122.html#addressing-domain">RFC 6122 § 2.2. Domainpart</a>
*/
public class Domainpart extends Part {
/**
*
*/
private static final long serialVersionUID = 1L;
private Domainpart(String domain) {
super(domain);
}
/**
* Get a {@link Domainpart} from a given {@link CharSequence} or {@code null} if the input is not a valid domainpart.
*
* @param cs the input CharSequence
* @return a Domainpart or {@code null}
*/
public static Domainpart fromOrNull(CharSequence cs) {
try {
return from(cs.toString());
} catch (XmppStringprepException e) {
return null;
}
}
/**
* Like {@link #from(String)} but does throw an unchecked {@link IllegalArgumentException} instead of a
* {@link XmppStringprepException}.
*
* @param cs the character sequence which should be transformed to a {@link Domainpart}
* @return the {@link Domainpart} if no exception occurs
* @throws IllegalArgumentException if the given input is not a valid {@link Domainpart}
* @see #from(String)
* @since 0.6.2
*/
public static Domainpart fromOrThrowUnchecked(CharSequence cs) {
try {
return from(cs.toString());
} catch (XmppStringprepException e) {
throw new IllegalArgumentException(e);
}
}
/**
* Get the {@link Domainpart} representing the input String.
*
* @param domain the input String.
* @return the domainpart.
* @throws XmppStringprepException if an error occurs.
*/
public static Domainpart from(String domain) throws XmppStringprepException {
return from(domain, JxmppContext.getDefaultContext());
}
/**
* Get the {@link Domainpart} representing the input String.
*
* @param domain the input String.
* @param context the JXMPP context.
* @return the domainpart.
* @throws XmppStringprepException if an error occurs.
*/
public static Domainpart from(String domain, JxmppContext context) throws XmppStringprepException {
if (domain == null) {
throw new XmppStringprepException(domain, "Input 'domain' must not be null");
}
// TODO cache
// RFC 6122 § 2.2 "If the domainpart includes a final character considered to be a label
// separator (dot) by [IDNA2003] or [DNS], this character MUST be stripped "
if (domain.length() > 0 && domain.charAt(domain.length() - 1) == '.') {
domain = domain.substring(0, domain.length() - 1);
}
domain = XmppStringPrepUtil.domainprep(domain, context);
// First prep the String, then assure the limits of the *result*
assertNotLongerThan1023BytesOrEmpty(domain);
return new Domainpart(domain);
}
}

View file

@ -1,183 +0,0 @@
/**
*
* Copyright © 2014-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.
* 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.jxmpp.jid.parts;
import org.jxmpp.JxmppContext;
import org.jxmpp.stringprep.XmppStringPrepUtil;
import org.jxmpp.stringprep.XmppStringprepException;
import org.jxmpp.util.XmppStringUtils;
/**
* A <i>localpart</i> of an XMPP address (JID). The localpart is the part before the
* first @ sign in an XMPP address and usually identifies the user (or the XMPP
* entity) within an XMPP service. It is also often referred to as "username",
* but note that the actual username used to login may be different from the
* resulting localpart of the user's JID.
* <p>
* You can create instances of this class from Strings using {@link #from(String)}.
* </p>
*
* @see <a href="http://xmpp.org/rfcs/rfc6122.html#addressing-localpart">RFC
* 6122 § 2.3. Localpart</a>
*/
public class Localpart extends Part {
/**
*
*/
private static final long serialVersionUID = 1L;
private transient String unescapedCache;
private Localpart(String localpart) {
super(localpart);
}
/**
* Return the <b>unescaped</b> String representation of this Localpart.
* <p>
* Since certain Unicode code points are disallowed in the localpart of a JID by the required stringprep profile,
* those need to get escaped when used in a real JID. The unescaped representation of the JID is only for
* presentation to a human user or for gatewaying to a non-XMPP system.
* </p>
*
* @return the unescaped String representation of this JID.
* @see org.jxmpp.jid.Jid#asUnescapedString()
* @since 0.6.1
*/
public String asUnescapedString() {
if (unescapedCache != null) {
return unescapedCache;
}
unescapedCache = XmppStringUtils.unescapeLocalpart(toString());
return unescapedCache;
}
/**
* Like {@link #from(String)} but does throw an unchecked {@link IllegalArgumentException} instead of a
* {@link XmppStringprepException}.
*
* @param cs the character sequence which should be transformed to a {@link Localpart}
* @return the {@link Localpart} if no exception occurs
* @throws IllegalArgumentException if the given input is not a valid {@link Localpart}
* @see #from(String)
* @since 0.6.2
*/
public static Localpart fromOrThrowUnchecked(CharSequence cs) {
try {
return from(cs.toString());
} catch (XmppStringprepException e) {
throw new IllegalArgumentException(e);
}
}
/**
* Like {@link #fromUnescaped(String)} but does throw an unchecked {@link IllegalArgumentException} instead of a
* {@link XmppStringprepException}.
*
* @param cs the character sequence which should be transformed to a {@link Localpart}
* @return the {@link Localpart} if no exception occurs
* @see #from(String)
* @since 0.6.2
*/
public static Localpart fromUnescapedOrThrowUnchecked(CharSequence cs) {
try {
return fromUnescaped(cs.toString());
} catch (XmppStringprepException e) {
throw new IllegalArgumentException(e);
}
}
/**
* Get a {@link Localpart} from a given {@link CharSequence} or {@code null} if the input is not a valid localpart.
*
* @param cs the input CharSequence
* @return a Localpart or {@code null}
*/
public static Localpart formUnescapedOrNull(CharSequence cs) {
try {
return fromUnescaped(cs);
} catch (XmppStringprepException e) {
return null;
}
}
/**
* Get a {@link Localpart} from an unescaped String.
*
* @param unescapedLocalpart an unescaped String representing a Localpart.
* @return a Localpart
* @throws XmppStringprepException if an error occurs.
* @since 0.6.2
*/
public static Localpart fromUnescaped(String unescapedLocalpart) throws XmppStringprepException {
String escapedLocalpartString = XmppStringUtils.escapeLocalpart(unescapedLocalpart);
return from(escapedLocalpartString);
}
/**
* Get a {@link Localpart} from an unescaped CharSequence.
*
* @param unescapedLocalpart an unescaped CharSequence representing a Localpart.
* @return a Localpart
* @throws XmppStringprepException if an error occurs.
* @since 0.6.2
*/
public static Localpart fromUnescaped(CharSequence unescapedLocalpart) throws XmppStringprepException {
return fromUnescaped(unescapedLocalpart.toString());
}
/**
* Get a {@link Localpart} from a given {@link CharSequence} or {@code null} if the input is not a valid localpart.
*
* @param cs the input CharSequence
* @return a Localpart or {@code null}
*/
public static Localpart fromOrNull(CharSequence cs) {
try {
return from(cs.toString());
} catch (XmppStringprepException e) {
return null;
}
}
/**
* Get the {@link Localpart} representing the input String.
*
* @param localpart the input String.
* @return the localpart.
* @throws XmppStringprepException if an error occurs.
*/
public static Localpart from(String localpart) throws XmppStringprepException {
return from(localpart, JxmppContext.getDefaultContext());
}
/**
* Get the {@link Localpart} representing the input String.
*
* @param localpart the input String.
* @param context the JXMPP context.
* @return the localpart.
* @throws XmppStringprepException if an error occurs.
*/
public static Localpart from(String localpart, JxmppContext context) throws XmppStringprepException {
localpart = XmppStringPrepUtil.localprep(localpart, context);
// First prep the String, then assure the limits of the *result*
assertNotLongerThan1023BytesOrEmpty(localpart);
return new Localpart(localpart);
}
}

View file

@ -1,102 +0,0 @@
/**
*
* Copyright © 2014-2019 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.jxmpp.jid.parts;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import org.jxmpp.stringprep.XmppStringprepException;
public abstract class Part implements CharSequence, Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private final String part;
protected Part(String part) {
this.part = part;
}
@Override
public final int length() {
return part.length();
}
@Override
public final char charAt(int index) {
return part.charAt(index);
}
@Override
public final CharSequence subSequence(int start, int end) {
return part.subSequence(start, end);
}
@Override
public final String toString() {
return part;
}
@Override
public final boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
return part.equals(other.toString());
}
@Override
public final int hashCode() {
return part.hashCode();
}
protected static void assertNotLongerThan1023BytesOrEmpty(String string) throws XmppStringprepException {
byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
// Better throw XmppStringprepException instead of IllegalArgumentException here, because users don't expect an
// IAE and it also makes the error handling for users easier.
if (bytes.length > 1023) {
throw new XmppStringprepException(string, "Given string is longer then 1023 bytes");
} else if (bytes.length == 0) {
throw new XmppStringprepException(string, "Argument can't be the empty string");
}
}
/**
* The cache holding the internalized value of this part. This needs to be transient so that the
* cache is recreated once the data was de-serialized.
*/
private transient String internalizedCache;
/**
* Returns the canonical String representation of this Part. See {@link String#intern} for details.
*
* @return the canonical String representation.
*/
public final String intern() {
if (internalizedCache == null) {
internalizedCache = toString().intern();
}
return internalizedCache;
}
}

View file

@ -1,119 +0,0 @@
/**
*
* Copyright © 2014-2024 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.jxmpp.jid.parts;
import org.jxmpp.JxmppContext;
import org.jxmpp.stringprep.XmppStringPrepUtil;
import org.jxmpp.stringprep.XmppStringprepException;
/**
* A <i>resourcepart</i> of an XMPP address (JID).
* <p>
* You can create instances of this class from Strings using {@link #from(String)}.
* </p>
*
* @see <a href="http://xmpp.org/rfcs/rfc6122.html#addressing-resource">RFC 6122 § 2.4. Resourcepart</a>
*/
public class Resourcepart extends Part {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* The empty resource part.
* <p>
* This empty resource part is the part that is represented by the empty String. This is useful in cases where you
* have a collection of Resourceparts that does not allow <code>null</code> values, but you want to deal with the
* "no resource" case.
* </p>
*/
public static final Resourcepart EMPTY = new Resourcepart("");
private Resourcepart(String resource) {
super(resource);
}
/**
* Get a {@link Resourcepart} from a given {@link CharSequence} or {@code null} if the input is not a valid resourcepart.
*
* @param cs the input CharSequence
* @return a Resourcepart or {@code null}
*/
public static Resourcepart fromOrNull(CharSequence cs) {
try {
return from(cs.toString());
} catch (XmppStringprepException e) {
return null;
}
}
/**
* Like {@link #from(String)} but does throw an unchecked {@link IllegalArgumentException} instead of a
* {@link XmppStringprepException}.
*
* @param cs the character sequence which should be transformed to a {@link Resourcepart}
* @return the {@link Resourcepart} if no exception occurs
* @throws IllegalArgumentException if the given input is not a valid {@link Resourcepart}
* @see #from(String)
* @since 0.6.2
*/
public static Resourcepart fromOrThrowUnchecked(CharSequence cs) {
try {
return from(cs.toString());
} catch (XmppStringprepException e) {
throw new IllegalArgumentException(e);
}
}
/**
* Get the {@link Resourcepart} representing the input String.
*
* @param resource the input String.
* @return the resource part.
* @throws XmppStringprepException if an error occurs.
*/
public static Resourcepart from(String resource) throws XmppStringprepException {
return from(resource, JxmppContext.getDefaultContext());
}
/**
* Get the {@link Resourcepart} representing the input String.
*
* @param resource the input String.
* @return the resource part.
* @throws XmppStringprepException if an error occurs.
*/
public static Resourcepart from(CharSequence resource) throws XmppStringprepException {
return from(resource.toString());
}
/**
* Get the {@link Resourcepart} representing the input String.
*
* @param resource the input String.
* @param context the JXMPP context.
* @return the resource part.
* @throws XmppStringprepException if an error occurs.
*/
public static Resourcepart from(String resource, JxmppContext context) throws XmppStringprepException {
resource = XmppStringPrepUtil.resourceprep(resource, context);
// First prep the String, then assure the limits of the *result*
assertNotLongerThan1023BytesOrEmpty(resource);
return new Resourcepart(resource);
}}

View file

@ -1,21 +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.
*/
/**
* Classes representing JID parts (Local-, Resource- and Domainpart).
*/
package org.jxmpp.jid.parts;

View file

@ -1,424 +0,0 @@
/**
*
* Copyright © 2014-2024 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.jxmpp.jid.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.DomainFullJid;
import org.jxmpp.jid.EntityFullJid;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
import org.jxmpp.util.XmppStringUtils;
public class JidUtil {
/**
* Check if the given CharSequence represents a typical and valid entity bare JID. This method does perform the same
* check as {@link #isValidEntityBareJid(CharSequence)} and additionally verifies that the domainpart of the JID
* contains at least one dot ('.') character.
* <p>
* For more information about the different verification methods see {@link #validateEntityBareJid(CharSequence)}.
* </p>
*
* @param jid the CharSequence to check.
* @return true if {@code jid} represents a valid entity bare JID, false otherwise
* @see #isValidEntityBareJid(CharSequence)
* @see EntityBareJid
*/
public static boolean isTypicalValidEntityBareJid(CharSequence jid) {
try {
validateTypicalEntityBareJid(jid);
} catch (NotAEntityBareJidStringException | XmppStringprepException e) {
return false;
}
return true;
}
/**
* Check if the given CharSequence is a typical and valid entity bare JID. This method does perform the same
* check as {@link #isValidEntityBareJid(CharSequence)} and additionally verifies that the domainpart of the JID
* contains at least one dot ('.') character.
* <p>
* The <code>TypicalValidEntityBareJid(CharSequence)</code> methods are useful if you expect your users to always
* enter a FQDN as domainpart. Whereas <code>isValidEntityBareJid(CharSequence)</code> and
* <code>validateEntityBareJid</code> accept also inputs like "foo@example", the "is typical JID" methods require
* the domainpart to contain a dot, e.g. "foo@example.org".
* </p>
*
* @param jidcs the JID CharSequence
* @return a BareJid instance representing the given JID CharSequence
* @throws NotAEntityBareJidStringException if the given CharSequence is not a bare JID.
* @throws XmppStringprepException if an error happens.
*/
public static EntityBareJid validateTypicalEntityBareJid(CharSequence jidcs) throws NotAEntityBareJidStringException, XmppStringprepException {
EntityBareJid jid = validateEntityBareJid(jidcs);
if (jid.getDomain().toString().indexOf('.') == -1) {
throw new NotAEntityBareJidStringException("Domainpart does not include a dot ('.') character");
}
return jid;
}
/**
* Check if the given CharSequence represents a valid entity bare JID. That
* is, it must consists exactly of a local- and a domainpart
* (&lt;localpart@domainpart&gt;).
* <p>
* This method is meant to validate user input and give fast feedback (e.g.
* with a red or green light) about if the user entered CharSequence
* represents a bare JID.
* </p>
*
* @param jid
* the CharSequence to check.
* @return true if {@code jid} represents a valid entity bare JID, false otherwise
* @see EntityBareJid
*/
public static boolean isValidEntityBareJid(CharSequence jid) {
try {
validateEntityBareJid(jid);
} catch (NotAEntityBareJidStringException | XmppStringprepException e) {
return false;
}
return true;
}
/**
* Check if the given CharSequence is a valid entity bare JID. That
* is, it must consists exactly of a local- and a domainpart
* (&lt;localpart@domainpart&gt;).
* <p>
* This is a convenience method meant to validate user entered bare JIDs. If
* the given {@code jid} is not a valid bare JID, then this method will
* throw either {@link NotAEntityBareJidStringException} or
* {@link XmppStringprepException}. The NotABareJidStringException will
* contain a meaningful message explaining why the given CharSequence is not a
* valid bare JID (e.g. "does not contain a '@' character").
* </p>
*
* @param jidcs the JID CharSequence
* @return a BareJid instance representing the given JID CharSequence
* @throws NotAEntityBareJidStringException if the given CharSequence is not a bare JID.
* @throws XmppStringprepException if an error happens.
*/
public static EntityBareJid validateEntityBareJid(CharSequence jidcs) throws NotAEntityBareJidStringException, XmppStringprepException {
String jid = jidcs.toString();
final int atIndex = jid.indexOf('@');
if (atIndex == -1) {
throw new NotAEntityBareJidStringException("'" + jid + "' does not contain a '@' character");
} else if (jid.indexOf('@', atIndex + 1) != -1) {
throw new NotAEntityBareJidStringException("'" + jid + "' contains multiple '@' characters");
}
final String localpart = XmppStringUtils.parseLocalpart(jid);
if (localpart == null || localpart.length() == 0) {
throw new NotAEntityBareJidStringException("'" + jid + "' has empty localpart");
}
final String domainpart = XmppStringUtils.parseDomain(jid);
if (domainpart == null || domainpart.length() == 0) {
throw new NotAEntityBareJidStringException("'" + jid + "' has empty domainpart");
}
return JidCreate.entityBareFromUnescaped(jid);
}
public static class NotAEntityBareJidStringException extends Exception {
/**
*
*/
private static final long serialVersionUID = -1710386661031655082L;
/**
* Construct a new "not a entity bare JID" exception.
*
* @param message the message of the exception.
*/
public NotAEntityBareJidStringException(String message) {
super(message);
}
}
/**
* Filter all entity bare JIDs.
*
* @param in the input collection.
* @param out the collection where the filtered JIDs are added to.
*/
public static void filterEntityBareJid(Collection<? extends Jid> in, Collection<? super EntityBareJid> out) {
for (Jid jid : in) {
EntityBareJid bareJid = jid.asEntityBareJidIfPossible();
if (bareJid != null) {
out.add(bareJid);
}
}
}
/**
* Filter all entity bare JIDs.
*
* @param input the input collection.
* @return a set containing all bare JIDs of the input collection.
*/
public static Set<EntityBareJid> filterEntityBareJidSet(Collection<? extends Jid> input) {
Set<EntityBareJid> res = new HashSet<EntityBareJid>(input.size());
filterEntityBareJid(input, res);
return res;
}
/**
* Filter all entity bare JIDs.
*
* @param input the input collection.
* @return a list containing all bare JIDs of the input collection.
*/
public static List<EntityBareJid> filterEntityBareJidList(Collection<? extends Jid> input) {
List<EntityBareJid> res = new ArrayList<EntityBareJid>(input.size());
filterEntityBareJid(input, res);
return res;
}
/**
* Filter all entity full JIDs.
*
* @param in the input collection.
* @param out the collection where the filtered JIDs are added to.
*/
public static void filterEntityFullJid(Collection<? extends Jid> in, Collection<? super EntityFullJid> out) {
for (Jid jid : in) {
EntityFullJid fullJid = jid.asEntityFullJidIfPossible();
if (fullJid != null) {
out.add(fullJid);
}
}
}
/**
* Filter all full JIDs.
*
* @param input the input collection.
* @return a set containing all full JIDs of the input collection.
*/
public static Set<EntityFullJid> filterEntityFullJidSet(Collection<? extends Jid> input) {
Set<EntityFullJid> res = new HashSet<EntityFullJid>(input.size());
filterEntityFullJid(input, res);
return res;
}
/**
* Filter all full JIDs.
*
* @param input the input collection.
* @return a list containing all full JIDs of the input collection.
*/
public static List<EntityFullJid> filterEntityFullJidList(Collection<? extends Jid> input) {
List<EntityFullJid> res = new ArrayList<EntityFullJid>(input.size());
filterEntityFullJid(input, res);
return res;
}
/**
* Filter all domain full JIDs.
*
* @param in the input collection.
* @param out the collection where the filtered JIDs are added to.
*/
public static void filterDomainFullJid(Collection<? extends Jid> in, Collection<? super DomainFullJid> out) {
for (Jid jid : in) {
DomainFullJid domainFullJid = jid.asDomainFullJidIfPossible();
if (domainFullJid != null) {
out.add(domainFullJid);
}
}
}
/**
* Filter all domain full JIDs.
*
* @param input the input collection.
* @return a set containing all domain full JIDs of the input collection.
*/
public static Set<DomainFullJid> filterDomainFullJidSet(Collection<? extends Jid> input) {
Set<DomainFullJid> res = new HashSet<DomainFullJid>(input.size());
filterDomainFullJid(input, res);
return res;
}
/**
* Filter all domain full JIDs.
*
* @param input the input collection.
* @return a list containing all domain full JIDs of the input collection.
*/
public static List<DomainFullJid> filterDomainFullJidList(Collection<? extends Jid> input) {
List<DomainFullJid> res = new ArrayList<DomainFullJid>(input.size());
filterDomainFullJid(input, res);
return res;
}
/**
* Convert the given collection of CharSequences to bare JIDs.
*
* @param jidStrings the collection of CharSequences.
* @return a set of bare JIDs.
*/
public static Set<EntityBareJid> entityBareJidSetFrom(Collection<? extends CharSequence> jidStrings) {
Set<EntityBareJid> res = new HashSet<EntityBareJid>(jidStrings.size());
entityBareJidsFrom(jidStrings, res, null);
return res;
}
/**
* Convert a collection of Strings to a Set of {@link EntityBareJid}'s.
* <p>
* If the optional argument <code>exceptions</code> is given, then all {@link XmppStringprepException} thrown while
* converting will be added to the list. Otherwise, if an XmppStringprepExceptions is thrown, it will be wrapped in
* a AssertionError Exception and throw.
* </p>
*
* @param jidStrings
* the strings that are going to get converted
* @param output
* the collection where the BareJid's will be added to
* @param exceptions the list of exceptions thrown while converting.
*/
public static void entityBareJidsFrom(Collection<? extends CharSequence> jidStrings, Collection<? super EntityBareJid> output,
List<XmppStringprepException> exceptions) {
for (CharSequence jid : jidStrings) {
try {
EntityBareJid bareJid = JidCreate.entityBareFrom(jid);
output.add(bareJid);
} catch (XmppStringprepException e) {
if (exceptions != null) {
exceptions.add(e);
} else {
throw new AssertionError(e);
}
}
}
}
/**
* Convert the given array of Strings to JIDs.
* <p>
* Note that errors while converting the Strings will be silently ignored.
* </p>
*
* @param jids a array of JID Strings.
* @return a set of JIDs.
*/
public static Set<Jid> jidSetFrom(String[] jids) {
return jidSetFrom(Arrays.asList(jids));
}
/**
* Convert the given collection of CharSequences to JIDs.
*
* @param jidStrings the collection of CharSequences.
* @return a set of JIDs.
*/
public static Set<Jid> jidSetFrom(Collection<? extends CharSequence> jidStrings) {
Set<Jid> res = new HashSet<Jid>(jidStrings.size());
jidsFrom(jidStrings, res, null);
return res;
}
/**
* Convert a collection of Strings to a Set of {@link Jid}'s.
* <p>
* If the optional argument <code>exceptions</code> is given, then all {@link XmppStringprepException} thrown while
* converting will be added to the list. Otherwise, if an XmppStringprepExceptions is thrown, it will be wrapped in
* a AssertionError Exception and throw.
* </p>
*
* @param jidStrings
* the strings that are going to get converted
* @param output
* the collection where the Jid's will be added to
* @param exceptions the list of exceptions thrown while converting.
*/
public static void jidsFrom(Collection<? extends CharSequence> jidStrings, Collection<? super Jid> output,
List<XmppStringprepException> exceptions) {
for (CharSequence jidString : jidStrings) {
try {
Jid jid = JidCreate.from(jidString);
output.add(jid);
} catch (XmppStringprepException e) {
if (exceptions != null) {
exceptions.add(e);
} else {
throw new AssertionError(e);
}
}
}
}
/**
* Convert a collection of JIDs to a list of Strings representing those JIDs.
*
* @param jids a collection of JIDs.
* @return a list of Strings.
*/
public static List<String> toStringList(Collection<? extends Jid> jids) {
List<String> res = new ArrayList<String>(jids.size());
toStrings(jids, res);
return res;
}
/**
* convert a collection of JIDs to a set of Strings representing those JIDs.
*
* @param jids a collection of JIDs.
* @return a set of String.
*/
public static Set<String> toStringSet(Collection<? extends Jid> jids) {
Set<String> res = new HashSet<String>(jids.size());
toStrings(jids, res);
return res;
}
/**
* Convert a collection of JIDs to a Collection of Strings.
*
* @param jids the collection of Strings to convert.
* @param jidStrings the collection of Strings to append to.
*/
public static void toStrings(Collection<? extends Jid> jids, Collection<? super String> jidStrings) {
for (Jid jid : jids) {
jidStrings.add(jid.toString());
}
}
/**
* Check if two JIDs are equals. Takes <code>null</code> values into consideration. Which means that this method will return <code>true</code> if both JIDs are <code>null</code>.
*
* @param jidOne The first JID to compare.
* @param jidTwo The second JID to compare.
* @return <code>true</code> if both JIDs are equals.
* @since 0.7.0
*/
public static boolean equals(Jid jidOne, Jid jidTwo) {
if (jidOne != null) {
return jidOne.equals(jidTwo);
}
return jidTwo == null;
}
}

View file

@ -1,21 +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.
*/
/**
* Utility classes for JIDs.
*/
package org.jxmpp.jid.util;