python Save JSON data, store in txt file

2023-01-22   ES  

Filter mode: This mode allows developers to use different standards to filter a set of objects and connect them through logical operations. This type of design pattern is a structural pattern, which combines multiple standards to obtain a single standard. [Rookie] In fact, a set of objects are screened according to conditions.

Our car manufacturer now has a lot of models, and now I just want to screen out the number of BWM.

package filter;

/************************************************
 *@ClassName : Car
 *@Description : TODO
 *@Author : NikolaZhang
 *@Date : 【2018/12/15 0015 17:21】
 *@Version : 1.0.0
 *************************************************/

public class Car {
    
    private String name;

    public String getName() {
    
        return name;
    }

    public Car(String name) {
    
        this.name = name;
    }
}

We use all the car as a parameter, and screen BWM.

package filter;

import java.util.ArrayList;
import java.util.List;

/************************************************
 *@ClassName : CarFilter
 *@Description : TODO
 *@Author : NikolaZhang
 *@Date : 【2018/12/15 0015 17:20】
 *@Version : 1.0.0
 *************************************************/

public class CarFilter {
    
    private List<Car> list = new ArrayList<>();

    public List<Car> filterCar(List<Car> listCar){
    
        for (Car car :listCar){
    
            if("bwm".equals(car.getName())){
    
                list.add(car);
            }
        }
        return list;
    }
}

package filter;

import java.util.ArrayList;
import java.util.List;

/************************************************
 *@ClassName : Test
 *@Description : TODO
 *@Author : NikolaZhang
 *@Date : 【2018/12/15 0015 17:20】
 *@Version : 1.0.0
 *************************************************/

public class Test {
    
    public static void main(String[] args) {
    
        List<Car> list = new ArrayList<>();
        list.add(new Car("bwm"));
        list.add(new Car("benz"));
        list.add(new Car("BWM"));

        CarFilter carFilter = new CarFilter();
        System.out.println("The number of eligible cars:"+carFilter.filterCar(list).size());
    }
}

[Rookie Tutorial]:http://www.runoob.com/design-pattern/filter-pattern.html

source

Related Posts

Engineering practice LFFD model test bug solution summary

MySQL Explain detailed introduction

PyTorch-Losses and optimizers understanding

Lesson 20 JCC assembly instruction

python Save JSON data, store in txt file

Random Posts

32-FTP and LFTP service

[Ruby-0] Regular Expression CPLUS

About ELEMENT-UI Table Rolling Style El-Scrollbar’s problem use Jack

bzoj1858 [Scoi2010] sequence operation

Unity guidance bag lost TAG value, layer value