com.relogiclabs.json.schema.internal.tree.TreeHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of relogiclabs-json-schema Show documentation
Show all versions of relogiclabs-json-schema Show documentation
The New JSON Schema prioritizes simplicity, conciseness, and readability, making
it user-friendly and accessible without the need for extensive prior knowledge.
It offers efficient read-write facilities, precise JSON document definition
through various data types and functions, and extensibility to meet modern web
service diverse requirements.
package com.relogiclabs.json.schema.internal.tree;
import com.relogiclabs.json.schema.exception.DuplicatePropertyKeyException;
import com.relogiclabs.json.schema.type.JProperty;
import java.util.List;
import java.util.function.Function;
import static com.relogiclabs.json.schema.internal.util.StreamHelper.halt;
import static com.relogiclabs.json.schema.internal.util.StringHelper.concat;
import static com.relogiclabs.json.schema.internal.util.StringHelper.quote;
import static com.relogiclabs.json.schema.message.MessageFormatter.formatForJson;
import static java.util.stream.Collectors.toMap;
public final class TreeHelper {
public static List requireUniqueness(List list, String errorCode) {
list.stream().collect(toMap(JProperty::getKey, Function.identity(),
(p1, p2) -> halt(new DuplicatePropertyKeyException(formatForJson(errorCode,
concat("Multiple key with name ", quote(p2.getKey()), " found"), p2)))
));
return list;
}
}