Example usage for java.util FormattableFlags ALTERNATE

List of usage examples for java.util FormattableFlags ALTERNATE

Introduction

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

Prototype

int ALTERNATE

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

Click Source Link

Document

Requires the output to use an alternate form.

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 w  w .  ja  v a  2  s . co  m*/
    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  a2s. 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)//from  w  w w  .ja v  a 2  s .c om
        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)/*from   ww w  .jav  a 2s.  c  o  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;/* w w w  .ja v a2s .  co  m*/

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

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