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

com.hazelcast.org.jsfr.json.filter.EqualityTypePredicate Maven / Gradle / Ivy

There is a newer version: 5.4.0
Show newest version
package com.hazelcast.org.jsfr.json.filter;

import com.hazelcast.org.jsfr.json.PrimitiveHolder;
import com.hazelcast.org.jsfr.json.path.JsonPath;
import com.hazelcast.org.jsfr.json.provider.JsonProvider;

public class EqualityTypePredicate extends BasicJsonPathFilter {

    private final Type type;

    public EqualityTypePredicate(JsonPath relativePath, Type type) {
        super(relativePath);
        this.type = type;
    }

    @Override
    public boolean apply(JsonPath jsonPosition, PrimitiveHolder primitiveHolder, JsonProvider jsonProvider) {
        if (!this.getRelativePath().matchFilterPath(jsonPosition)) {
            return false;
        }
        switch (type) {
            case ARRAY:
                return primitiveHolder == null && jsonPosition.isInsideArray();
            case OBJECT:
                return primitiveHolder == null && jsonPosition.isInsideObject();
            default:
                return primitiveHolder != null
                    && (this.getRelativePath().isInsideArray() == jsonPosition.isInsideArray())
                    && this.type.isInstanceOf(primitiveHolder.getValue(), jsonProvider);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy