Can this piece of Java code be encapsulated into a method?

problem description

this code is often used in my project. I want to package it into a method to reduce the amount of code, but I failed to do it because I am a rookie. Thank you in advance.
purpose: to change the classes hardwareServices and Hardware into formal parameters

the environmental background of the problems and what methods you have tried

Java version: 1.8
try to use generics, but end up reporting an error because you want to call the method of the class

related codes

/ / Please paste the code text below (do not replace the code with pictures)
private HardwareServices hardwareServices;
List < Hardware > hardwareList = hardwareServices.selectList (wrapper);

        if(hardwareList.size() > 0){
            for (Hardware i: hardwareList) {
                if(i.getName().equals(hardware.getName())){
                    if(i.getIsDelete() == 1){
                        wrapper.eq("is_delete", 1).eq("id", i.getId());
                        hardware.setIsDelete(0);
                        hardware.setChangeMan(selectUser.getName());
                        hardware.setUpdateTime(nowData);
                        hardwareServices.update(hardware, wrapper);
                        result.setValue(hardware);
                    }else{
                        result.setMsg("");
                        result.setCode(-1);
                    }
                    return result;
                }
            }
        }
        

here is the code from another place:
EntityWrapper < ProductProcess > wrapper = new EntityWrapper < ProductProcess > ();
List < ProductProcess > hardwareList=productProcessServices.selectList (wrapper);

        if(hardwareList.size() > 0){
            for (ProductProcess i: hardwareList) {
                if(i.getName().equals(productProcess.getName())){
                    if(i.getIsDelete() == 1){
                        wrapper.eq("is_delete", 1).eq("id", i.getId());
                        productProcess.setIsDelete(0);
                        productProcess.setChangeMan(selectUser.getName());
                        productProcess.setUpdateTime(nowData);
                        productProcessServices.update(productProcess, wrapper);
                        result.setValue(productProcess);
                    }else{
                        result.setMsg("");
                        result.setCode(-1);
                    }
                    return result;
                }
            }
        }

Aug.13,2021

I have asked the conditions and information I want in the question comments. I have the following suggestions for the subject's reference

.

conclusion: packaging together is not recommended for the following reasons

  1. The

    code encapsulates or abstracts the same methods and tool classes, which is personally thought to be based on the following two cases

    is either the same processing that has nothing to do with business, such as writing a tool class that takes the last element of the collection, or encryption tools, etc.
    is strongly related to business. Business An and business B have a business relationship. Similar to them, they can abstract an abstract business C. the related processing of business C is a common process that can be used by both An and B, such as collection AbstractCollection . It abstracts some collection common processing methods and other collection subclasses can use
  2. from the perspective of providing information, there is no relationship between Hardware and ProductProcess . It's just. It's just. They happen to have some of the same fields, and they happen to have roughly the same treatment in the code posted by the subject, and forced encapsulation together may cause strong coupling in the business. As a result, when a business, such as Hardware , makes slight changes in processing, it will be painful when you need to modify the encapsulated code. Do you either do special treatment in public code? Then this public method is not called a public method, so it can only be dealt with by writing a separate method. But that public method can only be called ProductProcess .
Menu