當前位置: 首頁>>代碼示例>>Java>>正文


Java X500Principal.hashCode方法代碼示例

本文整理匯總了Java中javax.security.auth.x500.X500Principal.hashCode方法的典型用法代碼示例。如果您正苦於以下問題:Java X500Principal.hashCode方法的具體用法?Java X500Principal.hashCode怎麽用?Java X500Principal.hashCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.security.auth.x500.X500Principal的用法示例。


在下文中一共展示了X500Principal.hashCode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import javax.security.auth.x500.X500Principal; //導入方法依賴的package包/類
public static void main(String[] args) {

        // test regular equals
        X500Principal p1 = new X500Principal(p1String);
        X500Principal p2 = new X500Principal(p2String);

        printName("Principal 1:", p1String, p1);
        printName("Principal 2:", p2String, p2);

        if (!p1.equals(p2))
            throw new SecurityException("Equals test failed: #1");

        X500Principal notEqual = new X500Principal("cn=test2");
        if (p1.equals(notEqual))
            throw new SecurityException("Equals test failed: #2");

        if (p1.equals(null))
            throw new SecurityException("Equals test failed: #3");

        if (p1.hashCode() != p2.hashCode())
            throw new SecurityException("Equals test failed: #4");

        // test multiple AVA's in an RDN
        X500Principal p3 = new X500Principal(p3String);
        X500Principal p4 = new X500Principal(p4String);

        printName("Principal 3:", p3String, p3);
        printName("Principal 4:", p4String, p4);

        if (!p3.equals(p4))
            throw new SecurityException("Equals test failed: #5");

        if (p1.equals(p3) || p2.equals(p3))
            throw new SecurityException("Equals test failed: #6");

        if (p3.hashCode() != p4.hashCode())
            throw new SecurityException("Equals test failed: #7");

        X500Principal p5 = new X500Principal(p5String);
        X500Principal p6 = new X500Principal(p6String);

        printName("Principal 5:", p5String, p5);
        printName("Principal 6:", p6String, p6);

        if (!p5.equals(p6))
            throw new SecurityException("Equals test failed: #8");

        if (p5.hashCode() != p6.hashCode())
            throw new SecurityException("Equals test failed: #9");

        X500Principal p7 = new X500Principal(p7String);
        X500Principal p8 = new X500Principal(p8String);

        printName("Principal 7:", p7String, p7);
        printName("Principal 8:", p8String, p8);

        if (!p7.equals(p8))
            throw new SecurityException("Equals test failed: #10");

        if (p7.hashCode() != p8.hashCode())
            throw new SecurityException("Equals test failed: #11");

        System.out.println("Equals test passed");
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:65,代碼來源:Equals.java


注:本文中的javax.security.auth.x500.X500Principal.hashCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。