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

com.hazelcast.org.jsfr.json.filter.NotEqualityTypePredicate 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 NotEqualityTypePredicate extends BasicJsonPathFilter {

    private final Type type;

    public NotEqualityTypePredicate(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.isInsideObject();
            case OBJECT:
                return primitiveHolder != null || jsonPosition.isInsideArray();
            default:
                if (primitiveHolder == null) {
                    JsonPath parent = jsonPosition.derivePath(jsonPosition.pathDepth() - 1);
                    return this.getRelativePath().isInsideArray() == parent.isInsideArray();
                } else {
                   return  (this.getRelativePath().isInsideArray() == jsonPosition.isInsideArray())
                        && !this.type.isInstanceOf(primitiveHolder.getValue(), jsonProvider);
                }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy