基本 Java Bean

2020-12-13 02:06

阅读:390

标签:location   plugins   cti   xxx   div   tostring   VID   values   import   

xml version="1.0" encoding="UTF-8"?>
project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    modelVersion>4.0.0modelVersion>

    groupId>com.ck.testgroupId>
    artifactId>CK_TestartifactId>
    version>1.0.0version>

    properties>
        java.version>1.8java.version>
        project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        framework.bom.version>3.18.0framework.bom.version>
        maven-compiler-plugin.version>3.6.0maven-compiler-plugin.version>
        maven-surefire-plugin.version>2.19.1maven-surefire-plugin.version>
        maven-source-plugin.version>3.0.1maven-source-plugin.version>
        maven-jar-plugin.version>3.0.2maven-jar-plugin.version>
        maven-war-plugin.version>3.0.0maven-war-plugin.version>
        maven-install-plugin.version>2.5.2maven-install-plugin.version>
    properties>

    dependencyManagement>
        dependencies>
            
            dependency>
                groupId>com.XXX.frameworkgroupId>
                artifactId>framework-bomartifactId>
                version>${framework.bom.version}version>
                type>pomtype>
                scope>importscope>
            dependency>
            
            dependency>
                groupId>org.projectlombokgroupId>
                artifactId>lombokartifactId>
                version>1.18.2version>
                scope>providedscope>
            dependency>
        dependencies>
    dependencyManagement>

    dependencies>
        
        dependency>
            groupId>org.projectlombokgroupId>
            artifactId>lombokartifactId>
        dependency>
        
        dependency>
            groupId>com.google.guavagroupId>
            artifactId>guavaartifactId>
        dependency>
    dependencies>


    build>
        pluginManagement>
            plugins>
                plugin>
                    groupId>org.apache.maven.pluginsgroupId>
                    artifactId>maven-compiler-pluginartifactId>
                    version>${maven-compiler-plugin.version}version>
                    configuration>
                        source>${java.version}source>
                        target>${java.version}target>
                        encoding>${project.build.sourceEncoding}encoding>
                    configuration>
                plugin>
                plugin>
                    groupId>org.apache.maven.pluginsgroupId>
                    artifactId>maven-surefire-pluginartifactId>
                    version>${maven-surefire-plugin.version}version>
                plugin>
                plugin>
                    groupId>org.apache.maven.pluginsgroupId>
                    artifactId>maven-source-pluginartifactId>
                    version>${maven-source-plugin.version}version>
                    executions>
                        execution>
                            id>attach-sourcesid>
                            goals>
                                goal>jar-no-forkgoal>
                            goals>
                        execution>
                    executions>
                plugin>
                plugin>
                    groupId>org.apache.maven.pluginsgroupId>
                    artifactId>maven-jar-pluginartifactId>
                    version>${maven-jar-plugin.version}version>
                plugin>
                plugin>
                    groupId>org.apache.maven.pluginsgroupId>
                    artifactId>maven-war-pluginartifactId>
                    version>${maven-war-plugin.version}version>
                plugin>
                plugin>
                    groupId>org.codehaus.mojogroupId>
                    artifactId>versions-maven-pluginartifactId>
                    version>2.5version>
                plugin>
                plugin>
                    artifactId>maven-eclipse-pluginartifactId>
                    version>2.9version>
                    configuration>
                        downloadSources>truedownloadSources>
                        ajdtVersion>noneajdtVersion>
                        additionalConfig>
                            file>
                                name>.settings/org.eclipse.jdt.core.prefsname>
                                content>
                                    org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
                                    eclipse.preferences.version=1
                                    org.eclipse.jdt.core.compiler.source=1.7
                                    org.eclipse.jdt.core.compiler.compliance=1.7
                                content>
                            file>
                        additionalConfig>
                    configuration>
                plugin>
            plugins>
        pluginManagement>
    build>

project>

 

 

package com.ck.test.misc;


import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ComparisonChain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Book implements Comparable {
    private String title;
    private String author;
    private String publisher;
    private String isbn;
    private double price;


    @Override
    public int hashCode() {
        return Objects.hashCode(title, author, publisher, isbn);
    }

    @Override
    public boolean equals(Object obj) {
        if(this == obj){
            return true;
        }
        if(obj == null){
            return false;
        }
        if(getClass() != obj.getClass()){
            return false;
        }
        if(!(obj instanceof Book)){
            return false;
        }
        Book other = (Book)obj;

        return Objects.equal(title, other.getTitle()) &&
                Objects.equal(author, other.getAuthor()) &&
                Objects.equal(publisher, other.getPublisher()) &&
                Objects.equal(isbn, other.getIsbn()) &&
                price == other.getPrice();
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this).omitNullValues()
                .add("title", title)
                .add("author", author)
                .add("publisher", publisher)
                .add("isbn", isbn)
                .add("price", price)
                .toString();
    }

    public static void main(String[] args){
        Book book = new Book("Core Java", "Tom", "JackMa", "11-22-33-44", 12.80);
        System.out.println(book);
    }

    @Override
    public int compareTo(Book o) {
        return ComparisonChain.start()
                .compare(this.title, o.getTitle())
                .compare(this.author, o.getAuthor())
                .compare(this.publisher, o.publisher)
                .compare(this.isbn, o.getIsbn())
                .compare(this.price, o.getPrice())
                .result();
    }

}

 

基本 Java Bean

标签:location   plugins   cti   xxx   div   tostring   VID   values   import   

原文地址:https://www.cnblogs.com/ylz8401/p/11025733.html


评论


亲,登录后才可以留言!