add comparable interface
This commit is contained in:
parent
93e201db8b
commit
34f64f6153
3 changed files with 45 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
|||
group = org.xbib
|
||||
name = net
|
||||
version = 1.0.2
|
||||
version = 1.0.3
|
||||
|
||||
junit.version = 4.12
|
||||
asciidoclet.version = 1.5.4
|
||||
|
|
|
@ -43,7 +43,7 @@ import java.util.logging.Logger;
|
|||
* --
|
||||
*
|
||||
*/
|
||||
public class URL implements Serializable {
|
||||
public class URL implements Comparable<URL>, Serializable {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(URL.class.getName());
|
||||
|
||||
|
@ -268,6 +268,23 @@ public class URL implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public String relativeReference() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (path != null) {
|
||||
sb.append(path);
|
||||
}
|
||||
if (query != null) {
|
||||
sb.append(QUESTION_CHAR).append(query);
|
||||
}
|
||||
if (fragment != null) {
|
||||
sb.append(NUMBER_SIGN_CHAR).append(fragment);
|
||||
}
|
||||
if (sb.length() == 0) {
|
||||
sb.append(SEPARATOR_CHAR);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String decode(String input) {
|
||||
try {
|
||||
return builder.percentDecoder.decode(input);
|
||||
|
@ -280,17 +297,7 @@ public class URL implements Serializable {
|
|||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other != null && other instanceof URL && toString().equals(other.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(true);
|
||||
}
|
||||
|
||||
public String toString(boolean withFragment) {
|
||||
private String toString(boolean withFragment) {
|
||||
if (internalStringRepresentation != null) {
|
||||
return internalStringRepresentation;
|
||||
}
|
||||
|
@ -298,11 +305,6 @@ public class URL implements Serializable {
|
|||
return internalStringRepresentation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scheme of this {@code URL}.
|
||||
* @return the scheme ('http' or 'file' or 'ftp' etc...) of the URL if it exists, or null.
|
||||
|
@ -403,6 +405,10 @@ public class URL implements Serializable {
|
|||
return !isNullOrEmpty(builder.scheme);
|
||||
}
|
||||
|
||||
public boolean isRelative() {
|
||||
return isNullOrEmpty(builder.scheme);
|
||||
}
|
||||
|
||||
public Comparator<URL> withFragmentComparator() {
|
||||
return new URLWithFragmentComparator();
|
||||
}
|
||||
|
@ -653,6 +659,26 @@ public class URL implements Serializable {
|
|||
return str == null || str.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other != null && other instanceof URL && toString().equals(other.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(URL o) {
|
||||
return toString().compareTo(o.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* The URL Builder embedded class is for building an URL by fluent API methods.
|
||||
*/
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The algorithm used for rendering is centered around this class,and is
|
||||
* The algorithm used for rendering is centered around this class, and is
|
||||
* adapted from the algorithm suggested in the RFC's appendix.
|
||||
*
|
||||
* Eventually, rendering can be viewed as joining a list of rendered strings
|
||||
|
|
Loading…
Reference in a new issue