@@ -0,0 +1,2524 @@
+package com.easternedgerobotics.rov.io;%0A%0Aimport com.easternedgerobotics.rov.value.MotionPowerValue;%0A%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport org.pmw.tinylog.Logger;%0A%0Aimport java.io.IOException;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.prefs.Preferences;%0A%0Apublic final class MotionPowerProfile %7B%0A    /**%0A     * The directory which contains the power profiles.%0A     */%0A    private final Preferences profileHome;%0A%0A    /**%0A     * A copy of power profiles to exist in RAM.%0A     */%0A    private final Map%3CInteger, MotionPowerValue%3E profiles = new HashMap%3C%3E();%0A%0A    /**%0A     * Create a power profile loader/ setter which works in the specified directory.%0A     *%0A     * @param profile the preferences directory.%0A     */%0A    public MotionPowerProfile(final String profile) %7B%0A        this.profileHome = Preferences.userRoot().node(profile);%0A    %7D%0A%0A    /**%0A     * Get the latest MotionPowerValue associated with the index.%0A     * Fetches from disk if not loaded.%0A     *%0A     * @param index the power profile index.%0A     * @return MotionPowerValue%0A     */%0A    public MotionPowerValue get(final int index) %7B%0A        return profiles.computeIfAbsent(index, i -%3E %7B%0A            final String profileName = String.format(%22profile-%25d%22, i);%0A            final String profileStr = profileHome.get(profileName, %22DEFAULT%22);%0A            if (profileStr.equals(%22DEFAULT%22)) %7B%0A                Logger.warn(%22The profile %7B%7D does not exist.%22, profileName);%0A                return new MotionPowerValue();%0A            %7D%0A            try %7B%0A                return new ObjectMapper().readValue(profileStr, MotionPowerValue.class);%0A            %7D catch (final IOException e) %7B%0A                Logger.warn(%22The profile %7B%7D could not be parsed from '%7B%7D': %7B%7D%22, profileName, profileStr, e);%0A                return new MotionPowerValue();%0A            %7D%0A        %7D);%0A    %7D%0A%0A    /**%0A     * Update the MotionPowerValue profile for a given index and write this value to disk.%0A     *%0A     * @param index the power profile index.%0A     * @param profile MotionPowerValue to be saved to disk.%0A     */%0A    public void set(final int index, final MotionPowerValue profile) %7B%0A        profiles.put(index, profile);%0A        final String profileName = String.format(%22profile-%25d%22, index);%0A        try %7B%0A            profileHome.put(profileName, new ObjectMapper().writeValueAsString(profile));%0A        %7D catch (final IOException e) %7B%0A            Logger.warn(%22The profile %7B%7D could not be saved to %7B%7D: %7B%7D%22, profile, profileName, e);%0A        %7D%0A    %7D%0A%7D%0A

Load and save motion power values to disk