001/*
002 * Copyright 2015-2020 the original author or authors
003 *
004 * This software is licensed under the Apache License, Version 2.0,
005 * the GNU Lesser General Public License version 2 or later ("LGPL")
006 * and the WTFPL.
007 * You may choose either license to govern your use of this software only
008 * upon the condition that you accept all of the terms of either
009 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL.
010 */
011package org.minidns.util;
012
013import org.minidns.dnsname.DnsName;
014
015/**
016 * Utilities related to internationalized domain names and dns name handling.
017 */
018public final class NameUtil {
019
020    /**
021     * Check if two internationalized domain names are equal, possibly causing
022     * a serialization of both domain names.
023     *
024     * @param name1 The first domain name.
025     * @param name2 The second domain name.
026     * @return True if both domain names are the same.
027     */
028    @SuppressWarnings("ReferenceEquality")
029    public static boolean idnEquals(String name1, String name2) {
030        if (name1 == name2) return true; // catches null, null
031        if (name1 == null) return false;
032        if (name2 == null) return false;
033        if (name1.equals(name2)) return true;
034
035        return DnsName.from(name1).compareTo(DnsName.from(name2)) == 0;
036    }
037
038}