Example usage for java.util Collections emptyMap

List of usage examples for java.util Collections emptyMap

Introduction

In this page you can find the example usage for java.util Collections emptyMap.

Prototype

@SuppressWarnings("unchecked")
public static final <K, V> Map<K, V> emptyMap() 

Source Link

Document

Returns an empty map (immutable).

Usage

From source file:com.ikanow.aleph2.analytics.services.GraphBuilderEnrichmentService.java

@Override
public void onStageInitialize(IEnrichmentModuleContext context, DataBucketBean bucket,
        EnrichmentControlMetadataBean control, Tuple2<ProcessingStage, ProcessingStage> previous_next,
        Optional<List<String>> next_grouping_fields) {

    _context.set(context);//from w  ww .  j  av a2  s.co m

    final GraphConfigBean dedup_config = BeanTemplateUtils
            .from(Optional.ofNullable(control.config()).orElse(Collections.emptyMap()), GraphConfigBean.class)
            .get();

    // Check if enabled
    final Optional<GraphSchemaBean> maybe_graph_schema = Optional
            .ofNullable(dedup_config.graph_schema_override()).map(Optional::of)
            .orElse(Optionals.of(() -> bucket.data_schema().graph_schema())); //(exists by construction)

    _enabled.set(maybe_graph_schema.map(gs -> Optional.ofNullable(gs.enabled()).orElse(true)).orElse(false));

    if (_enabled.get()) {
        // Get the configured graph db service's delegate and store it

        final GraphSchemaBean graph_schema = maybe_graph_schema.get(); //(exists by construction)

        context.getServiceContext()
                .getService(IGraphService.class, Optional.ofNullable(graph_schema.service_name()))
                .flatMap(graph_service -> graph_service.getUnderlyingPlatformDriver(
                        IEnrichmentBatchModule.class, Optional.of(this.getClass().getName())))
                .ifPresent(delegate -> _delegate.set(delegate));
        ;

        _delegate.optional().ifPresent(delegate -> delegate.onStageInitialize(context, bucket, control,
                previous_next, next_grouping_fields));
    }
}

From source file:com.androidex.volley.toolbox.BasicNetwork.java

@Override
public NetworkResponse performRequest(Request<?> request) throws VolleyError {
    long requestStart = SystemClock.elapsedRealtime();
    while (true) {
        HttpResponse httpResponse = null;
        byte[] responseContents = null;
        Map<String, String> responseHeaders = Collections.emptyMap();
        try {//from   w ww.  j  a va2  s . c o m
            // Gather headers.
            Map<String, String> headers = new HashMap<String, String>();
            addCacheHeaders(headers, request.getCacheEntry());
            httpResponse = mHttpStack.performRequest(request, headers);
            StatusLine statusLine = httpResponse.getStatusLine();
            int statusCode = statusLine.getStatusCode();

            responseHeaders = convertHeaders(httpResponse.getAllHeaders());
            // Handle cache validation.
            if (statusCode == HttpStatus.SC_NOT_MODIFIED) {
                Cache.Entry entry = request.getCacheEntry();
                if (entry == null) {
                    return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, null, responseHeaders, true,
                            SystemClock.elapsedRealtime() - requestStart);
                }
                // A HTTP 304 response does not have all header fields. We
                // have to use the header fields from the cache entry plus
                // the new ones from the response.
                // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
                entry.responseHeaders.putAll(responseHeaders);
                return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, entry.data, entry.responseHeaders, true,
                        SystemClock.elapsedRealtime() - requestStart);
            }

            // Some responses such as 204s do not have content.  We must check.
            if (httpResponse.getEntity() != null) {
                responseContents = entityToBytes(request, httpResponse.getEntity());
            } else {
                // Add 0 byte response as a way of honestly representing a
                // no-content request.
                responseContents = new byte[0];
            }
            // if the request is slow, log it.
            long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
            logSlowRequests(requestLifetime, request, responseContents, statusLine);

            if (statusCode < 200 || statusCode > 299) {
                throw new IOException();
            }
            return new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                    SystemClock.elapsedRealtime() - requestStart);
        } catch (SocketTimeoutException e) {
            attemptRetryOnException("socket", request, new TimeoutError());
        } catch (ConnectTimeoutException e) {
            attemptRetryOnException("connection", request, new TimeoutError());
        } catch (MalformedURLException e) {
            throw new RuntimeException("Bad URL " + request.getUrl(), e);
        } catch (IOException e) {
            int statusCode = 0;
            NetworkResponse networkResponse = null;
            if (httpResponse != null) {
                statusCode = httpResponse.getStatusLine().getStatusCode();
            } else {
                throw new NoConnectionError(new NetworkResponse(-1, null, responseHeaders, false,
                        SystemClock.elapsedRealtime() - requestStart), e);
            }
            VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl());
            if (responseContents != null) {
                networkResponse = new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                        SystemClock.elapsedRealtime() - requestStart);

                if (statusCode >= HttpStatus.SC_INTERNAL_SERVER_ERROR) {
                    throw new ServerError(networkResponse);
                } else {
                    if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) {
                        attemptRetryOnException("auth", request, new AuthFailureError(networkResponse));
                    } else {
                        throw new VolleyError(networkResponse);
                    }
                }
            } else {
                throw new NetworkError(networkResponse);
            }
        }
    }
}

From source file:com.streamsets.pipeline.stage.it.AllSdcTypesIT.java

@Parameterized.Parameters(name = "type({0})")
public static Collection<Object[]> data() throws Exception {
    return Arrays.asList(new Object[][] { { Field.create(Field.Type.BOOLEAN, true), true, Types.BOOLEAN, true },
            { Field.create(Field.Type.CHAR, 'A'), true, Types.VARCHAR, "A" },
            { Field.create(Field.Type.BYTE, (byte) 0x00), false, 0, null },
            { Field.create(Field.Type.SHORT, 10), true, Types.INTEGER, 10 },
            { Field.create(Field.Type.INTEGER, 10), true, Types.INTEGER, 10 },
            { Field.create(Field.Type.LONG, 10), true, Types.BIGINT, 10L },
            { Field.create(Field.Type.FLOAT, 1.5), true, Types.FLOAT, 1.5 },
            { Field.create(Field.Type.DOUBLE, 1.5), true, Types.DOUBLE, 1.5 },
            { Field.create(Field.Type.DATE, new Date(116, 5, 13)), true, Types.DATE, new Date(116, 5, 13) },
            { Field.create(Field.Type.DATETIME, date), true, Types.VARCHAR, datetimeFormat.format(date) },
            { Field.create(Field.Type.TIME, date), true, Types.VARCHAR, timeFormat.format(date) },
            { Field.create(Field.Type.DECIMAL, BigDecimal.valueOf(1.5)), true, Types.DECIMAL,
                    new BigDecimal(BigInteger.valueOf(15), 1, new MathContext(2, RoundingMode.FLOOR)) },
            { Field.create(Field.Type.STRING, "StreamSets"), true, Types.VARCHAR, "StreamSets" },
            { Field.create(Field.Type.BYTE_ARRAY, new byte[] { (byte) 0x00 }), true, Types.BINARY,
                    new byte[] { (byte) 0x00 } },
            { Field.create(Field.Type.MAP, Collections.emptyMap()), false, 0, null },
            { Field.create(Field.Type.LIST, Collections.emptyList()), false, 0, null },
            { Field.create(Field.Type.LIST_MAP, new LinkedHashMap<>()), false, 0, null }, });
}

From source file:brooklyn.rest.resources.ServerResourceIntegrationTest.java

/**
 * [sam] Other tests rely on brooklyn.properties not containing security properties so ..
 * I think the best way to test this is to set a security provider, then reload properties
 * and check no authentication is required.
 * /*from   w w w  .  j ava2  s.c om*/
 * [aled] Changing this test so doesn't rely on brooklyn.properties having no security
 * provider (that can lead to failures locally when running just this test). Asserts 
 */
@Test(groups = "Integration")
public void testSecurityProviderUpdatesWhenPropertiesReloaded() {
    BrooklynProperties brooklynProperties = BrooklynProperties.Factory.newEmpty();
    brooklynProperties.put("brooklyn.webconsole.security.users", "admin");
    brooklynProperties.put("brooklyn.webconsole.security.user.admin.password", "mypassword");
    UsernamePasswordCredentials defaultCredential = new UsernamePasswordCredentials("admin", "mypassword");

    ManagementContext mgmt = new LocalManagementContext(brooklynProperties);

    try {
        Server server = useServerForTest(BrooklynRestApiLauncher.launcher().managementContext(mgmt)
                .withoutJsgui().securityProvider(TestSecurityProvider.class).start());
        String baseUri = getBaseUri(server);

        HttpToolResponse response;
        final URI uri = URI.create(getBaseUri() + "/v1/server/properties/reload");
        final Map<String, String> args = Collections.emptyMap();

        // Unauthorised when no credentials, and when default credentials.
        response = HttpTool.httpPost(httpClientBuilder().uri(baseUri).build(), uri, args, args);
        assertEquals(response.getResponseCode(), HttpStatus.SC_UNAUTHORIZED);

        response = HttpTool.httpPost(httpClientBuilder().uri(baseUri).credentials(defaultCredential).build(),
                uri, args, args);
        assertEquals(response.getResponseCode(), HttpStatus.SC_UNAUTHORIZED);

        // Accepts TestSecurityProvider credentials, and we reload.
        response = HttpTool.httpPost(
                httpClientBuilder().uri(baseUri).credentials(TestSecurityProvider.CREDENTIAL).build(), uri,
                args, args);
        HttpTestUtils.assertHealthyStatusCode(response.getResponseCode());

        // Has no gone back to credentials from brooklynProperties; TestSecurityProvider credentials no longer work
        response = HttpTool.httpPost(httpClientBuilder().uri(baseUri).credentials(defaultCredential).build(),
                uri, args, args);
        HttpTestUtils.assertHealthyStatusCode(response.getResponseCode());

        response = HttpTool.httpPost(
                httpClientBuilder().uri(baseUri).credentials(TestSecurityProvider.CREDENTIAL).build(), uri,
                args, args);
        assertEquals(response.getResponseCode(), HttpStatus.SC_UNAUTHORIZED);

    } finally {
        ((ManagementContextInternal) mgmt).terminate();
    }
}

From source file:com.yaozu.object.volley.toolbox.BasicNetwork.java

@Override
public NetworkResponse performRequest(Request<?> request) throws VolleyError {
    long requestStart = SystemClock.elapsedRealtime();
    while (true) {
        HttpResponse httpResponse = null;
        byte[] responseContents = null;
        Map<String, String> responseHeaders = Collections.emptyMap();
        try {/*w  w  w.  ja v  a 2s . com*/
            // Gather headers.
            Map<String, String> headers = new HashMap<String, String>();
            addCacheHeaders(headers, request.getCacheEntry());
            httpResponse = mHttpStack.performRequest(request, headers);
            StatusLine statusLine = httpResponse.getStatusLine();
            int statusCode = statusLine.getStatusCode();

            responseHeaders = convertHeaders(httpResponse.getAllHeaders());
            // Handle cache validation.
            if (statusCode == HttpStatus.SC_NOT_MODIFIED) {

                Cache.Entry entry = request.getCacheEntry();
                if (entry == null) {
                    return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, null, responseHeaders, true,
                            SystemClock.elapsedRealtime() - requestStart);
                }

                // A HTTP 304 response does not have all header fields. We
                // have to use the header fields from the cache entry plus
                // the new ones from the response.
                // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
                entry.responseHeaders.putAll(responseHeaders);
                return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, entry.data, entry.responseHeaders, true,
                        SystemClock.elapsedRealtime() - requestStart);
            }

            // Handle moved resources
            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY
                    || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
                String newUrl = responseHeaders.get("Location");
                request.setRedirectUrl(newUrl);
            }

            // Some responses such as 204s do not have content.  We must check.
            if (httpResponse.getEntity() != null) {
                responseContents = entityToBytes(httpResponse.getEntity());
            } else {
                // Add 0 byte response as a way of honestly representing a
                // no-content request.
                responseContents = new byte[0];
            }

            // if the request is slow, log it.
            long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
            logSlowRequests(requestLifetime, request, responseContents, statusLine);

            if (statusCode < 200 || statusCode > 299) {
                throw new IOException();
            }
            return new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                    SystemClock.elapsedRealtime() - requestStart);
        } catch (SocketTimeoutException e) {
            attemptRetryOnException("socket", request, new TimeoutError());
        } catch (ConnectTimeoutException e) {
            attemptRetryOnException("connection", request, new TimeoutError());
        } catch (MalformedURLException e) {
            throw new RuntimeException("Bad URL " + request.getUrl(), e);
        } catch (IOException e) {
            int statusCode = 0;
            NetworkResponse networkResponse = null;
            if (httpResponse != null) {
                statusCode = httpResponse.getStatusLine().getStatusCode();
            } else {
                throw new NoConnectionError(e);
            }
            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY
                    || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
                VolleyLog.e("Request at %s has been redirected to %s", request.getOriginUrl(),
                        request.getUrl());
            } else {
                VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl());
            }
            if (responseContents != null) {
                networkResponse = new NetworkResponse(statusCode, responseContents, responseHeaders, false,
                        SystemClock.elapsedRealtime() - requestStart);
                if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) {
                    attemptRetryOnException("auth", request, new AuthFailureError(networkResponse));
                } else if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY
                        || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
                    attemptRetryOnException("redirect", request, new RedirectError(networkResponse));
                } else {
                    // TODO: Only throw ServerError for 5xx status codes.
                    throw new ServerError(networkResponse);
                }
            } else {
                throw new NetworkError(e);
            }
        }
    }
}

From source file:org.craftercms.core.xml.mergers.impl.cues.impl.MergeCueResolverImpl.java

@Override
public MergeCueContext getMergeCue(Element parent, Element child) {
    MergeCue parentMergeCue;/*from   ww w.ja  v  a 2  s  . c om*/
    MergeCue childMergeCue;

    Attribute parentMergeCueAttribute = getMergeCueAttribute(parent, parentMergeCues);
    if (parentMergeCueAttribute != null) {
        parentMergeCue = parentMergeCues.get(parentMergeCueAttribute.getQName());
    } else {
        parentMergeCue = defaultParentMergeCue;
    }

    Attribute childMergeCueAttribute = getMergeCueAttribute(child, childMergeCues);
    if (childMergeCueAttribute != null) {
        childMergeCue = childMergeCues.get(childMergeCueAttribute.getQName());
    } else {
        childMergeCue = defaultChildMergeCue;
    }

    MergeCue chosenMergeCue;
    Map<String, String> mergeCueParams;

    if (parentMergeCue.getPriority() > childMergeCue.getPriority()) {
        chosenMergeCue = parentMergeCue;

        if (parentMergeCueAttribute != null) {
            mergeCueParams = getMergeCueParams(parent, parentMergeCueAttribute);
        } else {
            mergeCueParams = Collections.emptyMap();
        }
    } else {
        chosenMergeCue = childMergeCue;

        if (childMergeCueAttribute != null) {
            mergeCueParams = getMergeCueParams(child, childMergeCueAttribute);
        } else {
            mergeCueParams = Collections.emptyMap();
        }
    }

    return new MergeCueContext(chosenMergeCue, parent, child, mergeCueParams);
}

From source file:com.iflytek.edu.cloud.frame.spring.rest.ServiceMethodInfoHandlerMapping.java

/**
 * Expose URI template variables, matrix variables, and producible media types in the request.
 * @see HandlerMapping#URI_TEMPLATE_VARIABLES_ATTRIBUTE
 * @see HandlerMapping#MATRIX_VARIABLES_ATTRIBUTE
 * @see HandlerMapping#PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
 *//*from   w  w w . j av a2  s.c  o  m*/
@Override
protected void handleMatch(ServiceMethodInfo info, String lookupPath, HttpServletRequest request) {
    super.handleMatch(info, lookupPath, request);
    request.setAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE, lookupPath);
    request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, Collections.emptyMap());
}

From source file:org.ops4j.pax.web.itest.base.client.HttpComponentsWrapper.java

HttpComponentsWrapper(Map<String, String> httpHeaders, String user, String password, String keyStore)
        throws Exception {
    if (httpHeaders != null) {
        this.httpHeaders = Collections.unmodifiableMap(httpHeaders);
    } else {//from  w  ww.ja v  a 2  s .c om
        this.httpHeaders = Collections.unmodifiableMap(Collections.emptyMap());
    }
    this.user = user;
    this.password = password;

    if (keyStore.startsWith("${")) {
        int indexOfPlaceHolder = keyStore.indexOf("}");
        String placeHolder = keyStore.substring(0, indexOfPlaceHolder);
        placeHolder = placeHolder.substring(2, placeHolder.length());
        String property = System.getProperty(placeHolder);
        this.keyStore = property + keyStore.substring(indexOfPlaceHolder + 1);
    } else {
        this.keyStore = keyStore;
    }

    httpclient = createHttpClient();
    httpAsyncClient.start();
}

From source file:com.github.pjungermann.config.specification.constraint.email.EmailConstraintTest.java

/**
 * Sets up the test data//from w w w . jav a2 s.c  o m
 */
@Override
protected void testDataSetUp() {
    with(false).valid("anything").buildAndAdd();

    with(true).valid("test@example.org").invalid("test@localhost").invalid("test@example.internal")
            .invalid("test@example.local").invalid("test@example.lan").invalid("test@my.custom.lan")
            .invalid("test@-localhost").invalid("test@-example.internal").invalid("test@-example.local")
            .invalid("test@-example.lan").invalid("test @-example.org").buildAndAdd();

    with(Collections.emptyMap()).valid("test@example.org").invalid("test@localhost")
            .invalid("test@example.internal").invalid("test@example.local").invalid("test@example.lan")
            .invalid("test@my.custom.lan").invalid("test@-localhost").invalid("test@-example.internal")
            .invalid("test@-example.local").invalid("test@-example.lan").invalid("test @-example.org")
            .buildAndAdd();

    with(singletonMap("local", false)).valid("test@example.org").invalid("test@localhost")
            .invalid("test@example.internal").invalid("test@example.local").invalid("test@example.lan")
            .invalid("test@my.custom.lan").invalid("test@-localhost").invalid("test@-example.internal")
            .invalid("test@-example.local").invalid("test@-example.lan").invalid("test @-example.org")
            .buildAndAdd();

    with(singletonMap("local", true)).valid("test@example.org").valid("test@localhost")
            .invalid("test@example.internal").invalid("test@example.local").invalid("test@example.lan")
            .invalid("test@my.custom.lan").invalid("test@-localhost").invalid("test@-example.internal")
            .invalid("test@-example.local").invalid("test@-example.lan").invalid("test @-example.org")
            .buildAndAdd();

    with(singletonMap("customTLDs", emptyList())).valid("test@example.org").invalid("test@localhost")
            .invalid("test@example.internal").invalid("test@example.local").invalid("test@example.lan")
            .invalid("test@my.custom.lan").invalid("test@-localhost").invalid("test@-example.internal")
            .invalid("test@-example.local").invalid("test@-example.lan").invalid("test @-example.org")
            .buildAndAdd();

    with(singletonMap("customTLDs", Arrays.asList("internal", "local", "lan"))).valid("test@example.org")
            .invalid("test@localhost").valid("test@example.internal").valid("test@example.local")
            .valid("test@example.lan").valid("test@my.custom.lan").invalid("test@-localhost")
            .invalid("test@-example.internal").invalid("test@-example.local").invalid("test@-example.lan")
            .invalid("test @-example.org").buildAndAdd();

    HashMap<String, Object> config1 = new HashMap<>();
    config1.put("local", false);
    config1.put("customTLDs", emptyList());
    with(config1).valid("test@example.org").invalid("test@localhost").invalid("test@example.internal")
            .invalid("test@example.local").invalid("test@example.lan").invalid("test@my.custom.lan")
            .invalid("test@-localhost").invalid("test@-example.internal").invalid("test@-example.local")
            .invalid("test@-example.lan").invalid("test @-example.org").buildAndAdd();

    HashMap<String, Object> config2 = new HashMap<>();
    config2.put("local", true);
    config2.put("customTLDs", Arrays.asList("internal", "local", "lan"));
    with(config2).valid("test@example.org").valid("test@localhost").valid("test@example.internal")
            .valid("test@example.local").valid("test@example.lan").valid("test@my.custom.lan")
            .invalid("test@-localhost").invalid("test@-example.internal").invalid("test@-example.local")
            .invalid("test@-example.lan").invalid("test @-example.org").buildAndAdd();
}

From source file:cop.maven.plugins.AbstractRamlConfigMojo.java

private void applyApiPart(@NotNull Map<String, Object> map) {
    checkMavenApiPart();//  w w w  . jav  a2s.  com
    Map<String, Object> api = getOrCreateMap(map, Config.KEY_API);

    put(api, this.api, Config.KEY_API_TITLE);
    put(api, this.api, Config.KEY_API_BASE_URI);
    put(api, this.api, Config.KEY_API_VERSION);
    put(api, this.api, Config.KEY_API_MEDIA_TYPE);

    Map<String, Object> doc = getOrCreateMap(api, Config.KEY_API_DOC);
    Map<String, Object> src = (Map<String, Object>) this.api.getOrDefault(Config.KEY_API_DOC,
            Collections.emptyMap());
    put(doc, src, Config.KEY_API_DOC_TITLE);
    put(doc, src, Config.KEY_API_DOC_CONTENT);
}