Java Code Examples for org.apache.commons.lang3.StringUtils#substring()

The following examples show how to use org.apache.commons.lang3.StringUtils#substring() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginConfigDto.java    From wecube-platform with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: WebSourceCodeEditor.java    From cuba with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: AbstractGraphMojo.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: WebUiComponents.java    From cuba with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: RedisKeyUtil.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 6
Source File: FileMapping.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: FileDataTypeUtil.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: MedidocLogicImpl.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: FileTools.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
	}
}
 
Example 10
Source File: VectorUtil.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
	}
}
 
Example 11
Source File: CRemove.java    From Discord-Streambot with MIT License 4 votes vote down vote up
@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);
}
 
Example 12
Source File: Task.java    From conductor with Apache License 2.0 4 votes vote down vote up
/**
 * @param reasonForIncompletion the reasonForIncompletion to set
 */
public void setReasonForIncompletion(String reasonForIncompletion) {
    this.reasonForIncompletion = StringUtils.substring(reasonForIncompletion, 0, 500);
}
 
Example 13
Source File: FileDescriptor.java    From cuba with Apache License 2.0 4 votes vote down vote up
public void setExtension(String extension) {
    this.extension = StringUtils.substring(extension, 0, 20);
}
 
Example 14
Source File: HardwareMapper.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
private String truncateMhz(String value) {
    return StringUtils.substring(value, 0, 16);
}
 
Example 15
Source File: HardwareMapper.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
private String parsePciBaseClass(String pciClass) {
    if (StringUtils.isBlank(pciClass)) {
        return null;
    }
    return StringUtils.substring(pciClass, -6, -4);
}
 
Example 16
Source File: HardwareMapper.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
private String parsePciSubClass(String pciClass) {
    if (StringUtils.isBlank(pciClass)) {
        return null;
    }
    return StringUtils.substring(pciClass, -4, -2);
}
 
Example 17
Source File: TestDefinitionFunctions.java    From proctor with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source File: InboundParamMatchServiceImpl.java    From smockin with Apache License 2.0 3 votes vote down vote up
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);
    }
 
Example 19
Source File: StringUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * [截取]从指定索引处(<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);
}
 
Example 20
Source File: FormatUtil.java    From rdf2x with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}