liquibase.Contexts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-core Show documentation
Show all versions of liquibase-core Show documentation
Liquibase is a tool for managing and executing database changes.
The newest version!
package liquibase;
import liquibase.util.StringUtil;
import java.util.*;
/**
* Wrapper for list of contexts.
*
*
* Contexts in Liquibase are expressions you can add to changesets to control which will be executed in any particular
* migration run. Any string can be used for the context name and they are checked case-insensitively.
*
*
* @see contexts in documentation
*/
public class Contexts {
private final HashSet contextStore = new HashSet<>();
public Contexts() {
}
public Contexts(String... contexts) {
if (contexts.length == 1) {
parseContextString(contexts[0]);
} else {
for (String context : contexts) {
this.contextStore.add(context.toLowerCase());
}
}
}
public Contexts(String contexts) {
if (contexts != null) {
contexts = contexts.replace("\\", "");
}
parseContextString(contexts);
}
public Contexts(Collection contexts) {
if (contexts != null) {
for (String context : contexts) {
this.contextStore.add(context.toLowerCase());
}
}
}
private void parseContextString(String contexts) {
contexts = StringUtil.trimToNull(contexts);
if (contexts == null) {
return;
}
for (String context : StringUtil.splitAndTrim(contexts, ",")) {
this.contextStore.add(context.toLowerCase());
}
}
public boolean add(String context) {
return this.contextStore.add(context.toLowerCase());
}
public boolean remove(String context) {
return this.contextStore.remove(context.toLowerCase());
}
@Override
public String toString() {
return StringUtil.join(new TreeSet<>(this.contextStore), ",");
}
public boolean isEmpty() {
return this.contextStore.isEmpty();
}
public Set getContexts() {
return Collections.unmodifiableSet(contextStore);
}
}