com.almworks.jira.structure.api.util.JsonMapUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of structure-api Show documentation
Show all versions of structure-api Show documentation
Public API for the Structure Plugin for JIRA
package com.almworks.jira.structure.api.util;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.json.*;
import java.util.*;
/**
* Utility methods for working with JSON maps.
*/
public class JsonMapUtil {
@Contract("_, false, _, _ -> !null")
public static Map copyParameters(Map, ?> parameters, boolean allowNull,
boolean makeImmutable, boolean verify)
{
boolean empty = parameters == null || parameters.isEmpty();
if (empty) {
if (allowNull) return null;
if (makeImmutable) return Collections.emptyMap();
}
return mergeParameters(makeImmutable, verify, parameters);
}
@NotNull
public static Map mergeParameters(boolean makeImmutable, boolean verify, Map, ?>... parameters) {
LinkedHashMap r = new LinkedHashMap<>();
if (parameters != null) {
for (Map, ?> map : parameters) {
if (map != null) {
for (Map.Entry, ?> e : map.entrySet()) {
Object key = e.getKey();
Object value = e.getValue();
if (verify) {
if (key == null) {
throw new IllegalArgumentException("null key");
}
if (!(key instanceof String)) {
throw new IllegalArgumentException("non-string key: " + key);
}
checkValidParameter(value);
}
r.put((String) key, copyParameter(value, makeImmutable));
}
}
}
}
return makeImmutable ? Collections.unmodifiableMap(r) : r;
}
public static Object copyParameter(Object value, boolean makeImmutable) {
value = unwrapJsonCollection(value);
if (value instanceof List) {
List list = (List) value;
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy