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

The following examples show how to use org.apache.commons.lang3.StringUtils#startsWith() . These examples are extracted from open source projects. 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
/**
 * Process the lines in leelaz's output. Example: info move D16 visits 7 winrate 4704 pv D16 Q16 D4
 *
 * @param line an output line
 */
private void processEngineOutputLine(String line) {
    String trimmed = StringUtils.trim(line);
    if (!StringUtils.startsWith(trimmed, "info")) {
        return;
    }

    final MutableList<MoveData> currentBestMoves = parseMoveDataLine(trimmed);
    if (CollectionUtils.isEmpty(currentBestMoves)) {
        return;
    }

    if (System.currentTimeMillis() - lastBestMoveUpdatedTime < 100) {
        return;
    }

    notificationExecutor.execute(() -> observers.bestMovesUpdated(currentBestMoves));
    lastBestMoveUpdatedTime = System.currentTimeMillis();
}
 
Example 2
Source Project: para   File: SecurityUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param request HTTP request
 * @return the appid if it's present in either the 'state' or 'appid' query parameters
 */
public static String getAppidFromAuthRequest(HttpServletRequest request) {
	String appid1 = request.getParameter("state");
	String appid2 = request.getParameter(Config._APPID);
	if (StringUtils.isBlank(appid1) && StringUtils.isBlank(appid2)) {
		if (StringUtils.startsWith(request.getRequestURI(), SAMLAuthFilter.SAML_ACTION + "/")) {
			return StringUtils.trimToNull(request.getRequestURI().substring(SAMLAuthFilter.SAML_ACTION.length() + 1));
		} else {
			return null;
		}
	} else if (!StringUtils.isBlank(appid1)) {
		return StringUtils.trimToNull(appid1);
	} else {
		return StringUtils.trimToNull(appid2);
	}
}
 
Example 3
/**
 * Process the lines in leelaz's output. Example: info move D16 visits 7 winrate 4704 pv D16 Q16 D4
 *
 * @param line an output line
 */
private void processEngineOutputLine(String line) {
    if (!StringUtils.startsWith(line, "info")) {
        return;
    }

    MoveData moveData = parseMoveDataLine(line);
    if (moveData == null) {
        return;
    }

    if (System.currentTimeMillis() - startPonderTime > Lizzie.optionSetting.getMaxAnalysisTime() * MILLISECONDS_IN_SECOND) {
        // we have pondered for enough time. pause pondering
        notificationExecutor.execute(this::pauseAnalyzing);
    }

    bestMoves.put(moveData.getCoordinate(), moveData);

    final List<MoveData> currentBestMoves = bestMoves.toSortedList(Comparator.comparingInt(MoveData::getPlayouts).reversed());
    notificationExecutor.execute(() -> observers.bestMovesUpdated(currentBestMoves));
}
 
Example 4
Source Project: webanno   File: UrlImporter.java    License: Apache License 2.0 6 votes vote down vote up
private Optional<Import> tryResolveUrl(URI base, String url)
{
    final Optional<Import> newImport;
    if (StringUtils.startsWith(url, WEBJARS_SCHEME)) {
        newImport = resolveWebJarsDependency(url);
    }
    else if (StringUtils.startsWith(url, CLASSPATH_SCHEME)) {
        newImport = resolveClasspathDependency(url);
    }
    else if (StringUtils.startsWith(url, WEB_CONTEXT_SCHEME)) {
        newImport = resolveWebContextDependency(url);
    }
    else if (scopeClass != null && StringUtils.startsWith(url, PACKAGE_SCHEME)) {
        newImport = resolvePackageDependency(url);
    }
    else {
        newImport = resolveLocalDependency(base, url);
    }

    return newImport;
}
 
Example 5
private Boolean shouldFilter(MappedStatement mappedStatement, DataPermission dataPermission) {
    if (dataPermission != null) {
        String methodName = StringUtils.substringAfterLast(mappedStatement.getId(), ".");
        String methodPrefix = dataPermission.methodPrefix();
        if (StringUtils.isNotBlank(methodPrefix) && StringUtils.startsWith(methodName, methodPrefix)) {
            return Boolean.TRUE;
        }
        String[] methods = dataPermission.methods();
        for (String method : methods) {
            if (StringUtils.equals(method, methodName)) {
                return Boolean.TRUE;
            }
        }
    }
    return Boolean.FALSE;
}
 
Example 6
Source Project: p4ic4idea   File: P4JavaExceptions.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Rethrowing checked exceptions but it's not required catch statement
 *
 * @apiNote after jdk1.8
 */
@SuppressWarnings("unchecked")
private static <E extends Throwable> void throwAsUnchecked(Exception exception) {
    String version = System.getProperty("java.version");
    if (StringUtils.startsWith(version, "1.7")) {
        throwAsUncheckedInJava7(exception);
    } else {
        /*
        * FIXME: if p4java upgrade to java 8, change to
        * <pre>
        *     throwAsUncheckedAfterJava8(exception);
        * </pre>
        *
         */
        getUnsafe().throwException(exception);
    }
}
 
Example 7
Source Project: super-cloudops   File: SerializeUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Annotate to object copying, only copy the methods that match.
 * 
 * @param annotation
 * @param object
 */
public static void annotationToObject(Object annotation, Object object) {
	if (annotation != null && object != null) {
		Class<?> annotationClass = annotation.getClass();
		Class<?> objectClass = object.getClass();
		if (objectClass != null) {
			for (Method m : objectClass.getMethods()) {
				if (StringUtils.startsWith(m.getName(), "set")) {
					try {
						String s = StringUtils.uncapitalize(StringUtils.substring(m.getName(), 3));
						Object obj = annotationClass.getMethod(s).invoke(annotation);
						if (obj != null && !"".equals(obj.toString())) {
							if (object == null) {
								object = objectClass.newInstance();
							}
							m.invoke(object, obj);
						}
					} catch (Exception e) {
						// 忽略所有设置失败方法
					}
				}
			}
		}
	}
}
 
Example 8
Source Project: easyweb   File: ObjectUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 注解到对象复制,只复制能匹配上的方法。
 * @param annotation
 * @param object
 */
public static void annotationToObject(Object annotation, Object object){
	if (annotation != null){
		Class<?> annotationClass = annotation.getClass();
		if (null == object) {
			return;
		}
		Class<?> objectClass = object.getClass();
		for (Method m : objectClass.getMethods()){
			if (StringUtils.startsWith(m.getName(), "set")){
				try {
					String s = StringUtils.uncapitalize(StringUtils.substring(m.getName(), 3));
					Object obj = annotationClass.getMethod(s).invoke(annotation);
					if (obj != null && !"".equals(obj.toString())){
						m.invoke(object, obj);
					}
				} catch (Exception e) {
					// 忽略所有设置失败方法
				}
			}
		}
	}
}
 
Example 9
Source Project: analysis-model   File: IntelParser.java    License: MIT License 6 votes vote down vote up
@Override
protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder builder) {
    String category = StringUtils.capitalize(matcher.group(5));

    Severity priority;
    if (StringUtils.startsWith(category, "Remark") || StringUtils.startsWith(category, "Message")) {
        priority = Severity.WARNING_LOW;
    }
    else if (StringUtils.startsWith(category, "Error")) {
        priority = Severity.WARNING_HIGH;
    }
    else {
        priority = Severity.WARNING_NORMAL;
    }

    return builder.setFileName(matcher.group(2))
            .setLineStart(matcher.group(3))
            .setColumnStart(matcher.group(4))
            .setCategory(category)
            .setMessage(matcher.group(6))
            .setSeverity(priority)
            .buildOptional();
}
 
Example 10
private String compareValue(Runtime runtime) {
	if (StringUtils.startsWith(this.value, "@")) {
		if ((!StringUtils.equals(this.value, DEFINE_TIME)) && (!StringUtils.equals(this.value, DEFINE_DATE))
				&& (!StringUtils.equals(this.value, DEFINE_MONTH))
				&& (!StringUtils.equals(this.value, DEFINE_SEASON))
				&& (!StringUtils.equals(this.value, DEFINE_YEAR))
				&& (!StringUtils.equals(this.value, DEFINE_PERSON))
				&& (!StringUtils.equals(this.value, DEFINE_IDENTITYLIST))
				&& (!StringUtils.equals(this.value, DEFINE_UNITALLLIST))
				&& (!StringUtils.equals(this.value, DEFINE_UNITLIST))) {
			String key = StringUtils.substring(this.value, 1);
			return Objects.toString(runtime.parameter.get(key), "");
		}
	}
	return this.value;
}
 
Example 11
Source Project: frpMgr   File: JsonMapper.java    License: MIT License 6 votes vote down vote up
/**
 * JSON字符串转换为 List<Map<String, Object>>
 */
public static List<Map<String, Object>> fromJsonForMapList(String jsonString){
	List<Map<String, Object>> result = ListUtils.newArrayList();
	if (StringUtils.startsWith(jsonString, "{")){
		Map<String, Object> map = fromJson(jsonString, Map.class);
		if (map != null){
			result.add(map);
		}
	}else if (StringUtils.startsWith(jsonString, "[")){
		List<Map<String, Object>> list = fromJson(jsonString, List.class);
		if (list != null){
			result = list;
		}
	}
	return result;
}
 
Example 12
/**
 * Returns the xpath full path of the given element. E.g something like /html/body/div[2]/p
 * 
 * @param driver
 * @param element
 * @return
 */
private String getElementXPath(WebDriver driver, WebElement element)
{
    String xpath = (String) ((JavascriptExecutor) driver).executeScript(
                "gPt=function(c){if(c.id!==''){return'id(\"'+c.id+'\")'}if(c===document.body){return c.tagName}var a=0;var e=c.parentNode.childNodes;for(var b=0;b<e.length;b++){var d=e[b];if(d===c){return gPt(c.parentNode)+'/'+c.tagName+'['+(a+1)+']'}if(d.nodeType===1&&d.tagName===c.tagName){a++}}};return gPt(arguments[0]).toLowerCase();",
                element);
    if (!StringUtils.startsWith(xpath, "id(\""))
        xpath = "/html/" + xpath;
    return xpath;
}
 
Example 13
/**
 * Determines which attributes are selected based on the passed in node
 * name.
 *
 * @param parent the parent node pointer
 * @param name the name of the selected attribute
 * @return a list with the selected attributes
 */
private List<String> createAttributeDataList(
        final ConfigurationNodePointer<T> parent, final QName name)
{
    final List<String> result = new ArrayList<>();
    if (!WILDCARD.equals(name.getName()))
    {
        addAttributeData(parent, result, qualifiedName(name));
    }
    else
    {
        final Set<String> names =
                new LinkedHashSet<>(parent.getNodeHandler()
                        .getAttributes(parent.getConfigurationNode()));
        final String prefix =
                name.getPrefix() != null ? prefixName(name.getPrefix(),
                        null) : null;
        for (final String n : names)
        {
            if (prefix == null || StringUtils.startsWith(n, prefix))
            {
                addAttributeData(parent, result, n);
            }
        }
    }

    return result;
}
 
Example 14
public static String trim(String uri) {
	if (StringUtils.isEmpty(uri)) {
		return "";
	}
	if (StringUtils.startsWith(uri, "/jaxrs/")) {
		return StringUtils.substringAfter(uri, "/jaxrs/");
	}
	if (StringUtils.startsWith(uri, "/")) {
		return StringUtils.substringAfter(uri, "/");
	}
	return uri;
}
 
Example 15
Source Project: incubator-atlas   File: DiscoveryREST.java    License: Apache License 2.0 5 votes vote down vote up
private String escapeTypeName(String typeName) {
    String ret;

    if (StringUtils.startsWith(typeName, "`") && StringUtils.endsWith(typeName, "`")) {
        ret = typeName;
    } else {
        ret = String.format("`%s`", typeName);
    }

    return ret;
}
 
Example 16
Source Project: archiva   File: DefaultWagonFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Wagon getWagon( WagonFactoryRequest wagonFactoryRequest )
    throws WagonFactoryException
{
    try
    {
        String protocol = StringUtils.startsWith( wagonFactoryRequest.getProtocol(), "wagon#" )
            ? wagonFactoryRequest.getProtocol()
            : "wagon#" + wagonFactoryRequest.getProtocol();

        // if it's a ntlm proxy we have to lookup the wagon light which support thats
        // wagon http client doesn't support that
        if ( wagonFactoryRequest.getNetworkProxy() != null && wagonFactoryRequest.getNetworkProxy().isUseNtlm() )
        {
            protocol = protocol + "-ntlm";
        }

        Wagon wagon = applicationContext.getBean( protocol, Wagon.class );
        wagon.addTransferListener( debugTransferListener );
        configureUserAgent( wagon, wagonFactoryRequest );
        return wagon;
    }
    catch ( BeansException e )
    {
        throw new WagonFactoryException( e.getMessage(), e );
    }
}
 
Example 17
Source Project: flowable-engine   File: TestRuleBean.java    License: Apache License 2.0 4 votes vote down vote up
public boolean startsWith(Object input, String value) {
    return StringUtils.startsWith(input.toString(), value);
}
 
Example 18
Source Project: torrssen2   File: DownloadService.java    License: MIT License 4 votes vote down vote up
public long create(DownloadList download) {
    long ret = 0L;

    String app = settingService.getDownloadApp();
    if(StringUtils.equals(app, "DOWNLOAD_STATION")) {
        String[] paths = StringUtils.split(download.getDownloadPath(), "/");

        if(paths.length > 1) {
            StringBuffer path = new StringBuffer();
            String name = null;
            for(int i = 0; i < paths.length; i++) {
                if(i < paths.length -1) {
                    path.append("/" + paths[i]);
                } else {
                    name = paths[i];
                }
            }
            fileStationService.createFolder(path.toString(), name);
        }
        if(downloadStationService.create(download.getUri(), download.getDownloadPath())) {
            for(DownloadList down: downloadStationService.list()) {
                if(StringUtils.equals(download.getUri(), down.getUri())) {
                    ret = down.getId();
                    download.setDbid(down.getDbid());
                }
            }
        }
    } else if(StringUtils.equals(app, "TRANSMISSION")) {
        if (StringUtils.startsWith(download.getUri(), "magnet")
            || StringUtils.equalsIgnoreCase(FilenameUtils.getExtension(download.getUri()), "torrent")) {
            ret = (long)transmissionService.torrentAdd(download.getUri(), download.getDownloadPath());
        } else {
            Optional<DownloadList> optionalSeq = downloadListRepository.findTopByOrderByIdDesc();
            if (optionalSeq.isPresent()) {
                Long id = optionalSeq.get().getId() + 100L;                    
                log.debug("id: " + id);
                ret = id;
            } else {
                ret = 100L;
            }
            download.setId(ret);
            httpDownloadService.createTransmission(download);
        }
        
    }

    if(ret > 0L) {
        download.setId(ret);
        downloadListRepository.save(download);
    }

    if(download.getAuto()) {
        WatchList watchList = new WatchList();
        watchList.setTitle(download.getRssTitle());
        watchList.setDownloadPath(download.getDownloadPath());
        if(!StringUtils.equals(download.getRssReleaseGroup(), "OTHERS")) {
            watchList.setReleaseGroup(download.getRssReleaseGroup());
        }
        
        watchListRepository.save(watchList);
    }

    return ret;
}
 
Example 19
Source Project: analysis-model   File: EclipseParser.java    License: MIT License 3 votes vote down vote up
/**
 * Sets the issue's category to {@code Javadoc} if the message starts with {@value #JAVADOC_PREFIX}, {@code Other}
 * otherwise. Unlike {@link #extractMessage(IssueBuilder, String)}, the {@code message} is assumed to be cleaned-up.
 * 
 * @param builder
 *     IssueBuilder to populate.
 * @param message
 *     issue to examine.
 */
static void extractCategory(final IssueBuilder builder, final String message) {
    if (StringUtils.startsWith(message, JAVADOC_PREFIX)) {
        builder.setCategory(Categories.JAVADOC);
    }
    else {
        builder.setCategory(Categories.OTHER);
    }
}
 
Example 20
/**
 * @param url 
 * @return whether the current Url starts with a file prefix
 */
public boolean hasUrlFilePrefix(String url) {
    return StringUtils.startsWith(url, TgolKeyStore.FILE_PREFIX);
}