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

net.intelie.liverig.plugin.data.CurvesSettingLogData Maven / Gradle / Ivy

The newest version!
package net.intelie.liverig.plugin.data;

import net.intelie.live.LiveJson;
import net.intelie.live.model.SettingLog;
import net.intelie.liverig.plugin.settings.SettingLogData;

import java.util.Map;

public class CurvesSettingLogData extends SettingLogData {

    private final Integer numOfCurves;

    public CurvesSettingLogData(SettingLogData data, Integer numOfCurves) {
        super(data);
        this.numOfCurves = numOfCurves;
    }

    public CurvesSettingLogData(SettingLog settingLog) {
        super(settingLog);
        this.numOfCurves = getNumberOfCurves(settingLog.getNewValue());
    }

    public Integer getNumOfCurves() {
        return numOfCurves;
    }

    private int getNumberOfCurves(String dumpCurves) {
        if (dumpCurves == null || dumpCurves.isEmpty()) {
            return 0;
        }
        // assumes the number of curves is the number of keys in the saved map.
        Map curvesMap = LiveJson.fromJson(dumpCurves, Map.class);
        return curvesMap != null ? curvesMap.size() : 0;
    }

    @Override
    public CurvesSettingLogData withoutNewValue() {
        //It's worth noting that it removes the newValue, but maintains the numOfCurves.
        //this is expected by the front end
        return new CurvesSettingLogData(super.withoutNewValue(), numOfCurves);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy