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

Refactor interface for builder collections #42

Merged
merged 4 commits into from
Apr 17, 2024

Conversation

hpmellema
Copy link
Contributor

@hpmellema hpmellema commented Apr 17, 2024

Description of changes

Updates the builder methods created for lists and maps to:

  1. Remove the remove* methods for lists and
  2. Remove list add* method in favor of a varargs setter
  3. Use Collection<T> for full list setter argument.

Example Generated list builder methods:

         public Builder list(Collection<String> list) {
            this.list = list != null ? new ArrayList<>(list) : null;
            return this;
        }

        public Builder addAllList(Collection<String> list) {
            if (this.list == null) {
                this.list = new ArrayList<>(list);
            } else {
                this.list.addAll(list);
            }
            return this;
        }

        public Builder list(String list) {
            if (this.list == null) {
                this.list = new ArrayList<>();
            }
            this.list.add(list);
            return this;
        }

        public Builder list(String... list) {
            if (this.list == null) {
                this.list = new ArrayList<>();
            }
            Collections.addAll(this.list, list);
            return this;
        }

Example Generated map builder methods:

         public Builder queryParams(Map<String, List<String>> queryParams) {
            this.queryParams = queryParams != null ? new LinkedHashMap<>(queryParams) : null;
            return this;
        }

        public Builder putAllQueryParams(Map<String, List<String>> queryParams) {
            if (this.queryParams == null) {
                this.queryParams = new LinkedHashMap<>(queryParams);
            } else {
                this.queryParams.putAll(queryParams);
            }
            return this;
        }

        public Builder putQueryParams(String key, List<String> value) {
           if (this.queryParams == null) {
               this.queryParams = new LinkedHashMap<>();
           }
           this.queryParams.put(key, value);
           return this;
        }

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@hpmellema hpmellema merged commit 91d62bf into smithy-lang:main Apr 17, 2024
3 checks passed
@hpmellema hpmellema deleted the refactor-builder-interface branch April 17, 2024 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants