use of net.viperfish.journal.framework.JournalPointer in project vsDiaryWriter by shilongdai.
the class OperationTest method testGetDateRange.
@Test
public void testGetDateRange() throws FailToSyncEntryException {
cleanUp();
Calendar cal = Calendar.getInstance();
cal.set(1990, 0, 1);
Date lowerBound = cal.getTime();
cal.set(1990, 1, 12);
Date upperBound = cal.getTime();
cal.set(1990, 0, 22);
Date inBound = cal.getTime();
Journal valid = new Journal();
valid.setDate(inBound);
valid.setSubject("valid entry");
valid.setContent("valid content");
db.addEntry(valid);
cal.set(1990, 2, 4);
Date outBound = cal.getTime();
Journal invalid = new Journal();
invalid.setDate(outBound);
invalid.setContent("out of bound");
invalid.setSubject("out of bound");
db.addEntry(invalid);
GetDateRangeOperation range = new GetDateRangeOperation(lowerBound, upperBound);
range.execute();
Set<JournalPointer> result = range.getResult();
Assert.assertEquals(true, result.contains(new JournalPointer(valid)));
Assert.assertEquals(false, result.contains(new JournalPointer(invalid)));
}
use of net.viperfish.journal.framework.JournalPointer in project vsDiaryWriter by shilongdai.
the class SearchEntryOperation method execute.
@Override
public void execute() {
Set<JournalPointer> searched = new TreeSet<>();
try {
if (firstTime) {
if (indexer().isMemoryBased()) {
for (Journal j : db().getAll()) {
indexer().add(j);
}
}
firstTime = false;
}
Iterable<Long> indexResult = indexer().search(query);
for (Long id : indexResult) {
Journal j = db().getEntry(id);
if (j == null) {
indexer().delete(id);
continue;
}
searched.add(new JournalPointer(j));
}
} finally {
setResult(searched);
}
}
Aggregations