private DateTime getTime (String timeString) { DateTimeZone timeZone = DateTimeZone.forID(MRCompactor.DEFAULT_COMPACTION_TIMEZONE); int splits = StringUtils.countMatches(timeString, "/"); String timePattern = ""; if (splits == 3) { timePattern = "YYYY/MM/dd/HH"; } else if (splits == 2) { timePattern = "YYYY/MM/dd"; } DateTimeFormatter timeFormatter = DateTimeFormat.forPattern(timePattern).withZone(timeZone); return timeFormatter.parseDateTime (timeString); }
@Benchmark public int countMatches() { // Using Apache Commons return StringUtils.countMatches(testString, "."); }
@Benchmark public int countMatches() { // Using Apache Commons return StringUtils.countMatches(testString, "."); }
/** * Sanitizes URL. * @param url URL to be sanitized. * @return Sanitized URL * @throws MalformedURLException */ @Override public URL sanitizeURL(URL url) throws MalformedURLException { String u = url.toExternalForm(); // Convert <FQDN>.tumblr.com/path to <FQDN>/path if needed if (StringUtils.countMatches(u, ".") > 2) { url = new URL(u.replace(".tumblr.com", "")); if (isTumblrURL(url)) { LOGGER.info("Detected tumblr site: " + url); } else { LOGGER.info("Not a tumblr site: " + url); } } return url; }
if(items.length > 1 && items.length <= StringUtils.countMatches(list, ",")) { if (!skipError) { throw new IllegalArgumentException( if(StringUtils.countMatches(s, "-") > 1) { if (!skipError) { throw new IllegalArgumentException(String.format(
public static LikeMatcher createMatcher(String patternStr) { if (patternStr == null) { throw new IllegalArgumentException("pattern is null"); } if (patternStr.contains(UNDERSCORE_SIGN)) { return new DefaultLikeMatcher(patternStr); } int count = StringUtils.countMatches(patternStr, PERCENT_SIGN); if (count == 1) { return new OnePercentSignLikeMatcher(patternStr); } else if (count == 2 && patternStr.startsWith(PERCENT_SIGN) && patternStr.endsWith(PERCENT_SIGN)) { return new TwoPercentSignLikeMatcher(patternStr); } else if (count == 3 && patternStr.startsWith(PERCENT_SIGN) && patternStr.endsWith(PERCENT_SIGN) && !patternStr.contains(PERCENT_SIGN + PERCENT_SIGN)) { return new ThreePercentSignLikeMatcher(patternStr); } else { return new DefaultLikeMatcher(patternStr); } } }
int numEnclosures = StringUtils.countMatches( currentSplit, enclosure ); boolean oddNumberOfEnclosures = ( numEnclosures % 2 != 0 ); boolean addSplit = false;
int ix = StringUtils.countMatches(fullName, POOL_SEPARATOR_STR); while (poolsByLevel.size() <= ix) { poolsByLevel.add(new LinkedList<WMPool>()); // We expect all the levels to have items.
protected enum RepositoryServers { DIS, POBS }
@Test public void search_metrics_with_pagination() throws Exception { insertNewCustomMetric("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); WsTester.Result result = newRequest() .setParam(Param.PAGE, "3") .setParam(Param.PAGE_SIZE, "4") .execute(); assertThat(StringUtils.countMatches(result.outputAsString(), "custom-key")).isEqualTo(2); }
@Test public void testUseDefaultSchemaName() throws Exception { String schemaName = ""; String tableName = "tableName"; String schemaTable = "default.tableName"; DatabaseMeta databaseMeta = spy( new DatabaseMeta( databaseXML ) ); doReturn( "someValue" ).when( databaseMeta ) .getFieldDefinition( any( ValueMetaInterface.class ), anyString(), anyString(), anyBoolean() ); doReturn( schemaTable ).when( databaseMeta ).getQuotedSchemaTableCombination( schemaName, tableName ); ValueMetaInterface valueMeta = mock( ValueMetaInterface.class ); when( valueMeta.clone() ).thenReturn( mock( ValueMetaInterface.class ) ); RowMetaInterface rowMetaInterface = mock( RowMetaInterface.class ); when( rowMetaInterface.size() ).thenReturn( 1 ); when( rowMetaInterface.searchValueMeta( anyString() ) ).thenReturn( valueMeta ); UpdateMeta updateMeta = new UpdateMeta(); updateMeta.setDatabaseMeta( databaseMeta ); updateMeta.setTableName( tableName ); updateMeta.setSchemaName( schemaName ); updateMeta.setKeyLookup( new String[] { "KeyLookup1", "KeyLookup2" } ); updateMeta.setKeyStream( new String[] { "KeyStream1", "KeyStream2" } ); updateMeta.setUpdateLookup( new String[] { "updateLookup1", "updateLookup2" } ); updateMeta.setUpdateStream( new String[] { "UpdateStream1", "UpdateStream2" } ); SQLStatement sqlStatement = updateMeta.getSQLStatements( new TransMeta(), mock( StepMeta.class ), rowMetaInterface, mock( Repository.class ), mock( IMetaStore.class ) ); String sql = sqlStatement.getSQL(); assertTrue( StringUtils.countMatches( sql, schemaTable ) == 2 ); }
assertEquals( 3, StringUtils.countMatches( sql, schemaTable ) );
int paramCount = StringUtils.countMatches(hqlStatement, "?");
@Test public void provisioned_projects_with_correct_pagination() { OrganizationDto org = db.organizations().insert(); for (int i = 1; i <= 10; i++) { db.components().insertComponent(newProvisionedProject(org, String.valueOf(i))); } userSessionRule.logIn().addPermission(PROVISION_PROJECTS, org); TestRequest request = ws.newRequest() .setParam(PARAM_ORGANIZATION, org.getKey()) .setParam(Param.PAGE, "3") .setParam(Param.PAGE_SIZE, "4"); String jsonOutput = request.execute().getInput(); assertThat(StringUtils.countMatches(jsonOutput, "provisioned-uuid-")).isEqualTo(2); }
int paramCount = StringUtils.countMatches(hqlStatement, "?");
@NotNull private SwaggerFileType getFileTypeFromRefValue( final String refValue, final SwaggerFileType singleDefinitionInFile, final SwaggerFileType multipleDefinitionsInRootFile, final SwaggerFileType multipleDefinitionsNotInRootFile) { if (refValue.contains(SwaggerConstants.REFERENCE_PREFIX)) { final String definitionPath = org.apache.commons.lang.StringUtils.substringAfterLast(refValue, SwaggerConstants.HASH); int slashCount = org.apache.commons.lang.StringUtils.countMatches(definitionPath, SwaggerConstants.SLASH); return slashCount == 1 ? multipleDefinitionsInRootFile : multipleDefinitionsNotInRootFile; } return singleDefinitionInFile; } }
@Test public void return_more_than_20_permissions() { loginAsAdmin(db.getDefaultOrganization()); for (int i = 0; i < 30; i++) { UserDto user = db.users().insertUser(newUserDto().setLogin("user-" + i)); db.organizations().addMember(db.getDefaultOrganization(), user); db.users().insertPermissionOnUser(user, SCAN); db.users().insertPermissionOnUser(user, PROVISION_PROJECTS); } String result = newRequest() .setParam(PAGE_SIZE, "100") .execute() .getInput(); assertThat(countMatches(result, "scan")).isEqualTo(30); }
@Test public void ghost_projects_with_correct_pagination() { OrganizationDto organization = db.organizations().insert(); for (int i = 1; i <= 10; i++) { int count = i; insertGhostProject(organization, dto -> dto.setDbKey("ghost-key-" + count)); } userSessionRule.logIn().addPermission(ADMINISTER, organization); TestResponse result = ws.newRequest() .setParam("organization", organization.getKey()) .setParam(Param.PAGE, "3") .setParam(Param.PAGE_SIZE, "4") .execute(); String json = result.getInput(); assertJson(json).isSimilarTo("{" + " \"p\": 3," + " \"ps\": 4," + " \"total\": 10" + "}"); assertThat(StringUtils.countMatches(json, "ghost-key-")).isEqualTo(2); }
/** * Return the empty record string. * * @return null filled record string. * @see #toRecordString() */ @Override public String toRecordString() { StringBuilder sb = new StringBuilder(); sb.append("null").append(",").append("null").append(","); sb.append("null").append(",").append("null").append(","); sb.append("null").append(",").append("null"); if (bandWidth != null) { sb.append(",").append("null").append(",").append("null"); } if (customValues != null) { int valueCount = StringUtils.countMatches(customValues, ",") + 1; for (int i = 0; i < valueCount; i++) { sb.append(",").append("null"); } } return sb.toString(); }
private void doGetInternal(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException, JSONException { switch (StringUtils.countMatches(req.getRequestURI(), "/")) { case 1: handleWelcomeReq(req, resp); return; case 5: final DatabaseIndexer indexer = getIndexer(req); if (indexer == null) { ServletUtils.sendJsonError(req, resp, 500, "error_creating_index"); return; } if (req.getParameter("q") == null) { indexer.info(req, resp); } else { indexer.search(req, resp); } return; } ServletUtils.sendJsonError(req, resp, 400, "bad_request"); }