Example usage for java.util Formatter locale

List of usage examples for java.util Formatter locale

Introduction

In this page you can find the example usage for java.util Formatter locale.

Prototype

public Locale locale() 

Source Link

Document

Returns the locale set by the construction of this formatter.

Usage

From source file:Main.java

public static void main(String[] args) {

    StringBuffer buffer = new StringBuffer();
    Formatter formatter = new Formatter(buffer, Locale.US);

    // format a new string
    String name = "from java2s.com";
    formatter.format("Hello %s !", name);

    // print the formatted string with default locale
    System.out.println(formatter + " " + formatter.locale());

}

From source file:Main.java

public static void main(String[] args) {

    StringBuffer buffer = new StringBuffer();
    Formatter formatter = new Formatter(buffer, Locale.US);

    // format a new string
    String name = "from java2s.com";
    formatter.format(Locale.US, "Hello %s !", name);

    // print the formatted string with specified locale
    System.out.println(formatter + " " + formatter.locale());

}

From source file:Main.java

public static void main(String[] args) {

    StringBuffer buffer = new StringBuffer();
    Formatter formatter = new Formatter(buffer, Locale.US);

    // format a new string
    String name = "from java2s.com";
    formatter.format("Hello %s !", name);

    // print the formatted string with default locale
    System.out.println(formatter);

    System.out.println(formatter.locale());
}

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 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 va  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 w w  w . j a v a2s  .  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  ww  w  .j a va 2s.c  om

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

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