com.vmware.l10n.utils.MapUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of singleton-manager-l10n Show documentation
Show all versions of singleton-manager-l10n Show documentation
A service that provides support for Software Internationalization and Localization
/*
* Copyright 2019-2022 VMware, Inc.
* SPDX-License-Identifier: EPL-2.0
*/
package com.vmware.l10n.utils;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.json.simple.parser.ContainerFactory;
import org.springframework.util.StringUtils;
public class MapUtil {
/*
* update the messages map with key/value with source format, e.g. "aa.bb"
* will be updated as "aa.bb.#HTML" if the new key contains source format
* '.#HTML'.
*/
public static void updateKeyValue(Map messages, String key,
Object value) {
String updatedTrimKey = "";
if (StringUtils.isEmpty(key)) {
return;
} else {
updatedTrimKey = getTrimKey(key);
}
Iterator it = messages.keySet().iterator();
boolean isNew = true;
while (it.hasNext()) {
String originalKey = it.next();
String originalTrimKey = getTrimKey(originalKey);
if (updatedTrimKey.equals(originalTrimKey)) {
if (originalKey.equals(key)) { // Source Format not changed.
messages.put(key, value);
} else { // Source Format changed.
messages.remove(originalKey);
messages.put(key, value);
}
isNew = false;
break;
}
}
if (isNew) {
// new key
messages.put(key, value);
}
}
/*
* get the trim key, e.g. get "a.b.c" from "a.b.c.#HTML".
*/
private static String getTrimKey(String key) {
String updatedTrimKey = "";
int index = key.lastIndexOf(".#");
if (index > 0) {
updatedTrimKey = key.substring(0, index);
} else {
updatedTrimKey = key;
}
return updatedTrimKey;
}
/**
* Get the factory which is used to create own object.
*
* @return
*/
public static ContainerFactory getContainerFactory() {
return new ContainerFactory() {
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy