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

org.vertexium.util.ExtendedDataMutationUtils Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.util;

import org.vertexium.mutation.AdditionalExtendedDataVisibilityAddMutation;
import org.vertexium.mutation.AdditionalExtendedDataVisibilityDeleteMutation;
import org.vertexium.mutation.ExtendedDataDeleteMutation;
import org.vertexium.mutation.ExtendedDataMutation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ExtendedDataMutationUtils {
    public static Map> getByTableThenRowId(
        Iterable extendedData,
        Iterable extendedDataDeletes,
        Iterable additionalExtendedDataVisibilities,
        Iterable additionalExtendedDataVisibilityDeletes
    ) {
        Map> results = new HashMap<>();

        if (extendedData != null) {
            for (ExtendedDataMutation m : extendedData) {
                Map byTable = results.computeIfAbsent(m.getTableName(), s -> new HashMap<>());
                Mutations byRow = byTable.computeIfAbsent(m.getRow(), s -> new Mutations());
                byRow.addExtendedDataMutation(m);
            }
        }

        if (extendedDataDeletes != null) {
            for (ExtendedDataDeleteMutation m : extendedDataDeletes) {
                Map byTable = results.computeIfAbsent(m.getTableName(), s -> new HashMap<>());
                Mutations byRow = byTable.computeIfAbsent(m.getRow(), s -> new Mutations());
                byRow.addExtendedDataDeleteMutation(m);
            }
        }

        if (additionalExtendedDataVisibilities != null) {
            for (AdditionalExtendedDataVisibilityAddMutation m : additionalExtendedDataVisibilities) {
                Map byTable = results.computeIfAbsent(m.getTableName(), s -> new HashMap<>());
                Mutations byRow = byTable.computeIfAbsent(m.getRow(), s -> new Mutations());
                byRow.addAdditionalExtendedDataVisibilityAddMutation(m);
            }
        }

        if (additionalExtendedDataVisibilityDeletes != null) {
            for (AdditionalExtendedDataVisibilityDeleteMutation m : additionalExtendedDataVisibilityDeletes) {
                Map byTable = results.computeIfAbsent(m.getTableName(), s -> new HashMap<>());
                Mutations byRow = byTable.computeIfAbsent(m.getRow(), s -> new Mutations());
                byRow.addAdditionalExtendedDataVisibilityDeleteMutation(m);
            }
        }

        return results;
    }

    public static class Mutations {
        private final List extendedData = new ArrayList<>();
        private final List extendedDataDeletes = new ArrayList<>();
        private final List additionalExtendedDataVisibilities = new ArrayList<>();
        private final List additionalExtendedDataVisibilityDeletes = new ArrayList<>();

        public Iterable getExtendedData() {
            return extendedData;
        }

        public Iterable getExtendedDataDeletes() {
            return extendedDataDeletes;
        }

        public Iterable getAdditionalExtendedDataVisibilities() {
            return additionalExtendedDataVisibilities;
        }

        public Iterable getAdditionalExtendedDataVisibilityDeletes() {
            return additionalExtendedDataVisibilityDeletes;
        }

        public void addExtendedDataMutation(ExtendedDataMutation extendedDataMutation) {
            extendedData.add(extendedDataMutation);
        }

        public void addExtendedDataDeleteMutation(ExtendedDataDeleteMutation m) {
            extendedDataDeletes.add(m);
        }

        public void addAdditionalExtendedDataVisibilityAddMutation(AdditionalExtendedDataVisibilityAddMutation m) {
            additionalExtendedDataVisibilities.add(m);
        }

        public void addAdditionalExtendedDataVisibilityDeleteMutation(AdditionalExtendedDataVisibilityDeleteMutation m) {
            additionalExtendedDataVisibilityDeletes.add(m);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy