Example usage for io.vertx.core.shareddata LocalMap replace

List of usage examples for io.vertx.core.shareddata LocalMap replace

Introduction

In this page you can find the example usage for io.vertx.core.shareddata LocalMap replace.

Prototype

@Override
@GenIgnore
boolean replace(K key, V oldValue, V newValue);

Source Link

Document

Replaces the entry for the specified key only if currently mapped to the specified value.

Usage

From source file:org.entcore.common.notification.TimelineHelper.java

License:Open Source License

private void appendTimelineEventsI18n(Map<String, JsonObject> i18ns) {
    LocalMap<String, String> eventsI18n = vertx.sharedData().getLocalMap("timelineEventsI18n");
    for (Map.Entry<String, JsonObject> e : i18ns.entrySet()) {
        String json = e.getValue().encode();
        if (StringUtils.isEmpty(json) || "{}".equals(StringUtils.stripSpaces(json)))
            continue;
        String j = json.substring(1, json.length() - 1) + ",";
        String resJson = j;//from w ww.j ava2 s .  c om
        String oldJson = eventsI18n.putIfAbsent(e.getKey(), j);
        if (oldJson != null && !oldJson.equals(j)) {
            resJson += oldJson;
            boolean appended = eventsI18n.replace(e.getKey(), oldJson, resJson);
            while (!appended) {
                oldJson = eventsI18n.get(e.getKey());
                resJson = j;
                resJson += oldJson;
                appended = eventsI18n.replace(e.getKey(), oldJson, resJson);
            }
        }
    }
}