Java Code Examples for org.apache.commons.lang.StringUtils#repeat()

The following examples show how to use org.apache.commons.lang.StringUtils#repeat() . 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: Misc.java    From iaf with Apache License 2.0 6 votes vote down vote up
public static String hide(String string, int mode) {
	if (StringUtils.isEmpty(string)) {
		return string;
	}
	int len = string.length();
	if (mode == 1) {
		if (len <= 2) {
			return string;
		}
		char firstChar = string.charAt(0);
		char lastChar = string.charAt(len - 1);
		return firstChar + StringUtils.repeat("*", len - 2) + lastChar;
	} else {
		return StringUtils.repeat("*", len);
	}
}
 
Example 2
Source File: TestConstraints.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a constraint name that is longer than the maximum allowed.
 */
public void testLongConstraintName()
{
    if (getSqlBuilder().getMaxConstraintNameLength() == -1)
    {
        return;
    }

    String       constraintName = StringUtils.repeat("Test", (getSqlBuilder().getMaxConstraintNameLength() / 4) + 3);
    final String modelXml       = 
        "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+
        "  <table name='roundtrip'>\n"+
        "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='avalue' type='DOUBLE'/>\n"+
        "    <index name='" + constraintName + "'>\n"+
        "      <index-column name='avalue'/>\n"+
        "    </index>\n"+
        "  </table>\n"+
        "</database>";

    performConstraintsTest(modelXml, true);
}
 
Example 3
Source File: BoxCrudTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * BOX新規登録時にSchemaに1024文字を指定して場合_201になることを確認.
 */
@Test
public void BOX新規登録時にSchemaに1024文字を指定して場合_201になることを確認() {
    DcRequest req = DcRequest.post(UrlUtils.cellCtl(CELL_NAME, ENTITY_TYPE_BOX));
    String schema = "http://" + StringUtils.repeat("x", 1012) + ".com/";
    String[] key = {"Name", "Schema" };
    String[] value = {"testBox", schema };
    req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN).addJsonBody(key, value);
    try {
        DcResponse res = request(req);

        // 400になることを確認
        assertEquals(HttpStatus.SC_CREATED, res.getStatusCode());
    } finally {
        deleteBoxRequest("testBox").returns();
    }
}
 
Example 4
Source File: MaskFormatterSubString.java    From rice with Educational Community License v2.0 6 votes vote down vote up
public String maskValue(Object value) {
    if (value == null) {
        return null;
    }

    // TODO: MOVE TO UNIT TEST: move this validation into the unit tests
    if (maskCharacter == null) {
        throw new RuntimeException("Mask character not specified. Check DD maskTo attribute.");
    }

    String strValue = value.toString();
    if (strValue.length() < maskLength) {
        return StringUtils.repeat(maskCharacter, maskLength);
    }
    if (maskLength > 0) {
        return StringUtils.repeat(maskCharacter, maskLength) + strValue.substring(maskLength);
    } else {
        return strValue;
    }
}
 
Example 5
Source File: TestProtoBufRpc.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout=6000)
public void testExtraLongRpc() throws Exception {
  TestRpcService2 client = getClient2();
  final String shortString = StringUtils.repeat("X", 4);
  EchoRequestProto echoRequest = EchoRequestProto.newBuilder()
      .setMessage(shortString).build();
  // short message goes through
  EchoResponseProto echoResponse = client.echo2(null, echoRequest);
  Assert.assertEquals(shortString, echoResponse.getMessage());
  
  final String longString = StringUtils.repeat("X", 4096);
  echoRequest = EchoRequestProto.newBuilder()
      .setMessage(longString).build();
  try {
    echoResponse = client.echo2(null, echoRequest);
    Assert.fail("expected extra-long RPC to fail");
  } catch (ServiceException se) {
    // expected
  }
}
 
Example 6
Source File: LogicalPlanConfigurationTest.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private void printTopology(OperatorMeta operator, DAG tplg, int level)
{
  String prefix = "";
  if (level > 0) {
    prefix = StringUtils.repeat(" ", 20 * (level - 1)) + "   |" + StringUtils.repeat("-", 17);
  }
  logger.debug(prefix + operator.getName());
  for (StreamMeta downStream : operator.getOutputStreams().values()) {
    if (!downStream.getSinks().isEmpty()) {
      for (LogicalPlan.InputPortMeta targetNode : downStream.getSinks()) {
        printTopology(targetNode.getOperatorMeta(), tplg, level + 1);
      }
    }
  }
}
 
Example 7
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when the table name is not a valid XML identifier and too long.
 */
public void testTableNameInvalidAndLong() throws Exception
{
    String   tableName = StringUtils.repeat("table name", 50);
    Database model     = readModel(
        "<?xml version='1.0' encoding='UTF-8'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='" + tableName + "'>\n"+
        "    <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='value' type='VARCHAR' size='50' required='true'/>\n"+
        "  </table>\n"+
        "</database>");
    String testedValue = "Some Text";

    SqlDynaBean bean = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));

    bean.set("id", new Integer(1));
    bean.set("value", testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <table id=\"1\" value=\"" + testedValue + "\">\n" +
                  "    <table-name>" + tableName + "</table-name>\n" +
                  "  </table>\n" +
                  "</data>\n");
}
 
Example 8
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when a column name is a valid tag,
 * and both the column name and value are longer than 255 characters.
 */
public void testColumnNameLongAndValueLong() throws Exception
{
    String columnName = StringUtils.repeat("value", 100);
    Database model = readModel(
        "<?xml version='1.0' encoding='UTF-8'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='test'>\n"+
        "    <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='" + columnName + "' type='VARCHAR' size='500' required='true'/>\n"+
        "  </table>\n"+
        "</database>");
    String testedValue = StringUtils.repeat("Some Text", 40);

    SqlDynaBean bean = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));

    bean.set("id", new Integer(1));
    bean.set(columnName, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column>\n" +
                  "      <column-name>" + columnName + "</column-name>\n" +
                  "      <column-value>" + testedValue + "</column-value>\n" +
                  "    </column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
Example 9
Source File: MySqlValueMetaBaseTest.java    From hop with Apache License 2.0 5 votes vote down vote up
@Test
public void test_Pdi_17126_mysql() throws Exception {
	String data = StringUtils.repeat("*", 10);
	initValueMeta(new MySqlDatabaseMeta(), DatabaseMeta.CLOB_LENGTH, data);

	verify(preparedStatementMock, times(1)).setString(0, data);
}
 
Example 10
Source File: TestDataReaderAndWriter.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the reader & writer behavior when a column name is a valid tag,
 * and the column name is longer than 255 characters and the value is shorter.
 */
public void testColumnNameLongAndValueShort() throws Exception
{
    String columnName = StringUtils.repeat("value", 100);
    Database model = readModel(
        "<?xml version='1.0' encoding='UTF-8'?>\n"+
        "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" +
        "  <table name='test'>\n"+
        "    <column name='id' type='INTEGER' primaryKey='true' required='true'/>\n"+
        "    <column name='" + columnName + "' type='VARCHAR' size='50' required='true'/>\n"+
        "  </table>\n"+
        "</database>");
    String testedValue = "Some Text";

    SqlDynaBean bean = (SqlDynaBean)model.createDynaBeanFor(model.getTable(0));

    bean.set("id", new Integer(1));
    bean.set(columnName, testedValue);

    roundtripTest(model, bean, "UTF-8",
                  "<?xml version='1.0' encoding='UTF-8'?>\n" +
                  "<data>\n" +
                  "  <test id=\"1\">\n" +
                  "    <column>\n" +
                  "      <column-name>" + columnName + "</column-name>\n" +
                  "      <column-value>" + testedValue + "</column-value>\n" +
                  "    </column>\n" +
                  "  </test>\n" +
                  "</data>\n");
}
 
Example 11
Source File: EsqlCheckVerifierTest.java    From sonar-esql-plugin with Apache License 2.0 4 votes vote down vote up
private static InternalSyntaxToken createToken(int line, @Nullable Integer column, int length) {
  String tokenValue = StringUtils.repeat("x", length);
  int tokenColumn = column == null ? 0 : column - 1;
  return new InternalSyntaxToken(line, tokenColumn, tokenValue, ImmutableList.<SyntaxTrivia>of(), 0, false);
}
 
Example 12
Source File: StringField.java    From intellij-swagger with MIT License 4 votes vote down vote up
@Override
public String getCompleteYaml(final int indentation) {
  final String leftPadding = StringUtils.repeat(" ", indentation);
  return leftPadding + getName() + ": " + CARET;
}
 
Example 13
Source File: ObjectField.java    From intellij-swagger with MIT License 4 votes vote down vote up
@Override
public String getCompleteYaml(final int indentation) {
  final String indentationPadding = StringUtils.repeat(" ", indentation);
  return indentationPadding + getName() + getYamlPlaceholderSuffix(indentation);
}
 
Example 14
Source File: SQLParseError.java    From tajo with Apache License 2.0 4 votes vote down vote up
private String getDetailedMessageWithLocation() {
  StringBuilder sb = new StringBuilder();
  int displayLimit = 80;
  String queryPrefix = "LINE " + line + ":" + " ";
  String prefixPadding = StringUtils.repeat(" ", queryPrefix.length());
  String locationString;

  int tokenLength = offendingToken.getStopIndex() - offendingToken.getStartIndex() + 1;
  if(tokenLength > 0){
    locationString = StringUtils.repeat(" ", charPositionInLine) + StringUtils.repeat("^", tokenLength);
  } else {
    locationString = StringUtils.repeat(" ", charPositionInLine) + "^";
  }

  sb.append("ERROR: ").append(header).append("\n");
  sb.append(queryPrefix);

  if (errorLine.length() > displayLimit) {
    int padding = (displayLimit / 2);

    String ellipsis = " ... ";
    int startPos = locationString.length() - padding - 1;
    if (startPos <= 0) {
      startPos = 0;
      sb.append(errorLine.substring(startPos, displayLimit)).append(ellipsis).append("\n");
      sb.append(prefixPadding).append(locationString);
    } else if (errorLine.length() - (locationString.length() + padding) <= 0) {
      startPos = errorLine.length() - displayLimit - 1;
      sb.append(ellipsis).append(errorLine.substring(startPos)).append("\n");
      sb.append(prefixPadding).append(StringUtils.repeat(" ", ellipsis.length()))
          .append(locationString.substring(startPos));
    } else {
      sb.append(ellipsis).append(errorLine.substring(startPos, startPos + displayLimit)).append(ellipsis).append("\n");
      sb.append(prefixPadding).append(StringUtils.repeat(" ", ellipsis.length()))
          .append(locationString.substring(startPos));
    }
  } else {
    sb.append(errorLine).append("\n");
    sb.append(prefixPadding).append(locationString);
  }
  return sb.toString();
}
 
Example 15
Source File: StringField.java    From intellij-swagger with MIT License 4 votes vote down vote up
@Override
public String getCompleteJson(final int indentation) {
  final String leftPadding = StringUtils.repeat(" ", indentation);
  return leftPadding + "\"" + getName() + "\": \"" + CARET + "\"";
}
 
Example 16
Source File: XsdViewWidget.java    From dynaform with Artistic License 2.0 4 votes vote down vote up
private static String replaceTabsWithSpaces(String line, int tabWidth) {
  String tab = StringUtils.repeat(" ", tabWidth);
  line = line.replace("\t", tab);
  return line;
}
 
Example 17
Source File: Arja_00101_s.java    From coming with MIT License 2 votes vote down vote up
/**
 * Represents this token as a String.
 *
 * @return String representation of the token
 */
public String toString() {
    return StringUtils.repeat(this.value.toString(), this.count);
}
 
Example 18
Source File: Arja_00137_s.java    From coming with MIT License 2 votes vote down vote up
/**
 * Represents this token as a String.
 *
 * @return String representation of the token
 */
public String toString() {
    return StringUtils.repeat(this.value.toString(), this.count);
}
 
Example 19
Source File: Arja_00121_s.java    From coming with MIT License 2 votes vote down vote up
/**
 * Represents this token as a String.
 *
 * @return String representation of the token
 */
public String toString() {
    return StringUtils.repeat(this.value.toString(), this.count);
}
 
Example 20
Source File: 1_DurationFormatUtils.java    From SimFix with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Represents this token as a String.
 *
 * @return String representation of the token
 */
public String toString() {
    return StringUtils.repeat(this.value.toString(), this.count);
}