]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/dns/SrvRecord.java
1 package org
.argeo
.cms
.dns
;
3 class SrvRecord
implements Comparable
<SrvRecord
> {
4 private final Integer priority
;
5 private final Integer weight
;
6 private final Integer port
;
7 private final String hostname
;
9 public SrvRecord(Integer priority
, Integer weight
, Integer port
, String hostname
) {
10 this.priority
= priority
;
13 this.hostname
= hostname
;
17 public int compareTo(SrvRecord other
) {
18 // https: // en.wikipedia.org/wiki/SRV_record
19 if (priority
!= other
.priority
)
20 return priority
- other
.priority
;
21 if (weight
!= other
.weight
)
22 return other
.weight
- other
.weight
;
23 String host
= toHost(false);
24 String otherHost
= other
.toHost(false);
25 if (host
.length() == otherHost
.length())
26 return host
.compareTo(otherHost
);
28 return host
.length() - otherHost
.length();
32 public boolean equals(Object obj
) {
33 if (obj
instanceof SrvRecord
) {
34 SrvRecord other
= (SrvRecord
) obj
;
35 return priority
== other
.priority
&& weight
== other
.weight
&& port
== other
.port
36 && hostname
.equals(other
.hostname
);
42 public String
toString() {
43 return priority
+ " " + weight
;
46 public String
toHost(boolean withPort
) {
47 String hostStr
= hostname
;
48 if (hostname
.charAt(hostname
.length() - 1) == '.')
49 hostStr
= hostname
.substring(0, hostname
.length() - 1);
50 return hostStr
+ (withPort ?
":" + port
: "");