ProcessLocationConst.java
package com.mycim.valueobject.consts;
import com.mycim.framework.utils.lang.StringUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ProcessLocationConst {
private static final String SEPARATOR = " TO ";
private static final Pattern PATTERN = Pattern.compile("(\\w{1,} TO \\w{1,})");
private ProcessLocationConst() {
}
/**
* Get the value before the separator {@value SEPARATOR} from ProcessLocation
*
* @param processLocation Source value. For example, BE, FE, BE-FE.
* @return If the format of the value is similar to BE-FE, return BE
*/
public static String getMoveInProcessLocation(String processLocation) {
Matcher matcher = PATTERN.matcher(processLocation);
if (matcher.matches()) {
return StringUtils.substringBefore(processLocation, SEPARATOR);
}
return processLocation;
}
/**
* Get the value after the separator {@value SEPARATOR} from ProcessLocation
*
* @param processLocation Source value. For example, BE, FE, BE-FE.
* @return If the format of the value is similar to BE-FE, return FE
*/
public static String getMoveOutProcessLocation(String processLocation) {
Matcher matcher = PATTERN.matcher(processLocation);
if (matcher.matches()) {
return StringUtils.substringAfter(processLocation, SEPARATOR);
}
return processLocation;
}
/**
* 获取 processLocation 中 存在 TO 的 后半部分,若不存在 TO 返回空串
* @param processLocation
* @return
*/
public static String getAfterProcessLocation(String processLocation) {
Matcher matcher = PATTERN.matcher(processLocation);
if (matcher.matches()) {
return StringUtils.substringAfter(processLocation, SEPARATOR);
}
return StringUtils.EMPTY;
}
}