Example usage for java.util FormattableFlags LEFT_JUSTIFY

List of usage examples for java.util FormattableFlags LEFT_JUSTIFY

Introduction

In this page you can find the example usage for java.util FormattableFlags LEFT_JUSTIFY.

Prototype

int LEFT_JUSTIFY

To view the source code for java.util FormattableFlags LEFT_JUSTIFY.

Click Source Link

Document

Left-justifies the output.

Usage

From source file:MyFormattableObject.java

public void formatTo(Formatter formatter, int flags, int width, int precision) {
    int alternateFlagValue = FormattableFlags.ALTERNATE & flags;
    if (alternateFlagValue == FormattableFlags.ALTERNATE) {
        System.out.println("FormattableFlags.ALTERNATE");
    }//w ww.j  av a  2s. com
    int upperFlagValue = FormattableFlags.UPPERCASE & flags;
    if (upperFlagValue == FormattableFlags.UPPERCASE) {
        System.out.println(FormattableFlags.UPPERCASE);
    }
    int leftJustifiedFlagValue = FormattableFlags.LEFT_JUSTIFY & flags;
    if (leftJustifiedFlagValue == FormattableFlags.LEFT_JUSTIFY) {
        System.out.println("Left-justified flag '-' is used");
    } else {
        System.out.println("Left-justified flag '-' is not used");
    }

    formatter.format("value");
}

From source file:net.dv8tion.jda.core.entities.impl.UserImpl.java

@Override
public void formatTo(Formatter formatter, int flags, int width, int precision) {
    boolean alt = (flags & FormattableFlags.ALTERNATE) == FormattableFlags.ALTERNATE;
    boolean upper = (flags & FormattableFlags.UPPERCASE) == FormattableFlags.UPPERCASE;
    boolean leftJustified = (flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags.LEFT_JUSTIFY;

    String out;//from ww w  . j  a  v a  2 s.c  o m
    if (!alt)
        out = getAsMention();
    else if (upper)
        out = String.format(formatter.locale(), "%S#%s", getName(), getDiscriminator());
    else
        out = String.format(formatter.locale(), "%s#%s", getName(), getDiscriminator());

    MiscUtil.appendTo(formatter, width, precision, leftJustified, out);
}

From source file:net.dv8tion.jda.core.entities.impl.MessageImpl.java

@Override
public void formatTo(Formatter formatter, int flags, int width, int precision) {
    boolean upper = (flags & FormattableFlags.UPPERCASE) == FormattableFlags.UPPERCASE;
    boolean leftJustified = (flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags.LEFT_JUSTIFY;
    boolean alt = (flags & FormattableFlags.ALTERNATE) == FormattableFlags.ALTERNATE;

    String out = alt ? getRawContent() : getContent();

    if (upper)// w w  w.j  a va2  s . co m
        out = out.toUpperCase(formatter.locale());

    try {
        Appendable appendable = formatter.out();
        if (precision > -1 && out.length() > precision) {
            appendable.append(Helpers.truncate(out, precision - 3)).append("...");
            return;
        }

        if (leftJustified)
            appendable.append(Helpers.rightPad(out, width));
        else
            appendable.append(Helpers.leftPad(out, width));
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}

From source file:net.dv8tion.jda.core.entities.impl.ReceivedMessage.java

@Override
public void formatTo(Formatter formatter, int flags, int width, int precision) {
    boolean upper = (flags & FormattableFlags.UPPERCASE) == FormattableFlags.UPPERCASE;
    boolean leftJustified = (flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags.LEFT_JUSTIFY;
    boolean alt = (flags & FormattableFlags.ALTERNATE) == FormattableFlags.ALTERNATE;

    String out = alt ? getContentRaw() : getContentDisplay();

    if (upper)//  www.  j a  va2  s.co m
        out = out.toUpperCase(formatter.locale());

    appendFormat(formatter, width, precision, leftJustified, out);
}

From source file:net.dv8tion.jda.core.entities.MessageChannel.java

@Override
default void formatTo(Formatter formatter, int flags, int width, int precision) {
    boolean leftJustified = (flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags.LEFT_JUSTIFY;
    boolean upper = (flags & FormattableFlags.UPPERCASE) == FormattableFlags.UPPERCASE;
    boolean alt = (flags & FormattableFlags.ALTERNATE) == FormattableFlags.ALTERNATE;
    String out;/*from  w ww  . j  ava2 s.  co  m*/

    out = upper ? getName().toUpperCase(formatter.locale()) : getName();
    if (alt)
        out = "#" + out;

    MiscUtil.appendTo(formatter, width, precision, leftJustified, out);
}