package org.openforis.collect.earth.ipcc.model;

import java.util.Objects;

public abstract class LandUseSubdivision<F> implements Comparable<LandUseSubdivision<F>>{

	protected LandUseCategory category;
	protected String code;
	protected String name;
	
	public LandUseSubdivision(LandUseCategory category, String code, String name) {
		super();
		this.category = category;
		this.code = code;
		this.name = name;
	}
	
	public abstract F getType();
	public abstract void setType(F type);
	
	public LandUseCategory getCategory() {
		return category;
	}
	public String getCode() {
		return code;
	}
	public String getName() {
		return name;
	}
	public void setCategory(LandUseCategory category) {
		this.category = category;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public int compareTo(LandUseSubdivision other) {
		if( this.getCategory().equals( other.getCategory() ) ){
			return this.getCode().compareTo( other.getCode() );
		}else {
			return this.getCategory().compareTo( other.getCategory() );
		}	
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		LandUseSubdivision<F> other = (LandUseSubdivision) obj;
		return Objects.equals(category, other.category) && Objects.equals(code, other.code) && Objects.equals(getType(), other.getType());
	}
	
	@Override
	public String toString() {
		return getCategory().getCode() + " / "  + getType() + " / "  + getCode();
	}
}

@@ -157,19 +157,16 @@
 division
-%3CF%3E
 %3E%7B%0D%0A%0D%0A%09p
@@ -1093,16 +1093,26 @@
 egory().
+getCode().
 compareT
@@ -1133,16 +1133,26 @@
 tegory()
+.getCode()
  );%0D%0A%09%09%7D

order the subdivisions correctly