1. 程式人生 > 其它 >微信小程式wx.navigateBack返回上一頁攜帶引數

微信小程式wx.navigateBack返回上一頁攜帶引數

技術標籤:實習的一年設計模式

本人為菜鳥,僅供參考,只為自己記錄學習

實體類

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Person {

    private String name;

    private String gender;

    private String school;
}

過濾器介面

public interface Filter {
    /**
     * 過濾的方法
     * @param source
     * @return
     */
    public
List<Person> getRes(List<Person> source); }

過濾器實現類

public class GenderFilter implements Filter {
    private String gender;

    @Override
    public List<Person> getRes(List<Person> source) {
        return source.stream().filter(item -> item.getGender().equals(gender)
).collect(Collectors.toList()); } public void setGender(String gender) { this.gender = gender; } public GenderFilter(String gender) { this.gender = gender; } }
public class NameFilter implements Filter {
    private String prefix;

    @Override
    public List<
Person>
getRes(List<Person> source) { return source.stream().filter(item ->{ if(prefix.length() > item.getName().length()) { return false; } else if(!prefix.equals(item.getName().substring(0, prefix.length()))) { return false; } else { return true; } }).collect(Collectors.toList()); } public void setPrefix(String prefix) { this.prefix = prefix; } public NameFilter(String prefix) { this.prefix = prefix; } }
public class SchoolFilter implements Filter {
    private List<String> schools = new ArrayList<>();

    @Override
    public List<Person> getRes(List<Person> source) {
        return source.stream().filter(item -> schools.contains(item.getSchool())).collect(Collectors.toList());
    }

    public void setSchools(List<String> schools) {
        this.schools = schools;
    }

    public void addSchool(String school) {
        schools.add(school);
    }

    public SchoolFilter(List<String> schools) {
        this.schools = schools;
    }
}

測試類

public class FilterTest {
    public static void main(String[] args) {
        Person wang = new Person("老王", "男", "成都理工");
        Person he = new Person("老賀", "男", "川大");
        Person luo = new Person("小羅", "男", "宜賓學院");
        Person zhang = new Person("小張", "女", "西南財經");

        List<Person> persons = new ArrayList<>();
        persons.add(wang);
        persons.add(he);
        persons.add(luo);
        persons.add(zhang);

        List<String> schools = new ArrayList<>();
        schools.add("宜賓學院");
        schools.add("西南財經");

        Filter nameFilter = new NameFilter("小");
        Filter genderFilter = new GenderFilter("女");
        Filter schoolFilter = new SchoolFilter(schools);

        persons = nameFilter.getRes(persons);
        persons = genderFilter.getRes(persons);
        persons = schoolFilter.getRes(persons);

        System.out.println(persons);
    }
}