@Override public boolean interests(String key) { return StringUtils.startsWith(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE); }
@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); } }
/** * <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); }
/** * <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); }
/** * Greys唯一不能看到的就是自己<br/> * 理论上有isSelf()挡住为啥这里还需要再次判断呢? * 原因很简单,因为Spy被派遣到对方的ClassLoader中去了 */ private static boolean isGreysClass(Class<?> clazz) { return StringUtils.startsWith(clazz.getCanonicalName(), "com.github.ompc.greys."); }
/** * 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; }
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); }
if (startsWith(sequence, searchString)) { return true;
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; }
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; }
@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); } } }
if (startsWith(str, wrapToken) && endsWith(str, wrapToken)) { final int startIndex = str.indexOf(wrapToken); final int endIndex = str.lastIndexOf(wrapToken);
/** * 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; }
private String toGeneralKey(String key) { String prefix = getPrivateKeyPrefix(); if (!StringUtils.startsWith(key, prefix)) { ErrorState.ILLEGAL_KEY_ACCESS.newBizException(); } return StringUtils.substring(key, prefix.length()); } }
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; }
/** * 兼容无前缀, 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); } }
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; }
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; }
/** * 兼容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); } }
/** * 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)); }