Example usage for java.util HashMap putAll

List of usage examples for java.util HashMap putAll

Introduction

In this page you can find the example usage for java.util HashMap putAll.

Prototype

public void putAll(Map<? extends K, ? extends V> m) 

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:uk.ac.kcl.itemProcessors.BioLarkDocumentItemProcessor.java

private Document executeWithRetryIgnoringExceptions(Document doc) {
    HashMap<String, Object> newMap = new HashMap<>();
    newMap.putAll(doc.getAssociativeArray());
    doc.getAssociativeArray().forEach((k, v) -> {
        if (fieldsToBioLark.contains(k)) {
            Object json = retryTemplate.execute(new RetryCallback<Object, BiolarkProcessingFailedException>() {
                public Object doWithRetry(RetryContext context) {
                    // business logic here
                    return restTemplate.postForObject(endPoint, v, Object.class);
                }/*from   w w w  .  j  av a2  s .c o  m*/
            }, new RecoveryCallback() {
                @Override
                public Object recover(RetryContext context) throws BiolarkProcessingFailedException {
                    LOG.warn("Biolark failed on document " + doc.getDocName());
                    ArrayList<LinkedHashMap<Object, Object>> al = new ArrayList<LinkedHashMap<Object, Object>>();
                    LinkedHashMap<Object, Object> hm = new LinkedHashMap<Object, Object>();
                    hm.put(fieldName, "biolark failed");
                    al.add(hm);
                    doc.getExceptions().add(new BiolarkProcessingFailedException(
                            "Biolark failed on document " + doc.getDocName()));
                    return al;
                }
            });
            newMap.put(fieldName, json);
        }
    });
    doc.getAssociativeArray().clear();
    doc.getAssociativeArray().putAll(newMap);
    return doc;
}

From source file:uk.ac.kcl.itemProcessors.WebserviceDocumentItemProcessor.java

private Document executeWithRetryThrowingExceptions(Document doc) {
    HashMap<String, Object> newMap = new HashMap<>();
    newMap.putAll(doc.getAssociativeArray());
    doc.getAssociativeArray().forEach((k, v) -> {
        if (fieldsToSendToWebservice.contains(k.toLowerCase())) {
            Object json = retryTemplate
                    .execute(new RetryCallback<Object, WebserviceProcessingFailedException>() {
                        public Object doWithRetry(RetryContext context) {
                            // business logic here
                            return restTemplate.postForObject(endPoint, v, Object.class);
                        }/*from  w  w  w.  j  a  v  a2  s .c om*/
                    }, new RecoveryCallback() {
                        @Override
                        public Object recover(RetryContext context) throws WebserviceProcessingFailedException {
                            LOG.warn(webserviceName + " failed on document " + doc.getDocName());
                            throw new WebserviceProcessingFailedException(
                                    webserviceName + "  failed on document " + doc.getDocName(),
                                    context.getLastThrowable());
                        }
                    });
            newMap.put(fieldName, json);
        }
    });
    doc.getAssociativeArray().clear();
    doc.getAssociativeArray().putAll(newMap);
    return doc;
}

From source file:org.apache.ambari.view.utils.ambari.URLStreamProviderBasicAuth.java

private HashMap<String, String> addHeaders(Map<String, String> customHeaders) {
    HashMap<String, String> newHeaders = new HashMap<String, String>();
    if (customHeaders != null)
        newHeaders.putAll(customHeaders);

    if (urlStreamProvider != null) {
        // basic auth is not needed for AmbariStreamProvider
        addBasicAuthHeaders(newHeaders);
    }/*  ww w. j a  v a 2s  .  c o  m*/
    addRequestedByHeaders(newHeaders);
    return newHeaders;
}

From source file:uk.ac.kcl.itemProcessors.WebserviceDocumentItemProcessor.java

private Document executeWithRetryIgnoringExceptions(Document doc) {
    HashMap<String, Object> newMap = new HashMap<>();
    newMap.putAll(doc.getAssociativeArray());
    doc.getAssociativeArray().forEach((k, v) -> {
        if (fieldsToSendToWebservice.contains(k.toLowerCase())) {
            Object json = retryTemplate
                    .execute(new RetryCallback<Object, WebserviceProcessingFailedException>() {
                        public Object doWithRetry(RetryContext context) {
                            // business logic here
                            Object ob = restTemplate.postForObject(endPoint, v, Object.class);

                            return ob;
                        }//from  w w w .ja v a 2 s.  c  o  m
                    }, new RecoveryCallback() {
                        @Override
                        public Object recover(RetryContext context) throws WebserviceProcessingFailedException {
                            LOG.warn(webserviceName + " failed on document " + doc.getDocName());
                            ArrayList<LinkedHashMap<Object, Object>> al = new ArrayList<LinkedHashMap<Object, Object>>();
                            LinkedHashMap<Object, Object> hm = new LinkedHashMap<Object, Object>();
                            hm.put(fieldName, webserviceName + " failed");
                            al.add(hm);
                            doc.getExceptions().add(new WebserviceProcessingFailedException(
                                    webserviceName + " failed on document " + doc.getDocName()));
                            return al;
                        }
                    });
            newMap.put(fieldName, json);
        }
    });
    doc.getAssociativeArray().clear();
    doc.getAssociativeArray().putAll(newMap);
    return doc;
}

From source file:eu.planets_project.pp.plato.evaluation.evaluators.ObjectEvaluator.java

public HashMap<MeasurementInfoUri, Value> evaluate(Alternative alternative, SampleObject sample,
        DigitalObject result, List<MeasurementInfoUri> measurementInfoUris, IStatusListener listener)
        throws EvaluatorException {

    listener.updateStatus("Objectevaluator: Start evaluation"); //" for alternative: %s, samle: %s", NAME, alternative.getName(), sample.getFullname()));

    HashMap<MeasurementInfoUri, Value> results = new HashMap<MeasurementInfoUri, Value>();

    for (MeasurementInfoUri measurementInfoUri : measurementInfoUris) {
        String propertyURI = measurementInfoUri.getAsURI();
        Scale scale = descriptor.getMeasurementScale(measurementInfoUri);
        if (scale == null) {
            // This means that I am not entitled to evaluate this measurementInfo and therefore supposed to skip it:
            continue;
        }//from   ww  w.j a  va2 s. c  o  m
        if (OBJECT_FORMAT_RELATIVEFILESIZE.equals(propertyURI)) {
            // evaluate here
            PositiveFloatValue v = (PositiveFloatValue) scale.createValue();
            double d = ((double) result.getData().getSize()) / sample.getData().getSize() * 100;
            long l = Math.round(d);
            d = ((double) l) / 100;
            v.setValue(d);
            results.put(measurementInfoUri, v);
            listener.updateStatus(String.format("Objectevaluator: evaluated measurement: %s = %s",
                    measurementInfoUri.getAsURI(), v.toString()));
        }
    }
    measurementInfoUris.removeAll(results.keySet());
    FITSEvaluator fitsEval = new FITSEvaluator();
    HashMap<MeasurementInfoUri, Value> fitsResults = fitsEval.evaluate(alternative, sample, result,
            measurementInfoUris, listener);
    fitsResults.putAll(results);

    return fitsResults;
}

From source file:org.cesecore.util.HashMapTest.java

@SuppressWarnings("rawtypes")
@Test/*  www .  j  a  v  a 2 s. c  o  m*/
public void testHashMapStrangeCharsSafe() throws Exception {
    HashMap<String, Comparable> h = new HashMap<String, Comparable>();
    h.put("foo0", Boolean.FALSE);
    h.put("foo1", "\0001\0002fooString");
    h.put("foo2", Integer.valueOf(2));
    h.put("foo3", Boolean.TRUE);
    h.put("foo4", "");
    HashMap<Object, Object> a = new Base64PutHashMap();
    a.putAll(h);

    // Write to XML
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(baos);
    encoder.writeObject(a);
    encoder.close();
    String data = baos.toString("UTF8");
    //log.error(data);

    try {
        XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(data.getBytes("UTF8")));
        HashMap<?, ?> b = (HashMap<?, ?>) decoder.readObject();
        decoder.close();
        @SuppressWarnings("unchecked")
        HashMap<Object, Object> c = new Base64GetHashMap(b);
        assertEquals(((Boolean) c.get("foo0")).booleanValue(), false);
        assertEquals(((Boolean) c.get("foo3")).booleanValue(), true);
        assertEquals(((String) c.get("foo1")), "\0001\0002fooString");
        assertEquals(((String) c.get("foo4")), "");
        assertEquals(((Integer) c.get("foo2")).intValue(), 2);

    } catch (ClassCastException e) {
        assertTrue(false);
    }
}

From source file:org.cesecore.util.HashMapTest.java

@SuppressWarnings("rawtypes")
@Test//from www .ja va 2  s .  c  o  m
public void testHashMapNormalCharsSafe() throws Exception {
    HashMap<String, Comparable> h = new HashMap<String, Comparable>();
    h.put("foo0", Boolean.FALSE);
    h.put("foo1", "fooString");
    h.put("foo2", Integer.valueOf(2));
    h.put("foo3", Boolean.TRUE);
    h.put("foo4", "");
    HashMap<Object, Object> a = new Base64PutHashMap();
    a.putAll(h);

    // Write to XML
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(baos);
    encoder.writeObject(a);
    encoder.close();
    String data = baos.toString("UTF8");
    //log.error(data);

    try {
        XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(data.getBytes("UTF8")));
        HashMap<?, ?> b = (HashMap<?, ?>) decoder.readObject();
        decoder.close();
        @SuppressWarnings("unchecked")
        HashMap<Object, Object> c = new Base64GetHashMap(b);
        assertEquals(((Boolean) c.get("foo0")).booleanValue(), false);
        assertEquals(((Boolean) c.get("foo3")).booleanValue(), true);
        assertEquals(((String) c.get("foo4")), "");
        assertEquals(((String) c.get("foo1")), "fooString");
        assertEquals(((Integer) c.get("foo2")).intValue(), 2);

    } catch (ClassCastException e) {
        assertTrue(false);
    }
}

From source file:contrail.correct.InvokeFlash.java

protected Map<String, ParameterDefinition> createParameterDefinitions() {
    HashMap<String, ParameterDefinition> defs = new HashMap<String, ParameterDefinition>();
    defs.putAll(super.createParameterDefinitions());
    ParameterDefinition flashBinary = new ParameterDefinition("flash_binary", "The path of flash binary ",
            String.class, new String(""));
    for (ParameterDefinition def : new ParameterDefinition[] { flashBinary }) {
        defs.put(def.getName(), def);/*ww  w.  j a  v a2  s .  com*/
    }
    for (ParameterDefinition def : ContrailParameters.getInputOutputPathOptions()) {
        defs.put(def.getName(), def);
    }
    return Collections.unmodifiableMap(defs);
}

From source file:ch.sbb.releasetrain.action.SendMailAction.java

@Override
public ActionResult doWork(ActionState state, HashMap properties) {

    EmailActionConfig config = (EmailActionConfig) state.getConfig();

    Map<String, String> params = new HashMap<>(config.getProperties());

    properties.putAll(params);

    String subject = replaceVars(config.getSubject(), properties);
    String text = replaceVars(config.getText(), properties);

    // List<MailReceiver> receiver =
    // config.readMailReveiverForMailinglist(mailinglist);

    String[] arr = config.getReceiver().split(",");

    smtpUtil.setMailhost(config.getSmtpServer());
    for (String rec : arr) {
        smtpUtil.send(config.getSender(), rec, subject, text);
    }/*  www  . j ava  2 s.  c o m*/
    return ActionResult.SUCCESS;

}

From source file:net.doubledoordev.backend.web.http.FreemarkerHandler.java

@Override
public String generate(Request request, int status, String reasonPhrase, String description,
        Throwable exception) {//from w  ww  . j a v  a  2s.c om
    HashMap<String, Object> data = new HashMap<>(request.getSession().attributes().size() + 10);
    data.putAll(request.getSession().attributes());
    data.put(STATUS, status);
    data.put("reasonPhrase", reasonPhrase);
    data.put("description", description);
    data.put("exception", exception);
    if (exception != null)
        data.put("stackTrace", ExceptionUtils.getStackTrace(exception));

    StringWriter stringWriter = new StringWriter();
    try {
        freemarker.getTemplate(ERROR_TEMPLATE).process(data, stringWriter);
    } catch (Exception e) {
        e.printStackTrace(new PrintWriter(stringWriter));
    }
    return stringWriter.toString();
}