/** * Converts property name to column name. */ public String convertPropertyNameToColumnName(final String propertyName) { StringBuilder tableName = new StringBuilder(propertyName.length() * 2); if (splitCamelCase) { String convertedTableName = Format.fromCamelCase(propertyName, separatorChar); tableName.append(convertedTableName); } else { tableName.append(propertyName); } if (!changeCase) { return tableName.toString(); } return uppercase ? toUppercase(tableName).toString() : toLowercase(tableName).toString(); }
public void out(final Chalk256 chalk256, final String string, final int maxLen) { System.out.print(chalk256.on(Format.alignLeftAndPad(string, maxLen))); }
@Override public String toString() { return super.toString() + "\nMax memory: " + Format.humanReadableByteCount(getMaxMemory(), false) + "\nTotal memory: " + Format.humanReadableByteCount(getTotalMemory(), false) + "\nFree memory: " + Format.humanReadableByteCount(getFreeMemory(), false) + "\nAvailableMemory memory: " + Format.humanReadableByteCount(getAvailableMemory(), false) + "\nProcess ID (PID): " + getCurrentPID(); }
sb.append(','); sb.append(toPrettyString(array[i])); sb.append(','); sb.append(toPrettyString(o)); i++;
@Test void testPadRight() { assertEquals(" 123", Format.alignRightAndPad("123", 6)); assertEquals("123", Format.alignRightAndPad("123", 3)); assertEquals("23", Format.alignRightAndPad("123", 2)); }
@Test void testTabsToSpaces() { String s = Format.convertTabsToSpaces("q\tqa\t", 3); assertEquals("q qa ", s); s = Format.convertTabsToSpaces("q\tqa\t", 0); assertEquals("qqa", s); }
@Test void testToPrettyString() { assertEquals(StringPool.NULL, Format.toPrettyString(null)); assertEquals("[A,B]", Format.toPrettyString(new String[]{"A", "B"})); assertEquals("[1,2]", Format.toPrettyString(new int[]{1,2})); assertEquals("[1,2]", Format.toPrettyString(new long[]{1,2})); assertEquals("[1,2]", Format.toPrettyString(new short[]{1,2})); assertEquals("[1,2]", Format.toPrettyString(new byte[]{1,2})); assertEquals("[1.0,2.0]", Format.toPrettyString(new double[]{1,2})); assertEquals("[1.0,2.0]", Format.toPrettyString(new float[]{1,2})); assertEquals("[true,false]", Format.toPrettyString(new boolean[] {true, false})); try { Format.toPrettyString(new char[]{'a','b'}); fail("error"); } catch (IllegalArgumentException e) { // ignore } assertEquals("[[1,2],[3,4]]", Format.toPrettyString(new int[][] {{1, 2}, {3, 4}})); List<Integer> list = new ArrayList<>(); list.add(1); list.add(4); assertEquals("{1,4}", Format.toPrettyString(list)); }
/** * Gets the value of a style property for the first element * in the set of matched elements. Returns <code>null</code> * if set is empty. */ public String css(String propertyName) { if (nodes.length == 0) { return null; } propertyName = Format.fromCamelCase(propertyName, '-'); String styleAttrValue = nodes[0].getAttribute("style"); if (styleAttrValue == null) { return null; } Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); return styles.get(propertyName); }
@Test void testPadLeft() { assertEquals("123 ", Format.alignLeftAndPad("123", 6)); assertEquals("123", Format.alignLeftAndPad("123", 3)); assertEquals("12", Format.alignLeftAndPad("123", 2)); }
@Test void testByteSizes_noSi() { assertEquals("10 B", Format.humanReadableByteCount(10, false)); assertEquals("1.0 KiB", Format.humanReadableByteCount(1024, false)); assertEquals("1.5 KiB", Format.humanReadableByteCount(1024 + 512, false)); }
sb.append(','); sb.append(toPrettyString(array[i])); sb.append(','); sb.append(toPrettyString(o)); i++;
/** * Converts entity (type) name to table name. */ public String convertEntityNameToTableName(String entityName) { int ndx = entityName.indexOf(entityNameTerminator); if (ndx != -1) { entityName = entityName.substring(0, ndx); } StringBuilder tableName = new StringBuilder(entityName.length() * 2); if (prefix != null) { tableName.append(prefix); } if (splitCamelCase) { String convertedTableName = Format.fromCamelCase(entityName, separatorChar); tableName.append(convertedTableName); } else { tableName.append(entityName); } if (suffix != null) { tableName.append(suffix); } if (!changeCase) { return tableName.toString(); } return uppercase ? toUppercase(tableName).toString() : toLowercase(tableName).toString(); }
public void out(final Chalk256 chalk256, final String string, final int maxLen) { System.out.print(chalk256.on(Format.alignLeftAndPad(string, maxLen))); }
@Override public String toString() { return super.toString() + "\nMax memory: " + Format.humanReadableByteCount(getMaxMemory(), false) + "\nTotal memory: " + Format.humanReadableByteCount(getTotalMemory(), false) + "\nFree memory: " + Format.humanReadableByteCount(getFreeMemory(), false) + "\nAvailableMemory memory: " + Format.humanReadableByteCount(getAvailableMemory(), false) + "\nProcess ID (PID): " + getCurrentPID(); }
/** * Sets one or more CSS properties for the set of matched elements. * By passing an empty value, that property will be removed. * Note that this is different from jQuery, where this means * that property will be reset to previous value if existed. */ public Jerry css(String propertyName, final String value) { propertyName = Format.fromCamelCase(propertyName, '-'); if (nodes.length == 0) { return this; } for (Node node : nodes) { String styleAttrValue = node.getAttribute("style"); Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); if (value.length() == 0) { styles.remove(propertyName); } else { styles.put(propertyName, value); } styleAttrValue = generateAttributeValue(styles, ';', ':'); node.setAttribute("style", styleAttrValue); } return this; }
/** * Sets one or more CSS properties for the set of matched elements. */ public Jerry css(final String... css) { if (nodes.length == 0) { return this; } for (Node node : nodes) { String styleAttrValue = node.getAttribute("style"); Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); for (int i = 0; i < css.length; i += 2) { String propertyName = css[i]; propertyName = Format.fromCamelCase(propertyName, '-'); String value = css[i + 1]; if (value.length() == 0) { styles.remove(propertyName); } else { styles.put(propertyName, value); } } styleAttrValue = generateAttributeValue(styles, ';', ':'); node.setAttribute("style", styleAttrValue); } return this; }
@Test void testFromCamelCase() { assertEquals("one two three", Format.fromCamelCase("oneTwoThree", ' ')); assertEquals("one-two-three", Format.fromCamelCase("oneTwoThree", '-')); assertEquals("one. two. three", Format.fromCamelCase("one.Two.Three", ' ')); assertEquals("user_name", Format.fromCamelCase("userName", '_')); assertEquals("user_name", Format.fromCamelCase("UserName", '_')); assertEquals("user_name", Format.fromCamelCase("USER_NAME", '_')); assertEquals("user_name", Format.fromCamelCase("user_name", '_')); assertEquals("user", Format.fromCamelCase("user", '_')); assertEquals("user", Format.fromCamelCase("User", '_')); assertEquals("user", Format.fromCamelCase("USER", '_')); assertEquals("user", Format.fromCamelCase("_user", '_')); assertEquals("user", Format.fromCamelCase("_User", '_')); assertEquals("_user", Format.fromCamelCase("__user", '_')); assertEquals("user__name", Format.fromCamelCase("user__name", '_')); }
/** * Converts property name to column name. */ public String convertPropertyNameToColumnName(final String propertyName) { StringBuilder tableName = new StringBuilder(propertyName.length() * 2); if (splitCamelCase) { String convertedTableName = Format.fromCamelCase(propertyName, separatorChar); tableName.append(convertedTableName); } else { tableName.append(propertyName); } if (!changeCase) { return tableName.toString(); } return uppercase ? toUppercase(tableName).toString() : toLowercase(tableName).toString(); }
/** * Gets the value of a style property for the first element * in the set of matched elements. Returns <code>null</code> * if set is empty. */ public String css(String propertyName) { if (nodes.length == 0) { return null; } propertyName = Format.fromCamelCase(propertyName, '-'); String styleAttrValue = nodes[0].getAttribute("style"); if (styleAttrValue == null) { return null; } Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); return styles.get(propertyName); }
/** * Converts entity (type) name to table name. */ public String convertEntityNameToTableName(String entityName) { int ndx = entityName.indexOf(entityNameTerminator); if (ndx != -1) { entityName = entityName.substring(0, ndx); } StringBuilder tableName = new StringBuilder(entityName.length() * 2); if (prefix != null) { tableName.append(prefix); } if (splitCamelCase) { String convertedTableName = Format.fromCamelCase(entityName, separatorChar); tableName.append(convertedTableName); } else { tableName.append(entityName); } if (suffix != null) { tableName.append(suffix); } if (!changeCase) { return tableName.toString(); } return uppercase ? toUppercase(tableName).toString() : toLowercase(tableName).toString(); }