Java Code Examples for org.apache.brooklyn.util.text.Strings#makePaddedString()
The following examples show how to use
org.apache.brooklyn.util.text.Strings#makePaddedString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Yamls.java From brooklyn-server with Apache License 2.0 | 6 votes |
/** Returns the original YAML with the found item replaced by the given replacement YAML. * @param replacement YAML to put in for the found item; * this YAML typically should not have any special indentation -- if required when replacing it will be inserted. * <p> * if replacing an inline map entry, the supplied entry must follow the structure being replaced; * for example, if replacing the value in <code>key: value</code> with a map, * supplying a replacement <code>subkey: value</code> would result in invalid yaml; * the replacement must be supplied with a newline, either before the subkey or after. * (if unsure we believe it is always valid to include an initial newline or comment with newline.) */ public String getFullYamlTextWithExtractReplaced(String replacement) { if (!found()) throw new IllegalStateException("Cannot perform replacement when item was not matched."); String result = yaml.substring(0, getStartOfThis()); String[] newLines = replacement.split("\n"); for (int i=1; i<newLines.length; i++) newLines[i] = Strings.makePaddedString("", getStartColumnOfThis(), "", " ") + newLines[i]; result += Strings.lines(newLines); if (replacement.endsWith("\n")) result += "\n"; int end = getEndOfThis(); result += yaml.substring(end); return result; }
Example 2
Source File: Time.java From brooklyn-server with Apache License 2.0 | 5 votes |
private static String toDecimal(long intPart, double fracPart, int decimalPrecision) { long powTen = 1; for (int i=0; i<decimalPrecision; i++) powTen *= 10; long fpr = Math.round(fracPart * powTen); if (fpr==powTen) { intPart++; fpr = 0; } return intPart + "." + Strings.makePaddedString(""+fpr, decimalPrecision, "0", ""); }
Example 3
Source File: Time.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** as {@link #getTimeZoneOffsetString(String, int, int, int)} where the {@link TimeZone} is already instantiated */ @SuppressWarnings("deprecation") public static String getTimeZoneOffsetString(TimeZone tz, int year, int month, int day) { int tzMins = tz.getOffset(new Date(year, month, day).getTime())/60/1000; String tzStr = (tzMins<0 ? "-" : "+") + Strings.makePaddedString(""+(Math.abs(tzMins)/60), 2, "0", "")+Strings.makePaddedString(""+(Math.abs(tzMins)%60), 2, "0", ""); return tzStr; }