Skip to content

Commit

Permalink
Update Language.java to use EnumSet directly
Browse files Browse the repository at this point in the history
  • Loading branch information
ascopes authored Apr 15, 2024
1 parent 0fffc5c commit 713a6fd
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.github.ascopes.protobufmavenplugin.generate;

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.EnumSet;

/**
* Supported generated source languages.
Expand All @@ -43,6 +43,11 @@ public enum Language {
this.flagName = flagName;
}

/**
* Get the flag name.
*
* @return the name of the flag to pass to {@code protoc}.
*/
public String getFlagName() {
return flagName;
}
Expand All @@ -59,22 +64,25 @@ public static LanguageSetBuilder setBuilder() {
*/
public static final class LanguageSetBuilder {

private final Set<Language> set;
private final ArrayList<Language> values;

private LanguageSetBuilder() {
set = new LinkedHashSet<>();
values = new ArrayList<>(4);
}

public LanguageSetBuilder addIf(boolean condition, Language language) {
if (condition) {
set.add(language);
}
return condition ? add(language) : this;
}

public LanguageSetBuilder add(Language language) {
values.add(language);
return this;
}

public Set<Language> build() {
return set;
public EnumSet<Language> build() {
return values.isEmpty()
? EnumSet.noneOf(Language.class)
: EnumSet.copyOf(values);
}
}
}

0 comments on commit 713a6fd

Please sign in to comment.