001/*
002 *  Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
003 *  <p>
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *  <p>
008 *  http://www.apache.org/licenses/LICENSE-2.0
009 *  <p>
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016
017package com.mybatisflex.processor.entity;
018
019import java.util.Objects;
020
021/**
022 * 列详细信息。
023 *
024 * @author 王帅
025 * @since 2023-07-01
026 */
027public class ColumnInfo implements Comparable<ColumnInfo> {
028
029    /**
030     * 属性名。
031     */
032    private String property;
033
034    /**
035     * 注释。
036     */
037    private String comment;
038
039    /**
040     * 列名。
041     */
042    private String column;
043
044    /**
045     * 别名。
046     */
047    private String[] alias;
048
049    public String getProperty() {
050        return property;
051    }
052
053    public void setProperty(String property) {
054        this.property = property;
055    }
056
057    public String getComment() {
058        return comment;
059    }
060
061    public void setComment(String comment) {
062        this.comment = comment;
063    }
064
065    public String getColumn() {
066        return column;
067    }
068
069    public void setColumn(String column) {
070        this.column = column;
071    }
072
073    public String[] getAlias() {
074        return alias;
075    }
076
077    public void setAlias(String[] alias) {
078        this.alias = alias;
079    }
080
081    @Override
082    public boolean equals(Object o) {
083        if (this == o) {
084            return true;
085        }
086        if (o == null || getClass() != o.getClass()) {
087            return false;
088        }
089        ColumnInfo that = (ColumnInfo) o;
090        return Objects.equals(property, that.property);
091    }
092
093    @Override
094    public int hashCode() {
095        return property != null ? property.hashCode() : 0;
096    }
097
098    @Override
099    public int compareTo(ColumnInfo o) {
100        // 先根据属性长度排序,属性名短的在上
101        int compare = Integer.compare(property.length(), o.property.length());
102        // 属性名长度一样,再按字母排序
103        return compare == 0 ? property.compareTo(o.property) : compare;
104    }
105
106}