Example usage for java.util FormattableFlags UPPERCASE

List of usage examples for java.util FormattableFlags UPPERCASE

Introduction

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

Prototype

int UPPERCASE

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

Click Source Link

Document

Converts the output to upper case according to the rules of the java.util.Locale locale given during creation of the formatter argument of the Formattable#formatTo formatTo() method.

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.j  a  v a 2 s . c o  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;/* w w w  .  java  2  s .c  om*/
    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  v a  2s  . com*/
        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  w  ww .  ja va  2s .c om
        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 a  2 s .c o m

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

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