@Test public void testMatches() { NoteData note = new NoteData(); Long tag1Id = new Random().nextLong(); Long tag2Id = tag1Id + 1; note.setTags(new ArrayList<TagData>()); note.getTags().add(new TagData(tag1Id, "test1")); note.getTags().add(new TagData(tag2Id, "test2")); Matcher<NoteData> matcher = new TagIdsMatcher(); Assert.assertTrue(matcher.matches(note)); matcher = new TagIdsMatcher(tag1Id); Assert.assertTrue(matcher.matches(note)); matcher = new TagIdsMatcher(tag2Id); Assert.assertTrue(matcher.matches(note)); matcher = new TagIdsMatcher(tag1Id, tag2Id); Assert.assertTrue(matcher.matches(note)); matcher = new TagIdsMatcher(tag1Id - 1, tag2Id); Assert.assertFalse(matcher.matches(note)); matcher = new TagIdsMatcher(tag1Id, tag2Id + 1); Assert.assertFalse(matcher.matches(note)); }
@Override public boolean matches(NoteData entity) { if (tagIds.isEmpty()) { return true; } Set<Long> entityTagIds = new HashSet<Long>(); for (TagData tag : entity.getTags()) { entityTagIds.add(tag.getId()); } for (Long tagId : tagIds) { if (!entityTagIds.contains(tagId)) { return false; } } return true; }
TagIdsMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (tagIds.isEmpty()) { return true; } Set<Long> entityTagIds = new HashSet<Long>(); for (TagData tag : entity.getTags()) { entityTagIds.add(tag.getId()); } for (Long tagId : tagIds) { if (!entityTagIds.contains(tagId)) { return false; } } return true; } }
TagIdsMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (tagIds.isEmpty()) { return true; } Set<Long> entityTagIds = new HashSet<Long>(); for (TagData tag : entity.getTags()) { entityTagIds.add(tag.getId()); } for (Long tagId : tagIds) { if (!entityTagIds.contains(tagId)) { return false; } } return true; } TagIdsMatcher(Collection<Long> tagIds);  TagIdsMatcher(Long... tagIds); }
TagIdsMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (tagIds.isEmpty()) { return true; } Set<Long> entityTagIds = new HashSet<Long>(); for (TagData tag : entity.getTags()) { entityTagIds.add(tag.getId()); } for (Long tagId : tagIds) { if (!entityTagIds.contains(tagId)) { return false; } } return true; } TagIdsMatcher(Collection<Long> tagIds);  TagIdsMatcher(Long... tagIds); @Override boolean matches(NoteData entity); }
TagIdsMatcher extends Matcher<NoteData> { @Override public boolean matches(NoteData entity) { if (tagIds.isEmpty()) { return true; } Set<Long> entityTagIds = new HashSet<Long>(); for (TagData tag : entity.getTags()) { entityTagIds.add(tag.getId()); } for (Long tagId : tagIds) { if (!entityTagIds.contains(tagId)) { return false; } } return true; } TagIdsMatcher(Collection<Long> tagIds);  TagIdsMatcher(Long... tagIds); @Override boolean matches(NoteData entity);  }