Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection properties as mutable types #379

Open
ljacqu opened this issue Sep 12, 2023 · 0 comments
Open

Collection properties as mutable types #379

ljacqu opened this issue Sep 12, 2023 · 0 comments
Labels
architecture Difficult architectural questions
Milestone

Comments

@ljacqu
Copy link
Member

ljacqu commented Sep 12, 2023

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.

@ljacqu ljacqu added the architecture Difficult architectural questions label Sep 12, 2023
@ljacqu ljacqu added this to the 2.0.0 milestone Sep 12, 2023
ljacqu added a commit that referenced this issue Sep 12, 2023
…perty builders

- Arrays, inline arrays and collections are now based on property types which can be constructed from other property paths
- Introduce an enum set type
- Refactor the property builders (remove inheritance among builders, rename methods for default values to be more clear)
- Lift requirement that the collections in properties are always unmodifiable; to be seen in more depth with #379
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture Difficult architectural questions
Development

No branches or pull requests

1 participant