package co.nstant.in.cbor.model;

import java.util.Objects;

public class DataItem {

    private final MajorType majorType;
	private Tag tag;

    protected DataItem(MajorType majorType) {
        this.majorType = majorType;
        Objects.requireNonNull(majorType, "majorType is null");
    }

    public MajorType getMajorType() {
        return majorType;
    }

	public void setTag(long tag) {
		if(tag < 0) {
			throw new IllegalArgumentException("tag number must be 0 or greater");
		}

		this.tag = new Tag(tag);
	}

	public void setTag(Tag tag) {
		Objects.requireNonNull(tag, "tag is null");
		this.tag = tag;
	}

	public void removeTag() {
		this.tag = null;
	}

	public Tag getTag() {
		return this.tag;
	}

	public boolean hasTag() {
		return (this.tag != null);
	}

	@Override
	public boolean equals(Object object) {
		if(this == object) {
			return true;
		}

		if(object instanceof DataItem) {
			DataItem otherDi = (DataItem) object;
			if(this.tag != null) {
				if(this.tag.equals(otherDi.getTag()) && this.majorType == otherDi.getMajorType()) {
					return true;
				}
			}
			else {
				if(otherDi.getTag() == null && this.majorType == otherDi.getMajorType()) {
					return true;
				}
			}
		}

		return false;
	}

	@Override
	public int hashCode() {
		int hash = Objects.hashCode(this.tag);
		return hash;
	}

    protected void assertTrue(boolean condition, String message) {
        if (!condition) {
            throw new IllegalArgumentException(message);
        }
    }

}

@@ -118,17 +118,20 @@
 orType;%0A
-%09
+    
 private 
@@ -364,17 +364,20 @@
 %0A    %7D%0A%0A
-%09
+    
 public v
@@ -399,20 +399,27 @@
  tag) %7B%0A
-%09%09
+        
 if
+ 
 (tag %3C 0
@@ -422,19 +422,28 @@
  %3C 0) %7B%0A
-%09%09%09
+            
 throw ne
@@ -505,23 +505,35 @@
 ater%22);%0A
-%09%09%7D%0A%0A%09%09
+        %7D%0A%0A        
 this.tag
@@ -549,21 +549,27 @@
 g(tag);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 public v
@@ -590,18 +590,24 @@
  tag) %7B%0A
-%09%09
+        
 Objects.
@@ -642,18 +642,24 @@
 null%22);%0A
-%09%09
+        
 this.tag
@@ -662,29 +662,35 @@
 .tag = tag;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 public void 
@@ -703,18 +703,24 @@
 Tag() %7B%0A
-%09%09
+        
 this.tag
@@ -728,21 +728,27 @@
 = null;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 public T
@@ -757,26 +757,32 @@
  getTag() %7B%0A
-%09%09
+        
 return this.
@@ -786,21 +786,27 @@
 is.tag;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 public b
@@ -823,18 +823,24 @@
 Tag() %7B%0A
-%09%09
+        
 return (
@@ -858,21 +858,27 @@
  null);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 @Overrid
@@ -875,25 +875,28 @@
   @Override%0A
-%09
+    
 public boole
@@ -922,20 +922,27 @@
 ject) %7B%0A
-%09%09
+        
 if
+ 
 (this ==
@@ -952,19 +952,28 @@
 ject) %7B%0A
-%09%09%09
+            
 return t
@@ -981,17 +981,30 @@
 ue;%0A
-%09%09%7D%0A%0A%09%09
+        %7D%0A%0A        
 if
+ 
 (obj
@@ -1030,19 +1030,28 @@
 Item) %7B%0A
-%09%09%09
+            
 DataItem
@@ -1080,21 +1080,31 @@
 object;%0A
-%09%09%09
+            
 if
+ 
 (this.ta
@@ -1116,22 +1116,35 @@
 null) %7B%0A
-%09%09%09%09
+                
 if
+ 
 (this.ta
@@ -1221,53 +1221,111 @@
 ) %7B%0A
-%09%09%09%09%09return true;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09else %7B%0A%09%09%09%09
+                    return true;%0A                %7D%0A            %7D%0A            else %7B%0A                
 if
+ 
 (oth
@@ -1397,44 +1397,92 @@
 ) %7B%0A
-%09%09%09%09%09return true;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09
+                    return true;%0A                %7D%0A            %7D%0A        %7D%0A%0A        
 retu
@@ -1495,13 +1495,19 @@
 se;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 @Ove
@@ -1512,17 +1512,20 @@
 verride%0A
-%09
+    
 public i
@@ -1544,65 +1544,57 @@
 ) %7B%0A
-%09%09int hash = Objects.hashCode(this.tag);%0A%09%09return hash;%0A%09
+        return Objects.hash(majorType, tag);%0A    
 %7D%0A%0A 

Include majorType in DataItem.hashCode