Search in sources :

Example 6 with JournalPointer

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)));
}
Also used : JournalPointer(net.viperfish.journal.framework.JournalPointer) Calendar(java.util.Calendar) Journal(net.viperfish.journal.framework.Journal) Date(java.util.Date) Test(org.junit.Test)

Example 7 with JournalPointer

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);
    }
}
Also used : JournalPointer(net.viperfish.journal.framework.JournalPointer) TreeSet(java.util.TreeSet) Journal(net.viperfish.journal.framework.Journal)

Aggregations

JournalPointer (net.viperfish.journal.framework.JournalPointer)7 Journal (net.viperfish.journal.framework.Journal)6 Date (java.util.Date)3 TreeSet (java.util.TreeSet)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Test (org.junit.Test)2 File (java.io.File)1 DateFormat (java.text.DateFormat)1 Calendar (java.util.Calendar)1 LinkedList (java.util.LinkedList)1 OperationWithResult (net.viperfish.journal.framework.OperationWithResult)1 PreferenceDialog (org.eclipse.jface.preference.PreferenceDialog)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 PageableTable (org.eclipse.nebula.widgets.pagination.table.PageableTable)1 ControlAdapter (org.eclipse.swt.events.ControlAdapter)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1