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

apoc.periodic.BatchMode Maven / Gradle / Ivy

There is a newer version: 5.25.1
Show newest version
package apoc.periodic;

import apoc.util.Util;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

enum BatchMode {
    BATCH,
    BATCH_SINGLE,
    SINGLE;


    private static final Map nameIndex =  new HashMap<>();
    static {
        for (BatchMode batchMode : BatchMode.values()) {
            nameIndex.put(batchMode.name(), batchMode);
        }
    }

   static BatchMode fromIterateList(boolean iterateList) {
        return iterateList ? BATCH : SINGLE;
    }

    static BatchMode fromConfig(Map config) {
        Object batchMode = config.get("batchMode");

        if(batchMode != null) {
            BatchMode lookedUpBatchMode = nameIndex.get(batchMode.toString().toUpperCase());
            if (lookedUpBatchMode == null) {
                throw new IllegalArgumentException("Invalid batch mode: `" + batchMode + "`. Valid values are: " + Arrays.toString(BatchMode.values()));
            }
            return lookedUpBatchMode;
        }

        Object iterateList = config.get("iterateList");
        if(iterateList != null) {
            return BatchMode.fromIterateList(Util.toBoolean(iterateList));
        }

        return BATCH;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy