zoukankan      html  css  js  c++  java
  • Java NStruct

    package org.rx.bean;
    
    import org.rx.Lazy;
    import org.rx.SystemException;
    
    import java.io.Serializable;
    import java.lang.reflect.Field;
    
    public abstract class NStruct implements Serializable {
        static final long               serialVersionUID = 42L;
        private transient Lazy<Field[]> fields           = new Lazy<>(() -> this.getClass().getDeclaredFields());
    
        @Override
        public int hashCode() {
            StringBuilder hex = new StringBuilder();
            for (Field field : fields.getValue()) {
                field.setAccessible(true);
                try {
                    Object val = field.get(this);
                    if (val != null) {
                        hex.append(val.hashCode());
                    }
                } catch (IllegalAccessException ex) {
                    throw SystemException.wrap(ex);
                }
            }
            return hex.toString().hashCode();
        }
    
        @Override
        public boolean equals(Object obj) {
            if (obj == null || !(obj instanceof NStruct)) {
                return false;
            }
            NStruct struct = (NStruct) obj;
            return this.hashCode() == struct.hashCode();
        }
    }
  • 相关阅读:
    巡回赛 -- 简单的拓扑排序
    最简单的拓扑排序
    blockhouses
    部分和问题
    jfinal路由简单解析
    python mysql
    Gradle--ubuntu
    解决ssh登录后闲置时间过长而断开连接
    业界有很多MQ产品
    avalon---qunar ued
  • 原文地址:https://www.cnblogs.com/Googler/p/7616274.html
Copyright © 2011-2022 走看看