Java对象通用比对工具

news2025/2/24 6:38:08

目录

背景

思路

实现


背景

  前段时间的任务中,遇到了需要识别两个对象不同属性的场景,如果使用传统的一个个属性比对equals方法,会存在大量的重复工作,而且为对象新增了属性后,比对方法也需要同步修改,不方便维护,于是便打算构造一个通用的比对方法,需要支持对象嵌套,并支持过滤比对逻辑的策略,适用大部分比对场景

思路

  一个java对象,他的属性是多样的,会有集合类型(如Collection,Map,Array)基本类型(如String,int,double,long等认为是最基本对象的比较),或者对象类型,本质上是一个树状的结构

怎么去遍历对象树

常用的方法就是递归,那怎么定义递归的终点?基于上面三种类型,定为基本类型的比对为递归的终点,对于集合类型,那就再对每一个元素进行比较,对于对象类型,遍历属性进行比较

为了达成通用目的,这里使用java反射实现,基于约定和性能考虑,只通过无参的getter方法获取属性进行比较,另外如何记录当前属性所在的路径?这里参考spel表达式,相对轻量直观

实现

首先定义递归过程记录的上下文信息

这里记录了根对象,当前处理的对象,以及反射获取的对象信息

protected static class CompareContext {
        //对比结果
        private List<CompareResult.CompareInfo> resCollect;
        //当前遍历的对象信息,用于定位
        private ArrayDeque<String> pathMessageStack;
        protected Object rootSourceObj;
        protected Object rootOtherObj;
        protected Object sourceObj;
        protected Object otherObj;
        protected Object sourceInvokeVal;
        protected Object otherInvokeVal;
        //过滤耗费时间
        private long filterCost;

        private String checkCycle() {
            Set<String> set = new LinkedHashSet<>();
            //出现重复退出
            while (set.add(pathMessageStack.removeLast())) {
            }
            String[] elements = new String[set.size()];
            Iterator<String> iterator = set.iterator();
            int index = 0;
            while (iterator.hasNext()) {
                elements[set.size() - 1 - index++] = iterator.next();
            }
            return getPath(elements);
        }

        protected String getPath(String[] elements) {
            Object obj = this.rootSourceObj == null ? this.rootOtherObj : this.rootSourceObj;
            String simpleName = obj.getClass().getSimpleName();
            StringBuilder builder = new StringBuilder(simpleName);
            if (elements == null) {
                elements = this.pathMessageStack.toArray(new String[0]);
            }
            for (int i = elements.length - 1; i >= 0; i--) {
                String cur = elements[i];
                String value = cur.substring(2);
                if (cur.startsWith(FIELD_SIGN)) {
                    builder.append(".").append(value);
                } else {
                    builder.append("[").append(value).append("]");
                }
            }
            return builder.toString();
        }
    }

基于这个上下文,定义过滤接口,因为有些属性可能不用比对,如果命中过滤接口,则跳过

@FunctionalInterface
public interface MethodFilter {
    boolean isSkipCompare(Method method, String methodKey, CompareUtil.CompareContext compareContext);
}

比对结果类,主要存放每个比对不通过属性的值及其路径信息

@Getter
@ToString
public class CompareResult {
    protected boolean same;
    protected Object source;
    protected Object other;
    protected List<CompareInfo> diffList;


    //=====额外信息,可以不关注====
    //整体对比耗时
    private long totalCostMill;

    //方法过滤耗时
    protected long methodFilterCostMill;



    protected void genCost(long start) {
        this.totalCostMill = System.currentTimeMillis() - start;
    }

   

    @Getter
    public static class CompareInfo {
        protected Object sourceVal;
        protected Object otherVal;
        protected String path;

        protected boolean isShow() {
            if (sourceVal == null || otherVal == null) {
                return true;
            }
            if (CompareUtil.getObjType(sourceVal) != Object.class) {
                return true;
            }
            if (sourceVal instanceof Collection) {
                return ((Collection<?>) sourceVal).size() != ((Collection<?>) otherVal).size();
            }
            if (sourceVal instanceof Map) {
                return ((Map<?, ?>) sourceVal).size() != ((Map<?, ?>) otherVal).size();
            }
            if (sourceVal.getClass().isArray()) {
                return ((Object[]) sourceVal).length != ((Object[]) otherVal).length;
            }
            return false;
        }

        @Override
        public String toString() {
            return String.format("path:%s,source:[%s],other:[%s]", path, sourceVal, otherVal);
        }
    }


    public String getBaseObjDiffInfo() {
        return getBaseObjDiffInfo("\n");
    }

    /**
     * 过滤出为空的父对象或基本对象,原生的diffList会包含父对象,不方便查看
     *
     * @param seperator
     * @return
     */
    public String getBaseObjDiffInfo(String seperator) {
        if (!same) {
            StringBuilder builder = new StringBuilder();
            diffList.stream().filter(CompareInfo::isShow).forEach(v -> builder.append(v).append(seperator));
            return builder.toString();
        }
        return "";
    }

}

随后定义入口方法

  public static <T> CompareResult compareObjByGetter(T source, T other, MethodFilter... methodFilters) {
        List<CompareResult.CompareInfo> diffList = new ArrayList<>();
        CompareContext compareContext = new CompareContext();
        compareContext.resCollect = diffList;
        compareContext.pathMessageStack = new ArrayDeque<>(MAX_DEEP_SIZE);
        compareContext.rootSourceObj = source;
        compareContext.rootOtherObj = other;
        long start = System.currentTimeMillis();
        boolean res = compareObjByGetter(source, other, compareContext, methodFilters);
        CompareResult compareResult = new CompareResult();
        compareResult.genCost(start);
        compareResult.diffList = diffList;
        compareResult.same = res;
        compareResult.other = other;
        compareResult.source = source;
        compareResult.methodFilterCostMill = compareContext.filterCost;
        return compareResult;
    }

主流程方法,流程如下

  1. 校验
    1. 路径长度校验
    2. 类校验
  2. 递归终点,对于基本类型,直接走比对方法,并生成路径
  3. 对于复合类型,递归进行比对逻辑
  4. 对于对象类型,采用反射获取具体值,并通过方法过滤进行比较
    1. 首先判断是否有public的无参数getter方法
    2. 有的话采用调用该方法获取两边的值,设置上下文信息
    3. 过滤器过滤无需比对的字段
    4. 如果任一方为空,构造结果
    5. 对于集合类型的属性,需要进一步获取里面的元素进行递归处理
    6. 对于对象类型或基本类型,重复上述步骤

主流程代码如下

private static <T> boolean compareObjByGetter(T source, T other, CompareContext compareContext, MethodFilter... methodFilters) {
        //对比路径太深或出现循环引用不支持
        if (compareContext.pathMessageStack.size() > MAX_DEEP_SIZE) {
            String path = compareContext.checkCycle();
            if (!StringUtils.isEmpty(path)) {
                //路径仅供参考,不一定准确
                throw new IllegalStateException(String.format("reference cycle happen,please check your object,path:%s", path));
            }
            throw new IllegalStateException(String.format("compare path over max size:%s,please check your object", MAX_DEEP_SIZE));
        }
        if(source==other){
            return true;
        }
        if (source == null || other == null) {
            generateResult(source, other, compareContext);
            return false;
        }
        if (!source.getClass().equals(other.getClass())) {
            throw new IllegalArgumentException(String.format("not the same object,class source:%s,class other:%s,path:%s", source.getClass(), other.getClass(),compareContext.getPath(null)));
        }
        //基本类型不再对比getter方法
        if (getObjType(source) != Object.class) {
            boolean isSame = compareBaseObj(source, other);
            if (!isSame) {
                generateResult(source, other, compareContext);
            }
            return isSame;
        }
        //复合类型
        if (isCollectionOrMapOrArray(source)) {
            return dealWithCMA(source, other, compareContext, methodFilters);
        }
        //对象类型,遍历对应的方法
        final boolean[] val = new boolean[]{true};
        ReflectionUtils.doWithMethods(source.getClass(), new ReflectionUtils.MethodCallback() {
            @Override
            public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
                String name = method.getName();

                if (method.getModifiers() == Modifier.PUBLIC && (name.startsWith("get") || name.startsWith("is"))) {
                    //有入参的getter不处理
                    if (method.getParameterTypes().length != 0) {
                        return;
                    }
                    String methodKey = method.getDeclaringClass().getName() + "#" + method.getName();
                    Object sourceInvokeVal = null;
                    Object otherInvokeVal = null;
                    try {
                        sourceInvokeVal = method.invoke(source);
                        otherInvokeVal = method.invoke(other);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    compareContext.otherObj = other;
                    compareContext.otherInvokeVal = otherInvokeVal;
                    compareContext.sourceObj = source;
                    compareContext.sourceInvokeVal = sourceInvokeVal;
                    //过滤,methodFilter是||关系
                    long start = System.currentTimeMillis();
                    try {
                        for (MethodFilter methodFilter : methodFilters) {
                            if (methodFilter.isSkipCompare(method, methodKey, compareContext)) {
                                return;
                            }
                        }
                    } finally {
                        compareContext.filterCost += System.currentTimeMillis() - start;
                    }
                    if (sourceInvokeVal == null && otherInvokeVal == null) {
                        return;
                    }
                    compareContext.pathMessageStack.push(String.format("%s%s", FIELD_SIGN, ColumnSelector.getFieldName(method.getName(), method.getDeclaringClass().getName())));
                    if (sourceInvokeVal == null || otherInvokeVal == null) {
                        generateResult(sourceInvokeVal, otherInvokeVal, compareContext);
                        val[0] = false;
                        compareContext.pathMessageStack.pop();
                        return;
                    }
                    if (isCollectionOrMapOrArray(sourceInvokeVal)) {
                        val[0] &= dealWithCMA(sourceInvokeVal, otherInvokeVal, compareContext, methodFilters);
                    } else {
                        //对象类型 or 基本类型
                        val[0] &= compareObjByGetter(sourceInvokeVal, otherInvokeVal, compareContext, methodFilters);
                    }
                    compareContext.pathMessageStack.pop();
                }
            }
        });
        return val[0];
    }

对于集合类型的处理如下

主要根据各自的特性取出元素,再给到上面的主流程去执行

 private static boolean dealWithCMA(Object sourceObj, Object otherObj, CompareContext compareContext, MethodFilter... methodFilters) {
        if(sourceObj==otherObj){
            return true;
        }
        boolean isDiff = true;
        if (sourceObj instanceof Collection) {

            Collection<?> sourceCollection = ((Collection<?>) sourceObj);
            Collection<?> otherCollection = ((Collection<?>) otherObj);
            //要求顺序,这里不做排序
            if (sourceCollection.size() != otherCollection.size()) {
                isDiff = false;
            } else {
                Iterator<?> sourceI = sourceCollection.iterator();
                Iterator<?> otherI = otherCollection.iterator();
                int index = 0;
                while (sourceI.hasNext()) {
                    Object sourceElement = sourceI.next();
                    Object otherElement = otherI.next();
                    //下一层不匹配的值
                    compareContext.pathMessageStack.push(String.format("%s%s", COLLECTION_SIGN, index++));
                    isDiff &= compareObjByGetter(sourceElement, otherElement, compareContext, methodFilters);
                    compareContext.pathMessageStack.pop();
                }
            }
        }

        if (sourceObj.getClass().isArray()) {
            Object[] sourceArray = (Object[]) sourceObj;
            Object[] otherArray = (Object[]) otherObj;
            if (sourceArray.length != otherArray.length) {
                isDiff = false;
            } else {
                for (int i = 0; i < sourceArray.length; i++) {
                    Object sourceElement = sourceArray[i];
                    Object otherElement = otherArray[i];
                    compareContext.pathMessageStack.push(String.format("%s%s", ARRAY_SIGN, i));
                    isDiff &= compareObjByGetter(sourceElement, otherElement, compareContext, methodFilters);
                    compareContext.pathMessageStack.pop();
                }
            }
        }
        if (sourceObj instanceof Map) {
            Map<?, ?> sourceMap = (Map) sourceObj;
            Map<?, ?> otherMap = (Map) otherObj;
            if (sourceMap.size() != otherMap.size()) {
                isDiff = false;
            } else {
                HashSet<?> otherKeySet = new HashSet<>(otherMap.keySet());
                for (Map.Entry<?, ?> entry : sourceMap.entrySet()) {
                    Object sourceKey = entry.getKey();
                    Object otherVal = otherMap.get(sourceKey);
                    otherKeySet.remove(sourceKey);
                    compareContext.pathMessageStack.push(String.format("%s%s", KEY_SIGN, sourceKey));
                    isDiff &= compareObjByGetter(entry.getValue(), otherVal, compareContext, methodFilters);
                    compareContext.pathMessageStack.pop();
                }
                if (!otherKeySet.isEmpty()) {
                    for (Object otherKey : otherKeySet) {
                        compareContext.pathMessageStack.push(String.format("%s%s", KEY_SIGN, otherKey));
                        isDiff &= compareObjByGetter(null, otherMap.get(otherKey), compareContext, methodFilters);
                        compareContext.pathMessageStack.pop();
                    }
                }
            }
        }
        if (!isDiff) {
            generateResult(sourceObj, otherObj, compareContext);
        }
        return isDiff;
    }

对于基本对象判断,如果返回object类型需要进一步解析判断,后续如果有其他基本对象,比如业务自定义的基本对象也可以往里面加,或者再进行优化,通过本地线程的方式动态指定基本对象类型

/**
     * 后续比对有其他基本类型可以往里加
     * @param obj
     * @return
     */
    protected static Class<?> getObjType(Object obj) {
        if (obj instanceof Integer) {
            return Integer.class;
        } else if (obj instanceof String) {
            return String.class;
        } else if (obj instanceof BigDecimal) {
            return BigDecimal.class;
        } else if (obj instanceof Long) {
            return Long.class;
        } else if (obj instanceof Enum) {
            return Enum.class;
        } else if (obj instanceof Double) {
            return Double.class;
        } else if (obj instanceof Boolean) {
            return Boolean.class;
        }
        return Object.class;
    }

对于基本类型的比较方法

private static <T> boolean compareBaseObj(T obj, T other) {
        //同一个对象直接通过
        if(obj==other){
            return true;
        }
        //数字类型
        if (obj instanceof Number && obj instanceof Comparable) {
            return ((Comparable<T>) obj).compareTo(other) == 0;
        }
        //其他类型
        return Objects.equals(obj, other);
    }

效果

Java对象比对功能实现大概如此,来看看效果

定义了比对对象

@Getter
    public static class ComposeObj {
        private String id;
        private Object[] arrays;

        private List<Object> list;

        private Map<String, Object> map;

        private ComposeObj son;

        private int idLength;

        public ComposeObj(String id) {
            this.id = id;
            this.idLength = id.length();
        }
    }

测试代码

 ComposeObj sourceObj = new ComposeObj("source");
        ComposeObj arrayObj = new ComposeObj("A1");
        sourceObj.arrays = new Object[]{arrayObj, new ComposeObj("A22")};
        sourceObj.list = Arrays.asList(new ComposeObj("C1"), new ComposeObj("C11"));
        Map<String, Object> map = new HashMap<>();
        map.put("test", "test");
        map.put("test2", "test2");
        sourceObj.map = map;

      ComposeObj  otherObj = new ComposeObj("other");
        ComposeObj arrayObj2 = new ComposeObj("A2");
        otherObj.arrays = new Object[]{arrayObj2, new ComposeObj("A22")};
        otherObj.list = Arrays.asList(new ComposeObj("C2"), new ComposeObj("C11"));
        Map<String, Object> map2 = new HashMap<>();
        map2.put("test", "test2");
        map2.put("test2", "test22");
        otherObj.map = map2;

测试方法

  CompareResult compareResult = CompareUtil.compareObjByGetter(sourceObj, otherObj);
        assert checkPath(compareResult);
        assert compareResult.getDiffList().size() == 9;
        log.info(compareResult.getBaseObjDiffInfo());

结果

默认的支持的表达式过滤器如下

/**
 * 通过简单的表达式
 * "*abc|xxx" ->标识以abc结尾或xxx的属性忽略,不做比对,*代表通配符
 */
public class RegexFieldFilter implements MethodFilter {
    private static final Cache<String, Pattern> REGEX_MAP = CacheBuilder.newBuilder()
            .softValues().maximumSize(2048).build();

    private final List<String> rules;

    private static final String WILDCARD = "*";
    //是否缓存结果,如果调用次数较多(比如属性为list,且实际场景数量较多)可以用启用
    private boolean cacheResult = false;
    //方法key
    private Cache<String, Boolean> resultMap;

    private final Set<String> equalsField = new HashSet<>();

    private final Map<String, String> prefixFieldMap = new HashMap<>();

    private final Map<String, String> suffixFieldMap = new HashMap<>();

    private RegexFieldFilter(String regex, boolean cacheResult) {
        this.cacheResult = cacheResult;
        rules = Splitter.on("|").splitToList(regex);
        for (String rule : rules) {
            //普通比对
            if (!rule.contains(WILDCARD)) {
                equalsField.add(rule);
            }
            //首尾通配符特殊逻辑
            if (onlyOneWildcard(rule)) {
                if (rule.startsWith(WILDCARD)) {
                    suffixFieldMap.put(rule, rule.substring(1));
                }
                if (rule.endsWith(WILDCARD)) {
                    prefixFieldMap.put(rule, rule.substring(0, rule.length() - 1));
                }
            }
        }
        if (cacheResult) {
            resultMap = CacheBuilder.newBuilder().softValues().maximumSize(1024).build();
        }

    }

    public static RegexFieldFilter of(String regex, boolean cacheResult) {
        return new RegexFieldFilter(regex, cacheResult);
    }

    public static RegexFieldFilter of(String regex) {
        return of(regex, false);
    }


    private boolean canSkip(String rule, String fieldName) {
        if (rule.contains(WILDCARD)) {
            if (suffixFieldMap.containsKey(rule)) {
                return fieldName.endsWith(suffixFieldMap.get(rule));
            }
            if (prefixFieldMap.containsKey(rule)) {
                return fieldName.startsWith(prefixFieldMap.get(rule));
            }
            //在中间或多个通配符
            String replace = StringUtils.replace(rule, WILDCARD, ".*");
            Pattern pattern = REGEX_MAP.asMap().computeIfAbsent(replace, Pattern::compile);
            return pattern.matcher(fieldName).matches();
        }
        return equalsField.contains(fieldName);
    }

    private boolean onlyOneWildcard(String rule) {
        if (!rule.contains(WILDCARD)) {
            return false;
        }
        return rule.indexOf(WILDCARD, rule.indexOf(WILDCARD) + 1) == -1;
    }

    @Override
    public boolean isSkipCompare(Method method, String methodKey, CompareUtil.CompareContext context) {
        return cacheResult ? resultMap.asMap().computeIfAbsent(methodKey, s -> judgeSkip(method)) : judgeSkip(method);

    }

    private boolean judgeSkip(Method method) {
        if (!CollectionUtils.isEmpty(rules)) {
            String name = method.getName();
            String fieldName = CompareUtil.getFieldName(name, method.getDeclaringClass().getCanonicalName());
            for (String rule : rules) {
                if (canSkip(rule, fieldName)) {
                    return true;
                }
            }
        }
        return false;
    }


}

测试代码如下,定义这个过滤会把属性名为arrays,带有'l',或者ma开头的属性都过滤掉,不参与比对逻辑

  boolean cacheResult = false;
        RegexFieldFilter of = RegexFieldFilter.of("arrays|*l*|ma*", cacheResult);
        CompareResult compareResult = CompareUtil.compareObjByGetter(source, other, of);
        assert checkPath(compareResult);
        assert compareResult.getDiffList().size() == 15;

ComopareUtil完整代码

https://github.com/97lele/redis-aux/tree/dev/common/src/main/java/com/xl/redisaux/common/utils/compare

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1902277.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

JUC(java.util.concurrent)中的常见类

文章目录 Callable接口ReentrantLockReentrantLock 和 synchronized 的区别:如何选择使用哪个锁? 信号量SemaphoreCountDownLatch多线程环境使用ArrayList多线程使用 哈希表相关面试题 JUC放了和多线程有关的组件 Callable接口 和Runnable一样是描述一个任务,但是有返回值,表…

查询某个县区数据,没有的数据用0补充。

加油&#xff0c;新时代打工人&#xff01; 思路&#xff1a; 先查出有数据的县区&#xff0c;用县区编码判断&#xff0c;不存在县区里的数据。然后&#xff0c;用union all进行两个SQL拼接起来。 SELECTt.regionCode,t.regionName,t.testNum,t.sampleNum,t.squareNum,t.crop…

springboot+vue+mybatis图书馆借阅管理系统+PPT+论文+讲解+售后

21世纪的今天&#xff0c;随着社会的不断发展与进步&#xff0c;人们对于信息科学化的认识&#xff0c;已由低层次向高层次发展&#xff0c;由原来的感性认识向理性认识提高&#xff0c;管理工作的重要性已逐渐被人们所认识&#xff0c;科学化的管理&#xff0c;使信息存储达到…

三分钟内了解卷轴模式

在数字化时代的浪潮中&#xff0c;卷轴商业模式巧妙地将积分体系、互动任务、社交裂变、虚拟经济体系以及个性化成长路径等多元要素融为一体。 积分体系&#xff1a;激发参与动力的源泉 卷轴商业模式的核心在于其精心构建的积分系统。新用户踏入平台&#xff0c;即获赠一笔启…

基于自编码器的时间序列异常检测方法(以传感器数据为例,MATLAB R2021b)

尽管近年来研究者对自编码器及其改进算法进行了深入研究&#xff0c;但现阶段仍存在以下问题亟须解决。 1) 无监督学习模式对特征提取能力的限制与有监督学习相比&#xff0c;无监督学习模式摆脱了对样本标签的依赖、避免了人工标注的困难&#xff0c;但也因此失去了样本标签的…

LLM - 循环神经网络(RNN)

1. RNN的关键点&#xff1a;即在处理序列数据时会有顺序的记忆。比如&#xff0c;RNN在处理一个字符串时&#xff0c;在对字母表顺序有记忆的前提下&#xff0c;处理这个字符串会更容易。就像人一样&#xff0c;读取下面第一个字符串会更容易&#xff0c;因为人对字母出现的顺序…

一站式解决方案:用ChatGPT和AutoGPT组建你的个人写作团队

ChatGPT 在 AI 内容创作领域带来了巨大的飞跃&#xff0c;然而它在撰写完整文章时偶尔会陷入废话和奇怪主题。作为专业作家、AI专家及OpenAI Beta测试人员&#xff0c;我一直探索AI写作。虽然ChatGPT表现出色&#xff0c;但有时难以达到创造高质量文章的标准。 最近&#xff0…

EtherCAT转Profinet网关配置说明第二讲:上位机软件配置

EtherCAT协议转Profinet协议网关模块&#xff08;XD-ECPNS20&#xff09;&#xff0c;不仅可以实现数据之间的通信&#xff0c;还可以实现不同系统之间的数据共享。EtherCAT协议转Profinet协议网关模块&#xff08;XD-ECPNS20&#xff09;具有高速传输的特点&#xff0c;因此通…

githup开了代理push不上去

你们好&#xff0c;我是金金金。 场景 git push出错 解决 cmd查看 git config --global http.proxy git config --global https.proxy 如果什么都没有&#xff0c;代表没设置全局代理&#xff0c;此时如果你开了代理&#xff0c;则执行如下&#xff0c;设置代理 git con…

Github:git提交代码到github

创建 GitHub 仓库 a. 登录到您的 GitHub 账户。 b. 点击右上角的 "" 图标&#xff0c;选择 "New repository"。 c. 填写仓库名称&#xff08;例如 "Mitemer"&#xff09;。 d. 添加项目描述&#xff08;可选&#xff09;。 e. 选择仓库为 &…

微信小程序的轻松音乐-计算机毕业设计源码48092

目 录 摘要 1 绪论 1.1研究背景与意义 1.2研究现状 1.3论文结构与章节安排 2 基于微信小程序的轻松音乐系统分析 2.1 可行性分析 2.1.1 技术可行性分析 2.1.2 经济可行性分析 2.1.3 法律可行性分析 2.2 系统功能分析 2.2.1 功能性分析 2.3 系统用例分析 2.4 系统…

排序——数据结构与算法 总结8

目录 8.1 排序相关概念 8.2 插入排序 8.2.1 直接插入排序&#xff1a; 8.2.2 折半插入排序&#xff1a; 8.2.3 希尔排序&#xff1a; 8.3 交换排序 8.3.1 冒泡排序&#xff1a; 8.3.2 快速排序&#xff1a; 8.4 选择排序 8.4.1 简单选择排序 8.4.2 堆排序 8.5 归并…

C++--partition库函数

介绍 在C中&#xff0c;partition函数通常是指STL&#xff08;Standard Template Library&#xff09;中的std::partition算法&#xff0c;它用于对一个序列进行分区操作。具体来说&#xff0c;std::partition接受一个范围和一个谓词&#xff08;predicate&#xff09;作为参数…

策略为王股票软件源代码-----如何修改为自己软件73------------主界面右下角,大盘指数,时间显示 ,

IDS_MAINFRAME_SHINDEXTIP "沪:%2.f %+.2f %.2f亿" IDS_MAINFRAME_SZINDEXTIP "深:%2.f %+.2f %.2f亿" 主界面右下角,大盘指数,时间显示 , if( TIMER_TIME == nIDEvent ) { CSPTime time = CSPTime::GetCurrentTime(); …

去除gif动图背景的工具网站

选择视频或GIF - 取消屏幕 (unscreen.com)https://www.unscreen.com/upload

【论文解读】LivePortrait:具有拼接和重定向控制的高效肖像动画

&#x1f4dc; 文献卡 英文题目: LivePortrait: Efficient Portrait Animation with Stitching and Retargeting Control;作者: Jianzhu Guo; Dingyun Zhang; Xiaoqiang Liu; Zhizhou Zhong; Yuan Zhang; Pengfei Wan; Di ZhangDOI: 10.48550/arXiv.2407.03168摘要翻译: *旨在…

以腾讯为例,手把手教你搭建产品帮助中心

一个精心设计的产品帮助中心对于提高用户满意度和体验至关重要。腾讯&#xff0c;作为全球领先的互联网企业&#xff0c;通过其多样化的产品线&#xff08;包括微信、QQ、腾讯游戏、腾讯视频等&#xff09;吸引了亿万用户。下面将以腾讯为例&#xff0c;向您展示如何搭建一个高…

mysql修改字符集为UTF-8

启动 mysql 服务 systemctl start mysqld 登录 mysql mysql -uroot -p 查询 mysql 字符集 ## 在 mysql 命令行下查询 mysql 状态 mysql>status; 退出 mysql 并关闭 mysql ## 退出 mysql mysql>exit; ## 关闭 mysql systemctl stop mysqld 编辑 my.cnf 配置文…

Golang语法规范和风格指南(一)——简单指南

1. 前引 一个语言的规范的学习是重要的&#xff0c;直接关系到你的代码是否易于维护和理解&#xff0c;同时学习好对应的语言规范可以在前期学习阶段有效规避该语言语法和未知编程风格的冲突。 这里是 Google 提供的规范&#xff0c;有助于大家在开始学习阶段对 Golang 进行一…

【IT领域新生必看】深入了解Java中的静态成员变量和实例成员变量:初学者的全方位指南

文章目录 引言什么是静态成员变量&#xff1f;定义和使用静态成员变量示例&#xff1a; 静态成员变量的特点示例&#xff1a; 什么是实例成员变量&#xff1f;定义和使用实例成员变量示例&#xff1a; 实例成员变量的特点示例&#xff1a; 静态成员变量与实例成员变量的区别作用…