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

com.zuunr.json.schema.validation.node.number.MultipleOfNode Maven / Gradle / Ivy

There is a newer version: 0.1.4
Show newest version
package com.zuunr.json.schema.validation.node.number;

import com.zuunr.json.JsonNumber;
import com.zuunr.json.JsonValue;
import com.zuunr.json.schema.Keywords;
import com.zuunr.json.schema.JsonSchema;
import com.zuunr.json.schema.validation.ValidationContext;
import com.zuunr.json.schema.validation.node.KeywordNode;

/**
 * @author Niklas Eldberger
 */
public class MultipleOfNode extends KeywordNode {

    public MultipleOfNode(JsonValue instance, JsonSchema schema, int keywordIndex, ValidationContext validationContext, JsonValue rootInstance) {
        super(instance, schema, keywordIndex, validationContext, rootInstance);
    }

    @Override
    protected Boolean calculateValid() {
        JsonNumber multipleOf = schema.getKeyword(Keywords.MULTIPLE_OF, JsonValue.NULL).getJsonNumber();
        long modulo = instance.getJsonNumber().longValue() % multipleOf.longValue();
        return instance.getJsonNumber().isJsonInteger() && modulo == 0;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy