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


Java StringUtils.substring方法代码示例

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


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

示例1: getType

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private Class<?> getType(String s) {
    String typeIdentifier = StringUtils.substring(s, s.length() - 1);
    Class<?> clazz;
    switch (typeIdentifier) {
        case "l":
            clazz = Long.class;
            break;
        case "s":
            clazz = String.class;
            break;
        case "d":
            clazz = Date.class;
            break;
        case "i":
            clazz = Integer.class;
            break;
        default:
            throw new RuntimeException("unknown type identifier: " + typeIdentifier);
    }
    return clazz;
}
 
开发者ID:nds842,项目名称:sql-first-mapper,代码行数:22,代码来源:SuffixParser.java

示例2: isAPIAuthNeeded

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
@Override
protected int isAPIAuthNeeded(String url) {
	if (url != null && this.excludedUrls != null
			&& this.excludedUrls.size() != 0) {
		if (url.startsWith("{") && url.endsWith("}")) {
			url = StringUtils.substring(url, 1, url.length() - 1);
		}
		String[] urls = url.split(",");
		for (String u : urls) {
			for (String excludedUrl : this.excludedUrls) {
				if (matcher.match(excludedUrl, u)) {
					return 0;
				}
			}
			return 1;
		}
	}
	return -1;
}
 
开发者ID:WinRoad-NET,项目名称:wrdocletbase,代码行数:20,代码来源:RESTDocBuilder.java

示例3: getBriefFromCommentText

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
protected String getBriefFromCommentText(String commentText) {
	int index = StringUtils.indexOf(commentText, '\n');
	if (index != -1) {
		commentText = StringUtils.substring(commentText, 0, index);
	}
	index = StringUtils.indexOfAny(commentText, ".!?。!?…");
	if (index > 0) {
		commentText = StringUtils.substring(commentText, 0, index);
	}
	if (StringUtils.length(commentText) > 8) {
		commentText = StringUtils.substring(commentText, 0, 8) + "…";
	}
	return commentText;
}
 
开发者ID:WinRoad-NET,项目名称:wrdocletbase,代码行数:15,代码来源:AbstractDocBuilder.java

示例4: restartHydrograph

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private void restartHydrograph() {
	logger.info("Starting New Hydrograph");
	String path = Platform.getInstallLocation().getURL().getPath();
	if ((StringUtils.isNotBlank(path)) && (StringUtils.startsWith(path, "/")) && (OSValidator.isWindows())) {
		path = StringUtils.substring(path, 1);
	}
	String command = path + HYDROGRAPH_EXE;
	Runtime runtime = Runtime.getRuntime();
	try {
		if (OSValidator.isWindows()) {
			String[] commandArray = { "cmd.exe", "/c", command };
			runtime.exec(commandArray);
		}
	} catch (IOException ioException) {
		logger.error("Exception occurred while starting hydrograph" + ioException);
	}
	System.exit(0);
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:19,代码来源:PreStartActivity.java

示例5: setRow

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private void setRow(int maxScore, int row, @Nullable String text) {
    if(row < 0 || row >= MAX_ROWS) return;

    int score = text == null ? -1 : maxScore - row - 1;
    if(this.scores[row] != score) {
        this.scores[row] = score;

        if(score == -1) {
            this.scoreboard.resetScores(this.players[row]);
        } else {
            this.objective.getScore(this.players[row]).setScore(score);
        }
    }

    if(!Objects.equals(this.rows[row], text)) {
        this.rows[row] = text;

        if(text != null) {
            /*
             Split the row text into prefix and suffix, limited to 16 chars each. Because the player name
             is a color code, we have to restore the color at the split in the suffix. We also have to be
             careful not to split in the middle of a color code.
            */
            int split = MAX_PREFIX - 1; // Start by assuming there is a color code right on the split
            if(text.length() < MAX_PREFIX || text.charAt(split) != ChatColor.COLOR_CHAR) {
                // If there isn't, we can fit one more char in the prefix
                split++;
            }

            // Split and truncate the text, and restore the color in the suffix
            String prefix = StringUtils.substring(text, 0, split);
            String lastColors = org.bukkit.ChatColor.getLastColors(prefix);
            String suffix =  lastColors + StringUtils.substring(text, split, split + MAX_SUFFIX - lastColors.length());
            this.teams[row].setPrefix(prefix);
            this.teams[row].setSuffix(suffix);
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:39,代码来源:SidebarMatchModule.java

示例6: getNodeId

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
 * Returns node id from full name.
 * The elements in full name is split by using '.';
 * We assume that the node id always comes before the last three '.'
 *
 * @param fullName full name
 * @return node id
 */
private String getNodeId(String fullName) {
    int index = StringUtils.lastOrdinalIndexOf(fullName,
            METRIC_DELIMITER, NUB_OF_DELIMITER);
    if (index != -1) {
        return StringUtils.substring(fullName, 0, index);
    } else {
        log.warn("Database {} contains malformed node id.", database);
        return null;
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:19,代码来源:DefaultInfluxDbMetricsRetriever.java

示例7: inject

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
/**
 * The injection of code for the specified jar package
 *
 * @param inJar
 * @param outJar
 * @throws IOException
 * @throws NotFoundException
 * @throws CannotCompileException
 */
public static List<String> inject(ClassPool pool,
                                  File inJar,
                                  File outJar,
                                  InjectParam injectParam) throws Exception {
    List<String> errorFiles = new ArrayList<String>();
    JarFile jarFile = newJarFile(inJar);

    outJar.getParentFile().mkdirs();
    FileOutputStream fileOutputStream = new FileOutputStream(outJar);
    JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(fileOutputStream));
    Enumeration<JarEntry> jarFileEntries = jarFile.entries();
    JarEntry jarEntry = null;
    while (jarFileEntries.hasMoreElements()) {
        jarEntry = jarFileEntries.nextElement();
        String name = jarEntry.getName();
        String className = StringUtils.replace(name, File.separator, "/");
        className = StringUtils.replace(className, "/", ".");
        className = StringUtils.substring(className, 0, className.length() - 6);
        if (!StringUtils.endsWithIgnoreCase(name, ".class")) {
            InputStream inputStream = jarFile.getInputStream(jarEntry);
            copyStreamToJar(inputStream, jos, name, jarEntry.getTime(), jarEntry);
            IOUtils.closeQuietly(inputStream);
        } else {
            byte[] codes;

            codes = inject(pool, className, injectParam);
            InputStream classInstream = new ByteArrayInputStream(codes);
            copyStreamToJar(classInstream, jos, name, jarEntry.getTime(), jarEntry);

        }
    }
    jarFile.close();
    IOUtils.closeQuietly(jos);
    return errorFiles;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:45,代码来源:CodeInjectByJavassist.java

示例8: 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

示例9: firstToUpper

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String firstToUpper(String value){
	if(StringUtils.isBlank(value))
		return "";
	value = StringUtils.trim(value);
	String f = StringUtils.substring(value,0,1);
	String s = "";
	if(value.length() > 1){
		s = StringUtils.substring(value,1);
	}
	return f.toUpperCase() + s;
}
 
开发者ID:alibaba,项目名称:QLExpress,代码行数:12,代码来源:CustBean.java

示例10: getDefaultJobName

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String getDefaultJobName(Object obj) {
    String className;
    if (obj instanceof JobCommand) {
        return ((JobCommand) obj).getJobName();
    } else if (obj instanceof Class) {
        className = ((Class) obj).getSimpleName();
    } else if (obj instanceof String) {
        className = (String) obj;
    } else {
        className = obj.getClass().getSimpleName();
    }
    return StringUtils.lowerCase(StringUtils.substring(className, 0, 1))
            + StringUtils.substring(className, 1);
}
 
开发者ID:sofn,项目名称:dag-runner,代码行数:15,代码来源:DagRunner.java

示例11: getJavaDoc

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private String getJavaDoc(IClassFile classFile) throws JavaModelException {
	BinaryType binaryType=(BinaryType)classFile.getType();
	if(binaryType.getSource() !=null && binaryType.getJavadocRange()!=null){
	String javaDoc=Constants.EMPTY_STRING;
		javaDoc = StringUtils.substring(binaryType.getSource().toString(), 0, binaryType.getJavadocRange().getLength());
	javaDoc = StringUtils.replaceEachRepeatedly(javaDoc, new String[] { "/*", "*/", "*" }, new String[] {
			Constants.EMPTY_STRING, Constants.EMPTY_STRING, Constants.EMPTY_STRING });
	}
	return javaDoc;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:11,代码来源:ClassDetails.java

示例12: createFormattedJavaDoc

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private String createFormattedJavaDoc(IMethod iMethod) throws JavaModelException {
	String source = iMethod.getSource();
	if (iMethod.getJavadocRange() != null) {
		javaDoc = StringUtils.substring(source, 0, iMethod.getJavadocRange().getLength());
		javaDoc = StringUtils.replaceEachRepeatedly(javaDoc, new String[] { "/*", "*/", "*" }, new String[] {
				Constants.EMPTY_STRING, Constants.EMPTY_STRING, Constants.EMPTY_STRING });
	}
	return javaDoc;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:10,代码来源:MethodDetails.java

示例13: getInstallationConfigPath

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
private static String getInstallationConfigPath()  {
	String path = Platform.getInstallLocation().getURL().getPath();
	if(StringUtils.isNotBlank(path) && StringUtils.startsWith(path, "/") && OSValidator.isWindows()){
		path = StringUtils.substring(path, 1);
	}
	
	return path + "config/service/config" ;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:9,代码来源:ApplicationWorkbenchWindowAdvisor.java

示例14: getVarNameFromMethodName

import org.apache.commons.lang.StringUtils; //导入方法依赖的package包/类
public static String getVarNameFromMethodName(String methodName) {
    String varName = StringUtils.substringAfter(methodName, "get");
    String firstChar = StringUtils.substring(varName, 0, 1);
    varName = varName.replaceFirst(firstChar, firstChar.toLowerCase());
    return varName;
}
 
开发者ID:luckyyeah,项目名称:YiDu-Novel,代码行数:7,代码来源:GenerateHtmlFileInterceptor.java

示例15: 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.substring方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。