@Override public int compare(Link lhs, Link rhs) { /* if priorities different: return <0 if right link priority less, >0 if lest priority less. if priorities same: return <0 if left updated time less, >0 if right updated time less. */ int priorityDiff = rhs.getPriority() - lhs.getPriority(); return priorityDiff != 0 ? priorityDiff : (int) (lhs.getUpdated() - rhs.getUpdated()); }
/** * Save new words into database. Words should contain different language. Link will be created and * saved into database and cache. */ public void addWords(Word word1, Word word2) { Link link = new Link(); Dao<Link> linkDao = DaoFactory.createDao(Link.class); link.setWord(dataBaseManager.insert(dao.setPersistable(word1))); link.setWord(dataBaseManager.insert(dao.setPersistable(word2))); link = dataBaseManager.insert(linkDao.setPersistable(link)); links.add(link); }
private Word loadWord(Link link, Language language) { Word target = new Word(); target.setId(link.getWordId(language)); target.setLanguage(language); return dataBaseManager.retrieve(dao.setPersistable(target)); }