@Test public void testUpdateTagsWithNewTags() throws Exception { TagService tagService = new TagService(); List<Tag> updated = tagService.updateTags(Arrays.asList("test1", "test2", "test3")); Ix.from(updated).foreach(tag -> assertEquals(1, tag.getPostCount())); }
public List<Tag> updateTags(Collection<String> tagNames) { List<Tag> persistentTags = Ix .from(tagNames) .map(Tag::createKey) .collectToList() .flatMap(keys -> Ix.from(ofy().load().keys(keys).values())) .map(tag -> tag.withPostCount(tag.getPostCount() + 1)) .toList(); List<String> persistentTagsAsNames = Ix.from(persistentTags).map(Tag::getName).toList(); return Ix .from(tagNames) .filter(s -> !persistentTagsAsNames.contains(s)) .collectToList() .filter(strings -> !strings.isEmpty()) .flatMap(Ix::from) .map(tagName -> Tag .builder() .id(Tag.createKey(tagName).getName()) .name(tagName) .rank(0.0D) .postCount(1L) .build()) .mergeWith(persistentTags) .toList(); }
TagService { public List<Tag> updateTags(Collection<String> tagNames) { List<Tag> persistentTags = Ix .from(tagNames) .map(Tag::createKey) .collectToList() .flatMap(keys -> Ix.from(ofy().load().keys(keys).values())) .map(tag -> tag.withPostCount(tag.getPostCount() + 1)) .toList(); List<String> persistentTagsAsNames = Ix.from(persistentTags).map(Tag::getName).toList(); return Ix .from(tagNames) .filter(s -> !persistentTagsAsNames.contains(s)) .collectToList() .filter(strings -> !strings.isEmpty()) .flatMap(Ix::from) .map(tagName -> Tag .builder() .id(Tag.createKey(tagName).getName()) .name(tagName) .rank(0.0D) .postCount(1L) .build()) .mergeWith(persistentTags) .toList(); } }
TagService { public List<Tag> updateTags(Collection<String> tagNames) { List<Tag> persistentTags = Ix .from(tagNames) .map(Tag::createKey) .collectToList() .flatMap(keys -> Ix.from(ofy().load().keys(keys).values())) .map(tag -> tag.withPostCount(tag.getPostCount() + 1)) .toList(); List<String> persistentTagsAsNames = Ix.from(persistentTags).map(Tag::getName).toList(); return Ix .from(tagNames) .filter(s -> !persistentTagsAsNames.contains(s)) .collectToList() .filter(strings -> !strings.isEmpty()) .flatMap(Ix::from) .map(tagName -> Tag .builder() .id(Tag.createKey(tagName).getName()) .name(tagName) .rank(0.0D) .postCount(1L) .build()) .mergeWith(persistentTags) .toList(); }  }
TagService { public List<Tag> updateTags(Collection<String> tagNames) { List<Tag> persistentTags = Ix .from(tagNames) .map(Tag::createKey) .collectToList() .flatMap(keys -> Ix.from(ofy().load().keys(keys).values())) .map(tag -> tag.withPostCount(tag.getPostCount() + 1)) .toList(); List<String> persistentTagsAsNames = Ix.from(persistentTags).map(Tag::getName).toList(); return Ix .from(tagNames) .filter(s -> !persistentTagsAsNames.contains(s)) .collectToList() .filter(strings -> !strings.isEmpty()) .flatMap(Ix::from) .map(tagName -> Tag .builder() .id(Tag.createKey(tagName).getName()) .name(tagName) .rank(0.0D) .postCount(1L) .build()) .mergeWith(persistentTags) .toList(); }  List<Tag> updateTags(Collection<String> tagNames); }
TagService { public List<Tag> updateTags(Collection<String> tagNames) { List<Tag> persistentTags = Ix .from(tagNames) .map(Tag::createKey) .collectToList() .flatMap(keys -> Ix.from(ofy().load().keys(keys).values())) .map(tag -> tag.withPostCount(tag.getPostCount() + 1)) .toList(); List<String> persistentTagsAsNames = Ix.from(persistentTags).map(Tag::getName).toList(); return Ix .from(tagNames) .filter(s -> !persistentTagsAsNames.contains(s)) .collectToList() .filter(strings -> !strings.isEmpty()) .flatMap(Ix::from) .map(tagName -> Tag .builder() .id(Tag.createKey(tagName).getName()) .name(tagName) .rank(0.0D) .postCount(1L) .build()) .mergeWith(persistentTags) .toList(); }  List<Tag> updateTags(Collection<String> tagNames);  }