/** * Represents this token as a String. * * @return String representation of the token */ @Override public String toString() { return StringUtils.repeat(this.value.toString(), this.count); } }
/** * <p>Repeat a String {@code repeat} times to form a * new String, with a String separator injected each time. </p> * * <pre> * StringUtils.repeat(null, null, 2) = null * StringUtils.repeat(null, "x", 2) = null * StringUtils.repeat("", null, 0) = "" * StringUtils.repeat("", "", 2) = "" * StringUtils.repeat("", "x", 3) = "xxx" * StringUtils.repeat("?", ", ", 3) = "?, ?, ?" * </pre> * * @param str the String to repeat, may be null * @param separator the String to inject, may be null * @param repeat number of times to repeat str, negative treated as zero * @return a new String consisting of the original String repeated, * {@code null} if null String input * @since 2.5 */ public static String repeat(final String str, final String separator, final int repeat) { if(str == null || separator == null) { return repeat(str, repeat); } // given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it final String result = repeat(str + separator, repeat); return removeEnd(result, separator); }
private String getStringForDisplay(String memoryStr) { int numSpacesToPad = MEMORY_STR_LEN - memoryStr.length(); return memoryStr + StringUtils.repeat(" ", numSpacesToPad); } }
private static StringBuilder newLine(StringBuilder builder, int indentDepth) { return builder.append("\n").append(StringUtils.repeat(' ', indentDepth)); } }
private static String whitespace( int numberOfWhitespaces ) { return StringUtils.repeat( " ", numberOfWhitespaces ); } }
/** * Push the input string to the right by appending a character before it, usually a space. * @param input the string to pad * @param padding the character to repeat to the left of the input string * @param length the desired total length including the padding * @return padding characters + input */ public static String padFront(String input, char padding, int length) { if (input.length() > length) { throw new IllegalArgumentException("input \"" + input + "\" longer than maxLength=" + length); } int numPaddingCharacters = length - input.length(); return StringUtils.repeat(padding, numPaddingCharacters) + input; } }
private static String getGenericTypeTree(Class<?> type, int indent) { String ret = ""; for (Field field : type.getDeclaredFields()) { if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) { continue; } ret += StringUtils.repeat(' ', indent) + field.getName() + ":" + field.getType().getName() + (field.getType().isEnum() ? " (is enum)" : "") + "\n"; if (!field.getType().isPrimitive()) { ret += getGenericTypeTree(field.getType(), indent + 4); } } return ret; }
@Override public String getCommandUsage() { StringBuffer sbuf = new StringBuffer(USAGE_PREFIX + COMMANDS); String banner = StringUtils.repeat("=", 66); sbuf.append(banner + "\n"); sbuf.append(CreateCommand.USAGE + ":\n\n" + CreateCommand.DESC + "\n"); sbuf.append(banner + "\n"); sbuf.append(DeleteCommand.USAGE + ":\n\n" + DeleteCommand.DESC + "\n"); sbuf.append(banner + "\n"); sbuf.append(ListCommand.USAGE + ":\n\n" + ListCommand.DESC + "\n"); return sbuf.toString(); }
protected String toString(int tabs) { StringBuilder sb = new StringBuilder(); if (MapUtils.isNotEmpty(map)) { sb.append("{\n"); for (Map.Entry<String, Object> entry : map.entrySet()) { sb.append(getString(entry.getKey(), entry.getValue(), tabs+1)); } sb.append(StringUtils.repeat(" ", (tabs-1)*2)).append("}"); } return sb.toString(); }
private static <T> String getSerializerTree(TypeInformation<T> ti, int indent) { String ret = ""; if (ti instanceof CompositeType) { ret += StringUtils.repeat(' ', indent) + ti.getClass().getSimpleName() + "\n"; CompositeType<T> cti = (CompositeType<T>) ti; String[] fieldNames = cti.getFieldNames(); for (int i = 0; i < cti.getArity(); i++) { TypeInformation<?> fieldType = cti.getTypeAt(i); ret += StringUtils.repeat(' ', indent + 2) + fieldNames[i] + ":" + getSerializerTree(fieldType, indent); } } else { if (ti instanceof GenericTypeInfo) { ret += StringUtils.repeat(' ', indent) + "GenericTypeInfo (" + ti.getTypeClass().getSimpleName() + ")\n"; ret += getGenericTypeTree(ti.getTypeClass(), indent + 4); } else { ret += StringUtils.repeat(' ', indent) + ti.toString() + "\n"; } } return ret; }
private static void printBlankKeyWarning() { logger.error(StringUtils.repeat("*", 80)); logger.error(centerString("A blank sensitive properties key was provided")); logger.error(centerString("Specify a unique key in nifi.properties")); logger.error(centerString("for nifi.sensitive.props.key")); logger.error(centerString("")); logger.error(centerString("The Encrypt Config Tool in NiFi Toolkit can be used to")); logger.error(centerString("migrate the flow to the new key")); logger.error(StringUtils.repeat("*", 80)); }
@Test public void testRepeat_StringStringInt() { assertNull(StringUtils.repeat(null, null, 2)); assertNull(StringUtils.repeat(null, "x", 2)); assertEquals("", StringUtils.repeat("", null, 2)); assertEquals("", StringUtils.repeat("ab", "", 0)); assertEquals("", StringUtils.repeat("", "", 2)); assertEquals("xx", StringUtils.repeat("", "x", 3)); assertEquals("?, ?, ?", StringUtils.repeat("?", ", ", 3)); }
@Test public void testRepeat_StringInt() { assertNull(StringUtils.repeat(null, 2)); assertEquals("", StringUtils.repeat("ab", 0)); assertEquals("", StringUtils.repeat("", 3)); assertEquals("aaa", StringUtils.repeat("a", 3)); assertEquals("", StringUtils.repeat("a", -2)); assertEquals("ababab", StringUtils.repeat("ab", 3)); assertEquals("abcabcabc", StringUtils.repeat("abc", 3)); final String str = StringUtils.repeat("a", 10000); // bigger than pad limit assertEquals(10000, str.length()); assertTrue(StringUtils.containsOnly(str, 'a')); }
private void progress(int index) { if (printer.isBroken()) { return; } final int rate = computeRate(index); printer.print(String.format("\r%s[%-" + width + "s]", prefix, StringUtils.repeat('#', rate))); printer.flush(); }
@Test public void shouldTrimDownLogFileNameToAReasonableSizeIfThePluginIdIsTooBig() throws Exception { assertPluginLogFile("abcd", "plugin-abcd.log"); String pluginIdWithLengthOf189 = repeat("a", 189); assertPluginLogFile(pluginIdWithLengthOf189, "plugin-" + pluginIdWithLengthOf189 + ".log"); String pluginIdWithLengthOf190 = repeat("a", 190); assertPluginLogFile(pluginIdWithLengthOf190, "plugin-" + pluginIdWithLengthOf189 + ".log"); String pluginIdWithLengthOf200 = repeat("a", 200); assertPluginLogFile(pluginIdWithLengthOf200, "plugin-" + pluginIdWithLengthOf189 + ".log"); }
private void printTypeNodeText(Node<? extends Type> node, int level) { String indent = StringUtils.repeat(" ", level); Type type = node.data(); output().printf("% 4d: %s%s %s (metaFlag: %x)%n", type.index(), indent, type.typeName(), type.fieldName(), type.metaFlag()); node.forEach(t -> printTypeNodeText(t, level + 1)); }
@Test public void testOverflow() { String text = StringUtils.repeat("h", 21); ExtendedColumnSerializer serializer = new ExtendedColumnSerializer(DataType.getType("extendedcolumn(20)")); MeasureIngester<ByteArray> ingester = measureType.newIngester(); ByteArray array = ingester.valueOf(new String[] { null, text }, null, null); ByteBuffer buffer = ByteBuffer.allocate(serializer.maxLength()); serializer.serialize(array, buffer); buffer.flip(); ByteArray des = serializer.deserialize(buffer); Assert.assertTrue(new ByteArray(StringUtils.repeat("h", 20).getBytes(StandardCharsets.UTF_8)).equals(des)); } }
@Test(timeout = 1000) public void shouldValidateLeadingAndTrailingSpacesOnExecCommandInReasonableTime() throws Exception { // See https://github.com/gocd/gocd/issues/3551 // This is only reproducible on longish strings, so don't try shortening the exec task length... String longPath = StringUtils.repeat("f", 100); CruiseConfig config = GoConfigMother.configWithPipelines("pipeline1"); config.findJob("pipeline1", "stage", "job").addTask(new ExecTask(longPath + " ", "arg1", (String) null)); output = new ByteArrayOutputStream(); try { xmlWriter.write(config, output, false); fail("expected to blow up"); } catch (XsdValidationException e) { assertThat(e.getMessage(), containsString("should conform to the pattern - \\S(.*\\S)?")); } }
@Test public void testNormal() { String text = StringUtils.repeat("h", 20); ExtendedColumnSerializer serializer = new ExtendedColumnSerializer(DataType.getType("extendedcolumn(20)")); MeasureIngester<ByteArray> ingester = measureType.newIngester(); ByteArray array = ingester.valueOf(new String[] { null, text }, null, null); ByteBuffer buffer = ByteBuffer.allocate(serializer.maxLength()); serializer.serialize(array, buffer); buffer.flip(); ByteArray des = serializer.deserialize(buffer); Assert.assertTrue(new ByteArray(text.getBytes(StandardCharsets.UTF_8)).equals(des)); }