@Test public void testMergeFilters() throws Exception { List<SxpBindingFilter<?, ? extends SxpFilterFields>> filterList = new ArrayList<>(); filterList.add(SxpBindingFilter.generateFilter(getPrefixListFilter(FilterType.Outbound), "GROUP")); assertEquals("GROUP", SxpBindingFilter.mergeFilters(filterList).getIdentifier()); filterList.add(SxpBindingFilter.generateFilter(getPrefixListFilter(FilterType.Outbound), "Peers")); assertEquals("MultiGroup[ GROUP Peers ]", SxpBindingFilter.mergeFilters(filterList).getIdentifier()); filterList.clear(); filterList.add(SxpBindingFilter.generateFilter(getPrefixListFilter(FilterType.Outbound), "Peers")); filterList.add(SxpBindingFilter.generateFilter(getPrefixListFilter(FilterType.Outbound), "GROUP")); assertEquals("MultiGroup[ GROUP Peers ]", SxpBindingFilter.mergeFilters(filterList).getIdentifier()); }
public static SxpBindingFilter<?, ? extends SxpFilterFields> mergeFilters( final Collection<SxpBindingFilter<?, ? extends SxpFilterFields>> values) { if (values == null || values.isEmpty()) { return null; } if (values.size() == 1) { return Iterables.get(values, 0); } StringBuilder builder = new StringBuilder().append("MultiGroup[ "); values.stream().map(SxpBindingFilter::getIdentifier).sorted().forEach(g -> builder.append(g).append(" ")); return new SxpBindingFilter(builder.append("]").toString()) { protected boolean filter(FilterEntries filterEntries, SxpBindingFields binding) { for (SxpBindingFilter filter : values) { if (filter.apply(binding)) { return true; } } return false; } }; }
SxpBindingFilter implements Function<SxpBindingFields, Boolean>, Predicate<SxpBindingFields> { public static SxpBindingFilter<?, ? extends SxpFilterFields> mergeFilters( final Collection<SxpBindingFilter<?, ? extends SxpFilterFields>> values) { if (values == null || values.isEmpty()) { return null; } if (values.size() == 1) { return Iterables.get(values, 0); } StringBuilder builder = new StringBuilder().append("MultiGroup[ "); values.stream().map(SxpBindingFilter::getIdentifier).sorted().forEach(g -> builder.append(g).append(" ")); return new SxpBindingFilter(builder.append("]").toString()) { protected boolean filter(FilterEntries filterEntries, SxpBindingFields binding) { for (SxpBindingFilter filter : values) { if (filter.apply(binding)) { return true; } } return false; } }; } }
SxpBindingFilter implements Function<SxpBindingFields, Boolean>, Predicate<SxpBindingFields> { public static SxpBindingFilter<?, ? extends SxpFilterFields> mergeFilters( final Collection<SxpBindingFilter<?, ? extends SxpFilterFields>> values) { if (values == null || values.isEmpty()) { return null; } if (values.size() == 1) { return Iterables.get(values, 0); } StringBuilder builder = new StringBuilder().append("MultiGroup[ "); values.stream().map(SxpBindingFilter::getIdentifier).sorted().forEach(g -> builder.append(g).append(" ")); return new SxpBindingFilter(builder.append("]").toString()) { protected boolean filter(FilterEntries filterEntries, SxpBindingFields binding) { for (SxpBindingFilter filter : values) { if (filter.apply(binding)) { return true; } } return false; } }; } private  SxpBindingFilter(String identifier); protected  SxpBindingFilter(R filter, String identifier); }
SxpBindingFilter implements Function<SxpBindingFields, Boolean>, Predicate<SxpBindingFields> { public static SxpBindingFilter<?, ? extends SxpFilterFields> mergeFilters( final Collection<SxpBindingFilter<?, ? extends SxpFilterFields>> values) { if (values == null || values.isEmpty()) { return null; } if (values.size() == 1) { return Iterables.get(values, 0); } StringBuilder builder = new StringBuilder().append("MultiGroup[ "); values.stream().map(SxpBindingFilter::getIdentifier).sorted().forEach(g -> builder.append(g).append(" ")); return new SxpBindingFilter(builder.append("]").toString()) { protected boolean filter(FilterEntries filterEntries, SxpBindingFields binding) { for (SxpBindingFilter filter : values) { if (filter.apply(binding)) { return true; } } return false; } }; } private  SxpBindingFilter(String identifier); protected  SxpBindingFilter(R filter, String identifier); R getSxpFilter(); String getIdentifier(); @Override Boolean apply(SxpBindingFields binding); @Override boolean test(SxpBindingFields binding); static SxpBindingFilter<?, ? extends SxpFilterFields> generateFilter(T filter,
            String peerGroupName); static SxpBindingFilter<?, ? extends SxpDomainFilterFields> generateFilter(
            T filter, String domainName); @Override boolean equals(Object o); @Override int hashCode(); static SxpBindingFilter<?, ? extends SxpFilterFields> mergeFilters(
            final Collection<SxpBindingFilter<?, ? extends SxpFilterFields>> values); static boolean checkInCompatibility(F filter1, F filter2); static SxpBindingFilter<?, ? extends SxpDomainFilterFields> mergeFilters(
            List<SxpBindingFilter<?, ? extends SxpDomainFilterFields>> values); }
SxpBindingFilter implements Function<SxpBindingFields, Boolean>, Predicate<SxpBindingFields> { public static SxpBindingFilter<?, ? extends SxpFilterFields> mergeFilters( final Collection<SxpBindingFilter<?, ? extends SxpFilterFields>> values) { if (values == null || values.isEmpty()) { return null; } if (values.size() == 1) { return Iterables.get(values, 0); } StringBuilder builder = new StringBuilder().append("MultiGroup[ "); values.stream().map(SxpBindingFilter::getIdentifier).sorted().forEach(g -> builder.append(g).append(" ")); return new SxpBindingFilter(builder.append("]").toString()) { protected boolean filter(FilterEntries filterEntries, SxpBindingFields binding) { for (SxpBindingFilter filter : values) { if (filter.apply(binding)) { return true; } } return false; } }; } private  SxpBindingFilter(String identifier); protected  SxpBindingFilter(R filter, String identifier); R getSxpFilter(); String getIdentifier(); @Override Boolean apply(SxpBindingFields binding); @Override boolean test(SxpBindingFields binding); static SxpBindingFilter<?, ? extends SxpFilterFields> generateFilter(T filter,
            String peerGroupName); static SxpBindingFilter<?, ? extends SxpDomainFilterFields> generateFilter(
            T filter, String domainName); @Override boolean equals(Object o); @Override int hashCode(); static SxpBindingFilter<?, ? extends SxpFilterFields> mergeFilters(
            final Collection<SxpBindingFilter<?, ? extends SxpFilterFields>> values); static boolean checkInCompatibility(F filter1, F filter2); static SxpBindingFilter<?, ? extends SxpDomainFilterFields> mergeFilters(
            List<SxpBindingFilter<?, ? extends SxpDomainFilterFields>> values);  }