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

net.hamnaberg.json.pointer.Ref Maven / Gradle / Ivy

package net.hamnaberg.json.pointer;

import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Pattern;

interface Ref {

     A fold(Function arrayF, Function propertyF, Supplier endOfArrayF);
}

class ArrayRef implements Ref {
    static Pattern pattern = Pattern.compile("0|[1-9][0-9]*");

    public final int index;

    public ArrayRef(int index) {
        this.index = index;
    }

    @Override
    public  A fold(Function arrayF, Function propertyF, Supplier endOfArrayF) {
        return arrayF.apply(this);
    }
}

enum EndOfArray implements Ref {
    INSTANCE;


    @Override
    public  A fold(Function arrayF, Function propertyF, Supplier endOfArrayF) {
        return endOfArrayF.get();
    }
}

class PropertyRef implements Ref {
    public final String name;

    public PropertyRef(String name) {
        this.name = name;
    }

    @Override
    public  A fold(Function arrayF, Function propertyF, Supplier endOfArrayF) {
        return propertyF.apply(this);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy