本文整理了Java中org.apache.commons.lang3.StringUtils.startsWith()
方法的一些代码示例,展示了StringUtils.startsWith()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.startsWith()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:startsWith
[英]Check if a CharSequence starts with a specified prefix.
nulls are handled without exceptions. Two nullreferences are considered to be equal. The comparison is case sensitive.
StringUtils.startsWith(null, null) = true
StringUtils.startsWith(null, "abc") = false
StringUtils.startsWith("abcdef", null) = false
StringUtils.startsWith("abcdef", "abc") = true
StringUtils.startsWith("ABCDEF", "abc") = false
[中]检查字符序列是否以指定的前缀开头。
空值的处理没有异常。两个空引用被认为是相等的。比较是区分大小写的。
StringUtils.startsWith(null, null) = true
StringUtils.startsWith(null, "abc") = false
StringUtils.startsWith("abcdef", null) = false
StringUtils.startsWith("abcdef", "abc") = true
StringUtils.startsWith("ABCDEF", "abc") = false
代码示例来源:origin: alibaba/nacos
@Override
public boolean interests(String key) {
return StringUtils.startsWith(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE);
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public Boolean evaluate(FunctionArgs args, EvaluationContext context) {
final String value = valueParam.required(args, context);
final String prefix = prefixParam.required(args, context);
final boolean ignoreCase = ignoreCaseParam.optional(args, context).orElse(false);
if (ignoreCase) {
return StringUtils.startsWithIgnoreCase(value, prefix);
} else {
return StringUtils.startsWith(value, prefix);
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Check if a CharSequence starts with a specified prefix.</p>
*
* <p>{@code null}s are handled without exceptions. Two {@code null}
* references are considered to be equal. The comparison is case sensitive.</p>
*
* <pre>
* StringUtils.startsWith(null, null) = true
* StringUtils.startsWith(null, "abc") = false
* StringUtils.startsWith("abcdef", null) = false
* StringUtils.startsWith("abcdef", "abc") = true
* StringUtils.startsWith("ABCDEF", "abc") = false
* </pre>
*
* @see java.lang.String#startsWith(String)
* @param str the CharSequence to check, may be null
* @param prefix the prefix to find, may be null
* @return {@code true} if the CharSequence starts with the prefix, case sensitive, or
* both {@code null}
* @since 2.4
* @since 3.0 Changed signature from startsWith(String, String) to startsWith(CharSequence, CharSequence)
*/
public static boolean startsWith(final CharSequence str, final CharSequence prefix) {
return startsWith(str, prefix, false);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Case insensitive check if a CharSequence starts with a specified prefix.</p>
*
* <p>{@code null}s are handled without exceptions. Two {@code null}
* references are considered to be equal. The comparison is case insensitive.</p>
*
* <pre>
* StringUtils.startsWithIgnoreCase(null, null) = true
* StringUtils.startsWithIgnoreCase(null, "abc") = false
* StringUtils.startsWithIgnoreCase("abcdef", null) = false
* StringUtils.startsWithIgnoreCase("abcdef", "abc") = true
* StringUtils.startsWithIgnoreCase("ABCDEF", "abc") = true
* </pre>
*
* @see java.lang.String#startsWith(String)
* @param str the CharSequence to check, may be null
* @param prefix the prefix to find, may be null
* @return {@code true} if the CharSequence starts with the prefix, case insensitive, or
* both {@code null}
* @since 2.4
* @since 3.0 Changed signature from startsWithIgnoreCase(String, String) to startsWithIgnoreCase(CharSequence, CharSequence)
*/
public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix) {
return startsWith(str, prefix, true);
}
代码示例来源:origin: oldmanpushcart/greys-anatomy
/**
* Greys唯一不能看到的就是自己<br/>
* 理论上有isSelf()挡住为啥这里还需要再次判断呢?
* 原因很简单,因为Spy被派遣到对方的ClassLoader中去了
*/
private static boolean isGreysClass(Class<?> clazz) {
return StringUtils.startsWith(clazz.getCanonicalName(), "com.github.ompc.greys.");
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Prepends the prefix to the start of the string if the string does not
* already start with any of the prefixes.
*
* @param str The string.
* @param prefix The prefix to prepend to the start of the string.
* @param ignoreCase Indicates whether the compare should ignore case.
* @param prefixes Additional prefixes that are valid (optional).
*
* @return A new String if prefix was prepended, the same string otherwise.
*/
private static String prependIfMissing(final String str, final CharSequence prefix, final boolean ignoreCase, final CharSequence... prefixes) {
if (str == null || isEmpty(prefix) || startsWith(str, prefix, ignoreCase)) {
return str;
}
if (prefixes != null && prefixes.length > 0) {
for (final CharSequence p : prefixes) {
if (startsWith(str, p, ignoreCase)) {
return str;
}
}
}
return prefix.toString() + str;
}
代码示例来源:origin: alibaba/nacos
public void doRaftAuth(HttpServletRequest req) throws Exception {
String token = req.getParameter("token");
if (StringUtils.equals(UtilsAndCommons.SUPER_TOKEN, token)) {
return;
}
String agent = req.getHeader("Client-Version");
if (StringUtils.startsWith(agent, UtilsAndCommons.NACOS_SERVER_HEADER)) {
return;
}
throw new IllegalAccessException("illegal access,agent= " + agent + ", token=" + token);
}
代码示例来源:origin: org.apache.commons/commons-lang3
if (startsWith(sequence, searchString)) {
return true;
代码示例来源:origin: gocd/gocd
public boolean passwordEquals(String p1, String p2) {
if (Objects.equals(p1, p2)) {
return true;
}
try {
if (StringUtils.startsWith(p1, "AES:") && StringUtils.startsWith(p2, "AES:")) {
return decrypt(p1).equals(decrypt(p2));
}
} catch (Exception e) {
return false;
}
return false;
}
代码示例来源:origin: alibaba/jvm-sandbox
private static String[] replaceWithSysPropUserHome(final String[] pathArray) {
if (ArrayUtils.isEmpty(pathArray)) {
return pathArray;
}
final String SYS_PROP_USER_HOME = System.getProperty("user.home");
for (int index = 0; index < pathArray.length; index++) {
if (StringUtils.startsWith(pathArray[index], "~")) {
pathArray[index] = StringUtils.replaceOnce(pathArray[index], "~", SYS_PROP_USER_HOME);
}
}
return pathArray;
}
代码示例来源:origin: simpligility/android-maven-plugin
@Override
public void visit( int version, int access, String name, String signature, String superName, String[] interfaces )
{
for ( String testPackage : parentPackages )
{
if ( StringUtils.startsWith( superName, testPackage ) )
{
flagAsFound();
// System.out.println(name + " extends " + superName);
}
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) {
final int startIndex = str.indexOf(wrapToken);
final int endIndex = str.lastIndexOf(wrapToken);
代码示例来源:origin: apache/incubator-gobblin
/**
* Extract all the keys that start with a <code>prefix</code> in {@link Properties} to a new {@link Properties}
* instance.
*
* @param properties the given {@link Properties} instance
* @param prefix of keys to be extracted
* @return a {@link Properties} instance
*/
public static Properties extractPropertiesWithPrefix(Properties properties, Optional<String> prefix) {
Preconditions.checkNotNull(properties);
Preconditions.checkNotNull(prefix);
Properties extractedProperties = new Properties();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
if (StringUtils.startsWith(entry.getKey().toString(), prefix.or(StringUtils.EMPTY))) {
extractedProperties.put(entry.getKey().toString(), entry.getValue());
}
}
return extractedProperties;
}
代码示例来源:origin: scouter-project/scouter
private String toGeneralKey(String key) {
String prefix = getPrivateKeyPrefix();
if (!StringUtils.startsWith(key, prefix)) {
ErrorState.ILLEGAL_KEY_ACCESS.newBizException();
}
return StringUtils.substring(key, prefix.length());
}
}
代码示例来源:origin: jamesdbloom/mockserver
private String getUri(HttpRequest request) {
String uri = new MockServerHttpRequestToFullHttpRequest().getURI(request);
if (Strings.isNullOrEmpty(uri)) {
uri = "/";
} else if (!StringUtils.startsWith(uri, "/")) {
uri = "/" + uri;
}
return uri;
}
代码示例来源:origin: springside/springside4
/**
* 兼容无前缀, classpath://, file:// 的情况获取文件
*
* 如果以classpath:// 定义的文件不存在会抛出IllegalArgumentException异常,以file://定义的则不会
*/
public static File asFile(String generalPath) throws IOException {
if (StringUtils.startsWith(generalPath, CLASSPATH_PREFIX)) {
String resourceName = StringUtils.substringAfter(generalPath, CLASSPATH_PREFIX);
return getFileByURL(ResourceUtil.asUrl(resourceName));
}
try {
// try URL
return getFileByURL(new URL(generalPath));
} catch (MalformedURLException ex) {
// no URL -> treat as file path
return new File(generalPath);
}
}
代码示例来源:origin: gocd/gocd
protected String destURL(File rootPath, File file, String src, String dest) {
String trimmedPattern = rtrimStandardrizedWildcardTokens(src);
if (StringUtils.equals(FilenameUtils.separatorsToUnix(trimmedPattern), FilenameUtils.separatorsToUnix(src))) {
return dest;
}
String trimmedPath = removeStart(subtractPath(rootPath, file), FilenameUtils.separatorsToUnix(trimmedPattern));
if (!StringUtils.startsWith(trimmedPath, "/") && StringUtils.isNotEmpty(trimmedPath)) {
trimmedPath = "/" + trimmedPath;
}
return dest + trimmedPath;
}
代码示例来源:origin: gocd/gocd
protected String destinationURL(File rootPath, File file, String src, String dest) {
String trimmedPattern = rtrimStandardrizedWildcardTokens(src);
if (StringUtils.equals(FilenameUtils.separatorsToUnix(trimmedPattern), FilenameUtils.separatorsToUnix(src))) {
return dest;
}
String trimmedPath = removeStart(subtractPath(rootPath, file), FilenameUtils.separatorsToUnix(trimmedPattern));
if (!StringUtils.startsWith(trimmedPath, "/") && StringUtils.isNotEmpty(trimmedPath)) {
trimmedPath = "/" + trimmedPath;
}
return dest + trimmedPath;
}
代码示例来源:origin: springside/springside4
/**
* 兼容file://与classpath://的情况的打开文件成Stream
*/
public static InputStream asStream(String generalPath) throws IOException {
if (StringUtils.startsWith(generalPath, CLASSPATH_PREFIX)) {
String resourceName = StringUtils.substringAfter(generalPath, CLASSPATH_PREFIX);
return ResourceUtil.asStream(resourceName);
}
try {
// try URL
return FileUtil.asInputStream(getFileByURL(new URL(generalPath)));
} catch (MalformedURLException ex) {
// no URL -> treat as file path
return FileUtil.asInputStream(generalPath);
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test StringUtils.startsWith()
*/
@Test
public void testStartsWith() {
assertTrue("startsWith(null, null)", StringUtils.startsWith(null, null));
assertFalse("startsWith(FOOBAR, null)", StringUtils.startsWith(FOOBAR, null));
assertFalse("startsWith(null, FOO)", StringUtils.startsWith(null, FOO));
assertTrue("startsWith(FOOBAR, \"\")", StringUtils.startsWith(FOOBAR, ""));
assertTrue("startsWith(foobar, foo)", StringUtils.startsWith(foobar, foo));
assertTrue("startsWith(FOOBAR, FOO)", StringUtils.startsWith(FOOBAR, FOO));
assertFalse("startsWith(foobar, FOO)", StringUtils.startsWith(foobar, FOO));
assertFalse("startsWith(FOOBAR, foo)", StringUtils.startsWith(FOOBAR, foo));
assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(foo, foobar));
assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(bar, foobar));
assertFalse("startsWith(foobar, bar)", StringUtils.startsWith(foobar, bar));
assertFalse("startsWith(FOOBAR, BAR)", StringUtils.startsWith(FOOBAR, BAR));
assertFalse("startsWith(foobar, BAR)", StringUtils.startsWith(foobar, BAR));
assertFalse("startsWith(FOOBAR, bar)", StringUtils.startsWith(FOOBAR, bar));
}
内容来源于网络,如有侵权,请联系作者删除!