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

The following are Jave code examples for showing how to use repeat() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: springboot-shiro-cas-mybatis   File: CasDelegatingLogger.java   View Source Code Vote up 6 votes
/**
 * Remove ticket id from the log message.
 *
 * @param msg the message
 * @return the modified message with tgt id removed
 */
private String removeTicketId(final String msg) {
    String modifiedMessage = msg;

    if (StringUtils.isNotBlank(msg)) {
        final Matcher matcher = TICKET_ID_PATTERN.matcher(msg);
        while (matcher.find()) {
            final String match = matcher.group();
            final String newId = matcher.group(1) + '-'
                    + StringUtils.repeat("*", match.length() - VISIBLE_ID_TAIL_LENGTH)
                    + StringUtils.right(match, VISIBLE_ID_TAIL_LENGTH);

            modifiedMessage = modifiedMessage.replaceAll(match, newId);
        }
    }
    return modifiedMessage;
}
 
Example 2
Project: springboot-shiro-cas-mybatis   File: CasDelegatingLogger.java   View Source Code Vote up 6 votes
/**
 * Remove ticket id from the log message.
 *
 * @param msg the message
 * @return the modified message with tgt id removed
 */
private String removeTicketId(final String msg) {
    String modifiedMessage = msg;

    if (StringUtils.isNotBlank(msg)) {
        final Matcher matcher = TICKET_ID_PATTERN.matcher(msg);
        while (matcher.find()) {
            final String match = matcher.group();
            final String newId = matcher.group(1) + '-'
                    + StringUtils.repeat("*", match.length() - VISIBLE_ID_TAIL_LENGTH)
                    + StringUtils.right(match, VISIBLE_ID_TAIL_LENGTH);

            modifiedMessage = modifiedMessage.replaceAll(match, newId);
        }
    }
    return modifiedMessage;
}
 
Example 3
Project: sierra   File: TabularResistanceSummary.java   View Source Code Vote up 6 votes
private static List<String> getScoresPR(Map<Gene, GeneDR> resistanceResults) {
	List<String> resistanceScoresAndLevels = new ArrayList<>();
	if (resistanceResults.containsKey(Gene.PR)) {
		GeneDR geneDR = resistanceResults.get(Gene.PR);
		for (Drug drug : pis) {
			int score = geneDR.getTotalDrugScore(drug).intValue();
			int level = geneDR.getDrugLevel(drug);
			resistanceScoresAndLevels.add(Integer.toString(score));
			resistanceScoresAndLevels.add(Integer.toString(level));
		}
	} else {
		String filler = StringUtils.repeat("NA", ",", pis.length * 2);
		resistanceScoresAndLevels = Arrays.asList(filler.split(","));
	}
	return resistanceScoresAndLevels;
}
 
Example 4
Project: sierra   File: TabularResistanceSummary.java   View Source Code Vote up 6 votes
private static List<String> getScoresIN(Map<Gene, GeneDR> resistanceResults) {
	List<String> resistanceScoresAndLevels = new ArrayList<>();
	if (resistanceResults.containsKey(Gene.IN)) {
		GeneDR geneDR = resistanceResults.get(Gene.IN);
		for (Drug drug : instis) {
			int score = geneDR.getTotalDrugScore(drug).intValue();
			int level = geneDR.getDrugLevel(drug);
			resistanceScoresAndLevels.add(Integer.toString(score));
			resistanceScoresAndLevels.add(Integer.toString(level));
		}
	} else {
		String filler = StringUtils.repeat("NA", ",", instis.length * 2);
		resistanceScoresAndLevels = Arrays.asList(filler.split(","));
	}
	return resistanceScoresAndLevels;
}
 
Example 5
Project: gaffer-doc   File: JavaSourceUtil.java   View Source Code Vote up 6 votes
public static String getRawJavaSnippet(final Class<?> clazz, final String modulePath, final String marker, final String start, final String end) {
    String javaCode = getRawJava(clazz.getName(), modulePath);
    final int markerIndex = javaCode.indexOf(marker);
    if (markerIndex < 0) {
        throw new IllegalArgumentException("Cannot find java snippet for: " + clazz.getName() + " " + marker);
    }

    javaCode = javaCode.substring(markerIndex);
    javaCode = javaCode.substring(javaCode.indexOf(start) + start.length());
    javaCode = javaCode.substring(0, javaCode.indexOf(end));
    javaCode = StringUtils.stripEnd(javaCode, " " + NEW_LINE);

    // Remove indentation
    final String trimmedJavaCode = javaCode.trim();
    final int leadingSpaces = javaCode.indexOf(trimmedJavaCode);
    if (leadingSpaces > 0) {
        final String spacesRegex = NEW_LINE + StringUtils.repeat(" ", leadingSpaces);
        javaCode = trimmedJavaCode.replace(spacesRegex, NEW_LINE);
    }

    return javaCode;
}
 
Example 6
Project: cas-server-4.2.1   File: CasDelegatingLogger.java   View Source Code Vote up 6 votes
/**
 * Remove ticket id from the log message.
 *
 * @param msg the message
 * @return the modified message with tgt id removed
 */
private String removeTicketId(final String msg) {
    String modifiedMessage = msg;

    if (StringUtils.isNotBlank(msg)) {
        final Matcher matcher = TICKET_ID_PATTERN.matcher(msg);
        while (matcher.find()) {
            final String match = matcher.group();
            final String newId = matcher.group(1) + '-'
                    + StringUtils.repeat("*", match.length() - VISIBLE_ID_TAIL_LENGTH)
                    + StringUtils.right(match, VISIBLE_ID_TAIL_LENGTH);

            modifiedMessage = modifiedMessage.replaceAll(match, newId);
        }
    }
    return modifiedMessage;
}
 
Example 7
Project: redirector   File: RightSide.java   View Source Code Vote up 6 votes
public String toString(int indent) {
    String valuesStr;
    if (values != null) {
        valuesStr = values.toString();
        if (valuesStr.length() > 20) {
            valuesStr = valuesStr.substring(0, 19) + "...}";
        }
    } else {
        valuesStr = namespacedList.toString();
        if (valuesStr.length() > 20) {
            valuesStr = valuesStr.substring(0, 19) + "...}";
        }
    }
    valuesStr = valuesStr + StringUtils.repeat(' ', indent);
    return valuesStr;
}
 
Example 8
Project: Lector   File: RenderElementRuler.java   View Source Code Vote up 5 votes
@Override
public String render(int dy, float ix, float iy) {
    float charw = ClientProxy.font.getWidth("" + '\u2014');
    int repeat = (int) ((1024 - x) / charw);
    String s = StringUtils.repeat('\u2014', repeat);
    ClientProxy.font.drawString(x, 512 - (y + dy) + 20, s, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
    return null;
}
 
Example 9
Project: cas-5.1.0   File: TicketIdSanitizationUtils.java   View Source Code Vote up 5 votes
/**
 * Remove ticket id from the message.
 *
 * @param msg the message
 * @return the modified message with tgt id removed
 */
public static String sanitize(final String msg) {
    String modifiedMessage = msg;
    if (StringUtils.isNotBlank(msg) && !Boolean.getBoolean("CAS_TICKET_ID_SANITIZE_SKIP")) {
        final Matcher matcher = TICKET_ID_PATTERN.matcher(msg);
        while (matcher.find()) {
            final String match = matcher.group();
            final String newId = matcher.group(1) + '-'
                    + StringUtils.repeat("*", match.length() - VISIBLE_TAIL_LENGTH)
                    + StringUtils.right(match, VISIBLE_TAIL_LENGTH);
            modifiedMessage = modifiedMessage.replaceAll(match, newId);
        }
    }
    return modifiedMessage;
}
 
Example 10
Project: weixin_api   File: TestFileStorage.java   View Source Code Vote up 5 votes
@BeforeClass
public static void setUpBeforeClass() throws Exception {
	datas = new HashMap<String, Object>();
	datas.put("k1", "v1");
	datas.put(nullKey, null);
	datas.put("k3", new Date());
	longKey = StringUtils.repeat("keys", 1024);
	datas.put(longKey, StringUtils.repeat("valuevalue", 10240));

}
 
Example 11
Project: diorite-configs-java8   File: CommentsWriter.java   View Source Code Vote up 5 votes
private void updateIndent(boolean up)
{
    if (up)
    {
        this.cachedIndent = StringUtils.repeat(' ', (++ this.indent) * 2);
    }
    else
    {
        this.cachedIndent = StringUtils.repeat(' ', (-- this.indent) * 2);
    }
}
 
Example 12
Project: plugin-bt-jira   File: JiraDao.java   View Source Code Vote up 5 votes
/**
 * Return the "IN" SQL query parameters like : ?,?,?
 */
protected String newIn(final Collection<?> items) {
	if (items.isEmpty()) {
		return "null";
	}
	return StringUtils.repeat("?", ",", items.size());
}
 
Example 13
Project: remember-me-back   File: ValidationTest.java   View Source Code Vote up 5 votes
@Test
public void titleTooLong() throws Exception {
    String title = StringUtils.repeat("x", 101);
    Blogpost blogpost = new Blogpost(title, "", "author", "https://www.google.fi");
    String blogpostJson = json(blogpost);
    this.mockMvc.perform(post("/api/v01/blogposts")
            .contentType(contentType)
            .content(blogpostJson))
            .andExpect(status().is(400))
            .andExpect(content().contentType(contentType))
            .andExpect((jsonPath("$", hasSize(1))))
            .andExpect(jsonPath("$[0].type", is("ERROR")))
            .andExpect(jsonPath("$[0].message", is("The title should be between 1 and 100 characters")))
            .andExpect(jsonPath("$[0].field", is("title")));
}
 
Example 14
Project: remember-me-back   File: ValidationTest.java   View Source Code Vote up 5 votes
@Test
public void authorTooLong() throws Exception {
    String author = StringUtils.repeat("x", 101);
    Blogpost blogpost = new Blogpost("title", "", author, "https://www.google.fi");
    String blogpostJson = json(blogpost);
    this.mockMvc.perform(post("/api/v01/blogposts")
            .contentType(contentType)
            .content(blogpostJson))
            .andExpect(status().is(400))
            .andExpect(content().contentType(contentType))
            .andExpect((jsonPath("$", hasSize(1))))
            .andExpect(jsonPath("$[0].type", is("ERROR")))
            .andExpect(jsonPath("$[0].message", is("The author should be between 1 and 100 characters")))
            .andExpect(jsonPath("$[0].field", is("author")));
}
 
Example 15
Project: sponge   File: StandaloneEngineBuilder.java   View Source Code Vote up 5 votes
public void printHelp() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setSyntaxPrefix("Usage: ");
    formatter.setOptionComparator(null);

    String columns = System.getenv(ENV_COLUMNS);
    if (columns != null) {
        try {
            formatter.setWidth(Integer.parseInt(columns));
        } catch (Exception e) {
            logger.warn(e.toString());
        }
    }

    String header = "Run the " + VersionInfo.PRODUCT + " standalone command-line application.\n\n";
    String leftPadding = StringUtils.repeat(' ', formatter.getLeftPadding());
    //@formatter:off
    String footer = new StringBuilder()
            .append("\nExamples (change directory to " + VersionInfo.PRODUCT + " bin/ first):\n")
            .append(leftPadding + "./" + EXECUTABLE_NAME + " -c ../examples/script/py/hello_world.xml\n")
            .append(leftPadding + "./" + EXECUTABLE_NAME + " -k helloWorldKb=../examples/script/py/hello_world.py\n")
            .append(leftPadding + "./" + EXECUTABLE_NAME + " -k ../examples/script/py/hello_world.py\n")
            .append(leftPadding + "./" + EXECUTABLE_NAME
                    + " -k filtersKb=../examples/script/py/filters.py -k heartbeatKb=../examples/script/js/rules_heartbeat.js\n")
            .append(leftPadding + "./" + EXECUTABLE_NAME
                    + " -k ../examples/standalone/multiple_kb_files/event_processors.py"
                    + ",../examples/standalone/multiple_kb_files/example2.py\n")
            .append("\nPress CTRL+C to exit the " + VersionInfo.PRODUCT + " standalone command-line application.\n")
            .append("\nSee http://sponge.openksavi.org for more details.").toString();
    //@formatter:on
    formatter.printHelp(EXECUTABLE_NAME, header, options, footer, true);
}
 
Example 16
Project: verify-service-provider   File: StringTableFormatter.java   View Source Code Vote up 5 votes
private static String formatTitle(int tableWidth, String title) {
    String tableTopBorder = StringUtils.repeat(TABLE_LINE_BORDER, tableWidth) + System.lineSeparator();
    String tableTitleRow = TABLE_SIDE_BORDER + " " + title + System.lineSeparator();
    String tableTitleBottomBorder = StringUtils.repeat(TABLE_TITLE_SEPARATOR, tableWidth) + System.lineSeparator();

    return System.lineSeparator() +
        tableTopBorder +
        tableTitleRow +
        tableTitleBottomBorder;
}
 
Example 17
Project: diorite-configs-java8   File: Emitter.java   View Source Code Vote up 5 votes
private String createRightBorder(String comment, int longest, String commentRightBorder)
{
    int commentLength = comment.length() + 2;
    String rightBorder;
    if (commentLength < longest)
    {
        rightBorder =
            StringUtils.repeat(' ', DioriteMathUtils.ceil(((double) (longest - commentLength)) / commentRightBorder.length())) + '#';
    }
    else
    {
        rightBorder = commentRightBorder;
    }
    return "# " + comment + rightBorder;
}
 
Example 18
Project: sql-on-json   File: SqlOnJson.java   View Source Code Vote up 4 votes
public Connection convert(JsonIterator jsonIterator) throws SQLException, ClassNotFoundException {
    Class.forName(driver);

    if (counter.get() > Integer.MAX_VALUE - 10) counter.set(0); // to avoid possible overflow, who knows =)
    final int id = counter.incrementAndGet();

    final Connection c = DriverManager.getConnection(url.replaceAll(INSTANCE_ID_PLACEHOLDER, String.valueOf(id)), username, password);
    try {
        final long start = System.currentTimeMillis();

        int countOfTables = 0;

        while (jsonIterator.hasNext()) {
            final JsonTable jsonTable = jsonIterator.next();

            if (jsonTable.data.size() == 0) continue;

            countOfTables++;

            List<ColumnType> columnTypes = new ArrayList<>();
            List<String> columnWithTypes = new ArrayList<>();
            List<String> columns = new ArrayList<>();

            final LinkedHashMap<String, ColumnType> cls = getColumns(jsonTable);

            final String sqlTableName = nameToSqlName(jsonTable.name);
            for (final Map.Entry<String, ColumnType> tt : cls.entrySet()) {
                columns.add(tt.getKey());
                columnTypes.add(tt.getValue());
                columnWithTypes.add(nameToSqlName(tt.getKey()) + " " + tt.getValue().getSqlName());
            }

            try (PreparedStatement ps = c.prepareStatement("create table " + sqlTableName + " (" + StringUtils.join(columnWithTypes, ", ") + ")")) {
                ps.execute();
            }

            String parameterPlaceholders = StringUtils.repeat("?", ",", cls.size());
            try (PreparedStatement ps = c.prepareStatement("insert into " + sqlTableName + " values (" + parameterPlaceholders + ")")) {
                for (int i = 0; i < jsonTable.data.size(); i++) {
                    JsonObject item = jsonTable.data.get(i).getAsJsonObject();
                    for (int cl = 1; cl <= cls.size(); cl++) {
                        JsonElement value = item.get(columns.get(cl - 1));
                        columnTypes.get(cl - 1).setToPs(ps, cl, value);
                    }
                    ps.execute();
                }
            }
        }


        LOGGER.info("JSON " + jsonIterator.getJsonLength() + " chars to SQL DB with "
                + countOfTables + " tables in " + (System.currentTimeMillis() - start) + " msec");
    } catch (Exception exception) {
        c.close();
        throw exception;
    }
    return c;
}
 
Example 19
Project: sierra   File: Codon69Handler.java   View Source Code Vote up 4 votes
public void apply() {
	// #26: leftAA and rightAA shouldn't overflow current sequence
	// or it will cause StringIndexOutOfBoundsException error
	int leftAA = Math.max(AA_WINDOW_LEFT_POS, firstAA);
	int rightAA = Math.min(
		AA_WINDOW_RIGHT_POS,
		firstAA + aaTripletLine.replace(" ", "").length() / 3);
	int magnetAA = AA_MAGNET_POS;
	if (magnetAA <= leftAA || magnetAA >= rightAA) {
		// magnetAA is outside of given sequence,
		// the code is still working but no need to re-align codons
		return;
	}

	int insertionCount;
	int leftNA = aaToNAPos(leftAA - firstAA);
	int rightNA = aaToNAPos(rightAA - firstAA);

	String control = "";
	String nas = alignedNAs.substring(leftNA, rightNA);
	String aaTriplet = aaTripletLine.substring(leftNA, rightNA);

	// step 1: remove all insertion dashes and spaces
	aaTriplet = aaTriplet.replace(" ", "");
	insertionCount = nas.length() - aaTriplet.length();
	if (insertionCount == 0) {
		return;
	}

	// step 2: re-generate control strings
	int tmpAALen = aaTriplet.length() / 3;
	for (int i=0; i < tmpAALen; i ++) {
		String na = nas.substring(i * 3, i * 3 + 3);
		String aa = aaTriplet.substring(i * 3, i * 3 + 3);
		// TODO: This may pollute the control line if there's any
		// frameshift inside the area. It's a bug and need to be fixed.
		control += CodonTranslation.generateControlString(na, aa);
	}

	// step 3: insert dashes
	int relMagnetNA = (magnetAA + 1 - leftAA) * 3;
	control =
		control.substring(0, relMagnetNA) +
		StringUtils.repeat("-", insertionCount) +
		control.substring(relMagnetNA);
	aaTriplet =
		aaTriplet.substring(0, relMagnetNA) +
		StringUtils.repeat(" ", insertionCount) +
		aaTriplet.substring(relMagnetNA);

	controlLine =
		controlLine.substring(0, leftNA) +
		control +
		controlLine.substring(rightNA);

	aaTripletLine =
		aaTripletLine.substring(0, leftNA) +
		aaTriplet +
		aaTripletLine.substring(rightNA);

	return;
}
 
Example 20
Project: galop   File: LineReaderTest.java   View Source Code Vote up 4 votes
@Test(expected = LineTooLargeException.class)
public void readLine_withLineLongerThanMaxSize_throwsLineTooLargeException() throws IOException {
    final String message = StringUtils.repeat('A', MAX_SIZE);
    final String line = message + "\r\n";
    createLineReader(line).readLine(MAX_SIZE);
}