当前位置: 首页>>代码示例>>Java>>正文


Java StringUtils.lastIndexOf方法代码示例

本文整理汇总了Java中org.apache.commons.lang.StringUtils.lastIndexOf方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.lastIndexOf方法的具体用法?Java StringUtils.lastIndexOf怎么用?Java StringUtils.lastIndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang.StringUtils的用法示例。


在下文中一共展示了StringUtils.lastIndexOf方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prevButtonListener

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
 *  The function will move cursor in reverse direction.
 * @param styledText
 * @param text
 * @param prevLineIndex
 * @param nextLineIndex
 * @return int[]
 */
public int[] prevButtonListener(StyledText styledText, String text, int prevLineIndex, int nextLineIndex){
	logger.debug("StyledText prev button selected");
	if(prevLineIndex == 0){
		prevLineIndex = styledText.getText().length() - 1;
	}
	int lastIndex = StringUtils.lastIndexOf(StringUtils.lowerCase(styledText.getText()), StringUtils.lowerCase(text), prevLineIndex-1);
	
	if(lastIndex < 0 ){
		prevLineIndex = styledText.getText().length() - 1;
		prevLineIndex= StringUtils.lastIndexOf(StringUtils.lowerCase(styledText.getText()), StringUtils.lowerCase(text), prevLineIndex-1);
		styledText.setSelection(prevLineIndex);
		setStyledRange(styledText, prevLineIndex, text.length(), null, Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));
		nextLineIndex = prevLineIndex + 1;
		return new int[]{prevLineIndex,nextLineIndex};
	}else{
		setStyledRange(styledText, lastIndex, text.length(), null, Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));
		styledText.setSelection(lastIndex);
		prevLineIndex = lastIndex;
		nextLineIndex = lastIndex + 1;
		styledText.redraw();
	}
	return new int[]{prevLineIndex,nextLineIndex};
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:32,代码来源:StyledTextEventListener.java

示例2: ArtifactFile

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public ArtifactFile(File file, String version) {
    name = file.getName();
    extension = "";
    classifier = "";
    boolean done = false;

    int startVersion = StringUtils.lastIndexOf(name, "-" + version);
    if (startVersion >= 0) {
        int endVersion = startVersion + version.length() + 1;
        if (endVersion == name.length()) {
            name = name.substring(0, startVersion);
            done = true;
        } else if (endVersion < name.length() && name.charAt(endVersion) == '-') {
            String tail = name.substring(endVersion + 1);
            name = name.substring(0, startVersion);
            classifier = StringUtils.substringBeforeLast(tail, ".");
            extension = StringUtils.substringAfterLast(tail, ".");
            done = true;
        } else if (endVersion < name.length() && StringUtils.lastIndexOf(name, ".") == endVersion) {
            extension = name.substring(endVersion + 1);
            name = name.substring(0, startVersion);
            done = true;
        }
    }
    if (!done) {
        extension = StringUtils.substringAfterLast(name, ".");
        name = StringUtils.substringBeforeLast(name, ".");
    }
    if (classifier.length() == 0) {
        classifier = null;
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:33,代码来源:ArtifactFile.java

示例3: convertKalturaMetadataToFieldsList

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
 * Method to process the KalturaMetadata object (and the XML it contains) into a list of field strings
 * @param metadata kaltura metadata object
 * @return List of field strings
 */
private List<String> convertKalturaMetadataToFieldsList(KalturaMetadata metadata) {
    List<String> fields = new ArrayList<String>();
    // if metadata exists for object
    if (metadata != null && StringUtils.isNotEmpty(metadata.xml)) {
        // check for malformed beginning of XML
        String metadataXml = metadata.xml;
        if (StringUtils.startsWithIgnoreCase(metadataXml, "xml=")){ 
            metadataXml = metadataXml.replaceAll("xml=", ""); 
        }

        // ensure XML begins with the <?xml tag
        int lastIndex = StringUtils.lastIndexOf(metadataXml, "<?xml");
        if(lastIndex > 0){
            metadataXml = StringUtils.substring(metadataXml, lastIndex);
        }

        // set the metadata's XML to the updated string
        metadata.xml = metadataXml;

        try {
            Document metadataDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(metadata.xml)));
            org.w3c.dom.Element root = metadataDoc.getDocumentElement();
            NodeList childNodes = root.getChildNodes();
            for (int i = 0; i < childNodes.getLength(); i++) {
                Node node = childNodes.item(i);
                if (node instanceof org.w3c.dom.Element) {
                    fields.add(node.getTextContent());
                }
            }
        } catch (Exception e) {
            throw new RuntimeException("Error processing metadata fields for kaltura metadata object (" + metadata.objectId + ") :: " + e + ", xml="+metadata.xml, e);
        }
    }
    return fields;
}
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:41,代码来源:KalturaAPIService.java

示例4: decodeMetadataPermissions

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
 * Decodes the permissions string into a map of values.
 * Keys: containerType, containerId, Owner, Hidden, Reusable, Remixable
 * 
 * @param permissionString the string representation of the permissions
 *      ("site:<siteId>::{<ownerId>}h,S,r" OR "playlist:<playlistId>::{<ownerId>}h,S,r")
 * @param failIfInvalid if true then this will throw an exception if the input string is invalid, otherwise it will return defaults
 * @return Map of permission data OR defaults if input string is invalid
 * @throws IllegalArgumentException if the string decoding fails
 */
protected Map<String, String> decodeMetadataPermissions(String permissionString, boolean failIfInvalid) {
    Map<String, String> decodedPermissions = new HashMap<String, String>(6);
    // check if permissions string is a valid format
    if (StringUtils.isNotEmpty(permissionString) 
            && StringUtils.contains(permissionString, "::{") 
            && (StringUtils.startsWith(permissionString, "site:") || StringUtils.startsWith(permissionString, "playlist:"))) {
        // first find the last "}" in the string (first from the right)
        int braceRight = StringUtils.lastIndexOf(permissionString, '}');
        if (braceRight == -1) {
            throw new IllegalArgumentException("Invalid format- no '}' (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        // find the last "::{" from the right of the brace
        int braceLeft = StringUtils.lastIndexOf(permissionString, "::{", braceRight);
        if (braceLeft == -1) {
            throw new IllegalArgumentException("Invalid format - no '::{' (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        // chop the string into the 3 parts dropping the braces and :: separators
        String containerStr = StringUtils.substring(permissionString, 0, braceLeft);
        braceLeft += 2; // shift over to the actual brace
        String ownerId = StringUtils.substring(permissionString, braceLeft+1, braceRight);
        if (StringUtils.isEmpty(ownerId)) {
            throw new IllegalArgumentException("Invalid format - no ownerId (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        decodedPermissions.put(METADATA_OWNER, ownerId);
        // get the containerId from the first piece
        if (StringUtils.startsWith(containerStr, "site:")) {
            decodedPermissions.put(METADATA_CONTAINER_TYPE, "site");
            decodedPermissions.put(METADATA_CONTAINER_ID, StringUtils.substring(containerStr, 5));
        } else if (StringUtils.startsWith(containerStr, "playlist:")) {
            decodedPermissions.put(METADATA_CONTAINER_TYPE, "playlist");
            decodedPermissions.put(METADATA_CONTAINER_ID, StringUtils.substring(containerStr, 9));
        } else {
            // should never really happen
            throw new IllegalArgumentException("Invalid format - bad prefix (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        if (StringUtils.isEmpty(decodedPermissions.get(METADATA_CONTAINER_ID))) {
            throw new IllegalArgumentException("Invalid format - no containerId (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        // split the permissions
        String perms = StringUtils.substring(permissionString, braceRight+1);
        if (StringUtils.isEmpty(perms)) {
            throw new IllegalArgumentException("Invalid format - no perms (e.g. 'site:<site_library_id>::{<ownerId>}h,S,r') for permissions string: "+permissionString);
        }
        // get the permissions ([0] = hidden, [1] = reusable, [2] = remixable)
        String[] permissions = StringUtils.split(perms, ',');
        decodedPermissions.put(METADATA_HIDDEN, permissions[0]);
        decodedPermissions.put(METADATA_REUSABLE, permissions[1]);
        decodedPermissions.put(METADATA_REMIXABLE, permissions[2]);

    } else { // load default metadata
        if (failIfInvalid) {
            throw new IllegalArgumentException("Invalid string format - fails to match basic rules (e.g. not empty, contains '::{' and starts with 'site' or 'playlist') for permissions string: "+permissionString);
        } else {
            decodedPermissions.put(METADATA_CONTAINER_TYPE, "");
            decodedPermissions.put(METADATA_CONTAINER_ID, "");
            decodedPermissions.put(METADATA_OWNER, null);
            decodedPermissions.put(METADATA_HIDDEN, DEFAULT_METADATA_HIDDEN);
            decodedPermissions.put(METADATA_REUSABLE, DEFAULT_METADATA_REUSABLE);
            decodedPermissions.put(METADATA_REMIXABLE, DEFAULT_METADATA_REMIXABLE);
        }
    }
    return decodedPermissions;
}
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:74,代码来源:KalturaAPIService.java


注:本文中的org.apache.commons.lang.StringUtils.lastIndexOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。