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:org.ambraproject.service.AmbraMailerImpl.java

/**
 * Send an email when the user selects to email an article to a friend
 * @param toEmailAddress toEmailAddress//from   w  w  w.java  2s  .c  om
 * @param fromEmailAddress fromEmailAddress
 * @param mapFields mapFields to fill up the template with the right values
 */
public void sendEmailThisArticleEmail(final String toEmailAddress, final String fromEmailAddress,
        final Map<String, String> mapFields) {
    final HashMap<String, Object> newMapFields = new HashMap<String, Object>();
    newMapFields.putAll(emailThisArticleMap);
    newMapFields.putAll(mapFields);
    sendEmail(toEmailAddress, fromEmailAddress, newMapFields);
}

From source file:org.yestech.jmlnitrate.util.ServletRequestAdaptor.java

public Map getParameterMap() {
    HashMap temp = new HashMap();
    temp.putAll(getRequest().getParameterMap());
    temp.putAll(parameters);/*from   www .java2  s.co m*/
    return temp;

}

From source file:fr.aliasource.webmail.server.GetSettingsImpl.java

public HashMap<String, String> getAllSettings() {
    if (logger.isDebugEnabled()) {
        logger.debug("getAllSettings");
    }/*from w  w  w  .ja va 2  s  .c  o m*/

    HashMap<String, String> ret = new HashMap<String, String>();
    FrontEndConfig feCfg = new FrontEndConfig();
    ret.putAll(feCfg.get());

    IAccount account = (IAccount) getThreadLocalRequest().getSession().getAttribute("account");

    /* We are probably logged using a servlet filter */

    if (account != null) {
        if (logger.isInfoEnabled()) {
            logger.info("logged in as " + account.getLogin() + "@" + account.getDomain());
        }
        ret.put(AJAX_LOGIN, "false");
        ret.put(CURRENT_LOGIN, account.getLogin());
        ret.put(CURRENT_DOMAIN, account.getDomain());

        ret.putAll(account.getServerSettings());
    } else {
        if ("false".equals(ret.get(AJAX_LOGIN))) {
            logger.warn("ajaxLogin disabled, but login not performed.");
        }
    }

    return ret;
}

From source file:jp.co.cyberagent.parquet.msgpack.compat.TestParquetThriftCompatibility.java

@Test
public void testing() {
    ParquetIterator parquet = ParquetIterator
            .fromResource("test-data/spark/parquet-thrift-compat.snappy.parquet");

    String[] suits = new String[] { "SPADES", "HEARTS", "DIAMONDS", "CLUBS" };
    for (int i = 0; i < 10; i++) {
        HashMap<Value, Value> nonNullablePrimitiveValues = new HashMap<>();
        {/*from  w  ww  .  jav a 2  s.co m*/
            HashMap<Value, Value> m = nonNullablePrimitiveValues;
            m.put(newString("boolColumn"), newBoolean(i % 2 == 0));
            m.put(newString("byteColumn"), newInteger(i));
            m.put(newString("shortColumn"), newInteger(i + 1));
            m.put(newString("intColumn"), newInteger(i + 2));
            m.put(newString("longColumn"), newInteger(i * 10));
            m.put(newString("doubleColumn"), newFloat(i + 0.2));
            // Thrift `BINARY` values are actually unencoded `STRING` values, and thus are always
            // treated as `BINARY (UTF8)` in parquet-thrift, since parquet-thrift always assume
            // Thrift `STRING`s are encoded using UTF-8.
            m.put(newString("binaryColumn"), newString("val_" + i));
            m.put(newString("stringColumn"), newString("val_" + i));
            // Thrift ENUM values are converted to Parquet binaries containing UTF-8 strings
            m.put(newString("enumColumn"), newString(suits[i % 4]));
        }

        HashMap<Value, Value> nullablePrimitiveValues = new HashMap<>();
        for (Map.Entry<Value, Value> entry : nonNullablePrimitiveValues.entrySet()) {
            Value key = newString("maybe" + StringUtils.capitalize(entry.getKey().toString()));
            Value value = (i % 3 == 0) ? newNil() : entry.getValue();
            nullablePrimitiveValues.put(key, value);
        }

        HashMap<Value, Value> complexValues = new HashMap<>();
        {
            HashMap<Value, Value> m = complexValues;
            m.put(newString("stringsColumn"),
                    newArray(newString("arr_" + i), newString("arr_" + (i + 1)), newString("arr_" + (i + 2))));
            // Thrift `SET`s are converted to Parquet `LIST`s
            m.put(newString("intSetColumn"), newArray(newInteger(i)));
            m.put(newString("intToStringColumn"),
                    newMap(newInteger(i), newString("val_" + i), newInteger(i + 1), newString("val_" + (i + 1)),
                            newInteger(i + 2), newString("val_" + (i + 2))));

            m.put(newString("complexColumn"), newMap(newInteger(i + 0), newComplexInnerValue(i),
                    newInteger(i + 1), newComplexInnerValue(i), newInteger(i + 2), newComplexInnerValue(i)));
        }

        HashMap<Value, Value> row = new HashMap<>();
        row.putAll(nonNullablePrimitiveValues);
        row.putAll(nullablePrimitiveValues);
        row.putAll(complexValues);

        Value expected = newMap(row);
        Value actual = parquet.next();
        assertThat(actual, is(expected));
    }
}

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

@Override
public Document process(final Document doc) throws Exception {
    LOG.debug("starting " + this.getClass().getSimpleName() + " on doc " + doc.getDocName());
    long startTime = System.currentTimeMillis();
    int contentLength = doc.getAssociativeArray().keySet().stream()
            .filter(k -> fieldsToGate.contains(k.toLowerCase()))
            .mapToInt(k -> ((String) doc.getAssociativeArray().get(k)).length()).sum();

    HashMap<String, Object> newMap = new HashMap<>();
    newMap.putAll(doc.getAssociativeArray());
    List<String> failedFieldsList = new ArrayList<String>(fieldsToGate);

    newMap.put(fieldName, new HashMap<String, Object>());

    doc.getAssociativeArray().forEach((k, v) -> {
        if (fieldsToGate.contains(k.toLowerCase())) {
            gate.Document gateDoc = null;
            try {
                gateDoc = Factory.newDocument((String) v);
                LOG.info("Going to process key: {} in document PK: {}, content length: {}", k,
                        doc.getPrimaryKeyFieldValue(), ((String) v).length());
                gateService.processDoc(gateDoc);
                ((HashMap<String, Object>) newMap.get(fieldName)).put(k, gateService.convertDocToJSON(gateDoc));

                // Remove the key from the list if GATE is successful
                failedFieldsList.remove(k.toLowerCase());
            } catch (Exception e) {
                LOG.warn("gate failed on doc {} (PK: {}): {}", doc.getDocName(), doc.getPrimaryKeyFieldValue(),
                        e);//from www.  ja  va2 s  .co m
                ArrayList<LinkedHashMap<Object, Object>> al = new ArrayList<LinkedHashMap<Object, Object>>();
                LinkedHashMap<Object, Object> hm = new LinkedHashMap<Object, Object>();
                hm.put("error", "see logs");
                al.add(hm);
                ((HashMap<String, Object>) newMap.get(fieldName)).put(k, hm);
            } finally {
                Factory.deleteResource(gateDoc);
            }
        }
    });
    if (failedFieldsList.size() == 0) {
        newMap.put("X-TL-GATE", "Success");
    } else {
        newMap.put("X-TL-GATE", "Failed fields: " + String.join(", ", failedFieldsList));
    }
    doc.getAssociativeArray().clear();
    doc.getAssociativeArray().putAll(newMap);
    long endTime = System.currentTimeMillis();
    LOG.info("{};Primary-Key:{};Total-Content-Length:{};Time:{} ms", this.getClass().getSimpleName(),
            doc.getPrimaryKeyFieldValue(), contentLength, endTime - startTime);
    LOG.debug("finished " + this.getClass().getSimpleName() + " on doc " + doc.getDocName());
    return doc;
}

From source file:org.pentaho.reporting.libraries.resourceloader.loader.raw.RawResourceLoader.java

/**
 * Derives a new resource key from the given key. If neither a path nor new
 * factory-keys are given, the parent key is returned.
 *
 * @param parent      the parent// w  w w.j  a v  a  2 s . co m
 * @param path        the derived path (can be null).
 * @param factoryKeys the optional factory keys (can be null).
 * @return the derived key.
 * @throws org.pentaho.reporting.libraries.resourceloader.ResourceKeyCreationException
 *          if the key cannot be derived for any reason.
 */
public ResourceKey deriveKey(final ResourceKey parent, final String path, final Map factoryKeys)
        throws ResourceKeyCreationException {
    if (path != null) {
        throw new ResourceKeyCreationException("Unable to derive key for new path.");
    }
    if (isSupportedKey(parent) == false) {
        throw new ResourceKeyCreationException("Assertation: Unsupported parent key type");
    }

    if (factoryKeys == null) {
        return parent;
    }

    final HashMap map = new HashMap();
    map.putAll(parent.getFactoryParameters());
    map.putAll(factoryKeys);
    return new ResourceKey(parent.getSchema(), parent.getIdentifier(), map);
}

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

private Document executeWithRetryThrowingExceptions(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);
                }/*  w w  w .j a  v  a2 s.c  o m*/
            }, new RecoveryCallback() {
                @Override
                public Object recover(RetryContext context) throws BiolarkProcessingFailedException {
                    LOG.warn("Biolark failed on document " + doc.getDocName());
                    throw new BiolarkProcessingFailedException("Biolark failed on document " + doc.getDocName(),
                            context.getLastThrowable());
                }
            });
            newMap.put(fieldName, json);
        }
    });
    doc.getAssociativeArray().clear();
    doc.getAssociativeArray().putAll(newMap);
    return doc;
}

From source file:com.eTilbudsavis.etasdk.network.impl.HttpURLNetwork.java

private void setHeaders(Request<?> request, HttpURLConnection connection) {
    HashMap<String, String> headers = new HashMap<String, String>(request.getHeaders().size());
    headers.putAll(request.getHeaders());
    for (String key : headers.keySet())
        connection.setRequestProperty(key, headers.get(key));
}

From source file:com.bitbreeds.webrtc.signaling.BindingService.java

public byte[] processBindingRequest(byte[] data, String userName, String password, InetSocketAddress sender) {

    logger.trace("Input: " + Hex.encodeHexString(data));

    StunMessage msg = StunMessage.fromBytes(data);

    logger.trace("InputParsed: " + msg);

    byte[] content = SignalUtil.joinBytesArrays(SignalUtil.twoBytesFromInt(0x01),
            SignalUtil.xor(SignalUtil.twoBytesFromInt(sender.getPort()),
                    Arrays.copyOf(msg.getHeader().getCookie(), 2)),
            SignalUtil.xor(sender.getAddress().getAddress(), msg.getHeader().getCookie()));

    StunAttribute attr = new StunAttribute(StunAttributeTypeEnum.XOR_MAPPED_ADDRESS, content);

    StunAttribute user = msg.getAttributeSet().get(StunAttributeTypeEnum.USERNAME);
    String strUser = new String(user.toBytes()).split(":")[0].trim();

    msg.validate(password, data);/*from ww w.j a  v a2  s  .co m*/

    HashMap<StunAttributeTypeEnum, StunAttribute> outSet = new HashMap<>();
    outSet.put(StunAttributeTypeEnum.XOR_MAPPED_ADDRESS, attr);
    outSet.putAll(msg.getAttributeSet());

    StunMessage output = StunMessage.fromData(StunRequestTypeEnum.BINDING_RESPONSE, msg.getHeader().getCookie(),
            msg.getHeader().getTransactionID(), outSet, true, true, strUser, password);

    byte[] bt = output.toBytes();
    logger.trace("Response: " + Hex.encodeHexString(bt));
    return bt;
}

From source file:com.eTilbudsavis.etasdk.network.impl.DefaultHttpNetwork.java

private void setHeaders(Request<?> request, HttpRequestBase http) {
    HashMap<String, String> headers = new HashMap<String, String>(request.getHeaders().size());
    headers.putAll(request.getHeaders());
    for (String key : headers.keySet())
        http.setHeader(key, headers.get(key));
}