de.obqo.decycle.maven.AllowConstraint Maven / Gradle / Ivy
package de.obqo.decycle.maven;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.ToString;
/**
* Base class for {@code <allow>} and {@code <allow-direct>} configuration elements. May either be used with
* a simple (string) content
*
* <allow>slice1, slice2, ...</allow>
*
* or with {@code <any-of>} / {@code <one-of>} children.
*
* <allow>
* <one-of>slice1, slice2<one-of>
* <any-of>slice3<any-of>
* <any-of>slice4, slice5<any-of>
* </allow>
*
* Mixing these two configuration types (i.e. using XML mixed content) is not possible.
*/
@Getter
@ToString
public abstract class AllowConstraint {
private final boolean direct;
private final List layers = new ArrayList<>();
/**
* simple content
*/
@Getter(AccessLevel.NONE)
private String content;
protected AllowConstraint(final boolean direct) {
this.direct = direct;
}
/**
* Adds an {@code <any-of>slice1, slice2, ...</any-of>} layer
*
* @param slices comma separated list of slice names
*/
public void setAnyOf(final String slices) {
this.layers.add(new Layer(false, slices));
}
/**
* Adds a {@code <one-of>slice1, slice2, ...</one-of>} layer
*
* @param slices comma separated list of slice names
*/
public void setOneOf(final String slices) {
this.layers.add(new Layer(true, slices));
}
/**
* Default setter for string-only content, for example {@code <allow>slice1, slice2, ...</allow>}
*
* Will be interpreted as list of {@code <any-of>} elements.
*
* @param slices comma separated list of slice names
*/
public void set(final String slices) {
this.content = slices;
}
public String get() {
return this.content;
}
}