package ch.ifocusit.livingdoc.plugin.mapping;

import com.google.common.collect.Ordering;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

public class MappingDefinition implements Comparable<MappingDefinition> {
    private Integer id;
    private String name;
    private String description;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Check the name
     */
    public MappingDefinition checkName() {
        name = name.trim().replace(" ", "_");
        return this;
    }

    @Override
    public int compareTo(MappingDefinition o) {
        return BY_ID.compound(BY_NAME).compound(BY_DESCRIPTION).nullsFirst().compare(this, o);
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override
    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj);
    }

    private static final Ordering<MappingDefinition> BY_ID = Ordering.natural().onResultOf(MappingDefinition::getId);
    private static final Ordering<MappingDefinition> BY_NAME = Ordering.natural().nullsFirst().onResultOf(MappingDefinition::getName);
    private static final Ordering<MappingDefinition> BY_DESCRIPTION = Ordering.natural().nullsFirst().onResultOf(MappingDefinition::getDescription);
}
@@ -40,16 +40,66 @@
 pping;%0A%0A
+import com.google.common.collect.ComparisonChain;%0A
 import c
@@ -1060,95 +1060,52 @@
 urn 
-BY_ID.compound(BY_NAME).compound(BY_DESCRIPTION).nullsFirst().compare(this, o);
+new Ordering%3CMappingDefinition%3E() %7B
 %0A    
-%7D%0A%0A
+    
     
@@ -1106,32 +1106,40 @@
       @Override%0A
+        
     public int h
@@ -1141,29 +1141,81 @@
 int 
-hashCode() %7B%0A
+compare(MappingDefinition left, MappingDefinition right) %7B%0A      
         
 retu
@@ -1214,582 +1214,683 @@
     
+  
 return 
-HashCodeBuilder.reflectionHashCode(this);
+ComparisonChain.start()
 %0A    
-%7D%0A%0A
     
-@Override%0A    public boolean equals(Object obj) %7B%0A        return EqualsBuilder.reflectionEquals(this, obj);%0A    %7D%0A%0A    private static final Ordering%3CMappingDefinition%3E BY_ID = Ordering.natural().onResultOf(MappingDefinition::getId);%0A    private static final Ordering%3CMappingDefinition%3E BY_NAME = Ordering.natural().nullsFirst().onResultOf(MappingDefinition::getName);%0A    private stat
+                .compare(left.getId(), right.getId(), Ordering.natural().nullsFirst())%0A                        .compare(left.getName(), right.getName(), Ordering.natural().nullsFirst())%0A                        .compare(left.getDescription(), right.getDescription(), Ordering.natural().nullsFirst())%0A                        .result();%0A            %7D%0A        %7D.nullsFirst()%0A                .compare(this, o);%0A    %7D%0A%0A    @Override%0A    publ
 ic 
-f
 in
-al Ordering%3CMappingDefinition%3E BY_DESCRIPTION = Ordering.natural().nullsFirst().onResultOf(MappingDefinition::getDescription);
+t hashCode() %7B%0A        return HashCodeBuilder.reflectionHashCode(this);%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object obj) %7B%0A        return EqualsBuilder.reflectionEquals(this, obj);%0A    %7D
 %0A%7D

correct casting