This question is asked here:
but I am not completely satisfied with the answers. I need a way to compare two URLs for equality, and ideally I wonβt write it manually . This library should understand that these URLs are equal.
http://stackoverflow.com https://stackoverflow.com/ https://stackoverflow.com/questions/ask https://stackoverflow.com/questions/ask/ http://stackoverflow.com?paramName= http://stackoverflow.com?paramName http://stackoverflow.com?paramName1=value1¶mName2=value2 http://stackoverflow.com?paramName2=value2¶mName1=value1 http://stackoverflow.com?param name 1=value 1 http://stackoverflow.com?param%20name%201=value%201
These URLs are not equal:
https://stackoverflow.com/questions/ask https://stackoverflow.com/questionz/ask http://stackoverflow.com?paramName1=value1¶mName2=value2 http://stackoverflow.com?paramName1=value1¶mName2=value3
And other complicated things like this. Where can I find such a library?
By the way, here is the unit test of this:
import org.junit.Test; import java.net.URI; import java.net.URISyntaxException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; public class UriTest { @Test public void equality() throws URISyntaxException { assertUrlsEqual("http://stackoverflow.com", "https://stackoverflow.com/"); assertUrlsEqual("https://stackoverflow.com/questions/ask", "https://stackoverflow.com/questions/ask/"); assertUrlsEqual("http://stackoverflow.com?paramName=", "http://stackoverflow.com?paramName"); assertUrlsEqual("http://stackoverflow.com?paramName1=value1¶mName2=value2", "http://stackoverflow.com?paramName2=value2¶mName1=value1"); assertUrlsEqual("http://stackoverflow.com?param name 1=value 1", "http://stackoverflow.com?param%20name%201=value%201"); } @Test public void notEqual() throws URISyntaxException { assertUrlsNotEqual("https://stackoverflow.com/questions/ask", "https://stackoverflow.com/questionz/ask"); assertUrlsNotEqual("http://stackoverflow.com?paramName1=value1¶mName2=value2", "http://stackoverflow.com?paramName1=value1¶mName2=value3"); } private void assertUrlsNotEqual(String u1, String u2) throws URISyntaxException {
source share