org.apache.commons.lang3.StringUtils#substring ( )源码实例Demo

下面列出了org.apache.commons.lang3.StringUtils#substring ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: wecube-platform   文件: PluginConfigDto.java
public TargetEntityWithFilterRule splitTargetEntityWithFilterRule() {
    String targetEntityWithFilterRule = getTargetEntityWithFilterRule();
    String packageString = "";
    String entity = "";
    String filterRule = "";
    int index1 = StringUtils.indexOf(targetEntityWithFilterRule, ":");
    if (index1 != -1) {
        packageString = StringUtils.substring(targetEntityWithFilterRule, 0, index1);
        int index2 = StringUtils.indexOf(targetEntityWithFilterRule, "{");

        if (index2 != -1) {
            entity = StringUtils.substring(targetEntityWithFilterRule, index1 + 1, index2);
            filterRule = StringUtils.substring(targetEntityWithFilterRule, index2);
        } else {
            entity = StringUtils.substring(targetEntityWithFilterRule, index1 + 1);
        }
    } else {
        packageString = targetEntityWithFilterRule;
    }

    return new TargetEntityWithFilterRule(packageString, entity, filterRule);
}
 
源代码2 项目: o2oa   文件: FileTools.java
public static String parent(String path) {
	int idx = StringUtils.lastIndexOfAny(path, new String[] { "\\", "/" });
	if (idx > 0) {
		return StringUtils.substring(path, 0, idx);
	} else {
		return path;
	}
}
 
源代码3 项目: icure-backend   文件: MedidocLogicImpl.java
private String computeProtocolCode(String name, String first, Long birth, Long req, String code) {
	return "" + StringUtils.substring(name.replaceAll(" ", ""), 0, 16)
			+ StringUtils.substring(first.replaceAll(" ", ""), 0, 8)
			+ ((int) (birth / (1000 * 3600 * 24)))
			+ ((int) (req / (1000 * 3600 * 24)))
			+ StringUtils.substring(code, 0, 20);
}
 
源代码4 项目: zuihou-admin-cloud   文件: FileDataTypeUtil.java
public static String getRelativePath(String pathPrefix, String path) {
    String remove = StringUtils.remove(path, pathPrefix + File.separator);

    log.info("remove={}, index={}", remove, remove.lastIndexOf(java.io.File.separator));
    String relativePath = StringUtils.substring(remove, 0, remove.lastIndexOf(java.io.File.separator));
    return relativePath;
}
 
源代码5 项目: windup   文件: FileMapping.java
private FileMapping(Pattern pattern)
{
    this.pattern = pattern;

    String normalizedPattern = StringUtils.replacePattern(pattern.pattern(), "\\s", "_");
    normalizedPattern = StringUtils.substring(normalizedPattern, 0, 10);
    this.id = this.getClass().getSimpleName()+ "_" + normalizedPattern
            + "_" + RandomStringUtils.randomAlphanumeric(2);
}
 
源代码6 项目: paascloud-master   文件: RedisKeyUtil.java
public static String createMqKey(String topic, String tag, String refNo, String body) {
	String temp = refNo;
	Preconditions.checkArgument(StringUtils.isNotEmpty(topic), "topic is null");
	Preconditions.checkArgument(StringUtils.isNotEmpty(tag), "tag is null");
	Preconditions.checkArgument(StringUtils.isNotEmpty(refNo), "refNo is null");
	Preconditions.checkArgument(StringUtils.isNotEmpty(body), "body is null");

	if (refNo.length() > REF_NO_MAX_LENGTH) {
		temp = StringUtils.substring(refNo, 0, REF_NO_MAX_LENGTH) + "...";
	}
	return topic + "_" + tag + "_" + temp + "-" + body.hashCode();
}
 
源代码7 项目: cuba   文件: WebSourceCodeEditor.java
@Override
public String applySuggestion(Suggestion suggestion, String text, int cursor) {
    String suggestionText = suggestion.getSuggestionText();

    if (suggestion.getStartPosition() > 0)
        return StringUtils.substring(text, 0, suggestion.getStartPosition()) + suggestionText
                + StringUtils.substring(text, cursor);
    return suggestionText + StringUtils.substring(text, cursor);
}
 
源代码8 项目: cuba   文件: WebUiComponents.java
protected String getMessagePack(String descriptorPath) {
    if (descriptorPath.contains("/")) {
        descriptorPath = StringUtils.substring(descriptorPath, 0, descriptorPath.lastIndexOf("/"));
    }

    String messagesPack = descriptorPath.replace("/", ".");
    int start = messagesPack.startsWith(".") ? 1 : 0;
    messagesPack = messagesPack.substring(start);
    return messagesPack;
}
 
源代码9 项目: depgraph-maven-plugin   文件: AbstractGraphMojo.java
private StyleResource getCustomStyleResource() throws MojoFailureException {
  StyleResource customStyleResource;
  if (StringUtils.startsWith(this.customStyleConfiguration, "classpath:")) {
    String resourceName = StringUtils.substring(this.customStyleConfiguration, 10, this.customStyleConfiguration.length());
    customStyleResource = new ClasspathStyleResource(resourceName, getClass().getClassLoader());
  } else {
    customStyleResource = new FileSystemStyleResource(Paths.get(this.customStyleConfiguration));
  }

  if (!customStyleResource.exists()) {
    throw new MojoFailureException("Custom configuration '" + this.customStyleConfiguration + "' does not exist.");
  }

  return customStyleResource;
}
 
源代码10 项目: Discord-Streambot   文件: CRemove.java
@Override
public void execute(MessageReceivedEvent e, String content) {
    Message message;
    GuildEntity guild = dao.getLongId(GuildEntity.class, e.getGuild().getId());
    if(!isAllowed(e.getGuild().getId(), e.getAuthor().getId(), allows, 1, commandEntity))
        message = new MessageBuilder().appendString("You are not allowed to use this command").build();
    else if(getPermissionsLevel(e.getGuild().getId(), e.getAuthor().getId(), commandEntity) == 1){
        QueueitemEntity queueitemEntity = new QueueitemEntity();
        queueitemEntity.setGuild(guild);
        queueitemEntity.setCommand("`!streambot remove " + content + "`");
        queueitemEntity.setUserId(Long.parseLong(e.getAuthor().getId()));
        dao.saveOrUpdate(queueitemEntity);

        message = new MessageBuilder()
                .appendString("Your request will be treated by a manager soon! (type `!streambot list manager` to check the managers list)")
                .build();
    }
    else if(null == content || content.isEmpty()) message = new MessageBuilder()
            .appendString("Missing option")
            .build();
    else {
        String option = "";
        try{
            option = StringUtils.substring(content, 0, content.indexOf(" "));
        } catch(StringIndexOutOfBoundsException sioobe){
            Logger.writeToErr(sioobe, "Content : " + content);
        }
        if(option.isEmpty()) message = new MessageBuilder()
                .appendString("It looks like an argument is missing. Please make sure you got the command right.")
                .build();
        else{
            String[] contents = content.substring(content.indexOf(" ")).split("\\|");
            switch (option) {
                case "game":
                    message = removeGame(guild, contents);
                    break;
                case "channel":
                    message = removeChannel(guild, contents);
                    break;
                case "tag":
                    message = removeTag(guild, contents);
                    break;
                case "manager":
                    message = removeManagers(guild, e.getMessage().getMentionedUsers(), e.getAuthor().getId());
                    break;
                case "team":
                    message = removeTeam(guild, contents);
                    break;
                default:
                    message = new MessageBuilder()
                            .appendString("Unknown option: " + option)
                            .build();
                    break;
            }
        }
    }
    MessageHandler.getInstance().addCreateToQueue(e.getTextChannel().getId(), MessageCreateAction.Type.GUILD, message);
}
 
源代码11 项目: conductor   文件: Task.java
/**
 * @param reasonForIncompletion the reasonForIncompletion to set
 */
public void setReasonForIncompletion(String reasonForIncompletion) {
    this.reasonForIncompletion = StringUtils.substring(reasonForIncompletion, 0, 500);
}
 
源代码12 项目: flink   文件: VectorUtil.java
/**
 * Parse the sparse vector from a formatted string.
 *
 * <p>The format of a sparse vector is space separated index-value pairs, such as "0:1 2:3 3:4".
 * If the sparse vector has determined vector size, the size is prepended to the head. For example,
 * the string "$4$0:1 2:3 3:4" represents a sparse vector with size 4.
 *
 * @param str A formatted string representing a sparse vector.
 * @throws IllegalArgumentException If the string is of invalid format.
 */
public static SparseVector parseSparse(String str) {
	try {
		if (org.apache.flink.util.StringUtils.isNullOrWhitespaceOnly(str)) {
			return new SparseVector();
		}

		int n = -1;
		int firstDollarPos = str.indexOf(HEADER_DELIMITER);
		int lastDollarPos = -1;
		if (firstDollarPos >= 0) {
			lastDollarPos = StringUtils.lastIndexOf(str, HEADER_DELIMITER);
			String sizeStr = StringUtils.substring(str, firstDollarPos + 1, lastDollarPos);
			n = Integer.valueOf(sizeStr);
			if (lastDollarPos == str.length() - 1) {
				return new SparseVector(n);
			}
		}

		int numValues = StringUtils.countMatches(str, String.valueOf(INDEX_VALUE_DELIMITER));
		double[] data = new double[numValues];
		int[] indices = new int[numValues];
		int startPos = lastDollarPos + 1;
		int endPos;
		for (int i = 0; i < numValues; i++) {
			int colonPos = StringUtils.indexOf(str, INDEX_VALUE_DELIMITER, startPos);
			if (colonPos < 0) {
				throw new IllegalArgumentException("Format error.");
			}
			endPos = StringUtils.indexOf(str, ELEMENT_DELIMITER, colonPos);

			if (endPos == -1) {
				endPos = str.length();
			}
			indices[i] = Integer.valueOf(str.substring(startPos, colonPos).trim());
			data[i] = Double.valueOf(str.substring(colonPos + 1, endPos).trim());
			startPos = endPos + 1;
		}
		return new SparseVector(n, indices, data);
	} catch (Exception e) {
		throw new IllegalArgumentException(
			String.format("Fail to getVector sparse vector from string: \"%s\".", str), e);
	}
}
 
源代码13 项目: cuba   文件: FileDescriptor.java
public void setExtension(String extension) {
    this.extension = StringUtils.substring(extension, 0, 20);
}
 
源代码14 项目: uyuni   文件: HardwareMapper.java
private String truncateMhz(String value) {
    return StringUtils.substring(value, 0, 16);
}
 
源代码15 项目: uyuni   文件: HardwareMapper.java
private String parsePciBaseClass(String pciClass) {
    if (StringUtils.isBlank(pciClass)) {
        return null;
    }
    return StringUtils.substring(pciClass, -6, -4);
}
 
源代码16 项目: uyuni   文件: HardwareMapper.java
private String parsePciSubClass(String pciClass) {
    if (StringUtils.isBlank(pciClass)) {
        return null;
    }
    return StringUtils.substring(pciClass, -4, -2);
}
 
源代码17 项目: proctor   文件: TestDefinitionFunctions.java
/**
 * Formats a revision for display, truncating it to the first 7 characters.
 */
public static String formatRevision(final String revision) {
    return StringUtils.substring(revision, 0, 7);
}
 
源代码18 项目: smockin   文件: InboundParamMatchServiceImpl.java
String extractArgName(final int matchStartPos, final ParamMatchTypeEnum paramMatchType, final String responseBody, final boolean isNested) {

        final int start = matchStartPos + (ParamMatchTypeEnum.PARAM_PREFIX + paramMatchType).length();
        final int closingPos = StringUtils.indexOf(responseBody, (isNested) ? "))" : ")", start);

        return StringUtils.substring(responseBody, start, closingPos);
    }
 
源代码19 项目: rdf2x   文件: FormatUtil.java
/**
 * Get shortened and cleaned name from an arbitrary string
 *
 * @param str       string clean and shorten
 * @param maxLength maximum length of the resulting name
 * @return shortened and cleaned name
 */
public static String getCleanName(String str, Integer maxLength) {
    return StringUtils.substring(FormatUtil.removeSpecialChars(str), 0, maxLength);
}
 
源代码20 项目: feilong-core   文件: StringUtil.java
/**
 * [截取]从指定索引处(<code>beginIndex</code>)的字符开始,直到此字符串末尾.
 * 
 * <p>
 * 如果 <code>beginIndex</code>是负数,那么表示倒过来截取,从结尾开始截取长度,此时等同于 {@link #substringLast(String, int)}
 * </p>
 *
 * <pre class="code">
 * StringUtil.substring(null, *)   = null
 * StringUtil.substring("", *)     = ""
 * StringUtil.substring("abc", 0)  = "abc"
 * StringUtil.substring("abc", 2)  = "c"
 * StringUtil.substring("abc", 4)  = ""
 * StringUtil.substring("abc", -2) = "bc"
 * StringUtil.substring("abc", -4) = "abc"
 * StringUtil.substring("jinxin.feilong",6)    =.feilong
 * </pre>
 * 
 * @param text
 *            内容 the String to get the substring from, may be null
 * @param beginIndex
 *            从指定索引处 the position to start from,negative means count back from the end of the String by this many characters
 * @return 如果 <code>text</code> 是null,返回 null<br>
 *         An empty ("") String 返回 "".<br>
 * @see org.apache.commons.lang3.StringUtils#substring(String, int)
 * @see #substringLast(String, int)
 */
public static String substring(final String text,final int beginIndex){
    return StringUtils.substring(text, beginIndex);
}
 
 同类方法