Java 8 Formatter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Formatter class.

This code example shows how to use the following methods:format
    } 
 
    void doLog(LogRecord record)
    { 
        super.log( record );
        writer.print( formatter.format( record ) );
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getHead, getTail
public class OldSimpleFormatterTest extends TestCase {
 
    SimpleFormatter sf = new SimpleFormatter();
 
    public void testSimpleFormatter() { 
        assertEquals("Head for this SimpleFormatter should be empty", "", sf.getHead(null));
        assertEquals("Tail for this SimpleFormatter should be empty", "", sf.getTail(null));
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getTail
        h.publish(r);
        assertEquals("head string is not empty", "", f.getHead(h));
    } 
 
    public void testGetTail() { 
        assertEquals("tail string is not empty", "", f.getTail(null));
        assertEquals("tail string is not empty", "", f.getTail(h));
        h.publish(r);
        assertEquals("tail string is not empty", "", f.getTail(h));
    } 
 
    public void testFormatMessage() { 
        // The RI fails in this test because it uses a MessageFormat to format 
        // the message even though it doesn't contain "{0". The spec says that 
        // this would indicate that a MessageFormat should be used and else no 
        // formatting should be done. 
        String pattern = "pattern without 0 {1, number}";
        r.setMessage(pattern);
        assertEquals(pattern, f.formatMessage(r));
    } 
6
CodeRank
This code example shows how to use the following methods:getHead, getTail
public class OldSimpleFormatterTest extends TestCase {
 
    SimpleFormatter sf = new SimpleFormatter();
 
    public void testSimpleFormatter() { 
        assertEquals("Head for this SimpleFormatter should be empty", "", sf.getHead(null));
        assertEquals("Tail for this SimpleFormatter should be empty", "", sf.getTail(null));
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getTail
        h.publish(r);
        assertEquals("head string is not empty", "", f.getHead(h));
    } 
 
    public void testGetTail() { 
        assertEquals("tail string is not empty", "", f.getTail(null));
        assertEquals("tail string is not empty", "", f.getTail(h));
        h.publish(r);
        assertEquals("tail string is not empty", "", f.getTail(h));
    } 
 
    public void testFormatMessage() { 
        // The RI fails in this test because it uses a MessageFormat to format 
        // the message even though it doesn't contain "{0". The spec says that 
        // this would indicate that a MessageFormat should be used and else no 
        // formatting should be done. 
        String pattern = "pattern without 0 {1, number}";
        r.setMessage(pattern);
        assertEquals(pattern, f.formatMessage(r));
    } 
5
CodeRank
This code example shows how to use the following methods:getTail
	public void testGetHead() { 
		assertEquals("", sf.getHead(null));
	} 
 
	public void testGetTail() { 
		assertEquals("", sf.getTail(null));
	} 
} 
5
CodeRank
This code example shows how to use the following methods:getTail
	public void testGetHead() { 
		assertEquals("", f.getHead(null));
	} 
 
	public void testGetTail() { 
		assertEquals("", f.getTail(null));
	} 
 
	public void testFormatMessage() { 
		assertEquals(MSG, f.formatMessage(r));
 
		String pattern = "test formatter {0, number}";
		r.setMessage(pattern);
		assertEquals(pattern, f.formatMessage(r));
 
		Object[] oa = new Object[0];
		r.setParameters(oa);
		assertEquals(pattern, f.formatMessage(r));
 
		oa = new Object[] { new Integer(100), new Float(1.1) };
4
CodeRank
This code example shows how to use the following methods:formatMessage
    } 
     
    private void logWithThrowable(Logger logger, LogRecord record) 
    { 
        int loggedLevel = record.getLevel().intValue();
        Object message = formatter.formatMessage(record);
        Throwable throwable = record.getThrown();
         
        if (loggedLevel == Level.SEVERE.intValue())
        { 
           logger.error(message, throwable);
           return; 
        } 
 
        if (loggedLevel == Level.WARNING.intValue())
        { 
           logger.warn(message, throwable);
           return; 
        } 
 
4
CodeRank
See Code Examples for Java 8 Formatter Methods: