当前位置: 首页>>代码示例>>Java>>正文


Java Set.of方法代码示例

本文整理汇总了Java中java.util.Set.of方法的典型用法代码示例。如果您正苦于以下问题:Java Set.of方法的具体用法?Java Set.of怎么用?Java Set.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Set的用法示例。


在下文中一共展示了Set.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkModuleDescriptor

import java.util.Set; //导入方法依赖的package包/类
static void checkModuleDescriptor(ModuleDescriptor md, String... packages) throws IOException {
    String mainClass = md.name().replace('m', 'p') + ".Main";
    if (!md.mainClass().get().equals(mainClass)) {
        throw new RuntimeException(md.mainClass().toString());
    }

    // ModuleTarget attribute should be present
    if (!hasModuleTarget(md.name())) {
        throw new RuntimeException("ModuleTarget missing for " + md.name());
    }

    Set<String> pkgs = md.packages();
    if (!pkgs.equals(Set.of(packages))) {
        throw new RuntimeException(pkgs + " expected: " + Set.of(packages));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Main.java

示例2: testOfWithHiddenFiles

import java.util.Set; //导入方法依赖的package包/类
/**
 * Test ModuleFinder.of with a directory containing hidden files
 */
public void testOfWithHiddenFiles() throws Exception {
    Path dir = Files.createTempDirectory(USER_DIR, "mods");
    createExplodedModule(dir.resolve("m"), "m",
            "com/.ignore",
            "com/foo/.ignore",
            "com/foo/foo.properties");

    ModuleFinder finder = ModuleFinder.of(dir);
    ModuleReference mref = finder.find("m").orElse(null);
    assertNotNull(mref);

    Set<String> expectedPackages;
    if (System.getProperty("os.name").startsWith("Windows")) {
        expectedPackages = Set.of("com", "com.foo");
    } else {
        expectedPackages = Set.of("com.foo");
    }
    assertEquals(mref.descriptor().packages(), expectedPackages);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:ModuleFinderTest.java

示例3: inaccessibleFields

import java.util.Set; //导入方法依赖的package包/类
public static Set<String> inaccessibleFields() {
    // Only public fields of pkg.A are accessible to independent
    // class pkg.subpkg.C
    return Set.of(
            "f_private",
            "f_private_final",
            "f_protected",
            "f_protected_final",
            "f_package",
            "f_package_final",
            "f_private_static",
            "f_private_static_final",
            "f_protected_static",
            "f_protected_static_final",
            "f_package_static",
            "f_package_static_final"
    );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:C.java

示例4: modifiers

import java.util.Set; //导入方法依赖的package包/类
/**
 * Returns an immutable set of the module modifiers derived from the flags.
 */
private Set<ModuleDescriptor.Modifier> modifiers() {
    int n = 0;
    if (open) n++;
    if (synthetic) n++;
    if (mandated) n++;
    if (n == 0) {
        return Collections.emptySet();
    } else {
        ModuleDescriptor.Modifier[] mods = new ModuleDescriptor.Modifier[n];
        if (open) mods[--n] = ModuleDescriptor.Modifier.OPEN;
        if (synthetic) mods[--n] = ModuleDescriptor.Modifier.SYNTHETIC;
        if (mandated) mods[--n] = ModuleDescriptor.Modifier.MANDATED;
        return Set.of(mods);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Builder.java

示例5: testEraName

import java.util.Set; //导入方法依赖的package包/类
/**
 * tests that era names retrieved from Calendar.getDisplayNames map should
 * match with that of Era names retrieved from DateFormatSymbols.getEras()
 * method for all Gregorian Calendar locales .
 */
public static void testEraName() {
    Set<Locale> allLocales = Set.of(Locale.getAvailableLocales());
    Set<Locale> JpThlocales = Set.of(
            new Locale("th", "TH"),
            new Locale("ja", "JP", "JP"), new Locale("th", "TH", "TH")
    );
    Set<Locale> allLocs = new HashSet<>(allLocales);
    // Removing Japense and Thai Locales to check  Gregorian Calendar Locales
    allLocs.removeAll(JpThlocales);
    allLocs.forEach((locale) -> {
        Calendar cal = Calendar.getInstance(locale);
        Map<String, Integer> names = cal.getDisplayNames(Calendar.ERA, Calendar.ALL_STYLES, locale);
        DateFormatSymbols symbols = new DateFormatSymbols(locale);
        String[] eras = symbols.getEras();
        for (String era : eras) {
            if (!names.containsKey(era)) {
                reportMismatch(names.keySet(), eras, locale);
            }
        }
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:Bug8167273.java

示例6: testNewModuleToBuildOpenModule

import java.util.Set; //导入方法依赖的package包/类
public void testNewModuleToBuildOpenModule() {
    Set<ModuleDescriptor.Modifier> ms = Set.of(ModuleDescriptor.Modifier.OPEN);
    ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo", ms).build();
    assertTrue(descriptor.modifiers().equals(ms));
    assertTrue(descriptor.isOpen());

    ms = Set.of(ModuleDescriptor.Modifier.OPEN, ModuleDescriptor.Modifier.SYNTHETIC);
    descriptor = ModuleDescriptor.newModule("foo", ms).build();
    assertTrue(descriptor.modifiers().equals(ms));
    assertTrue(descriptor.isOpen());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ModuleDescriptorTest.java

示例7: testRetainModuleTarget

import java.util.Set; //导入方法依赖的package包/类
/**
 * Verify the plugin to retain ModuleTarget attribute
 */
@Test
public void testRetainModuleTarget() throws Throwable {
    if (!hasJmods()) return;

    // create an image using JMOD files
    Path dir = Paths.get("retainModuleTargetTest");
    String mp = Paths.get(JAVA_HOME, "jmods").toString() +
        File.pathSeparator + JMODS_DIR.toString();

    Set<String> modules = Set.of("m1", "m4");
    assertTrue(JLINK_TOOL.run(System.out, System.out,
        "--output", dir.toString(),
        "--exclude-resources", "m4/p4/dummy/*",
        "--add-modules", modules.stream().collect(Collectors.joining(",")),
        "--module-path", mp) == 0);

    // verify ModuleDescriptor
    Path java = dir.resolve("bin").resolve("java");
    assertTrue(executeProcess(java.toString(),
                    "--add-exports", "java.base/jdk.internal.module=m1,m4",
                    "--add-exports", "java.base/jdk.internal.org.objectweb.asm=m1,m4",
                    "--add-modules=m1", "-m", "m4", "retainModuleTarget")
        .outputTo(System.out)
        .errorTo(System.out)
        .getExitValue() == 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:UserModuleTest.java

示例8: testModulePackagesAttribute

import java.util.Set; //导入方法依赖的package包/类
/**
 * Verify the module descriptor if package p4.dummy is excluded at link time.
 */
@Test
public void testModulePackagesAttribute() throws Throwable {
    if (!hasJmods()) return;

    // create an image using JMOD files
    Path dir = Paths.get("packagesTest");
    String mp = Paths.get(JAVA_HOME, "jmods").toString() +
        File.pathSeparator + JMODS_DIR.toString();

    Set<String> modules = Set.of("m1", "m4");
    assertTrue(JLINK_TOOL.run(System.out, System.out,
        "--output", dir.toString(),
        "--exclude-resources", "m4/p4/dummy/*",
        "--add-modules", modules.stream().collect(Collectors.joining(",")),
        "--module-path", mp) == 0);

    // verify ModuleDescriptor
    Path java = dir.resolve("bin").resolve("java");
    assertTrue(executeProcess(java.toString(),
                    "--add-exports", "java.base/jdk.internal.module=m1,m4",
                    "--add-exports", "java.base/jdk.internal.org.objectweb.asm=m1,m4",
                    "--add-modules=m1", "-m", "m4")
        .outputTo(System.out)
        .errorTo(System.out)
        .getExitValue() == 0);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:UserModuleTest.java

示例9: test4

import java.util.Set; //导入方法依赖的package包/类
@Test
public void test4() {
    int rc = jar("-cf mmr.jar module-info.class -C classes . " +
            "--release 9 module-info.class -C mr9 .");
    Assert.assertEquals(rc, 0);

    String s = new String(errbytes.toByteArray());
    Assert.assertTrue(Message.NEW_CONCEALED_PACKAGE_WARNING.match(s, "p/internal/Bar.class"));

    jar("-tf mmr.jar");

    Set<String> actual = lines(outbytes);
    Set<String> expected = Set.of(
            "META-INF/",
            "META-INF/MANIFEST.MF",
            "module-info.class",
            "META-INF/versions/9/module-info.class",
            "p/",
            "p/Hi.class",
            "META-INF/versions/9/",
            "META-INF/versions/9/p/",
            "META-INF/versions/9/p/Hi.class",
            "META-INF/versions/9/p/internal/",
            "META-INF/versions/9/p/internal/Bar.class"
    );
    Assert.assertEquals(actual, expected);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:Basic.java

示例10: inaccessibleFields

import java.util.Set; //导入方法依赖的package包/类
public static Set<String> inaccessibleFields() {
    // Only public and protected fields of pkg.A are accessible to subclass
    // pkg.subpkg.B
    return Set.of(
            "f_private",
            "f_private_final",
            "f_package",
            "f_package_final",
            "f_private_static",
            "f_private_static_final",
            "f_package_static",
            "f_package_static_final"
    );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:B_extends_A.java

示例11: inaccessibleFields

import java.util.Set; //导入方法依赖的package包/类
public static Set<String> inaccessibleFields() {
    // All fields of pkg.A are accessible to itself
    return Set.of();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:A.java

示例12: nullDisallowed4

import java.util.Set; //导入方法依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void nullDisallowed4() {
    Set.of("a", "b", "c", null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:SetFactories.java

示例13: dupsDisallowedN

import java.util.Set; //导入方法依赖的package包/类
@Test(expectedExceptions=IllegalArgumentException.class)
public void dupsDisallowedN() {
    String[] array = stringArray.clone();
    array[0] = array[1];
    Set<String> set = Set.of(array);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:SetFactories.java

示例14: multiBaseModules

import java.util.Set; //导入方法依赖的package包/类
@Test
public static void multiBaseModules() throws IOException {
    Path dest = Paths.get("test2");
    HashesTest ht = new HashesTest(dest);

    /*
     * y2 -----------> y1
     *    |______
     *    |      |
     *    V      V
     *    z3 -> z2
     *    |      |
     *    |      V
     *    |---> z1
     */

    ht.makeModule("z1");
    ht.makeModule("z2", "z1");
    ht.makeModule("z3", "z1", "z2");

    ht.makeModule("y1");
    ht.makeModule("y2", "y1", "z2", "z3");

    Set<String> ys = Set.of("y1", "y2");
    Set<String> zs = Set.of("z1", "z2", "z3");

    // create JMOD files
    Stream.concat(ys.stream(), zs.stream()).forEach(ht::makeJmod);

    // run jmod hash command
    runJmod(List.of("hash", "--module-path", ht.lib.toString(),
                    "--hash-modules", ".*"));

    /*
     * z1 and y1 are the modules with hashes recorded.
     */
    ht.checkHashes("y1", "y2");
    ht.checkHashes("z1", "z2", "z3", "y2");
    Stream.concat(ys.stream(), zs.stream())
          .filter(mn -> !mn.equals("y1") && !mn.equals("z1"))
          .forEach(mn -> assertTrue(ht.hashes(mn) == null));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:43,代码来源:HashesTest.java

示例15: dupsDisallowed4

import java.util.Set; //导入方法依赖的package包/类
@Test(expectedExceptions=IllegalArgumentException.class)
public void dupsDisallowed4() {
    Set<String> set = Set.of("a", "b", "c", "a");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:SetFactories.java


注:本文中的java.util.Set.of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。