-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
198 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* | ||
* Copyright © 2014-2020 Florian Schmaus | ||
* 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. | ||
|
@@ -382,6 +382,71 @@ public interface Jid extends Comparable<Jid>, CharSequence, Serializable { | |
*/ | ||
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 | [email protected] | true | | ||
* | dom.example | [email protected]/res | true | | ||
* | dom.example/res | dom.exmple | false | | ||
* | dom.example/res | dom.example/res | false | (different from isParentOf) | ||
* | dom.example/res | [email protected] | false | | ||
* | dom.example/res | [email protected]/res | false | | ||
* | [email protected] | dom.example | false | | ||
* | [email protected] | dom.example/res | false | | ||
* | [email protected] | [email protected] | false | (different from isParentOf) | ||
* | [email protected] | [email protected]/res | true | | ||
* | [email protected]/res | dom.example | false | | ||
* | [email protected]/res | dom.example/res | false | | ||
* | [email protected]/res | [email protected] | false | | ||
* | [email protected]/res | [email protected]/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. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
* | ||
* Copyright © 2014 Florian Schmaus | ||
* 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. | ||
|
@@ -54,6 +54,34 @@ public void testJidIsParentOf() throws XmppStringprepException { | |
assertTrue(fullJid.isParentOf(fullJid)); | ||
} | ||
|
||
@Test | ||
public void testJidIsStrictParentOf() throws XmppStringprepException { | ||
final Jid domainBareJid = JidCreate.from("dom.example"); | ||
final Jid domainFullJid = JidCreate.from("dom.example/res"); | ||
final Jid bareJid = JidCreate.from("[email protected]"); | ||
final Jid fullJid = JidCreate.from("[email protected]/res"); | ||
|
||
assertFalse(domainBareJid.isStrictParentOf(domainBareJid)); // different from isParentOf | ||
assertTrue(domainBareJid.isStrictParentOf(domainFullJid)); | ||
assertTrue(domainBareJid.isStrictParentOf(bareJid)); | ||
assertTrue(domainBareJid.isStrictParentOf(fullJid)); | ||
|
||
assertFalse(domainFullJid.isStrictParentOf(domainBareJid)); | ||
assertFalse(domainFullJid.isStrictParentOf(domainFullJid)); // different from isParentOf | ||
assertFalse(domainFullJid.isStrictParentOf(bareJid)); | ||
assertFalse(domainFullJid.isStrictParentOf(fullJid)); | ||
|
||
assertFalse(bareJid.isStrictParentOf(domainBareJid)); | ||
assertFalse(bareJid.isStrictParentOf(domainFullJid)); | ||
assertFalse(bareJid.isStrictParentOf(bareJid)); // different from isParentOf | ||
assertTrue(bareJid.isStrictParentOf(fullJid)); | ||
|
||
assertFalse(fullJid.isStrictParentOf(domainBareJid)); | ||
assertFalse(fullJid.isStrictParentOf(domainFullJid)); | ||
assertFalse(fullJid.isStrictParentOf(bareJid)); | ||
assertFalse(fullJid.isStrictParentOf(fullJid)); // different from isParentOf | ||
} | ||
|
||
@Test | ||
public void stripFinalDot() throws XmppStringprepException { | ||
String domain = "foo.bar."; | ||
|