Compare commits
2 Commits
74b62aa4de
...
7afbe9ef92
Author | SHA1 | Date |
---|---|---|
![]() |
7afbe9ef92 | 5 years ago |
![]() |
1e40707633 | 5 years ago |
@ -0,0 +1,35 @@ |
||||
package me.bearns.fias.util; |
||||
|
||||
import me.bearns.fias.domain.Addrobj; |
||||
import me.bearns.fias.domain.House; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.HashSet; |
||||
import java.util.Objects; |
||||
import java.util.Set; |
||||
import java.util.function.Predicate; |
||||
|
||||
public class RegionFilter implements Predicate { |
||||
|
||||
private final Set<String> set = new HashSet<>(); |
||||
|
||||
public RegionFilter(String codes) { |
||||
if(codes!=null){ |
||||
Arrays.stream(codes.split(",")).filter(Objects::nonNull).filter(s -> s.matches("^\\d{2}$")).forEach(set::add); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public boolean test(Object o) { |
||||
|
||||
String regioncode = null; |
||||
|
||||
if(o instanceof Addrobj){ |
||||
regioncode = ((Addrobj) o).regioncode; |
||||
} else if(o instanceof House){ |
||||
regioncode = ((House) o).regioncode; |
||||
} |
||||
|
||||
return regioncode != null && set.contains(regioncode); |
||||
} |
||||
} |
Loading…
Reference in new issue