AuthMe / ConfigMe

A simple configuration management library for any Java project!
MIT License
37 stars 14 forks source link

Collection properties as mutable types #379

Open ljacqu opened 11 months ago

ljacqu commented 11 months ago

I think it makes sense to have default values of list properties, set properties and similar immutable, but it's a bit cumbersome to have to work around the current value being immutable whenever we want to add or remove a value. It might make sense to just always hold the default value as mutable (i.e. by copying the default value over into an ArrayList or similar when it's not in the resource), or by providing a method that redefines the list to be mutable if needed (for ListProperty):

    public List<E> getOrInitAsMutableList(@NotNull SettingsManager settingsManager) {
        List<E> value = settingsManager.getProperty(this);
        if (value.getClass() != ArrayList.class) {
            value = new ArrayList<>(value);
            settingsManager.setProperty(this, value);
        }
        return value;
    }

I think ideally we have the default value immutable, the current value always mutable. I don't think the performance impact of copying over entries should be noticeable.