@Test public void shouldGetCorrectCategoryNumber() { NewznabXmlItem item = buildBasicRssItem(); item.setTorznabAttributes(Collections.singletonList(new NewznabAttribute("category", "2000"))); List<Integer> integers = testee.tryAndGetCategoryAsNumber(item); assertThat(integers.size(), is(1)); assertThat(integers.get(0), is(2000)); item.setTorznabAttributes(Collections.singletonList(new NewznabAttribute("category", "10000"))); integers = testee.tryAndGetCategoryAsNumber(item); assertThat(integers.size(), is(1)); assertThat(integers.get(0), is(10000)); item.setTorznabAttributes(Arrays.asList(new NewznabAttribute("category", "2000"), new NewznabAttribute("category", "10000"))); integers = testee.tryAndGetCategoryAsNumber(item); integers.sort(Comparator.naturalOrder()); assertThat(integers.size(), is(2)); assertThat(integers.get(0), is(2000)); assertThat(integers.get(1), is(10000)); item.setTorznabAttributes(Arrays.asList(new NewznabAttribute("category", "2000"), new NewznabAttribute("category", "2040"))); integers = testee.tryAndGetCategoryAsNumber(item); integers.sort(Comparator.naturalOrder()); assertThat(integers.size(), is(2)); assertThat(integers.get(0), is(2000)); assertThat(integers.get(1), is(2040)); item.setTorznabAttributes(Arrays.asList(new NewznabAttribute("category", "2000"), new NewznabAttribute("category", "2040"), new NewznabAttribute("category", "10000"))); integers = testee.tryAndGetCategoryAsNumber(item); integers.sort(Comparator.naturalOrder()); assertThat(integers.size(), is(3)); assertThat(integers.get(0), is(2000)); assertThat(integers.get(1), is(2040)); }
protected List<Integer> tryAndGetCategoryAsNumber(NewznabXmlItem item) { Set<Integer> foundCategories = new HashSet<>(); if (item.getCategory() != null) { try { foundCategories.add(Integer.parseInt(item.getCategory())); } catch (NumberFormatException e) { } } foundCategories.addAll(item.getNewznabAttributes().stream().filter(x -> x.getName().equals("category")).map(x -> Integer.valueOf(x.getValue())).collect(Collectors.toList())); foundCategories.addAll(item.getTorznabAttributes().stream().filter(x -> x.getName().equals("category")).map(x -> Integer.valueOf(x.getValue())).collect(Collectors.toList())); return new ArrayList<>(foundCategories); }
Torznab extends Newznab { protected List<Integer> tryAndGetCategoryAsNumber(NewznabXmlItem item) { Set<Integer> foundCategories = new HashSet<>(); if (item.getCategory() != null) { try { foundCategories.add(Integer.parseInt(item.getCategory())); } catch (NumberFormatException e) { } } foundCategories.addAll(item.getNewznabAttributes().stream().filter(x -> x.getName().equals("category")).map(x -> Integer.valueOf(x.getValue())).collect(Collectors.toList())); foundCategories.addAll(item.getTorznabAttributes().stream().filter(x -> x.getName().equals("category")).map(x -> Integer.valueOf(x.getValue())).collect(Collectors.toList())); return new ArrayList<>(foundCategories); } }
Torznab extends Newznab { protected List<Integer> tryAndGetCategoryAsNumber(NewznabXmlItem item) { Set<Integer> foundCategories = new HashSet<>(); if (item.getCategory() != null) { try { foundCategories.add(Integer.parseInt(item.getCategory())); } catch (NumberFormatException e) { } } foundCategories.addAll(item.getNewznabAttributes().stream().filter(x -> x.getName().equals("category")).map(x -> Integer.valueOf(x.getValue())).collect(Collectors.toList())); foundCategories.addAll(item.getTorznabAttributes().stream().filter(x -> x.getName().equals("category")).map(x -> Integer.valueOf(x.getValue())).collect(Collectors.toList())); return new ArrayList<>(foundCategories); }  }
Torznab extends Newznab { protected List<Integer> tryAndGetCategoryAsNumber(NewznabXmlItem item) { Set<Integer> foundCategories = new HashSet<>(); if (item.getCategory() != null) { try { foundCategories.add(Integer.parseInt(item.getCategory())); } catch (NumberFormatException e) { } } foundCategories.addAll(item.getNewznabAttributes().stream().filter(x -> x.getName().equals("category")).map(x -> Integer.valueOf(x.getValue())).collect(Collectors.toList())); foundCategories.addAll(item.getTorznabAttributes().stream().filter(x -> x.getName().equals("category")).map(x -> Integer.valueOf(x.getValue())).collect(Collectors.toList())); return new ArrayList<>(foundCategories); }   }
Torznab extends Newznab { protected List<Integer> tryAndGetCategoryAsNumber(NewznabXmlItem item) { Set<Integer> foundCategories = new HashSet<>(); if (item.getCategory() != null) { try { foundCategories.add(Integer.parseInt(item.getCategory())); } catch (NumberFormatException e) { } } foundCategories.addAll(item.getNewznabAttributes().stream().filter(x -> x.getName().equals("category")).map(x -> Integer.valueOf(x.getValue())).collect(Collectors.toList())); foundCategories.addAll(item.getTorznabAttributes().stream().filter(x -> x.getName().equals("category")).map(x -> Integer.valueOf(x.getValue())).collect(Collectors.toList())); return new ArrayList<>(foundCategories); }    }