Improve builders interface

This commit is contained in:
Clément Fournier
2017-11-28 18:49:23 +01:00
parent 345cc50f78
commit abdb96238d
2 changed files with 29 additions and 3 deletions

View File

@ -4,7 +4,9 @@
package net.sourceforge.pmd.properties.builders;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import net.sourceforge.pmd.properties.MultiValuePropertyDescriptor;
@ -36,8 +38,8 @@ public abstract class MultiValuePropertyBuilder<V, T extends MultiValuePropertyB
* @return The same builder
*/
@SuppressWarnings("unchecked")
public T defaultValues(List<V> val) {
this.defaultValues = val;
public T defaultValues(Collection<? extends V> val) {
this.defaultValues = new ArrayList<>(val);
return (T) this;
}

View File

@ -5,6 +5,7 @@
package net.sourceforge.pmd.properties.builders;
import java.util.Arrays;
import java.util.Collection;
/**
@ -22,12 +23,35 @@ public abstract class SinglePackagedPropertyBuilder<V, T extends SinglePackagedP
}
/**
* Specify the allowed package prefixes.
*
* @param packs The package prefixes
*
* @return The same builder
*/
@SuppressWarnings("unchecked")
public T legalPackageNames(String[] packs) {
public T legalPackageNames(String... packs) {
if (packs != null) {
this.legalPackageNames = Arrays.copyOf(packs, packs.length);
}
return (T) this;
}
/**
* Specify the allowed package prefixes.
*
* @param packs The package prefixes
*
* @return The same builder
*/
@SuppressWarnings("unchecked")
public T legalPackageNames(Collection<String> packs) {
if (packs != null) {
this.legalPackageNames = packs.toArray(new String[0]);
}
return (T) this;
}
}