private OrgContent getContentObject() { if (content == null) { content = new OrgContent(); } return content; }
/** * @return {@code true} if there is a text below heading, {@code false} otherwise */ public boolean hasContent() { return content != null && !content.isEmpty(); }
public boolean hasTimestamps() { if (timestamps == null) { return false; } if (dirty) { reparse(); } return !timestamps.isEmpty(); }
@Test public void testReparse() { OrgContent o = new OrgContent(); o.append("<2000-01-01 10:10>"); o.set("\n\n<2001-01-01 10:10>"); Assert.assertEquals(1, o.getTimestamps().size()); Assert.assertEquals("<2001-01-01 10:10>", o.getTimestamps().get(0).toString()); }
@Test public void testTimestamp() { OrgContent o = new OrgContent(); o.append("<2000-01-01 10:10>"); Assert.assertEquals(1, o.getTimestamps().size()); Assert.assertEquals("<2000-01-01 10:10>", o.getTimestamps().get(0).toString()); }
@Test public void testEmptyContent() { OrgContent o = new OrgContent(); Assert.assertEquals(0, o.getTimestamps().size()); Assert.assertFalse(o.hasTimestamps()); } }
public void setContent(String s) { getContentObject().set(s); }
public List<OrgRange> getTimestamps() { return getContentObject().getTimestamps(); }
public boolean hasTimestamps() { return getContentObject().hasTimestamps(); }
public void appendContent(String s) { getContentObject().append(s); }
/** * Content (body). Text after the heading. * * @return the content text */ public String getContent() { return getContentObject().toString(); }
@Test public void testTimestampMultiline() { OrgContent o = new OrgContent(); o.append("<2000-01-01 10:10>\n<2001-01-01 10:10>"); Assert.assertEquals(2, o.getTimestamps().size()); Assert.assertEquals("<2000-01-01 10:10>", o.getTimestamps().get(0).toString()); Assert.assertEquals("<2001-01-01 10:10>", o.getTimestamps().get(1).toString()); }
/** Parse all plain timestamps in this content and rebuild the timestamps list. */ private void reparse() { timestamps.clear(); Matcher m = OrgPatterns.DT_OR_RANGE_P.matcher(toString()); while (m.find()) { timestamps.add(OrgRange.parse(m.group())); } dirty = false; }
/** * @return the list of plain timestamps in this content text */ public List<OrgRange> getTimestamps() { if (timestamps == null) { timestamps = new ArrayList<>(); } if (dirty) { reparse(); } return timestamps; }