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

io.permit.sdk.util.ContextStore Maven / Gradle / Ivy

There is a newer version: 983f46e
Show newest version
package io.permit.sdk.util;

import java.util.ArrayList;

interface ContextTransform {
    public Context mutate(Context context);
}

public class ContextStore {
    private Context baseContext = new Context();
    private ArrayList transforms = new ArrayList();

    // override context keys
    public void add(Context context) {
        this.baseContext.putAll(context);
    }

    public void registerTransform(ContextTransform transform) {
        this.transforms.add(transform);
    }

    public Context getDerivedContext(Context context) {
        Context derivedContext = new Context();
        derivedContext.putAll(baseContext);
        derivedContext.putAll(context);
        return derivedContext;
    }

    public Context transform(Context initialContext) {
        Context context = new Context();
        context.putAll(initialContext);

        for (final ContextTransform transformFunction : transforms) {
            Context nextContext = transformFunction.mutate(context);
            context.clear();
            context.putAll(nextContext);
        }
        return context;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy