Java Formatter Usage substitution(Formatter formatter, int flags, int width, int precision, StringBuilder obj)

Here you can find the source of substitution(Formatter formatter, int flags, int width, int precision, StringBuilder obj)

Description

substitution

License

Mozilla Public License

Declaration

public static void substitution(Formatter formatter, int flags, int width, int precision, StringBuilder obj) 

Method Source Code


//package com.java2s;
//License from project: Mozilla Public License 

import java.util.FormattableFlags;
import java.util.Formatter;

public class Main {
    public static void substitution(Formatter formatter, int flags, int width, int precision, StringBuilder obj) {
        StringBuilder sb = new StringBuilder(obj.length());
        if (precision == -1 || obj.length() < precision) {
            sb.append(obj.toString());//from w  w  w .j  a v  a  2  s  .c  o  m
        } else {
            sb.append(obj.substring(0, precision - 3)).append("...");
        }

        final int L = sb.length();
        if (L < width) {
            for (int i = 0; i < width - L; i++) {
                if ((flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags.LEFT_JUSTIFY) {
                    sb.append(' ');
                } else {
                    sb.insert(0, ' ');
                }
            }
        }
        formatter.format(sb.toString());
    }
}

Related

  1. long2Mac(final long macAddress)
  2. millisToHumanTime(long milliseconds)
  3. msToHumanReadableDelta(long start)
  4. numberWithLeadingZeroes(int n, int totalChars)
  5. showVxlanHeaderOutput()
  6. toHexString(final byte[] data)
  7. toReadableSize(long bytes)
  8. toTwoDigit(double f)
  9. toUUIDFormat(byte[] bytes)