Skip to content

Collection properties as mutable types #379

@ljacqu

Description

@ljacqu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureDifficult architectural questions

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions