All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.relogiclabs.json.schema.internal.tree.TreeHelper Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.12.1
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy