List of usage examples for org.apache.commons.lang3 StringUtils repeat
public static String repeat(final char ch, final int repeat)
From source file:org.voltdb.catalog.CatalogDiffEngine.java
/** * Pre-order walk of catalog generating add, delete and set commands * that compose that full difference.//from w ww. j av a2 s . c o m * @param prevType * @param newType */ private void diffRecursively(CatalogType prevType, CatalogType newType) { assert (prevType != null) : "Null previous object found in catalog diff traversal."; assert (newType != null) : "Null new object found in catalog diff traversal"; Object materializerValue = null; // Consider shifting into the strict more required within materialized view definitions. if (prevType instanceof Table) { // Under normal circumstances, it's highly unpossible that another (nested?) table will // appear in the details of a materialized view table. So, when it does (!?), be sure to // complain -- and don't let it throw off the accounting of the strict diff mode. // That is, don't set the local "materializerValue". if (m_inStrictMatViewDiffMode) { // Maybe this should log or append to m_errors? System.out.println("ERROR: unexpected nesting of a Table in CatalogDiffEngine."); } else { materializerValue = prevType.getField("materializer"); if (materializerValue != null) { // This table is a materialized view, so the changes to it and its children are // strictly limited, e.g. no adding/dropping columns. // In a future development, such changes may be allowed, but they may be implemented // differently (get different catalog commands), such as through a wholesale drop/add // of the entire view and materialized table definitions. // The non-null local "materializerValue" is a reminder to pop out of this mode // before returning from this level of the recursion. m_inStrictMatViewDiffMode = true; if (m_triggeredVerbosity) { System.out.println("DEBUG VERBOSE diffRecursively entering strict mat view mode"); } } } } // diff local fields for (String field : prevType.getFields()) { // this field is (or was) set at runtime, so ignore it for diff purposes if (field.equals("isUp")) { continue; } boolean verbosityTriggeredHere = false; if ((!m_triggeredVerbosity) && field.equals(m_triggerForVerbosity)) { System.out.println( "DEBUG VERBOSE diffRecursively verbosity (triggered by field '" + field + "' is ON"); verbosityTriggeredHere = true; m_triggeredVerbosity = true; } // check if the types are different // options are: both null => same // one null and one not => different // both not null => check Object.equals() Object prevValue = prevType.getField(field); Object newValue = newType.getField(field); if ((prevValue == null) != (newValue == null)) { if (m_triggeredVerbosity) { if (prevValue == null) { System.out.println("DEBUG VERBOSE diffRecursively found new '" + field + "' only."); } else { System.out.println("DEBUG VERBOSE diffRecursively found prev '" + field + "' only."); } } writeModification(newType, prevType, field); } // if they're both not null (above/below ifs implies this) else if (prevValue != null) { // if comparing CatalogTypes (both must be same) if (prevValue instanceof CatalogType) { assert (newValue instanceof CatalogType); String prevPath = ((CatalogType) prevValue).getCatalogPath(); String newPath = ((CatalogType) newValue).getCatalogPath(); if (prevPath.compareTo(newPath) != 0) { if (m_triggeredVerbosity) { int padWidth = StringUtils.indexOfDifference(prevPath, newPath); String pad = StringUtils.repeat(" ", padWidth); System.out.println( "DEBUG VERBOSE diffRecursively found a path change to '" + field + "':"); System.out.println("DEBUG VERBOSE prevPath=" + prevPath); System.out.println("DEBUG VERBOSE diff at->" + pad + "^ position:" + padWidth); System.out.println("DEBUG VERBOSE newPath=" + newPath); } writeModification(newType, prevType, field); } } // if scalar types else { if (prevValue.equals(newValue) == false) { if (m_triggeredVerbosity) { System.out.println( "DEBUG VERBOSE diffRecursively found a scalar change to '" + field + "':"); System.out.println("DEBUG VERBOSE diffRecursively prev:" + prevValue); System.out.println("DEBUG VERBOSE diffRecursively new :" + newValue); } writeModification(newType, prevType, field); } } } if (verbosityTriggeredHere) { System.out.println("DEBUG VERBOSE diffRecursively verbosity is OFF"); m_triggeredVerbosity = false; } } // recurse for (String field : prevType.getChildCollections()) { boolean verbosityTriggeredHere = false; if (field.equals(m_triggerForVerbosity)) { System.out.println("DEBUG VERBOSE diffRecursively verbosity ON"); m_triggeredVerbosity = true; verbosityTriggeredHere = true; } CatalogMap<? extends CatalogType> prevMap = prevType.getCollection(field); CatalogMap<? extends CatalogType> newMap = newType.getCollection(field); getCommandsToDiff(field, prevMap, newMap); if (verbosityTriggeredHere) { System.out.println("DEBUG VERBOSE diffRecursively verbosity OFF"); m_triggeredVerbosity = false; } } if (materializerValue != null) { // Just getting back from recursing into a materialized view table, // so drop the strictness required only in that context. // It's safe to assume that the prior mode to which this must pop back is the non-strict // mode because nesting of table definitions is unpossible AND we guarded against its // potential side effects, above, anyway. m_inStrictMatViewDiffMode = false; } }
From source file:org.voltdb.regressionsuites.TestFixedSQLSuite.java
private void subTestENG7480() throws IOException, ProcCallException { Client client = getClient();/*from w w w. ja v a 2s . c om*/ String sql; sql = "insert into R1 Values(1, 'MA', 2, 2.2);"; client.callProcedure("@AdHoc", sql); // query constants interpreted as DECIMAL // // operation between float and decimal // sql = "SELECT 0.1 + (1-0.1) + ratio FROM R1"; runQueryGetDouble(client, sql, 3.2); sql = "SELECT 0.1 + (1-0.1) - ratio FROM R1"; runQueryGetDouble(client, sql, -1.2); sql = "SELECT 0.1 + (1-0.1) / ratio FROM R1"; runQueryGetDouble(client, sql, 0.509090909091); sql = "SELECT 0.1 + (1-0.1) * ratio FROM R1"; runQueryGetDouble(client, sql, 2.08); // reverse order sql = "SELECT 0.1 + ratio + (1-0.1) FROM R1"; runQueryGetDouble(client, sql, 3.2); sql = "SELECT 0.1 + ratio - (1-0.1) FROM R1"; runQueryGetDouble(client, sql, 1.4); sql = "SELECT 0.1 + ratio / (1-0.1) FROM R1"; runQueryGetDouble(client, sql, 2.544444444444); sql = "SELECT 0.1 + ratio * (1-0.1) FROM R1"; runQueryGetDouble(client, sql, 2.08); // // operation between decimal and integer // sql = "SELECT 0.1 + (1-0.1) + NUM FROM R1"; runQueryGetDecimal(client, sql, 3.0); sql = "SELECT 0.1 + (1-0.1) - NUM FROM R1"; runQueryGetDecimal(client, sql, -1.0); sql = "SELECT 0.1 + (1-0.1) / NUM FROM R1"; runQueryGetDecimal(client, sql, 0.55); sql = "SELECT 0.1 + (1-0.1) * NUM FROM R1"; runQueryGetDecimal(client, sql, 1.9); // reverse order sql = "SELECT 0.1 + NUM + (1-0.1) FROM R1"; runQueryGetDecimal(client, sql, 3.0); sql = "SELECT 0.1 + NUM - (1-0.1) FROM R1"; runQueryGetDecimal(client, sql, 1.2); sql = "SELECT 0.1 + NUM / (1-0.1) FROM R1"; runQueryGetDecimal(client, sql, 2.322222222222); sql = "SELECT 0.1 + NUM * (1-0.1) FROM R1"; runQueryGetDecimal(client, sql, 1.9); // // test Out of range decimal and float // // test overflow and any underflow decimal are rounded sql = "SELECT NUM + 111111111111111111111111111111111111111.1111 FROM R1"; if (isHSQL()) { verifyStmtFails(client, sql, "HSQL-BACKEND ERROR"); verifyStmtFails(client, sql, "to the left of the decimal point is 39 and the max is 26"); } else { verifyStmtFails(client, sql, "Maximum precision exceeded. " + "Maximum of 26 digits to the left of the decimal point"); } sql = "SELECT NUM + 111111.1111111111111111111111111111111111111 FROM R1"; runQueryGetDecimal(client, sql, 111113.1111111111111111111111111111111111111); sql = "SELECT NUM + " + StringUtils.repeat("1", 256) + ".1111E1 FROM R1"; runQueryGetDouble(client, sql, Double.parseDouble(StringUtils.repeat("1", 255) + "3.1111E1")); sql = "SELECT NUM + " + StringUtils.repeat("1", 368) + ".1111E1 FROM R1"; verifyStmtFails(client, sql, "java.lang.NumberFormatException"); // test stored procedure VoltTable vt = null; vt = client.callProcedure("R1_PROC1").getResults()[0]; validateTableColumnOfScalarDecimal(vt, 0, new BigDecimal[] { new BigDecimal(2.1) }); vt = client.callProcedure("R1_PROC2").getResults()[0]; validateTableColumnOfScalarFloat(vt, 0, new double[] { 2.1 }); truncateTables(client, "R1"); }
From source file:org.xwiki.extension.internal.converter.ExtensionIdConverter.java
private static ExtensionId toExtensionId(String value, int end, Version defaultVersion) { String valueString = value;/*from w ww.j a v a 2 s . c o m*/ int index = valueString.lastIndexOf('/'); String id = valueString; Version version; if (index > 0 && index < end) { int backslashes = countBackslashes(valueString, index); if (backslashes > 0) { StringBuilder builder = new StringBuilder(); builder.append(valueString.substring(0, index - backslashes)); builder.append(StringUtils.repeat('\\', backslashes / 2)); builder.append(valueString.substring(index)); valueString = builder.toString(); index -= backslashes - (backslashes / 2); if (backslashes % 2 == 1) { return toExtensionId(valueString, index - backslashes - 1, defaultVersion); } } id = valueString.substring(0, index); version = new DefaultVersion(valueString.substring(index + 1)); } else { id = valueString; version = defaultVersion; } return new ExtensionId(id, version); }
From source file:org.xwiki.messagestream.MessageStreamTest.java
@Test public void testPostPublicMessageWithLongMessage() throws Exception { Event postedMessage = setupForPublicMessage(); this.stream.postPublicMessage(StringUtils.repeat('a', 10000)); Assert.assertEquals(StringUtils.repeat('a', 2000), postedMessage.getBody()); }
From source file:org.xwiki.messagestream.MessageStreamTest.java
@Test public void testPostPersonalMessageWithLongMessage() throws Exception { Event postedMessage = setupForPersonalMessage(); this.stream.postPersonalMessage(StringUtils.repeat('a', 10000)); Assert.assertEquals(StringUtils.repeat('a', 2000), postedMessage.getBody()); }
From source file:org.xwiki.messagestream.MessageStreamTest.java
@Test public void testPostDirectMessageWithLongMessage() throws Exception { Event postedMessage = setupForDirectMessage(); this.stream.postDirectMessageToUser(StringUtils.repeat('a', 10000), this.targetUser); Assert.assertEquals(StringUtils.repeat('a', 2000), postedMessage.getBody()); }
From source file:org.xwiki.rendering.internal.parser.xwiki10.ListSyntaxFilter.java
public String filterList(String content, FilterContext filterContext) { StringBuffer listResult = new StringBuffer(); Matcher matcher = LISTITEMSYNTAX_PATTERN.matcher(content); int currentIndex = 0; char currentListSign = 0; for (; matcher.find(); currentIndex = matcher.end()) { String before = content.substring(currentIndex, matcher.start()); if (currentIndex > 0) { before = CleanUtil.setLeadingNewLines(before, 1); }//from ww w .j a v a2s. c o m StringBuffer listItemResult = new StringBuffer(); String listSigns = matcher.group(2); char listSign = listSigns.charAt(0); String listString; String listStyle = ""; if (listSign == '#') { listString = StringUtils.repeat('1', listSigns.length()) + "."; } else if (listSign == '1') { listString = listSigns; } else { if (listSign == '-') { listStyle = "square"; listString = StringUtils.repeat('*', listSigns.length()); } else if (listSign == 'a') { listStyle = "lower-alpha"; listString = StringUtils.repeat('*', listSigns.length() - 1); } else if (listSign == 'A') { listStyle = "upper-alpha"; listString = StringUtils.repeat('*', listSigns.length() - 1); } else if (listSign == 'i') { listStyle = "lower-roman"; listString = StringUtils.repeat('*', listSigns.length() - 1); } else if (listSign == 'I') { listStyle = "upper-roman"; listString = StringUtils.repeat('*', listSigns.length() - 1); } else if (listSign == 'g') { listStyle = "lower-greek"; listString = StringUtils.repeat('*', listSigns.length() - 1); } else if (listSign == 'h') { listStyle = "hiragana"; listString = StringUtils.repeat('*', listSigns.length() - 1); } else if (listSign == 'H') { listStyle = "hiragana-iroha"; listString = StringUtils.repeat('*', listSigns.length() - 1); } else if (listSign == 'k') { listStyle = "katakana"; listString = StringUtils.repeat('*', listSigns.length() - 1); } else if (listSign == 'K') { listStyle = "katakana-iroha"; listString = StringUtils.repeat('*', listSigns.length() - 1); } else if (listSign == 'j') { listStyle = "hebrew"; listString = StringUtils.repeat('*', listSigns.length() - 1); } else if (listSign == '*') { listString = listSigns; } else { // This should never append this.logger.error("Unknown list sign: " + listSign); listString = StringUtils.repeat('*', listSigns.length()); } } if (listSign != currentListSign) { if (currentListSign != 0 && currentIndex > 0) { before = CleanUtil.setTrailingNewLines(before, 2); } if (listStyle.length() > 0) { listItemResult.append(filterContext.addProtectedContent( MessageFormat.format("(% style=\"list-style-type: {0}\" %)\n", listStyle), false)); } } listItemResult.append(filterContext.addProtectedContent(matcher.group(1) + listString, false)); listItemResult.append(matcher.group(3)); listResult.append(before); listResult.append(listItemResult); currentListSign = listSign; } if (currentIndex == 0) { return content; } listResult.append(content.substring(currentIndex)); return CleanUtil.extractVelocity(listResult, filterContext); }
From source file:org.xwiki.rendering.internal.parser.xwiki10.SectionSyntaxFilter.java
@Override public String filter(String content, FilterContext filterContext) { StringBuffer result = new StringBuffer(); Matcher matcher = SECTIONSYNTAX_PATTERN.matcher(content); int currentIndex = 0; for (; matcher.find(); currentIndex = matcher.end()) { String before = content.substring(currentIndex, matcher.start()); before += matcher.group(1);/*from www. j a v a2s .c o m*/ if (currentIndex > 0) { // 1.0 syntax section consume all following new lines before = CleanUtil.removeLeadingNewLines(before); before = "\n\n" + before; } result.append(before); CleanUtil.setTrailingNewLines(result, 2); String headerSyntax = filterContext .addProtectedContent(StringUtils.repeat('=', (matcher.group(2).length() + 1) / 2), false); String headerContent = headerSyntax + ' ' + matcher.group(4) + ' ' + headerSyntax; result.append(CleanUtil.extractVelocity(headerContent, filterContext)); } if (currentIndex == 0) { return content; } String end = content.substring(currentIndex); if (currentIndex > 0) { // 1.0 syntax section consume all following new lines end = CleanUtil.removeLeadingNewLines(end); end = "\n\n" + end; } result.append(end); return result.toString(); }
From source file:org.xwiki.rendering.internal.renderer.plain.PlainTextChainingRenderer.java
@Override public void onEmptyLines(int count) { getPrinter().print(StringUtils.repeat(NL, count)); }
From source file:org.xwiki.rendering.internal.renderer.xwiki20.XWikiSyntaxChainingRenderer.java
@Override public void beginHeader(HeaderLevel level, String id, Map<String, String> parameters) { printEmptyLine();// www . j a va 2 s .co m printParameters(parameters); print(StringUtils.repeat("=", level.getAsInt()) + " "); }