Java 类java.util.FormattableFlags 实例源码

项目:FJ-VDMJ    文件:CharacterValue.java   
@Override
public void formatTo(Formatter formatter, int flags, int width, int precision)
{
    String s = null;

    if ((flags & FormattableFlags.ALTERNATE) > 0)
    {
        s = toString();
    }
    else
    {
        s = "" + unicode;
    }

    formatTo(s, formatter, flags, width, precision);
}
项目:FJ-VDMJ    文件:CharacterValue.java   
@Override
public void formatTo(Formatter formatter, int flags, int width, int precision)
{
    String s = null;

    if ((flags & FormattableFlags.ALTERNATE) > 0)
    {
        s = toString();
    }
    else
    {
        s = "" + unicode;
    }

    formatTo(s, formatter, flags, width, precision);
}
项目:JDA    文件: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;
    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);
}
项目:vdmj    文件:CharacterValue.java   
@Override
public void formatTo(Formatter formatter, int flags, int width, int precision)
{
    String s = null;

    if ((flags & FormattableFlags.ALTERNATE) > 0)
    {
        s = toString();
    }
    else
    {
        s = "" + unicode;
    }

    formatTo(s, formatter, flags, width, precision);
}
项目:jcabi-log    文件:SecretDecor.java   
@Override
public void formatTo(final Formatter formatter, final int flags,
    final int width, final int precision) {
    if (this.secret == null) {
        formatter.format("NULL");
    } else {
        final StringBuilder fmt = new StringBuilder(10);
        fmt.append('%');
        if ((flags & FormattableFlags.LEFT_JUSTIFY) != 0) {
            fmt.append('-');
        }
        if (width != 0) {
            fmt.append(width);
        }
        if ((flags & FormattableFlags.UPPERCASE) == 0) {
            fmt.append('s');
        } else {
            fmt.append('S');
        }
        formatter.format(
            fmt.toString(),
            SecretDecor.scramble(this.secret)
        );
    }
}
项目:jcabi-log    文件:AbstractDecorTest.java   
/**
 * AbstractDecor can convert object to text, via Logger.
 * @throws Exception If some problem inside
 */
@Test
public final void convertsDifferentFormatsViaLogger() throws Exception {
    final StringBuilder format = new StringBuilder();
    format.append('%');
    if ((this.flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags
        .LEFT_JUSTIFY) {
        format.append('-');
    }
    if (this.width > 0) {
        format.append(Integer.toString(this.width));
    }
    if (this.precision > 0) {
        format.append('.').append(Integer.toString(this.precision));
    }
    if ((this.flags & FormattableFlags.UPPERCASE) == FormattableFlags
        .UPPERCASE) {
        format.append('S');
    } else {
        format.append('s');
    }
    MatcherAssert.assertThat(
        Logger.format(format.toString(), this.decor()),
        Matchers.equalTo(this.text)
    );
}
项目:jcabi-log    文件:SizeDecorTest.java   
/**
 * Params for this parametrized test.
 * @return Array of arrays of params for ctor
 */
@Parameters
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public static Collection<Object[]> params() {
    return Arrays.asList(
        new Object[][] {
            // @checkstyle MagicNumber (14 lines)
            {null, "NULL", 0, 0, 0},
            {1L, "1b", 0, 0, 0},
            {123L, "  123b", 0, 6, 0},
            {1024L, "1.000Kb", 0, 0, 3},
            {5120L, "5Kb", 0, 0, 0},
            {12345L, "12.056Kb", 0, 0, 3},
            {12345L, "12.1Kb  ", FormattableFlags.LEFT_JUSTIFY, 8, 1},
            {98765432L, "94.190MB", FormattableFlags.UPPERCASE, 0, 3},
            {98765432L, "94.190Mb", 0, 0, 3},
            {90L * 1024 * 1024 * 1024, "90Gb", 0, 0, 0},
            {13L * 1024 * 1024 * 1024 * 1024, "13Tb", 0, 0, 0},
            {33L * 1024 * 1024 * 1024 * 1024 * 1024, "33Pb", 0, 0, 0},
            {3L * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, "3Eb", 0, 0, 0},
        }
    );
}
项目:jcabi-log    文件:MsDecorTest.java   
/**
 * Params for this parametrized test.
 * @return Array of arrays of params for ctor
 */
@Parameters
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public static Collection<Object[]> params() {
    return Arrays.asList(
        new Object[][] {
            // @checkstyle LineLength (20 lines)
            // @checkstyle MagicNumber (20 lines)
            {null, "NULL", 0, 0, 0},
            {13L, "13ms", 0, 0, -1},
            {13L, "13.0ms", 0, 0, 1},
            {1024L, "1s", 0, 0, 0},
            {6001L, "6.0010s", 0, 0, 4},
            {122001L, "  2MIN", FormattableFlags.UPPERCASE, 6, 0},
            {3789003L, "1hr", 0, 0, 0},
            {86400000L, "1days", 0, 0, 0},
            {864000000L, "10days", 0, 0, 0},
        }
    );
}
项目:FJ-VDMJ    文件:SeqValue.java   
@Override
public void formatTo(Formatter formatter, int flags, int width, int precision)
{
    String s = values.toString();

    if ((flags & FormattableFlags.ALTERNATE) == 0 && s.charAt(0) == '"')
    {
        s = s.substring(1, s.length()-1);
    }

    formatTo(s, formatter, flags, width, precision);
}
项目:FJ-VDMJ    文件:Value.java   
protected void formatTo(String value, Formatter formatter, int flags, int width, int precision)
{
    StringBuilder sb = new StringBuilder("%");

    switch (flags)
    {
        case FormattableFlags.LEFT_JUSTIFY:
            sb.append('-');
            break;

        case FormattableFlags.ALTERNATE:
            sb.append('#');
            break;
    }

    if (width > 0)
    {
        sb.append(width);
    }

    if (precision > 0)
    {
        sb.append('.');
        sb.append(precision);
    }

    sb.append('s');

    formatter.format(sb.toString(), value);
}
项目:FJ-VDMJ    文件:SeqValue.java   
@Override
public void formatTo(Formatter formatter, int flags, int width, int precision)
{
    String s = values.toString();

    if ((flags & FormattableFlags.ALTERNATE) == 0 && s.charAt(0) == '"')
    {
        s = s.substring(1, s.length()-1);
    }

    formatTo(s, formatter, flags, width, precision);
}
项目:FJ-VDMJ    文件:Value.java   
protected void formatTo(String value, Formatter formatter, int flags, int width, int precision)
{
    StringBuilder sb = new StringBuilder("%");

    switch (flags)
    {
        case FormattableFlags.LEFT_JUSTIFY:
            sb.append('-');
            break;

        case FormattableFlags.ALTERNATE:
            sb.append('#');
            break;
    }

    if (width > 0)
    {
        sb.append(width);
    }

    if (precision > 0)
    {
        sb.append('.');
        sb.append(precision);
    }

    sb.append('s');

    formatter.format(sb.toString(), value);
}
项目:JDA    文件:IMentionable.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;
    String out = upper ? getAsMention().toUpperCase(formatter.locale()) : getAsMention();

    MiscUtil.appendTo(formatter, width, precision, leftJustified, out);
}
项目:JDA    文件:AbstractMessage.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;

    String out = content;

    if (upper)
        out = out.toUpperCase(formatter.locale());

    appendFormat(formatter, width, precision, leftJustified, out);
}
项目:JDA    文件:TextChannel.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;

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

    MiscUtil.appendTo(formatter, width, precision, leftJustified, out);
}
项目:vdmj    文件:SeqValue.java   
@Override
public void formatTo(Formatter formatter, int flags, int width, int precision)
{
    String s = values.toString();

    if ((flags & FormattableFlags.ALTERNATE) == 0 && s.charAt(0) == '"')
    {
        s = s.substring(1, s.length()-1);
    }

    formatTo(s, formatter, flags, width, precision);
}
项目:vdmj    文件:Value.java   
protected void formatTo(String value, Formatter formatter, int flags, int width, int precision)
{
    StringBuilder sb = new StringBuilder("%");

    switch (flags)
    {
        case FormattableFlags.LEFT_JUSTIFY:
            sb.append('-');
            break;

        case FormattableFlags.ALTERNATE:
            sb.append('#');
            break;
    }

    if (width > 0)
    {
        sb.append(width);
    }

    if (precision > 0)
    {
        sb.append('.');
        sb.append(precision);
    }

    sb.append('s');

    formatter.format(sb.toString(), value);
}
项目:In-the-Box-Fork    文件:FormattableFlagsTest.java   
/**
 * @test java.util.FormattableFlags ConstantFieldValues
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "Verifies fields.",
    method = "!Constants",
    args = {}
)
public void test_ConstantFieldValues() {
    assertEquals(1, FormattableFlags.LEFT_JUSTIFY);
    assertEquals(2, FormattableFlags.UPPERCASE);
    assertEquals(4, FormattableFlags.ALTERNATE);
}
项目:cn1    文件:FormatterTest.java   
public void formatTo(Formatter formatter, int flags, int width,
        int precision) throws IllegalFormatException {
    if ((flags & FormattableFlags.UPPERCASE) != 0) {
        formatter.format("CUSTOMIZED FORMAT FUNCTION" + " WIDTH: "
                + width + " PRECISION: " + precision);
    } else {
        formatter.format("customized format function" + " width: "
                + width + " precision: " + precision);
    }
}
项目:jcabi-log    文件:ExceptionDecor.java   
@Override
public void formatTo(final Formatter formatter, final int flags,
    final int width, final int precision) {
    final String text;
    if (this.throwable == null) {
        text = "NULL";
    } else if ((flags & FormattableFlags.ALTERNATE) == 0) {
        final StringWriter writer = new StringWriter();
        this.throwable.printStackTrace(new PrintWriter(writer));
        text = writer.toString();
    } else {
        text = this.throwable.getMessage();
    }
    formatter.format("%s", text);
}
项目:jcabi-log    文件:NanoDecorTest.java   
/**
 * Params for this parametrized test.
 * @return Array of arrays of params for ctor
 */
@Parameters
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public static Collection<Object[]> params() {
    return Arrays.asList(
        new Object[][] {
            // @checkstyle LineLength (20 lines)
            // @checkstyle MagicNumber (20 lines)
            {null, "NULL", 0, 0, 0},
            {13L, "13ns", 0, 0, -1},
            {13L, "13.0ns", 0, 0, 1},
            {25L, "25.00ns", 0, 0, 2},
            {234L, "234.0ns", 0, 0, 1},
            {1024L, "1µs", 0, 0, 0},
            {1056L, "1.056µs", 0, 0, 3},
            {9022L, "9.02µs", 0, 0, 2},
            {53111L, "53.11µs   ", FormattableFlags.LEFT_JUSTIFY, 10, 2},
            {53156L, "   53µs", 0, 7, 0},
            {87090432L, "  87ms", 0, 6, 0},
            {87090543L, "87.09ms", 0, 0, 2},
            {87090548L, "87.0905ms", 0, 0, 4},
            {6001001001L, "6.0010s", 0, 0, 4},
            {122001001001L, "  2MIN", FormattableFlags.UPPERCASE, 6, 0},
            {3789001001001L, "63.15002min", 0, 0, 5},
            {3789002002002L, "63.2min", 0, 0, 1},
            {3789003003003L, "63min", 0, 0, 0},
            {342000004004004L, "5700min", 0, 0, 0},
        }
    );
}
项目:jcabi-log    文件:SecretDecorTest.java   
/**
 * Params for this parametrized test.
 * @return Array of arrays of params for ctor
 */
@Parameters
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public static Collection<Object[]> params() {
    return Arrays.asList(
        new Object[][] {
            // @checkstyle MagicNumber (4 lines)
            {"testing", "t***g", 0, 0, 0},
            {"ouch", "o***h  ", FormattableFlags.LEFT_JUSTIFY, 7, 5},
            {"x", " X***X", FormattableFlags.UPPERCASE, 6, 0},
            {null, "NULL", FormattableFlags.UPPERCASE, 6, 0},
        }
    );
}
项目:freeVM    文件:FormatterTest.java   
public void formatTo(Formatter formatter, int flags, int width,
        int precision) throws IllegalFormatException {
    if ((flags & FormattableFlags.UPPERCASE) != 0) {
        formatter.format("CUSTOMIZED FORMAT FUNCTION" + " WIDTH: "
                + width + " PRECISION: " + precision);
    } else {
        formatter.format("customized format function" + " width: "
                + width + " precision: " + precision);
    }
}
项目:freeVM    文件:FormatterTest.java   
public void formatTo(Formatter formatter, int flags, int width,
        int precision) throws IllegalFormatException {
    if ((flags & FormattableFlags.UPPERCASE) != 0) {
        formatter.format("CUSTOMIZED FORMAT FUNCTION" + " WIDTH: "
                + width + " PRECISION: " + precision);
    } else {
        formatter.format("customized format function" + " width: "
                + width + " precision: " + precision);
    }
}
项目:j2objc    文件:FormattableFlagsTest.java   
/**
 * @test java.util.FormattableFlags ConstantFieldValues
 */
public void test_ConstantFieldValues() {
    assertEquals(1, FormattableFlags.LEFT_JUSTIFY);
    assertEquals(2, FormattableFlags.UPPERCASE);
    assertEquals(4, FormattableFlags.ALTERNATE);
}
项目:cn1    文件:FormattableFlagsTest.java   
/**
 * @test java.util.FormattableFlags ConstantFieldValues
 */
public void test_ConstantFieldValues() {
    assertEquals(1, FormattableFlags.LEFT_JUSTIFY);
    assertEquals(2, FormattableFlags.UPPERCASE);
    assertEquals(4, FormattableFlags.ALTERNATE);
}
项目:freeVM    文件:FormattableFlagsTest.java   
/**
 * @test java.util.FormattableFlags ConstantFieldValues
 */
public void test_ConstantFieldValues() {
    assertEquals(1, FormattableFlags.LEFT_JUSTIFY);
    assertEquals(2, FormattableFlags.UPPERCASE);
    assertEquals(4, FormattableFlags.ALTERNATE);
}
项目:freeVM    文件:FormattableFlagsTest.java   
/**
 * @test java.util.FormattableFlags ConstantFieldValues
 */
public void test_ConstantFieldValues() {
    assertEquals(1, FormattableFlags.LEFT_JUSTIFY);
    assertEquals(2, FormattableFlags.UPPERCASE);
    assertEquals(4, FormattableFlags.ALTERNATE);
}