com.networknt.schema.resource.MapSchemaMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-schema-validator Show documentation
Show all versions of json-schema-validator Show documentation
A json schema validator that supports draft v4, v6, v7, v2019-09 and v2020-12
package com.networknt.schema.resource;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import com.networknt.schema.AbsoluteIri;
/**
* Map implementation of {@link SchemaMapper}.
*/
public class MapSchemaMapper implements SchemaMapper {
private final Function mappings;
public MapSchemaMapper(Map mappings) {
this(mappings::get);
}
public MapSchemaMapper(Function mappings) {
this.mappings = mappings;
}
/**
* Apply the mapping function if the predicate is true.
*
* @param test the predicate
* @param mappings the mapping
*/
public MapSchemaMapper(Predicate test, Function mappings) {
this.mappings = iri -> {
if (test.test(iri)) {
return mappings.apply(iri);
}
return null;
};
}
@Override
public AbsoluteIri map(AbsoluteIri absoluteIRI) {
String mapped = this.mappings.apply(absoluteIRI.toString());
if (mapped != null) {
return AbsoluteIri.of(mapped);
}
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy