| 1 |
/* |
| 2 |
* Copyright 2015-2020 the original author or authors |
| 3 |
* |
| 4 |
* This software is licensed under the Apache License, Version 2.0, |
| 5 |
* the GNU Lesser General Public License version 2 or later ("LGPL") |
| 6 |
* and the WTFPL. |
| 7 |
* You may choose either license to govern your use of this software only |
| 8 |
* upon the condition that you accept all of the terms of either |
| 9 |
* the Apache License 2.0, the LGPL 2.1+ or the WTFPL. |
| 10 |
*/ |
| 11 |
package org.minidns.util; |
| 12 |
|
| 13 |
import org.minidns.dnsname.DnsName; |
| 14 |
|
| 15 |
/** |
| 16 |
* Utilities related to internationalized domain names and dns name handling. |
| 17 |
*/ |
| 18 |
public final class NameUtil { |
| 19 |
|
| 20 |
/** |
| 21 |
* Check if two internationalized domain names are equal, possibly causing |
| 22 |
* a serialization of both domain names. |
| 23 |
* |
| 24 |
* @param name1 The first domain name. |
| 25 |
* @param name2 The second domain name. |
| 26 |
* @return True if both domain names are the same. |
| 27 |
*/ |
| 28 |
@SuppressWarnings("ReferenceEquality") |
| 29 |
public static boolean idnEquals(String name1, String name2) { |
| 30 |
if (name1 == name2) return true; // catches null, null |
| 31 |
if (name1 == null) return false; |
| 32 |
if (name2 == null) return false; |
| 33 |
if (name1.equals(name2)) return true; |
| 34 |
|
| 35 |
return DnsName.from(name1).compareTo(DnsName.from(name2)) == 0; |
| 36 |
} |
| 37 |
|
| 38 |
} |