Java Code Examples for org.apache.commons.lang.StringUtils.substringBeforeLast()

The following are Jave code examples for showing how to use substringBeforeLast() of the org.apache.commons.lang.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: canal-elasticsearch   File: SimpleEsAdapter.java   Source Code and License Vote up 7 votes
public SimpleEsAdapter(CanalConf canalConf) {

        String accept = canalConf.getAccept();
        String[] acceptArr = accept.split(DELIMITER);
        for (String str : acceptArr) {
            String[] strArr = str.split(CONNECTOR);
            if (strArr.length == 3) {
                String dataBaseTable = StringUtils.substringBeforeLast(str, CONNECTOR_TEP);
                String idColumn = StringUtils.substringAfterLast(str, CONNECTOR_TEP);
                idPair.put(dataBaseTable, idColumn);

                logger.info("Add accept :{}", str);
            }
        }

    }
 
Example 2
Project: Reer   File: DefaultTaskContainer.java   Source Code and License Vote up 6 votes
public Task findByPath(String path) {
    if (!GUtil.isTrue(path)) {
        throw new InvalidUserDataException("A path must be specified!");
    }
    if (!path.contains(Project.PATH_SEPARATOR)) {
        return findByName(path);
    }

    String projectPath = StringUtils.substringBeforeLast(path, Project.PATH_SEPARATOR);
    ProjectInternal project = this.project.findProject(!GUtil.isTrue(projectPath) ? Project.PATH_SEPARATOR : projectPath);
    if (project == null) {
        return null;
    }
    projectAccessListener.beforeRequestingTaskByPath(project);

    return project.getTasks().findByName(StringUtils.substringAfterLast(path, Project.PATH_SEPARATOR));
}
 
Example 3
Project: otter-G   File: ExceptionRuleMonitor.java   Source Code and License Vote up 6 votes
private void check(AlarmRule rule, NodeAlarmEvent alarmEvent) {
    if (!inPeriod(rule)) {
        return;
    }

    String matchValue = rule.getMatchValue();
    matchValue = StringUtils.substringBeforeLast(matchValue, "@");

    String[] matchValues = StringUtils.split(matchValue, ",");

    for (String match : matchValues) {
        if (StringUtils.containsIgnoreCase(alarmEvent.getMessage(), match)) {
            String message = String.format(MESAGE_FORMAT, alarmEvent.getPipelineId(), alarmEvent.getNid(),
                                           alarmEvent.getMessage());
            sendAlarm(rule, message);
            break;
        }
    }
}
 
Example 4
Project: Reer   File: ArtifactFile.java   Source Code and License Vote up 5 votes
public ArtifactFile(File file, String version) {
    name = file.getName();
    extension = "";
    classifier = "";
    boolean done = false;

    int startVersion = StringUtils.lastIndexOf(name, "-" + version);
    if (startVersion >= 0) {
        int endVersion = startVersion + version.length() + 1;
        if (endVersion == name.length()) {
            name = name.substring(0, startVersion);
            done = true;
        } else if (endVersion < name.length() && name.charAt(endVersion) == '-') {
            String tail = name.substring(endVersion + 1);
            name = name.substring(0, startVersion);
            classifier = StringUtils.substringBeforeLast(tail, ".");
            extension = StringUtils.substringAfterLast(tail, ".");
            done = true;
        } else if (endVersion < name.length() && StringUtils.lastIndexOf(name, ".") == endVersion) {
            extension = name.substring(endVersion + 1);
            name = name.substring(0, startVersion);
            done = true;
        }
    }
    if (!done) {
        extension = StringUtils.substringAfterLast(name, ".");
        name = StringUtils.substringBeforeLast(name, ".");
    }
    if (classifier.length() == 0) {
        classifier = null;
    }
}
 
Example 5
Project: Reer   File: AllTestResults.java   Source Code and License Vote up 5 votes
private PackageTestResults addPackageForClass(String className) {
    String packageName = StringUtils.substringBeforeLast(className, ".");
    if (packageName.equals(className)) {
        packageName = "";
    }
    return addPackage(packageName);
}
 
Example 6
Project: DBus   File: CheckFullPullEvent.java   Source Code and License Vote up 5 votes
/**
 * 获取全量拉取的最新节点
 * @param fullPullerRootNode
 * @param curator
 * @return 子节点的全路径,之前非全路径,后面的path部分进行了拼接
 * @throws Exception
 */
private List<String> filter(String fullPullerRootNode, CuratorFramework curator) throws Exception {
    List<String> flattedFullpullerNodeName = new ArrayList<>();

    //get all node list
    fetchZkNodeRecursively(fullPullerRootNode,flattedFullpullerNodeName, curator);

    HashMap<String, Integer> map = new HashMap<String, Integer>();
    for (String znode : flattedFullpullerNodeName) {
        String key = StringUtils.substringBeforeLast(znode, "/");
        String ver = StringUtils.substringAfterLast(znode, "/");
        Integer version = Integer.parseInt(ver);
        if (map.containsKey(key)) {
            Integer tempVersion = map.get(key);
            if (version > tempVersion) {
                map.put(key, version);
            }
        } else {
            map.put(key, version);
        }
    }

    List<String> wkList = new ArrayList<String>();
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
        wkList.add(StringUtils.join(new String[] {entry.getKey(), String.valueOf(entry.getValue())}, "/"));
    }
    return wkList;
}
 
Example 7
Project: otter-G   File: ProcessTimeoutRuleMonitor.java   Source Code and License Vote up 5 votes
private String checkTimeout(AlarmRule rule, Map<Long, Long> processTime) {
    if (!inPeriod(rule)) {
        return StringUtils.EMPTY;
    }

    String matchValue = rule.getMatchValue();
    matchValue = StringUtils.substringBeforeLast(matchValue, "@");
    Long maxSpentTime = Long.parseLong(StringUtils.trim(matchValue));
    List<Long> timeoutProcessIds = new LinkedList<Long>();
    Collections.sort(timeoutProcessIds);
    long maxSpent = 0;
    for (Entry<Long, Long> entry : processTime.entrySet()) {
        // maxSpentTime 是秒,而processTime的value是毫秒
        if (entry.getValue() >= (maxSpentTime * 1000)) {
            timeoutProcessIds.add(entry.getKey());
            maxSpent = maxSpent > entry.getValue() ? maxSpent : entry.getValue();
        }
    }

    if (CollectionUtils.isEmpty(timeoutProcessIds)) {
        return StringUtils.EMPTY;
    }

    String processIds = StringUtils.join(timeoutProcessIds, ",");
    String message = String.format(TIME_OUT_MESSAGE, rule.getPipelineId(), processIds, (maxSpent / 1000));
    sendAlarm(rule, message);
    return message;
}
 
Example 8
Project: otter-G   File: DelayStatRuleMonitor.java   Source Code and License Vote up 5 votes
private boolean checkDelayTime(AlarmRule rule, Long delayTime) {

        if (!inPeriod(rule)) {
            return false;
        }

        String matchValue = rule.getMatchValue();
        matchValue = StringUtils.substringBeforeLast(matchValue, "@");
        Long maxDelayTime = Long.parseLong(StringUtils.trim(matchValue));
        if (delayTime >= maxDelayTime * 1000) {
            sendAlarm(rule, String.format(DELAY_TIME_MESSAGE, rule.getPipelineId(), delayTime));
            return true;
        }
        return false;
    }
 
Example 9
Project: otter-G   File: PositionTimeoutRuleMonitor.java   Source Code and License Vote up 5 votes
private boolean checkTimeout(AlarmRule rule, long elapsed) {
    if (!inPeriod(rule)) {
        return false;
    }

    String matchValue = rule.getMatchValue();
    matchValue = StringUtils.substringBeforeLast(matchValue, "@");
    Long maxSpentTime = Long.parseLong(StringUtils.trim(matchValue));
    // sinceLastSync是毫秒,而 maxSpentTime 是秒
    if (elapsed >= (maxSpentTime * 1000)) {
        sendAlarm(rule, String.format(TIME_OUT_MESSAGE, rule.getPipelineId(), (elapsed / 1000)));
        return true;
    }
    return false;
}
 
Example 10
Project: otter-G   File: PipelineTimeoutRuleMonitor.java   Source Code and License Vote up 5 votes
private boolean checkTimeout(AlarmRule rule, long elapsed) {
    if (!inPeriod(rule)) {
        return false;
    }

    String matchValue = rule.getMatchValue();
    matchValue = StringUtils.substringBeforeLast(matchValue, "@");
    Long maxSpentTime = Long.parseLong(StringUtils.trim(matchValue));
    // sinceLastSync是毫秒,而 maxSpentTime 是秒
    if (elapsed >= (maxSpentTime * 1000)) {
        sendAlarm(rule, String.format(TIME_OUT_MESSAGE, rule.getPipelineId(), (elapsed / 1000)));
        return true;
    }
    return false;
}
 
Example 11
Project: Hydrograph   File: ComponentValidator.java   Source Code and License Vote up 5 votes
/**
 * Validates given component state
 * 
 * @param {@link Component}
 * @return true - if component has valid state
 */
public boolean validate(Component component){
	PropertyToolTipInformation propertyToolTipInformation= new PropertyToolTipInformation(ISSUE_PROPERTY_NAME, HIDE_TOOLTIP, TOOLTIP_DATATYPE);
	boolean validationStatus=true;
	String errorMessages="";
	if(componentValidators!=null && componentValidators.containsKey(component.getType().toUpperCase())){
		for(IComponentValidator componentValidator: componentValidators.get(component.getType().toUpperCase())){
			
			String errorMessage = componentValidator.validateComponent(component);
			if(errorMessage!=null){
				errorMessages = errorMessages + errorMessage + "\n";
			}
		}
		
		errorMessages=StringUtils.substringBeforeLast(errorMessages, "\n");
		
		if(!StringUtils.isEmpty(errorMessages)){
			propertyToolTipInformation= new PropertyToolTipInformation(ISSUE_PROPERTY_NAME, SHOW_TOOLTIP, TOOLTIP_DATATYPE);
			propertyToolTipInformation.setPropertyValue(errorMessages);
			validationStatus = false;
		}
		
		component.getTooltipInformation().put(ISSUE_PROPERTY_NAME,propertyToolTipInformation );
	}
	
	return validationStatus;
}
 
Example 12
Project: maven-release-yearly-policy   File: YearlyVersionPolicy.java   Source Code and License Vote up 5 votes
private String incrementSubVersion(final String subVersion) {
    if (StringUtils.isNumeric(subVersion)) {
        return Integer.toString(Integer.parseInt(subVersion) + 1);
    }

    final String headVersionPart = StringUtils.substringBeforeLast(subVersion, ".");
    final String tailVersionPart = StringUtils.substringAfterLast(subVersion, ".");
    final Integer newSubVersion = Integer.parseInt(tailVersionPart) + 1;

    return headVersionPart + "." + newSubVersion.toString();
}
 
Example 13
Project: Reer   File: LibraryPublishArtifact.java   Source Code and License Vote up 4 votes
private static String determineName(File file) {
    return StringUtils.substringBeforeLast(file.getName(), ".");
}
 
Example 14
Project: lams   File: WebUtil.java   Source Code and License Vote up 3 votes
/**
    * <p>
    * This helper method create the struts action forward name using the path. It will chop all path related
    * characters, such as "/" and ".do".
    * </p>
    *
    * <p>
    * For example:
    * <li><code>getStrutsForwardNameFromPath("/DisplayParallelActivity.do")<code>
    * = displayParallelActivity</li>
    * </p>
    *
    * @param path
    * @return
    */
   public static String getStrutsForwardNameFromPath(String path) {
String pathWithoutSlash = StringUtils.substringAfter(path, "/");
String orginalForwardName = StringUtils.substringBeforeLast(pathWithoutSlash, ".do");

return StringUtils.uncapitalize(orginalForwardName);

   }
 
Example 15
Project: personium-core   File: UriUtils.java   Source Code and License Vote up 2 votes
/**
 * getUnitUrl.
 * @param cellUrl String
 * @param index int from last
 * @return url String
 */
public static String getUnitUrl(String cellUrl, int index) {
    String[] list = cellUrl.split(STRING_SLASH);
    // 指定文字が最後から指定数で発見された文字より前の文字を切り出す
    return StringUtils.substringBeforeLast(cellUrl, list[list.length - index]);
}