Example usage for org.apache.commons.lang StringUtils repeat

List of usage examples for org.apache.commons.lang StringUtils repeat

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils repeat.

Prototype

public static String repeat(String str, int repeat) 

Source Link

Document

Repeat a String repeat times to form a new String.

Usage

From source file:com.redhat.rhn.manager.user.test.UpdateUserCommandTest.java

public void testValidPassword() {
    command.setEmail("jesusr@redhat.com");
    // = maxlen/*from   w w w  .  j  ava  2 s.  c o m*/
    assertPassword(StringUtils.repeat("a", UserDefaults.get().getMinPasswordLength()), command);
    // = maxlen
    assertPassword(StringUtils.repeat("a", UserDefaults.get().getMaxPasswordLength()), command);

    // random string
    String randomPassword = TestUtils.randomString();
    if (randomPassword.length() > 64) {
        randomPassword = randomPassword.substring(0, 64);
    }

    assertPassword(randomPassword, command);
    assertPassword("Th1$_i5-V@Lid", command);
}

From source file:adalid.core.expressions.AbstractScalarX.java

@Override
protected String fieldsToString(int n, String key, boolean verbose, boolean fields, boolean maps) {
    String tab = verbose ? StringUtils.repeat(" ", 4) : "";
    String fee = verbose ? StringUtils.repeat(tab, n) : "";
    String faa = " = ";
    String foo = verbose ? EOL : ", ";
    String string = super.fieldsToString(n, key, verbose, fields, maps);
    if (fields || verbose) {
        if (verbose) {
            if (_operator != null) {
                string += fee + tab + "operator" + faa + _operator + foo;
            }//  w ww.j a va2  s  . com
            if (_operand instanceof NaryExpression) {
                Expression valor = (Expression) _operand;
                string += valor.toString(n + 1, "operand");
            } else {
                string += fee + tab + "operand" + faa + getValueString(_operand) + foo;
            }
        }
    }
    return string;
}

From source file:hd3gtv.tools.Hexview.java

public String getView() {
    StringBuilder sb = new StringBuilder();

    int pos_number_size = String.valueOf(size).length();
    char[] string_view = new char[COLS];

    long current_pos;
    int zeros_to_add;
    String hex_number;//  w  ww .  j  a va  2 s.c om
    int value;
    for (int pos = this.pos; pos < len; pos++) {
        if (pos % COLS == 0) {
            current_pos = offset + (pos - this.pos);

            zeros_to_add = pos_number_size - String.valueOf(current_pos).length();
            sb.append(StringUtils.repeat("0", zeros_to_add));
            sb.append(current_pos);
            sb.append(" ");
        }

        if (pos % COLS == 4 | pos % COLS == 12 | pos % COLS == 20 | pos % COLS == 28) {
            sb.append(".");
        } else if (pos % COLS == 8 | pos % COLS == 16 | pos % COLS == 24) {
            sb.append("|");
        } else {
            sb.append(" ");
        }

        value = Byte.toUnsignedInt(datas[pos]);
        hex_number = String.format("%x", value);
        if (hex_number.length() == 1) {
            sb.append("0");
        }
        sb.append(hex_number);

        if (value > 31 & value < 127) {
            string_view[pos % COLS] = (char) datas[pos];
        } else {
            string_view[pos % COLS] = '.';
        }

        if (pos % COLS == COLS - 1) {
            sb.append(" ");
            for (int pos_sv = 0; pos_sv < string_view.length; pos_sv++) {
                if (pos_sv % (COLS / 2) == 0) {
                    sb.append(" ");
                }
                sb.append(string_view[pos_sv]);
            }

            sb.append(LINESEPARATOR);
        }
    }

    if ((len % COLS) > 0) {
        int empty_bytes = COLS - (len % COLS);
        for (int pos = 0; pos < empty_bytes; pos++) {
            sb.append("   ");
        }
        sb.append(" ");
        for (int pos = 0; pos < (len % COLS); pos++) {
            if (pos % (COLS / 2) == 0) {
                sb.append(" ");
            }
            sb.append(string_view[pos]);
        }
    }

    return sb.toString();
}

From source file:com.hp.autonomy.frontend.find.core.web.ControllerUtilsImpl.java

private String getBaseUrl(final HttpServletRequest request) {
    final String originalUri = (String) request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);
    final String requestUri = originalUri != null ? originalUri : request.getRequestURI();
    final String path = requestUri.replaceFirst(request.getContextPath(), "");
    final int depth = StringUtils.countMatches(path, "/") - 1;

    return depth <= 0 ? "." : StringUtils.repeat("../", depth);
}

From source file:cfa.vo.sed.science.stacker.SedStackTest.java

public void add(List<String> names, String newName) {

    char c = '@';
    int i = 1;/*from w w  w  .  j a v a2s.  c  o  m*/
    int j = 1;
    while (names.contains(newName + (c == '@' ? "" : "." + StringUtils.repeat(String.valueOf(c), j)))) {
        int val = j * 26;
        if (i % val == 0) {
            c = '@';
            j++;
        }
        c++;
        i++;
    }
    names.add(newName + (c == '@' ? "" : "." + StringUtils.repeat(String.valueOf(c), j)));

}

From source file:fr.xebia.demo.ws.employee.EmployeeServiceIntegrationTest.java

@Test(expected = SOAPFaultException.class)
public void testPutEmployeeFirstNameTooLong() throws Exception {
    int id = random.nextInt();

    Employee employee = new Employee();
    employee.setId(id);/*from www. j a  v a 2 s  . co  m*/
    employee.setLastName("Doe-" + id);
    String firstName = StringUtils.repeat("John ", 100);
    Assert.assertTrue("firstName must be longer than 256 chars to exceed Schema constraint",
            firstName.length() > 256);
    employee.setFirstName(firstName);
    employee.setGender(Gender.MALE);
    employee.setBirthdate(new Date(new GregorianCalendar(1976, 01, 05).getTimeInMillis()));

    try {
        employeeService.putEmployee(new Holder<Employee>(employee));
    } catch (SOAPFaultException e) {
        e.printStackTrace();
        throw e;
    }
    /*
     * throws javax.xml.ws.soap.SOAPFaultException: Marshalling Error: cvc-maxLength-valid: Value '...' with length = '500' is not
     * facet-valid with respect to maxLength '256' for type '#AnonType_firstNameEmployee'.
     */

}

From source file:au.id.hazelwood.sos.model.user.UserValidationTest.java

@Test
public void testFirstName() throws Exception {
    assertValidation("firstName", "Ricky");
    assertValidation("firstName", "Ricky Jack");
    assertValidation("firstName", "O'Brien-O'Connor");
    assertValidation("firstName", "Connor Tomas O'Brien");
    assertValidation("firstName", "");
    assertValidation("firstName", null);
    assertValidation("firstName", StringUtils.repeat("a", 20));
    assertValidation("firstName", StringUtils.repeat("a", 21), "size must be between 0 and 20");
    assertValidation("firstName", " ", "not a well-formed name");
    assertValidation("firstName", "-", "not a well-formed name");
    assertValidation("firstName", "A- -B", "not a well-formed name");
}

From source file:com.liveramp.cascading_ext.counters.Counters.java

public static String prettyCountersString(Flow flow) {
    Map<FlowStepStats, List<Counter>> counters = Counters.getCountersByStep(flow);
    StringBuilder builder = new StringBuilder("\n").append(StringUtils.repeat("=", 90)).append("\n");

    builder.append("Counters for ").append(flow.getName() == null ? "unnamed flow" : "flow " + flow.getName())
            .append("\n").append("  with input ").append(prettyTaps(flow.getSources())).append("\n")
            .append("  and output ").append(prettyTaps(flow.getSinks())).append("\n");

    for (Map.Entry<FlowStepStats, List<Counter>> entry : counters.entrySet()) {
        builder.append("  Step: ").append(entry.getKey().getName()).append("\n");

        if (entry.getValue().isEmpty()) {
            builder.append("    No counters found.\n");
            continue;
        }// w w  w . j  ava2  s .c  o m

        boolean anyTuplesRead = false;
        boolean anyTuplesWritten = false;
        for (Counter counter : entry.getValue()) {
            if (counter.getValue() != null && counter.getValue() > 0) {
                builder.append("    ").append(counter).append("\n");

                if (counter.getName().equals("Tuples_Read")) {
                    anyTuplesRead = true;
                }
                if (counter.getName().equals("Tuples_Written")) {
                    anyTuplesWritten = true;
                }
            }
        }

        if (anyTuplesRead && !anyTuplesWritten) {
            builder.append("  *** BLACK HOLE WARNING *** The above step had input but no output\n");
        }
    }
    builder.append(StringUtils.repeat("=", 90)).append("\n");
    return builder.toString();
}

From source file:io.cloudslang.lang.cli.services.SyncTriggerEventListener.java

@Override
public synchronized void onEvent(ScoreEvent scoreEvent) throws InterruptedException {
    @SuppressWarnings("unchecked")
    Map<String, Serializable> data = (Map<String, Serializable>) scoreEvent.getData();
    switch (scoreEvent.getEventType()) {
    case EventConstants.SCORE_FINISHED_EVENT:
        flowFinished.set(true);/*w  w  w. j  a va2  s . c  o m*/
        break;
    case EventConstants.SCORE_ERROR_EVENT:
        errorMessage.set(SCORE_ERROR_EVENT_MSG + data.get(EventConstants.SCORE_ERROR_LOG_MSG) + " , "
                + data.get(EventConstants.SCORE_ERROR_MSG));
        break;
    case EventConstants.SCORE_FAILURE_EVENT:
        consolePrinter.printWithColor(RED, FLOW_FINISHED_WITH_FAILURE_MSG);
        flowFinished.set(true);
        break;
    case EventConstants.MAVEN_DEPENDENCY_BUILD:
        printDownloadArtifactMessage((String) data.get(EventConstants.MAVEN_DEPENDENCY_BUILD));
        break;
    case EventConstants.MAVEN_DEPENDENCY_BUILD_FINISHED:
        printDownloadArtifactMessage((String) data.get(EventConstants.MAVEN_DEPENDENCY_BUILD_FINISHED));
        break;
    case ScoreLangConstants.SLANG_EXECUTION_EXCEPTION:
        errorMessage.set(SLANG_STEP_ERROR_MSG + data.get(LanguageEventData.EXCEPTION));
        break;
    case ScoreLangConstants.EVENT_STEP_START:
        LanguageEventData eventData = (LanguageEventData) data;
        if (eventData.getStepType() == LanguageEventData.StepType.STEP) {
            String stepName = eventData.getStepName();
            String path = eventData.getPath();
            int matches = StringUtils.countMatches(path, ExecutionPath.PATH_SEPARATOR);
            String prefix = StringUtils.repeat(STEP_PATH_PREFIX, matches);
            consolePrinter.printWithColor(YELLOW, prefix + stepName);
        }
        break;
    case ScoreLangConstants.EVENT_OUTPUT_END:
        // Step end case
        if ((data.get(LanguageEventData.STEP_TYPE)).equals((LanguageEventData.StepType.STEP))) {
            if (this.isDebugMode) {
                Map<String, Serializable> stepOutputs = extractNotEmptyOutputs(data);
                String path = ((LanguageEventData) data).getPath();
                int matches = StringUtils.countMatches(path, ExecutionPath.PATH_SEPARATOR);
                String prefix = StringUtils.repeat(STEP_PATH_PREFIX, matches);

                for (Map.Entry<String, Serializable> entry : stepOutputs.entrySet()) {
                    consolePrinter.printWithColor(WHITE, prefix + entry.getKey() + " = " + entry.getValue());
                }
            }
        }

        // Flow end case
        else if (data.containsKey(LanguageEventData.OUTPUTS) && data.containsKey(LanguageEventData.PATH)
                && data.get(LanguageEventData.PATH).equals(EXEC_START_PATH)) {
            Map<String, Serializable> outputs = extractNotEmptyOutputs(data);
            if (outputs.size() > 0) {
                printForOperationOrFlow(data, WHITE, "\n" + OPERATION_OUTPUTS, "\n" + FLOW_OUTPUTS);
                for (Map.Entry<String, Serializable> entry : outputs.entrySet()) {
                    consolePrinter.printWithColor(WHITE, "- " + entry.getKey() + " = " + entry.getValue());
                }
            }
        }
        break;
    case ScoreLangConstants.EVENT_EXECUTION_FINISHED:
        flowFinished.set(true);
        printFinishEvent(data);
        break;
    default:
        break;
    }
}

From source file:de.taimos.pipeline.aws.cloudformation.EventPrinter.java

private void printLine() {
    this.listener.getLogger().println(StringUtils.repeat("-", 231));
}