List of usage examples for org.apache.commons.lang3 StringUtils startsWithAny
public static boolean startsWithAny(final CharSequence string, final CharSequence... searchStrings)
Check if a CharSequence starts with any of an array of specified strings.
StringUtils.startsWithAny(null, null) = false StringUtils.startsWithAny(null, new String[] {"abc"}) = false StringUtils.startsWithAny("abcxyz", null) = false StringUtils.startsWithAny("abcxyz", new String[] {""}) = false StringUtils.startsWithAny("abcxyz", new String[] {"abc"}) = true StringUtils.startsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true
From source file:com.technophobia.substeps.model.Util.java
public static String[] getArgs(final String patternString, final String sourceString, final String[] keywordPrecedence) { log.debug("Util getArgs String[] with pattern: " + patternString + " and sourceStr: " + sourceString); String[] rtn = null;/* w w w .j a v a 2 s .c o m*/ ArrayList<String> argsList = null; String patternCopy = new String(patternString); if (keywordPrecedence != null && StringUtils.startsWithAny(patternString, keywordPrecedence)) { // for (String s : keywordPrecedence) { patternCopy = StringUtils.removeStart(patternCopy, s); } patternCopy = "(?:" + StringUtils.join(keywordPrecedence, "|") + ")" + patternCopy; } final Pattern pattern = Pattern.compile(patternCopy); final Matcher matcher = pattern.matcher(sourceString); final int groupCount = matcher.groupCount(); // TODO - this doesn't work if we're not doing strict matching if (matcher.find()) { for (int i = 1; i <= groupCount; i++) { final String arg = matcher.group(i); if (arg != null) { if (argsList == null) { argsList = new ArrayList<String>(); } argsList.add(arg); } } } if (argsList != null) { rtn = argsList.toArray(new String[argsList.size()]); if (log.isDebugEnabled()) { final StringBuilder buf = new StringBuilder(); buf.append("returning args: "); for (final String s : argsList) { buf.append("[").append(s).append("] "); } log.debug(buf.toString()); } } return rtn; }
From source file:de.vandermeer.skb.commons.utils.Json2Collections.java
/** * Reads JSON from the input scanner, transforms into an SKB map and logs errors. * // w w w . jav a 2 s. c o m * This method parses the <code>input</code> and removes every line starting with either of the two possible single line comments: '//' and '#'. * It then calls s2o with the altered input. * @param input scanner wit JSON specification * @return a tree with information from the JSON file or null in case of errors */ public Object read(Scanner input) { Object ret = null; if (input != null) { String content = new String(); try { while (input.hasNextLine()) { String line = input.nextLine(); if (!StringUtils.startsWithAny(line.trim(), new String[] { "//", "#" })) content += line.trim(); } } catch (Exception ignore) { } ret = this.s2o(content); } return ret; }
From source file:com.technophobia.substeps.model.Arguments.java
public static String[] getArgs(final String patternString, final String sourceString, final String[] keywordPrecedence, Config cfg) { log.debug("Arguments getArgs String[] with pattern: " + patternString + " and sourceStr: " + sourceString); String[] rtn = null;//from w ww. j a v a2s. c om ArrayList<String> argsList = null; String patternCopy = patternString; if (keywordPrecedence != null && StringUtils.startsWithAny(patternString, keywordPrecedence)) { // for (String s : keywordPrecedence) { patternCopy = StringUtils.removeStart(patternCopy, s); } patternCopy = "(?:" + StringUtils.join(keywordPrecedence, "|") + ")" + patternCopy; } final Pattern pattern = Pattern.compile(patternCopy); final Matcher matcher = pattern.matcher(sourceString); final int groupCount = matcher.groupCount(); // TODO - this doesn't work if we're not doing strict matching if (matcher.find()) { for (int i = 1; i <= groupCount; i++) { final String arg = substituteValues(matcher.group(i), cfg); if (arg != null) { if (argsList == null) { argsList = new ArrayList<>(); } argsList.add(arg); } } } if (argsList != null) { rtn = argsList.toArray(new String[argsList.size()]); if (log.isDebugEnabled()) { final StringBuilder buf = new StringBuilder(); buf.append("returning args: "); for (final String s : argsList) { buf.append("[").append(s).append("] "); } log.debug(buf.toString()); } } return rtn; }
From source file:com.ipcglobal.fredimport.process.Reference.java
/** * Check europe prefixes.//from www . j a v a2 s .c o m * * @param lastCategory the last category * @return true, if successful */ public boolean checkEuropePrefixes(String lastCategory) { return StringUtils.startsWithAny(lastCategory, europePrefixes); }
From source file:ch.cyberduck.core.manta.MantaSession.java
protected boolean isWorldReadable(final MantaObject mantaObject) { final MantaAccountHomeInfo accountHomeInfo = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath());/*from w w w . j a va2 s. co m*/ return StringUtils.startsWithAny(mantaObject.getPath(), accountHomeInfo.getAccountPublicRoot().getAbsolute()); }
From source file:org.apache.fineract.infrastructure.dataexport.service.DataExportReadPlatformServiceImpl.java
@Override public DataExportEntityData retrieveTemplate(String baseEntityName) { DataExportEntityData dataExportEntityData = null; DataExportBaseEntity dataExportBaseEntity = DataExportBaseEntity.fromEntityName(baseEntityName); DataExportCoreTable dataExportCoreTable = DataExportCoreTable .newInstance(dataExportBaseEntity.getTableName()); if (dataExportBaseEntity.isValid()) { Collection<DatatableData> datatables = new ArrayList<>(); Collection<EntityColumnMetaData> columns = new ArrayList<>(); LinkedHashMap<String, EntityColumnMetaData> uniqueColumns = new LinkedHashMap<>(); final Collection<EntityColumnMetaData> nonCoreColumns = DataExportUtils .getTableColumnsMetaData(dataExportBaseEntity.getTableName(), jdbcTemplate); final Collection<RegisteredTable> registeredTables = this.registeredTableRepository .findAllByApplicationTableName(dataExportBaseEntity.getTableName()); for (RegisteredTable registeredTable : registeredTables) { Long category = (registeredTable.getCategory() != null) ? registeredTable.getCategory().longValue() : null;/*from ww w . java 2s . c o m*/ String tableName = registeredTable.getRegisteredTableName(); // only return user created or musoni system datatables (ml_loan_details, etc.) if (StringUtils.startsWithAny(tableName, new String[] { DataExportApiConstants.USER_CREATED_DATATABLE_NAME_PREFIX, DataExportApiConstants.MUSONI_SYSTEM_DATATABLE_NAME_PREFIX })) { DatatableData datatableData = DatatableData.create(registeredTable.getApplicationTableName(), tableName, null, category, null, registeredTable.isSystemDefined(), registeredTable.getDisplayName()); datatables.add(datatableData); } } // add the core datatables to the list of datatables for (DataExportCoreDatatable coreDatatable : DataExportCoreDatatable.values()) { DataExportBaseEntity baseEntity = coreDatatable.getBaseEntity(); if (dataExportBaseEntity.equals(baseEntity)) { DatatableData datatableData = DatatableData.create(baseEntity.getTableName(), coreDatatable.getTableName(), null, 0L, null, false, coreDatatable.getDisplayName()); datatables.add(datatableData); } } // add the core columns for (DataExportCoreColumn coreColumn : DataExportCoreColumn.values()) { if (coreColumn.getBaseEntity() == null || (coreColumn.getBaseEntity() != null && coreColumn.getBaseEntity().equals(dataExportBaseEntity))) { String columnLabel = DataExportUtils.createHumanReadableTableColumnLabel(coreColumn.getLabel(), dataExportCoreTable); EntityColumnMetaData metaData = EntityColumnMetaData.newInstance(coreColumn.getName(), columnLabel, coreColumn.getType(), coreColumn.isNullable()); uniqueColumns.put(coreColumn.getName(), metaData); } } // add the non-core columns for (EntityColumnMetaData nonCoreColumn : nonCoreColumns) { String columnLabel = DataExportUtils.createHumanReadableTableColumnLabel(nonCoreColumn.getLabel(), dataExportCoreTable); // update the label property nonCoreColumn.updateLabel(columnLabel); uniqueColumns.put(nonCoreColumn.getName(), nonCoreColumn); } // convert LinkedHashMap to ArrayList columns.addAll(uniqueColumns.values()); dataExportEntityData = DataExportEntityData.newInstance(dataExportBaseEntity.getEntityName(), dataExportBaseEntity.getTableName(), datatables, columns); } return dataExportEntityData; }
From source file:org.flowable.dmn.engine.impl.el.ELConditionExpressionPreParser.java
protected static String parseSegmentWithOperator(String expression) { String parsedExpressionSegment; if (expression.length() < 2 || !StringUtils.startsWithAny(expression, OPERATORS)) { parsedExpressionSegment = " == " + expression; } else {/*w w w . j a v a2 s . c om*/ parsedExpressionSegment = " " + expression; } return parsedExpressionSegment; }
From source file:org.jbb.lib.metrics.domain.MeterFilterBuilder.java
private boolean nameStartsWith(Meter.Id id, String... prefixes) { return StringUtils.startsWithAny(id.getName(), prefixes); }
From source file:org.kisoonlineapp.startup.StartupSqlReader.java
final void readFromInputStream(InputStream is) throws IOException { final BufferedReader br = new BufferedReader(new InputStreamReader(is)); try {/* w w w . j av a2 s . c o m*/ String key = null; StringBuilder value = new StringBuilder(); for (String line; (line = br.readLine()) != null;) { if (StringUtils.startsWithAny(line, new String[] { "#", "---" })) { continue; } line = StringUtils.removeEnd(line, "\\"); if (StringUtils.contains(line, '=')) { if (key == null) { String[] splitted = StringUtils.split(line, "=", 2); if (splitted.length == 2) { key = splitted[0]; value.append(splitted[1]); } else if (splitted.length == 1) { key = splitted[0]; value.append(""); } } else { value.append(line); } } else if (StringUtils.isBlank(line)) { if (key != null) { this.statementMap.put(key, value.toString()); key = null; value = new StringBuilder(); } } else { value.append(line); } } if (key != null) { this.statementMap.put(key, value.toString()); } } finally { br.close(); } }
From source file:org.kuali.kra.award.awardhierarchy.sync.service.AwardSyncServiceImpl.java
/** * Run the {@link AwardDocumentRule#processSaveDocument} and {@link AwardDocumentRule#processRunAuditBusinessRules} * against award. Add all messages generated from running the rules to logList as {@link AwardSyncLog}. * Return false if any of the error keys generated by the rules are not in the ignoredMessageKeys list. * @param award/*from ww w . j a v a 2 s . co m*/ * @param logs * @return */ protected boolean validateModifiedAward(AwardDocument award, AwardSyncStatus awardStatus) { AwardDocumentRule rule = new AwardDocumentRule(); boolean result = true; if (!rule.processSaveDocument(award)) { getAwardSyncUtilityService().getLogsFromSaveErrors(awardStatus); } if (!rule.processRunAuditBusinessRules(award)) { getAwardSyncUtilityService().getLogsFromAuditErrors(awardStatus); } String[] ignoredErrors = IGNORED_MESSAGE_KEYS.split(","); for (AwardSyncLog log : awardStatus.getValidationLogs()) { if (!StringUtils.startsWithAny(log.getMessageKey(), ignoredErrors) && !log.isSuccess()) { result = false; } else { log.setSuccess(true); } } return result; }