FormatInfo fi = new FormatInfo();
public boolean equals(Object o) { if (!super.equals(o)) { return false; } if(!(o instanceof FormattingNode)) { return false; } FormattingNode r = (FormattingNode) o; return (formatInfo != null ? formatInfo.equals(r.formatInfo) : r.formatInfo == null); }
int min = formattingInfo.getMin(); int max = formattingInfo.getMax(); if(formattingInfo.isLeftTruncate()) { buf.append(s.substring(len - max)); } else { if (formattingInfo.isLeftPad()) { SpacePadder.leftPad(buf, s, min); } else {
Node T() throws ScanException { Token t = getCurentToken(); expectNotNull(t, "a LITERAL or '%'"); switch (t.getType()) { case Token.LITERAL: advanceTokenPointer(); return new Node(Node.LITERAL, t.getValue()); case Token.PERCENT: advanceTokenPointer(); // System.out.println("% token found"); FormatInfo fi; Token u = getCurentToken(); FormattingNode c; expectNotNull(u, "a FORMAT_MODIFIER, SIMPLE_KEYWORD or COMPOUND_KEYWORD"); if (u.getType() == Token.FORMAT_MODIFIER) { fi = FormatInfo.valueOf((String) u.getValue()); advanceTokenPointer(); c = C(); c.setFormatInfo(fi); } else { c = C(); } return c; default: return null; } }
@Test public void testRightPad() { { FormatInfo fi = FormatInfo.valueOf("-40"); FormatInfo witness = new FormatInfo(); witness.setMin(40); witness.setLeftPad(false); assertEquals(witness, fi); } { FormatInfo fi = FormatInfo.valueOf("-12.5"); FormatInfo witness = new FormatInfo(); witness.setMin(12); witness.setMax(5); witness.setLeftPad(false); assertEquals(witness, fi); } { FormatInfo fi = FormatInfo.valueOf("-14.-5"); FormatInfo witness = new FormatInfo(); witness.setMin(14); witness.setMax(5); witness.setLeftPad(false); witness.setLeftTruncate(false); assertEquals(witness, fi); } }
@Test public void testMinOnly() { { FormatInfo fi = FormatInfo.valueOf("49"); FormatInfo witness = new FormatInfo(); witness.setMin(49); assertEquals(witness, fi); } { FormatInfo fi = FormatInfo.valueOf("-587"); FormatInfo witness = new FormatInfo(); witness.setMin(587); witness.setLeftPad(false); assertEquals(witness, fi); } }
@Test public void testBasic() { { FormatInfo fi = FormatInfo.valueOf("45"); FormatInfo witness = new FormatInfo(); witness.setMin(45); assertEquals(witness, fi); } { FormatInfo fi = FormatInfo.valueOf("4.5"); FormatInfo witness = new FormatInfo(); witness.setMin(4); witness.setMax(5); assertEquals(witness, fi); } }
@Test public void testMaxOnly() { { FormatInfo fi = FormatInfo.valueOf(".49"); FormatInfo witness = new FormatInfo(); witness.setMax(49); assertEquals(witness, fi); } { FormatInfo fi = FormatInfo.valueOf(".-5"); FormatInfo witness = new FormatInfo(); witness.setMax(5); witness.setLeftTruncate(false); assertEquals(witness, fi); } } }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (formatInfo != null ? formatInfo.hashCode() : 0); return result; } }
public String convert(int i) { String s = Integer.toString(i); FormatInfo formattingInfo = getFormattingInfo(); if (formattingInfo == null) { return s; } int min = formattingInfo.getMin(); StringBuilder sbuf = new StringBuilder(); for (int j = s.length(); j < min; ++j) { sbuf.append('0'); } return sbuf.append(s).toString(); }
@Test public void testEndingInDot() { try { FormatInfo.valueOf("45."); fail("45. is not a valid format info string"); } catch (IllegalArgumentException iae) { // OK } }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (formatInfo != null ? formatInfo.hashCode() : 0); return result; } }
int min = formattingInfo.getMin(); int max = formattingInfo.getMax(); if (formattingInfo.isLeftTruncate()) { buf.append(s.substring(len - max)); } else { if (formattingInfo.isLeftPad()) { SpacePadder.leftPad(buf, s, min); } else {
FormatInfo fi = new FormatInfo();
expectNotNull(u, "a FORMAT_MODIFIER, KEYWORD or LEFT_PARENTHESIS"); if (u.getType() == Token.FORMAT_MODIFIER) { fi = FormatInfo.valueOf((String) u.getValue()); advanceTokenPointer(); c = C();
public boolean equals(Object o) { if (!super.equals(o)) { return false; } if(!(o instanceof FormattingNode)) { return false; } FormattingNode r = (FormattingNode) o; return (formatInfo != null ? formatInfo.equals(r.formatInfo) : r.formatInfo == null); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + (formatInfo != null ? formatInfo.hashCode() : 0); return result; } }
int min = formattingInfo.getMin(); int max = formattingInfo.getMax(); if(formattingInfo.isLeftTruncate()) { buf.append(s.substring(len - max)); } else { if (formattingInfo.isLeftPad()) { SpacePadder.leftPad(buf, s, min); } else {
FormatInfo fi = new FormatInfo();
Node T() throws ScanException { Token t = getCurentToken(); expectNotNull(t, "a LITERAL or '%'"); switch (t.getType()) { case Token.LITERAL: advanceTokenPointer(); return new Node(Node.LITERAL, t.getValue()); case Token.PERCENT: advanceTokenPointer(); // System.out.println("% token found"); FormatInfo fi; Token u = getCurentToken(); FormattingNode c; expectNotNull(u, "a FORMAT_MODIFIER, SIMPLE_KEYWORD or COMPOUND_KEYWORD"); if (u.getType() == Token.FORMAT_MODIFIER) { fi = FormatInfo.valueOf((String) u.getValue()); advanceTokenPointer(); c = C(); c.setFormatInfo(fi); } else { c = C(); } return c; default: return null; } }