Java Code Examples for java.util.Map.of()

The following are Jave code examples for showing how to use of() of the java.util.Map class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: bach   File: JdkToolTests.java   View Source Code Vote up 6 votes
@Test
void dumpJavaOptions() {
  List<String> expectedLines =
      List.of(
          "java",
          "--dry-run",
          "--patch-module",
          "  com.greetings=xxx",
          "--module-path",
          "  mods",
          "--module",
          "  com.greetings/com.greetings.Main",
          "1",
          "2",
          "NEW");
  Bach.JdkTool.Java java = new Bach.JdkTool.Java();
  java.dryRun = true;
  java.patchModule = Map.of("com.greetings", List.of(Paths.get("xxx")));
  java.modulePath = List.of(Paths.get("mods"));
  java.module = "com.greetings/com.greetings.Main";
  java.args = List.of(1, "2", Thread.State.NEW);
  assertLinesMatch(expectedLines, dump(java.toCommand()));
}
 
Example 2
Project: openjdk-jdk10   File: GenerateJLIClassesPlugin.java   View Source Code Vote up 6 votes
/**
 * @return the list of default DirectMethodHandle methods to generate.
 */
private static Map<String, Set<String>> defaultDMHMethods() {
    return Map.of(
        DMH_INVOKE_VIRTUAL, Set.of("L_L", "LL_L", "LLI_I", "L3_V"),
        DMH_INVOKE_SPECIAL, Set.of("LL_I", "LL_L", "LLF_L", "LLD_L", "L3_L",
            "L4_L", "L5_L", "L6_L", "L7_L", "L8_L", "LLI_I", "LLI_L",
            "LLIL_I", "LLII_I", "LLII_L", "L3I_L", "L3I_I", "LLILI_I",
            "LLIIL_L", "LLIILL_L", "LLIILL_I", "LLIIL_I", "LLILIL_I",
            "LLILILL_I", "LLILII_I", "LLI3_I", "LLI3L_I", "LLI3LL_I",
            "LLI3_L", "LLI4_I"),
        DMH_INVOKE_STATIC, Set.of("LII_I", "LIL_I", "LILIL_I", "LILII_I",
            "L_I", "L_L", "L_V", "LD_L", "LF_L", "LI_I", "LII_L", "LLI_L",
            "LL_V", "LL_L", "L3_L", "L4_L", "L5_L", "L6_L", "L7_L",
            "L8_L", "L9_L", "L10_L", "L10I_L", "L10II_L", "L10IIL_L",
            "L11_L", "L12_L", "L13_L", "L14_L", "L14I_L", "L14II_L")
    );
}
 
Example 3
Project: openjdk-jdk10   File: RedefineModuleTest.java   View Source Code Vote up 6 votes
/**
 * Use redefineModule to update java.base to export jdk.internal.misc
 */
public void testAddExports() {
    Module baseModule = Object.class.getModule();
    Module thisModule = this.getClass().getClassLoader().getUnnamedModule();
    String pkg = "jdk.internal.misc";

    // pre-conditions
    assertFalse(baseModule.isExported(pkg));
    assertFalse(baseModule.isExported(pkg, thisModule));

    // update java.base to export jdk.internal.misc to an unnamed module
    Map<String, Set<Module>> extraExports = Map.of(pkg, Set.of(thisModule));
    redefineModule(baseModule, Set.of(), extraExports, Map.of(), Set.of(), Map.of());
    assertFalse(baseModule.isExported(pkg));
    assertTrue(baseModule.isExported(pkg, thisModule));
    assertFalse(baseModule.isOpen(pkg));
    assertFalse(baseModule.isOpen(pkg, thisModule));
}
 
Example 4
Project: openjdk-jdk10   File: RedefineModuleTest.java   View Source Code Vote up 6 votes
/**
 * Use redefineModule to update java.base to open jdk.internal.loader
 */
public void testAddOpens() {
    Module baseModule = Object.class.getModule();
    Module thisModule = this.getClass().getClassLoader().getUnnamedModule();
    String pkg = "jdk.internal.loader";

    // pre-conditions
    assertFalse(baseModule.isOpen(pkg));
    assertFalse(baseModule.isOpen(pkg, thisModule));

    // update java.base to open dk.internal.loader to an unnamed module
    Map<String, Set<Module>> extraExports = Map.of(pkg, Set.of(thisModule));
    redefineModule(baseModule, Set.of(), Map.of(), extraExports, Set.of(), Map.of());
    assertFalse(baseModule.isExported(pkg));
    assertTrue(baseModule.isExported(pkg, thisModule));
    assertFalse(baseModule.isOpen(pkg));
    assertTrue(baseModule.isOpen(pkg, thisModule));
}
 
Example 5
Project: openjdk-jdk10   File: RedefineModuleTest.java   View Source Code Vote up 6 votes
/**
 * Test redefineClass by attempting to update java.base to provide a service
 * where the service provider class is not in the module.
 */
@Test(expectedExceptions = IllegalArgumentException.class)
public void testProvideServiceNotInModule() {
    Module baseModule = Object.class.getModule();
    class MyProvider extends URLStreamHandlerProvider {
        @Override
        public URLStreamHandler createURLStreamHandler(String protocol) {
            return null;
        }
    }

    // attempt to update java.base to provide MyProvider
    Map<Class<?>, List<Class<?>>> extraProvides
        = Map.of(URLStreamHandlerProvider.class, List.of(MyProvider.class));
    redefineModule(baseModule, Set.of(), Map.of(), Map.of(), Set.of(), extraProvides);
}
 
Example 6
Project: openjdk-jdk10   File: RedefineModuleTest.java   View Source Code Vote up 5 votes
@Test(expectedExceptions = IllegalArgumentException.class)
public void testExportPackageToEmptySet() {
    // attempt to update java.base to export jdk.internal.misc to nobody
    Module baseModule = Object.class.getModule();
    Map<String, Set<Module>> extraExports = Map.of("jdk.internal.misc", Set.of());
    redefineModule(baseModule, Set.of(), extraExports, Map.of(), Set.of(), Map.of());
}
 
Example 7
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void nullValueDisallowed2() {
    Map<Integer, String> map = Map.of(0, "a", 1, null);
}
 
Example 8
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void nullKeyDisallowed7() {
    Map<Integer, String> map = Map.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e",
                                      5, "f", null, "g");
}
 
Example 9
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void nullKeyDisallowed9() {
    Map<Integer, String> map = Map.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e",
                                      5, "f", 6, "g", 7, "h", null, "i");
}
 
Example 10
Project: openjdk-jdk10   File: CookieManager.java   View Source Code Vote up 4 votes
public Map<String, List<String>>
    get(URI uri, Map<String, List<String>> requestHeaders)
    throws IOException
{
    // pre-condition check
    if (uri == null || requestHeaders == null) {
        throw new IllegalArgumentException("Argument is null");
    }

    // if there's no default CookieStore, no way for us to get any cookie
    if (cookieJar == null)
        return Map.of();

    boolean secureLink = "https".equalsIgnoreCase(uri.getScheme());
    List<HttpCookie> cookies = new java.util.ArrayList<>();
    String path = uri.getPath();
    if (path == null || path.isEmpty()) {
        path = "/";
    }
    for (HttpCookie cookie : cookieJar.get(uri)) {
        // apply path-matches rule (RFC 2965 sec. 3.3.4)
        // and check for the possible "secure" tag (i.e. don't send
        // 'secure' cookies over unsecure links)
        if (pathMatches(path, cookie.getPath()) &&
                (secureLink || !cookie.getSecure())) {
            // Enforce httponly attribute
            if (cookie.isHttpOnly()) {
                String s = uri.getScheme();
                if (!"http".equalsIgnoreCase(s) && !"https".equalsIgnoreCase(s)) {
                    continue;
                }
            }
            // Let's check the authorize port list if it exists
            String ports = cookie.getPortlist();
            if (ports != null && !ports.isEmpty()) {
                int port = uri.getPort();
                if (port == -1) {
                    port = "https".equals(uri.getScheme()) ? 443 : 80;
                }
                if (isInPortList(ports, port)) {
                    cookies.add(cookie);
                }
            } else {
                cookies.add(cookie);
            }
        }
    }

    // apply sort rule (RFC 2965 sec. 3.3.4)
    List<String> cookieHeader = sortByPath(cookies);

    return Map.of("Cookie", cookieHeader);
}
 
Example 11
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void nullValueDisallowed8() {
    Map<Integer, String> map = Map.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e",
                                      5, "f", 6, "g", 7, null);
}
 
Example 12
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=IllegalArgumentException.class)
public void dupKeysDisallowed9() {
    Map<Integer, String> map = Map.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e",
                                      5, "f", 6, "g", 7, "h", 0, "i");
}
 
Example 13
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=IllegalArgumentException.class)
public void dupKeysDisallowed10() {
    Map<Integer, String> map = Map.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e",
                                      5, "f", 6, "g", 7, "h", 8, "i", 0, "j");
}
 
Example 14
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void nullValueDisallowed5() {
    Map<Integer, String> map = Map.of(0, "a", 1, "b", 2, "c", 3, "d", 4, null);
}
 
Example 15
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void nullValueDisallowed4() {
    Map<Integer, String> map = Map.of(0, "a", 1, "b", 2, "c", 3, null);
}
 
Example 16
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void nullValueDisallowed1() {
    Map<Integer, String> map = Map.of(0, null);
}
 
Example 17
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=IllegalArgumentException.class)
public void dupKeysDisallowed2() {
    Map<Integer, String> map = Map.of(0, "a", 0, "b");
}
 
Example 18
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void nullKeyDisallowed10() {
    Map<Integer, String> map = Map.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e",
                                      5, "f", 6, "g", 7, "h", 8, "i", null, "j");
}
 
Example 19
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=IllegalArgumentException.class)
public void dupKeysDisallowed4() {
    Map<Integer, String> map = Map.of(0, "a", 1, "b", 2, "c", 0, "d");
}
 
Example 20
Project: openjdk-jdk10   File: MapFactories.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=NullPointerException.class)
public void nullValueDisallowed9() {
    Map<Integer, String> map = Map.of(0, "a", 1, "b", 2, "c", 3, "d", 4, "e",
                                      5, "f", 6, "g", 7, "h", 8, null);
}