Java Code Examples for org.apache.commons.lang.StringUtils#indexOf()
The following examples show how to use
org.apache.commons.lang.StringUtils#indexOf() .
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
Source File: CompactionPathParser.java From incubator-gobblin with Apache License 2.0 | 6 votes |
private void parseTimeAndDatasetName (FileSystemDataset dataset, CompactionParserResult rst) { String commonBase = rst.getSrcBaseDir(); String fullPath = dataset.datasetURN(); int startPos = fullPath.indexOf(commonBase) + commonBase.length(); String relative = StringUtils.removeStart(fullPath.substring(startPos), "/"); int delimiterStart = StringUtils.indexOf(relative, rst.getSrcSubDir()); if (delimiterStart == -1) { throw new StringIndexOutOfBoundsException(); } int delimiterEnd = relative.indexOf("/", delimiterStart); String datasetName = StringUtils.removeEnd(relative.substring(0, delimiterStart), "/"); String timeString = StringUtils.removeEnd(relative.substring(delimiterEnd + 1), "/"); rst.datasetName = datasetName; rst.timeString = timeString; rst.time = getTime (timeString); }
Example 2
Source File: VariableCPInstruction.java From systemds with Apache License 2.0 | 6 votes |
@Override public void updateInstructionThreadID(String pattern, String replace) { if( opcode == VariableOperationCode.CreateVariable || opcode == VariableOperationCode.SetFileName ) { //replace in-memory instruction getInput2().setName(getInput2().getName().replaceAll(pattern, replace)); // Find a start position of file name string. int iPos = StringUtils.ordinalIndexOf(instString, Lop.OPERAND_DELIMITOR, CREATEVAR_FILE_NAME_VAR_POS); // Find a end position of file name string. int iPos2 = StringUtils.indexOf(instString, Lop.OPERAND_DELIMITOR, iPos+1); StringBuilder sb = new StringBuilder(); sb.append(instString.substring(0,iPos+1)); // It takes first part before file name. // This will replace 'pattern' with 'replace' string from file name. sb.append(ProgramConverter.saveReplaceFilenameThreadID(instString.substring(iPos+1, iPos2+1), pattern, replace)); sb.append(instString.substring(iPos2+1)); // It takes last part after file name. instString = sb.toString(); } }
Example 3
Source File: Version.java From tddl5 with Apache License 2.0 | 6 votes |
/** * 根据jar包的路径,找到对应的版本号 */ public static String getVerionByPath(String file) { if (file != null && file.length() > 0 && StringUtils.contains(file, ".jar")) { int index = StringUtils.indexOf(file, ".jar"); file = file.substring(0, index); int i = file.lastIndexOf('/'); if (i >= 0) { file = file.substring(i + 1); } i = file.indexOf("-"); if (i >= 0) { file = file.substring(i + 1); } while (file.length() > 0 && !Character.isDigit(file.charAt(0))) { i = file.indexOf("-"); if (i >= 0) { file = file.substring(i + 1); } else { break; } } return file; } else { return null; } }
Example 4
Source File: LabsLookupSecurityTravelAuthorizationDocumentBase.java From rice with Educational Community License v2.0 | 6 votes |
/** * Tests the case in which the a new conversion field is added so that a field that is not referenced in either the * data dictionary or the Uif (the traveler type code) appears in the email address field, which is not secured. * * @throws Exception */ protected void testTransactionalLookupSecurityAddHiddenConversionField() throws Exception { waitAndClickTravelerQuickfinder(); final String xpathExpression = "//iframe[contains(@src,'" + FRAME_URL + "')]"; driver.switchTo().frame(driver.findElement(By.xpath(xpathExpression))); final String currentUrl = driver.getCurrentUrl(); assertTrue("Url doesn't have CONVERSION_FIELDS (" + CONVERSION_FIELDS + ")", StringUtils.indexOf(currentUrl, CONVERSION_FIELDS) > -1); int splitPosition = StringUtils.indexOf(currentUrl, CONVERSION_FIELDS) + CONVERSION_FIELDS.length(); String before = StringUtils.substring(currentUrl, 0, splitPosition); String after = StringUtils.substring(currentUrl, splitPosition); String newUrl = before + ERRANT_CONVERSION_FIELD + after; jGrowl("Opening -> "+newUrl); open(newUrl); waitForPageToLoad(); waitAndClickSearch3(); waitAndClickReturnValue(); final String xpathExpression2 = "//div[contains(@data-label,'Email Address')]"; String emailAddress = waitAndGetAttribute(By.xpath(xpathExpression2),"value"); assertTrue("Non-secure field emailAddress was not empty", StringUtils.isBlank(emailAddress)); }
Example 5
Source File: KualiMaintenanceForm.java From rice with Educational Community License v2.0 | 6 votes |
/** * This overridden method ... * * @see KualiDocumentFormBase#shouldMethodToCallParameterBeUsed(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest) */ @Override public boolean shouldMethodToCallParameterBeUsed( String methodToCallParameterName, String methodToCallParameterValue, HttpServletRequest request) { // the user clicked on a document initiation link if (StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL) || StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL) || StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL) || StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION) || StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_DELETE_METHOD_TO_CALL)) { return true; } if ( StringUtils.indexOf(methodToCallParameterName, KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.TOGGLE_INACTIVE_METHOD ) == 0 ) { return true; } return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request); }
Example 6
Source File: ContractsGrantsInvoiceDocumentErrorLogLookupableHelperServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * Manipulate fields for search criteria in order to get the results the user really wants. * * @param fieldValues * @return updated search criteria fieldValues */ protected Map<String, String> updateFieldValuesForSearchCriteria(Map<String, String> fieldValues) { Map<String, String> newFieldValues = new HashMap<>(); newFieldValues.putAll(fieldValues); // Add wildcard character to start and end of accounts field so users can search for single account // within the delimited list of accounts without having to add the wildcards explicitly themselves. String accounts = newFieldValues.get(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS); if (StringUtils.isNotBlank(accounts)) { // only add wildcards if they haven't already been added (for some reason this method gets called twice when generating the pdf report) if (!StringUtils.startsWith(accounts, KFSConstants.WILDCARD_CHARACTER)) { accounts = KFSConstants.WILDCARD_CHARACTER + accounts; } if (!StringUtils.endsWith(accounts, KFSConstants.WILDCARD_CHARACTER)) { accounts += KFSConstants.WILDCARD_CHARACTER; } } newFieldValues.put(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS, accounts); // Increment to error date by one day so that the correct results are retrieved. // Since the error date is stored as both a date and time in the database records with an error date // the same as the error date the user enters on the search criteria aren't retrieved without this modification. String errorDate = newFieldValues.get(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ERROR_DATE_TO); int index = StringUtils.indexOf(errorDate, SearchOperator.LESS_THAN_EQUAL.toString()); if (index == StringUtils.INDEX_NOT_FOUND) { index = StringUtils.indexOf(errorDate, SearchOperator.BETWEEN.toString()); if (index != StringUtils.INDEX_NOT_FOUND) { incrementErrorDate(newFieldValues, errorDate, index); } } else { incrementErrorDate(newFieldValues, errorDate, index); } return newFieldValues; }
Example 7
Source File: KualiMaintenanceForm.java From rice with Educational Community License v2.0 | 6 votes |
/** * This overridden method ... * * @see KualiDocumentFormBase#shouldPropertyBePopulatedInForm(java.lang.String, javax.servlet.http.HttpServletRequest) */ @Override public boolean shouldPropertyBePopulatedInForm( String requestParameterName, HttpServletRequest request) { // the user clicked on a document initiation link //add delete check for 3070 String methodToCallActionName = request.getParameter(KRADConstants.DISPATCH_REQUEST_PARAMETER); if (StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL) || StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL) || StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL) || StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION) || StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_DELETE_METHOD_TO_CALL)) { return true; } if ( StringUtils.indexOf(methodToCallActionName, KRADConstants.TOGGLE_INACTIVE_METHOD ) == 0 ) { return true; } return super.shouldPropertyBePopulatedInForm(requestParameterName, request); }
Example 8
Source File: Locate.java From incubator-tajo with Apache License 2.0 | 6 votes |
/** * Returns the position of the first occurance of substr in string after position pos (using one-based index). * * if substr is empty string, it always matches except * pos is greater than string length + 1.(mysql locate() function spec.) * At any not matched case, it returns 0. */ private int locate(String str, String substr, int pos) { if (substr.length() == 0) { if (pos <= (str.length() + 1)) { return pos; } else { return 0; } } int idx = StringUtils.indexOf(str, substr, pos - 1); if (idx == -1) { return 0; } return idx + 1; }
Example 9
Source File: DateUtils.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Index of sign charaters (i.e. '+' or '-'). * * @param str The string to search * @param startPos The start position * @return the index of the first sign character or -1 if not found */ private static int indexOfSignChars(String str, int startPos) { int idx = StringUtils.indexOf(str, '+', startPos); if (idx < 0) { idx = StringUtils.indexOf(str, '-', startPos); } return idx; }
Example 10
Source File: EsBulkResponseSummary.java From soundwave with Apache License 2.0 | 5 votes |
public String getFailedMessage(int max) { int count = 0; StringBuilder stringBuilder = new StringBuilder(); for (Map.Entry<String, String> entry : failed.entrySet()) { if (StringUtils.indexOf(entry.getValue(), "VersionConflictEngineException") < 0) { stringBuilder.append(String.format("id:%s error:%s", entry.getKey(), entry.getValue())); count++; if (count >= max) { break; } } } return stringBuilder.toString(); }
Example 11
Source File: SampleExtensionService.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private String createDescription() { int index = StringUtils.indexOf(LOREM_IPSUM, ' ', RANDOM.nextInt(LOREM_IPSUM.length())); if (index < 0) { index = LOREM_IPSUM.length(); } return LOREM_IPSUM.substring(0, index); }
Example 12
Source File: FuncSubstringIndex.java From antsdb with GNU Lesser General Public License v3.0 | 5 votes |
private String indexOf(String str, String delim, Long count) { int pos = -1; for (int i=0; i<count; i++) { pos = StringUtils.indexOf(str, delim, pos+1); if (pos < 0) { return str; } } return str.substring(0, pos); }
Example 13
Source File: CfTableRepository.java From mybatis-dalgen with Apache License 2.0 | 5 votes |
/** * Sets cf operation cdata. * * @param cfTable the cf table * @param e the e * @param cfOperation the cf operation */ private void setCfOperationCdata(CfTable cfTable, Element e, CfOperation cfOperation) { String cXml = e.asXML(); String[] lines = StringUtils.split(cXml, "\n"); StringBuilder sb = new StringBuilder(); for (int i = 1; i < lines.length - 1; i++) { if (i > 1) { sb.append("\n"); } sb.append(lines[i]); } String cdata = sb.toString(); //SQlDESC String sqlDesc = cdata.replaceAll(FOR_DESC_SQL_P, " "); sqlDesc = sqlDesc.replaceAll(FOR_DESC_SQL_PN, " "); cfOperation.setSqlDesc(sqlDesc); String text = e.getTextTrim(); if (StringUtils.indexOf(text, "*") > 0) { Matcher m = STAR_BRACKET.matcher(text); if (!m.find()) { cdata = StringUtils.replace(cdata, "*", "<include refid=\"Base_Column_List\" />"); } } //? 参数替换 不指定类型 cdata = delQuestionMarkParam(cdata, cfOperation, cfTable); //添加sql注释,以便于DBA 分析top sql 定位 cfOperation.setCdata(addSqlAnnotation(cdata, cfOperation.getName(), cfTable.getSqlname())); //pageCount添加 setCfOperationPageCdata(cdata, cfOperation); }
Example 14
Source File: ConfInit.java From mybatis-dalgen with Apache License 2.0 | 5 votes |
/** * Copy and over write file. * * @param soureName the soure name * @param outFile the out file * @throws IOException the io exception */ private static void copyAndOverWriteFile(String soureName, File outFile) throws IOException { //目录不存在则创建 if (!outFile.getParentFile().exists()) { outFile.getParentFile().mkdirs(); } //不是文件则不copy 判断标准为文件含 点 号 if (StringUtils.indexOf(soureName, '.') == -1) { return; } BufferedReader reader = null; BufferedWriter writer = null; try { reader = new BufferedReader(new InputStreamReader( ConfInit.class.getResourceAsStream("/" + soureName))); writer = new BufferedWriter(new FileWriter(outFile)); String line; while ((line = reader.readLine()) != null) { writer.write(line); writer.write("\n"); } writer.flush(); } catch (NullPointerException e) { System.out.println("======"); } finally { if (reader != null) { reader.close(); } if (writer != null) { writer.close(); } } }
Example 15
Source File: CoreUtils.java From oxd with Apache License 2.0 | 5 votes |
public static String cleanUpLog(String log) { try { // remove `client_secret` from logs final int index = StringUtils.indexOf(log, "client_secret"); if (index != -1) { final int commaIndex = StringUtils.indexOf(log, ",", index + 1); return log.substring(0, index - 1) + log.substring(commaIndex + 1, log.length()); } } catch (Exception e) { LOG.error(e.getMessage(), e); } return log; }
Example 16
Source File: PortletCacheService.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * {@inheritDoc} */ public void processPortletEvent( PortletEvent event ) { String strKey = "[" + CACHE_PORTLET_PREFIX + event.getPortletId( ) + "]"; for ( String strKeyTemp : (List<String>) getCache( ).getKeys( ) ) { if ( StringUtils.indexOf( strKeyTemp, strKey ) != -1 ) { getCache( ).remove( strKeyTemp ); } } }
Example 17
Source File: UtilLoggingXmlLogImporter.java From otroslogviewer with Apache License 2.0 | 5 votes |
protected String extractFileName(String clazz) { int clazzStart = StringUtils.lastIndexOf(clazz, '.') + 1; clazzStart = Math.max(0, clazzStart); int clazzEnd = StringUtils.indexOf(clazz, '$'); if (clazzEnd < 0) { clazzEnd = clazz.length(); } return StringUtils.substring(clazz, clazzStart, clazzEnd); }
Example 18
Source File: FileUtils.java From Aooms with Apache License 2.0 | 5 votes |
/** * 获取扩展名 * * @param fileName * @return */ public static String getExtension(String fileName) { if (StringUtils.INDEX_NOT_FOUND == StringUtils.indexOf(fileName, DOT)) return StringUtils.EMPTY; String ext = StringUtils.substring(fileName, StringUtils.lastIndexOf(fileName, DOT)); return StringUtils.trimToEmpty(ext); }
Example 19
Source File: RangerPerfTracer.java From ranger with Apache License 2.0 | 5 votes |
public static RangerPerfTracer getPerfTracer(Log logger, String tag) { String data = ""; String realTag = ""; if (tag != null) { int indexOfTagEndMarker = StringUtils.indexOf(tag, tagEndMarker); if (indexOfTagEndMarker != -1) { realTag = StringUtils.substring(tag, 0, indexOfTagEndMarker); data = StringUtils.substring(tag, indexOfTagEndMarker); } else { realTag = tag; } } return RangerPerfTracerFactory.getPerfTracer(logger, realTag, data); }
Example 20
Source File: MentionedInCommitStrategy.java From jira-ext-plugin with Apache License 2.0 | 4 votes |
/** * Parse Jira ticket numbers, ie SSD-101, out of the given ChangeLogSet.Entry. * * <p>Ticket number should be somewhere in the commit message</p> * * @param change * * @return */ @Override public List<JiraCommit> getJiraIssuesFromChangeSet(final ChangeLogSet.Entry change) { final List<JiraCommit> result = new ArrayList<>(); final List<String> foundTickets = new ArrayList<>(); for (String validJiraPrefix : Config.getGlobalConfig().getJiraTickets()) { String msg = change.getMsg(); if (change instanceof GitChangeSet) { msg = ((GitChangeSet) change).getComment(); } while (StringUtils.isNotEmpty(msg)) { final int foundPos = StringUtils.indexOf(msg, validJiraPrefix); if (foundPos == -1) { break; } final String firstOccurrence = msg.substring(foundPos + validJiraPrefix.length()); final String regex = "\\A[0-9]*"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(firstOccurrence); if (!matcher.find()) { break; } /** * It is totally unclear why a regex for the entire * Jira ticket identifier is not a configuration item * It is strange to be seperating the ticket number from the * prefix, just to put it back together again - * without using either seperately. * * This would be a trivial change to the config, and * #probably# not break any existing code other than these isolated * areas where the prefix is being searched. */ final String ticketNumber = matcher.group(); if (StringUtils.isEmpty(ticketNumber)) { break; } final String resultingTicket = validJiraPrefix + ticketNumber; if (!foundTickets.contains(resultingTicket)) { foundTickets.add(resultingTicket); result.add(new JiraCommit(resultingTicket, change)); } msg = firstOccurrence; } } return result; }