private static String indentString(int indent) { return Strings.repeat(INDENT, indent); } }
private static String indentString(int indent) { return Strings.repeat(" ", indent); }
/** * Format an indeterminate progress bar: [ <=> ] */ public static String formatProgressBar(int width, int tick) { int markerWidth = 3; // must be odd >= 3 (1 for each < and > marker, the rest for "=" int range = width - markerWidth; // "lower" must fall within this range for the marker to fit within the bar int lower = tick % range; if (((tick / range) % 2) == 1) { // are we going or coming back? lower = range - lower; } return repeat(" ", lower) + "<" + repeat("=", markerWidth - 2) + ">" + repeat(" ", width - (lower + markerWidth)); }
private void print(Integer indentLevel, String value) { out.println(Strings.repeat(INDENT, indentLevel) + value); } }
private static String center(String s, int maxWidth, int padding) { int width = consoleWidth(s); checkState(width <= maxWidth, "string width is greater than max width"); int left = (maxWidth - width) / 2; int right = maxWidth - (left + width); return repeat(" ", left + padding) + s + repeat(" ", right + padding); }
private void appendLine(String template, Object... arguments) { result.append(repeat("\t", level)).append(format(template + "\n", arguments)); } }
private static String align(String s, int maxWidth, int padding, boolean right) { int width = consoleWidth(s); checkState(width <= maxWidth, "string width is greater than max width"); String large = repeat(" ", (maxWidth - width) + padding); String small = repeat(" ", padding); return right ? (large + s + small) : (small + s + large); }
private static String indentString(int indent) { return Strings.repeat(" ", indent); }
private List<String> createVarcharValuesNoNull() { List<String> values = new ArrayList<>(); for (int i = 0; i < ROWS; ++i) { values.add(Strings.repeat("0", 4)); } return values; } }
public void testRepeat_null() { try { Strings.repeat(null, 5); fail(); } catch (NullPointerException expected) { } }
private void output(int indent, String message, Object... args) { String formattedMessage = format(message, args); result.append(format("%s%s\n", Strings.repeat(" ", indent), formattedMessage)); } }
private List<String> createVarcharValuesWithNulls() { Random random = new Random(); List<String> values = new ArrayList<>(); for (int i = 0; i < ROWS; ++i) { if (random.nextBoolean()) { values.add(Strings.repeat("0", 4)); } else { values.add(null); } } return values; } }
public void testRepeat() { String input = "20"; assertEquals("", Strings.repeat(input, 0)); assertEquals("20", Strings.repeat(input, 1)); assertEquals("2020", Strings.repeat(input, 2)); assertEquals("202020", Strings.repeat(input, 3)); assertEquals("", Strings.repeat("", 4)); for (int i = 0; i < 100; ++i) { assertEquals(2 * i, Strings.repeat(input, i).length()); } try { Strings.repeat("x", -1); fail(); } catch (IllegalArgumentException expected) { } try { // Massive string Strings.repeat("12345678", (1 << 30) + 3); fail(); } catch (ArrayIndexOutOfBoundsException expected) { } }
@Test public void testDeallocate() throws Exception { try (Connection connection = createConnection()) { for (int i = 0; i < 200; i++) { try { connection.prepareStatement("SELECT '" + repeat("a", 300) + "'").close(); } catch (Exception e) { throw new RuntimeException("Failed at " + i, e); } } } }
public void testReallySimpleFingerprints() { assertEquals(8581389452482819506L, fingerprint("test".getBytes(UTF_8))); // 32 characters long assertEquals(-4196240717365766262L, fingerprint(Strings.repeat("test", 8).getBytes(UTF_8))); // 256 characters long assertEquals(3500507768004279527L, fingerprint(Strings.repeat("test", 64).getBytes(UTF_8))); }
/** * Test for Guava issue 1061: http://code.google.com/p/guava-libraries/issues/detail?id=1061 * * <p>CharStreams.copy was failing to clear its CharBuffer after each read call, which effectively * reduced the available size of the buffer each time a call to read didn't fill up the available * space in the buffer completely. In general this is a performance problem since the buffer size * is permanently reduced, but with certain Reader implementations it could also cause the buffer * size to reach 0, causing an infinite loop. */ public void testCopyWithReaderThatDoesNotFillBuffer() throws IOException { // need a long enough string for the buffer to hit 0 remaining before the copy completes String string = Strings.repeat("0123456789", 100); StringBuilder b = new StringBuilder(); // the main assertion of this test is here... the copy will fail if the buffer size goes down // each time it is not filled completely long copied = CharStreams.copy(newNonBufferFillingReader(new StringReader(string)), b); assertEquals(string, b.toString()); assertEquals(string.length(), copied); }
private void reallyTestAllMatches(CharMatcher matcher, CharSequence s) { assertTrue(matcher.matches(s.charAt(0))); assertEquals(0, matcher.indexIn(s)); assertEquals(0, matcher.indexIn(s, 0)); assertEquals(1, matcher.indexIn(s, 1)); assertEquals(-1, matcher.indexIn(s, s.length())); assertEquals(s.length() - 1, matcher.lastIndexIn(s)); assertTrue(matcher.matchesAnyOf(s)); assertTrue(matcher.matchesAllOf(s)); assertFalse(matcher.matchesNoneOf(s)); assertEquals("", matcher.removeFrom(s)); assertEquals(Strings.repeat("z", s.length()), matcher.replaceFrom(s, 'z')); assertEquals(Strings.repeat("ZZ", s.length()), matcher.replaceFrom(s, "ZZ")); assertEquals("", matcher.trimFrom(s)); assertEquals(s.length(), matcher.countIn(s)); }
private static void printStatement(String sql) { println(sql.trim()); println(""); ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE /* anything */); Statement statement = SQL_PARSER.createStatement(sql, parsingOptions); println(statement.toString()); println(""); println(SqlFormatter.formatSql(statement, Optional.empty())); println(""); assertFormattedSql(SQL_PARSER, statement); println(repeat("=", 60)); println(""); }
private DataTypeTest mysqlCharTypeTest() { return DataTypeTest.create() .addRoundTrip(charDataType("char", 1), "") .addRoundTrip(charDataType("char", 1), "a") .addRoundTrip(charDataType(1), "") .addRoundTrip(charDataType(1), "a") .addRoundTrip(charDataType(8), "abc") .addRoundTrip(charDataType(8), "12345678") .addRoundTrip(charDataType(255), repeat("a", 255)); }