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:org.openmhealth.shimmer.common.controller.LegacyAuthorizationController.java

/**
 * Endpoint for triggering domain approval.
 *
 * @param username The user record for which we're authorizing a shim.
 * @param clientRedirectUrl The URL to which the external shim client  will be redirected after authorization is
 * complete./*from ww  w  .j a  v  a  2s .c o m*/
 * @param shim The shim registry key of the shim we're approving
 * @return AuthorizationRequest parameters, including a boolean flag if already authorized.
 */
@RequestMapping(value = "/authorize/{shim}", produces = APPLICATION_JSON_VALUE)
public AuthorizationRequestParameters authorize(@RequestParam(value = "username") String username,
        @RequestParam(value = "client_redirect_url", required = false) String clientRedirectUrl,
        @PathVariable("shim") String shim) throws ShimException {

    setPassThroughAuthentication(username, shim);
    AuthorizationRequestParameters authParams = shimRegistry.getShim(shim)
            .getAuthorizationRequestParameters(username, Collections.emptyMap());
    /**
     * Save authorization parameters to local repo. They will be
     * re-fetched via stateKey upon approval.
     */
    authParams.setUsername(username);
    authParams.setClientRedirectUrl(clientRedirectUrl);

    authParametersRepo.save(authParams);

    return authParams;
}

From source file:com.fengduo.bee.commons.core.lang.CollectionUtils.java

private static <K extends Number, V extends Object> Map<K, V> toNumberMap(Collection<V> values, String property,
        Number keyValue) {/*from www .j  ava  2s.c o  m*/
    if (values == null) {
        return Collections.emptyMap();
    }
    Map<K, V> valueMap = new HashMap<K, V>(values.size());
    for (V value : values) {
        try {
            String keyValueStr = BeanUtils.getProperty(value, property);
            if (NumberUtils.isNumber(keyValueStr)) {
                try {
                    // K valueTypeInstance = keyType.newInstance();
                    Object key = MethodUtils.invokeExactMethod(keyValue, "valueOf", keyValueStr);
                    valueMap.put((K) key, value);
                } catch (Exception e) {
                    throw new IllegalArgumentException("Unsupport key Type" + keyValue.getClass().getName(),
                            e);
                }
            } else {
                throw new IllegalArgumentException(
                        "Expect" + keyValue.getClass().getName() + ",Value Actul is " + keyValueStr);
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }
    }
    return valueMap;
}

From source file:com.haulmont.cuba.gui.data.impl.CollectionDatasourceImpl.java

@Override
public void refresh() {
    if (savedParameters == null)
        refresh(Collections.emptyMap());
    else
        refresh(savedParameters);
}

From source file:org.openmrs.module.metadatasharing.handler.impl.SerializedObjectHandler.java

/**
 * @see org.openmrs.module.metadatasharing.handler.MetadataPropertiesHandler#getProperties(java.lang.Object)
 *//* w  w w  .  java 2 s. c  om*/
@Override
public Map<String, Object> getProperties(SerializedObject object) {
    return Collections.emptyMap();
}

From source file:io.pivotal.strepsirrhini.chaosloris.web.ApplicationControllerTest.java

@Test
public void createNullApplicationId() throws Exception {
    this.mockMvc//ww w. j a  va 2s.c om
            .perform(
                    post("/applications").contentType(APPLICATION_JSON).content(asJson(Collections.emptyMap())))
            .andExpect(status().isBadRequest());
}

From source file:eu.stratosphere.nephele.plugins.PluginManager.java

@SuppressWarnings("unchecked")
private Map<String, AbstractPluginLoader> loadPlugins(final File configFile,
        final PluginLookupService pluginLookupService) {

    final Map<String, AbstractPluginLoader> tmpPluginList = new LinkedHashMap<String, AbstractPluginLoader>();

    final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    // Ignore comments in the XML file
    docBuilderFactory.setIgnoringComments(true);
    docBuilderFactory.setNamespaceAware(true);

    try {// ww w. j ava 2s  . co  m

        final DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
        final Document doc = builder.parse(configFile);

        if (doc == null) {
            LOG.error("Unable to load plugins: doc is null");
            return Collections.emptyMap();
        }

        final Element root = doc.getDocumentElement();
        if (root == null) {
            LOG.error("Unable to load plugins: root is null");
            return Collections.emptyMap();
        }

        if (!"plugins".equals(root.getNodeName())) {
            LOG.error("Unable to load plugins: unknown element " + root.getNodeName());
            return Collections.emptyMap();
        }

        final NodeList pluginNodes = root.getChildNodes();

        int pluginCounter = 0;
        for (int i = 0; i < pluginNodes.getLength(); ++i) {

            final Node pluginNode = pluginNodes.item(i);

            // Ignore text at this point
            if (pluginNode instanceof Text) {
                continue;
            }

            if (!"plugin".equals(pluginNode.getNodeName())) {
                LOG.error("Unable to load plugins: unknown element " + pluginNode.getNodeName());
                continue;
            }

            // Increase plugin counter
            ++pluginCounter;

            final NodeList pluginChildren = pluginNode.getChildNodes();
            String pluginName = null;
            String pluginClass = null;
            Configuration pluginConfiguration = null;

            for (int j = 0; j < pluginChildren.getLength(); ++j) {

                final Node pluginChild = pluginChildren.item(j);

                // Ignore text at this point
                if (pluginChild instanceof Text) {
                    continue;
                }

                if ("name".equals(pluginChild.getNodeName())) {
                    pluginName = getTextChild(pluginChild);
                    if (pluginName == null) {
                        LOG.error("Skipping plugin " + pluginCounter
                                + " from configuration because it does not provide a proper name");
                        continue;
                    }
                }

                if ("class".equals(pluginChild.getNodeName())) {
                    pluginClass = getTextChild(pluginChild);
                    if (pluginClass == null) {
                        LOG.error("Skipping plugin " + pluginCounter
                                + " from configuration because it does not provide a loader class");
                        continue;
                    }
                }

                if ("configuration".equals(pluginChild.getNodeName())) {

                    pluginConfiguration = new Configuration();

                    final NodeList configurationNodes = pluginChild.getChildNodes();
                    for (int k = 0; k < configurationNodes.getLength(); ++k) {

                        final Node configurationNode = configurationNodes.item(k);

                        // Ignore text at this point
                        if (configurationNode instanceof Text) {
                            continue;
                        }

                        if (!"property".equals(configurationNode.getNodeName())) {
                            LOG.error("Unexpected node " + configurationNode.getNodeName() + ", skipping...");
                            continue;
                        }

                        String key = null;
                        String value = null;

                        final NodeList properties = configurationNode.getChildNodes();
                        for (int l = 0; l < properties.getLength(); ++l) {

                            final Node property = properties.item(l);

                            // Ignore text at this point
                            if (configurationNode instanceof Text) {
                                continue;
                            }

                            if ("key".equals(property.getNodeName())) {
                                key = getTextChild(property);
                                if (key == null) {
                                    LOG.warn("Skipping configuration entry for plugin " + pluginName
                                            + " because of invalid key");
                                    continue;
                                }
                            }

                            if ("value".equals(property.getNodeName())) {
                                value = getTextChild(property);
                                if (value == null) {
                                    LOG.warn("Skipping configuration entry for plugin " + pluginName
                                            + " because of invalid value");
                                    continue;
                                }
                            }
                        }

                        if (key != null && value != null) {
                            pluginConfiguration.setString(key, value);
                        }
                    }

                }
            }

            if (pluginName == null) {
                LOG.error("Plugin " + pluginCounter + " does not provide a name, skipping...");
                continue;
            }

            if (pluginClass == null) {
                LOG.error("Plugin " + pluginCounter + " does not provide a loader class, skipping...");
                continue;
            }

            if (pluginConfiguration == null) {
                LOG.warn("Plugin " + pluginCounter
                        + " does not provide a configuration, using default configuration");
                pluginConfiguration = new Configuration();
            }

            Class<? extends AbstractPluginLoader> loaderClass;

            try {
                loaderClass = (Class<? extends AbstractPluginLoader>) Class.forName(pluginClass);
            } catch (ClassNotFoundException e) {
                LOG.error("Unable to load plugin " + pluginName + ": " + StringUtils.stringifyException(e));
                continue;
            }

            if (loaderClass == null) {
                LOG.error("Unable to load plugin " + pluginName + ": loaderClass is null");
                continue;
            }

            Constructor<? extends AbstractPluginLoader> constructor;
            try {
                constructor = (Constructor<? extends AbstractPluginLoader>) loaderClass
                        .getConstructor(String.class, Configuration.class, PluginLookupService.class);
            } catch (SecurityException e) {
                LOG.error("Unable to load plugin " + pluginName + ": " + StringUtils.stringifyException(e));
                continue;
            } catch (NoSuchMethodException e) {
                LOG.error("Unable to load plugin " + pluginName + ": " + StringUtils.stringifyException(e));
                continue;
            }

            if (constructor == null) {
                LOG.error("Unable to load plugin " + pluginName + ": constructor is null");
                continue;
            }

            AbstractPluginLoader pluginLoader = null;

            try {
                pluginLoader = constructor.newInstance(pluginName, pluginConfiguration, pluginLookupService);
            } catch (IllegalArgumentException e) {
                LOG.error("Unable to load plugin " + pluginName + ": " + StringUtils.stringifyException(e));
                continue;
            } catch (InstantiationException e) {
                LOG.error("Unable to load plugin " + pluginName + ": " + StringUtils.stringifyException(e));
                continue;
            } catch (IllegalAccessException e) {
                LOG.error("Unable to load plugin " + pluginName + ": " + StringUtils.stringifyException(e));
                continue;
            } catch (InvocationTargetException e) {
                LOG.error("Unable to load plugin " + pluginName + ": " + StringUtils.stringifyException(e));
                continue;
            }

            if (pluginLoader == null) {
                LOG.error("Unable to load plugin " + pluginName + ": pluginLoader is null");
                continue;
            }

            LOG.info("Successfully loaded plugin " + pluginName);
            tmpPluginList.put(pluginName, pluginLoader);
        }

    } catch (IOException e) {
        LOG.error("Error while loading plugins: " + StringUtils.stringifyException(e));
    } catch (SAXException e) {
        LOG.error("Error while loading plugins: " + StringUtils.stringifyException(e));
    } catch (ParserConfigurationException e) {
        LOG.error("Error while loading plugins: " + StringUtils.stringifyException(e));
    }

    return Collections.unmodifiableMap(tmpPluginList);
}

From source file:com.arpnetworking.metrics.vertx.SinkHandlerTest.java

@Test
public void testHandleWithEmptyMaps() throws JsonProcessingException {
    final String messageBody = OBJECT_MAPPER.writeValueAsString(
            ImmutableMap.of(ANNOTATIONS_KEY, Collections.emptyMap(), TIMER_SAMPLES_KEY, Collections.emptyMap(),
                    COUNTER_SAMPLES_KEY, Collections.emptyMap(), GAUGE_SAMPLES_KEY, Collections.emptyMap()));
    Mockito.doReturn(messageBody).when(_message).body();
    _handler.handle(_message);//from  w ww. ja va2 s . com
    Mockito.verify(_mockSink)
            .record(new SinkVerticle.DefaultEvent.Builder().setAnnotations(Collections.emptyMap())
                    .setCounterSamples(Collections.emptyMap()).setGaugeSamples(Collections.emptyMap())
                    .setTimerSamples(Collections.emptyMap()).build());
}

From source file:com.jeremydyer.reporting.docker.DockerReportingTask.java

@OnScheduled
public void setup(final ConfigurationContext context) throws IOException {
    final Map<String, ?> config = Collections.emptyMap();
}

From source file:ai.api.twilio.BaseTwilioServlet.java

/**
 * Send request to api.ai/*w w w.  ja  va  2s . co m*/
 * 
 * @param query
 * @param parameters
 *            - parameters received from www.twilio.com
 * @return response from api.ai
 */
protected String sendRequestToApiAi(String query, Map<String, String[]> parameters) {
    HttpResponse response = null;
    try {
        StringEntity input = new StringEntity(createApiRequest(query, parameters),
                ContentType.APPLICATION_JSON);

        response = POOLING_HTTP_CLIENT.execute(RequestBuilder.post()
                .setUri(TwilioProperties.INSTANCE.getApiUrl())
                .addHeader("Authorization", "Bearer " + TwilioProperties.INSTANCE.getApiAccessToken())
                .addHeader("Accept", ContentType.APPLICATION_JSON.getMimeType()).setEntity(input).build());

        if (response.getStatusLine().getStatusCode() / 100 != 2) {
            return "Error: " + response.getStatusLine();
        }
        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

        StringBuilder resultBuilder = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            resultBuilder.append(line);
        }

        ApiResponse resultResp = gson.fromJson(resultBuilder.toString(), ApiResponse.class);
        if (Strings.isNullOrEmpty(Optional.ofNullable(resultResp.result).map(r -> r.fulfillment)
                .map(f -> f.speech).orElse(null))) {
            return "Action: " + Optional.ofNullable(resultResp.result).map(r -> r.action).orElse("none") + "\n"
                    + gson.toJson(Optional.ofNullable(resultResp.result).map(r -> r.parameters)
                            .orElse(Collections.emptyMap()));
        }
        return resultResp.result.fulfillment.speech;
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
        return "Error: " + e.getMessage();
    } finally {
        if (response != null) {
            try {
                EntityUtils.consume(response.getEntity());
            } catch (IOException e) {
                // Ignore
            }
        }
    }
}