package com.github.davidmoten.rtree;

import com.github.davidmoten.rtree.geometry.Geometry;
import com.github.davidmoten.rtree.geometry.HasGeometry;
import com.google.common.base.Preconditions;

public final class Entry<T> implements HasGeometry {
    private final T value;
    private final Geometry geometry;

    public Entry(T value, Geometry geometry) {
        Preconditions.checkNotNull(value);
        Preconditions.checkNotNull(geometry);
        this.value = value;
        this.geometry = geometry;
    }

    public static <T> Entry<T> entry(T value, Geometry geometry) {
        return new Entry<T>(value, geometry);
    }

    public T value() {
        return value;
    }

    @Override
    public Geometry geometry() {
        return geometry;
    }

    @Override
    public String toString() {
        return "Entry [value=" + value + ", geometry=" + geometry + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((geometry == null) ? 0 : geometry.hashCode());
        result = prime * result + ((value == null) ? 0 : value.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final Entry<?> other = (Entry<?>) obj;
        if (geometry == null) {
            if (other.geometry() != null)
                return false;
        } else if (!geometry.equals(other.geometry()))
            return false;
        if (value == null) {
            if (other.value() != null)
                return false;
        } else if (!value.equals(other.value()))
            return false;
        return true;
    }

}

@@ -134,32 +134,160 @@
 ry.HasGeometry;%0A
+import com.github.davidmoten.util.ObjectsHelper;%0Aimport com.google.common.base.Objects;%0Aimport com.google.common.base.Optional;%0A
 import com.googl
@@ -369,20 +369,17 @@
 metry %7B%0A
-    
+%09
 private 
@@ -393,20 +393,17 @@
  value;%0A
-    
+%09
 private 
@@ -428,20 +428,17 @@
 metry;%0A%0A
-    
+%09
 public E
@@ -472,24 +472,18 @@
 etry) %7B%0A
-        
+%09%09
 Precondi
@@ -509,24 +509,18 @@
 value);%0A
-        
+%09%09
 Precondi
@@ -549,24 +549,18 @@
 metry);%0A
-        
+%09%09
 this.val
@@ -571,24 +571,18 @@
  value;%0A
-        
+%09%09
 this.geo
@@ -599,27 +599,21 @@
 ometry;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 public s
@@ -663,32 +663,26 @@
 geometry) %7B%0A
-        
+%09%09
 return new E
@@ -707,27 +707,21 @@
 metry);%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 public T
@@ -727,32 +727,26 @@
 T value() %7B%0A
-        
+%09%09
 return value
@@ -747,27 +747,21 @@
  value;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Overrid
@@ -758,28 +758,25 @@
 %0A%09@Override%0A
-    
+%09
 public Geome
@@ -788,32 +788,26 @@
 eometry() %7B%0A
-        
+%09%09
 return geome
@@ -811,27 +811,21 @@
 ometry;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Overrid
@@ -822,28 +822,25 @@
 %0A%09@Override%0A
-    
+%09
 public Strin
@@ -854,24 +854,18 @@
 ing() %7B%0A
-        
+%09%09
 return %22
@@ -921,27 +921,21 @@
  + %22%5D%22;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Overrid
@@ -932,28 +932,25 @@
 %0A%09@Override%0A
-    
+%09
 public int h
@@ -965,254 +965,57 @@
 ) %7B%0A
-        final int prime = 31;%0A        int result = 1;%0A        result = prime * result + ((geometry == null) ? 0 : geometry.hashCode());%0A        result = prime * result + ((value == null) ? 0 : value.hashCode());%0A        return result;%0A    %7D%0A%0A    
+%09%09return Objects.hashCode(value, geometry);%0A%09%7D%0A%0A%09
 @Ove
@@ -1020,20 +1020,17 @@
 verride%0A
-    
+%09
 public b
@@ -1061,607 +1061,234 @@
 ) %7B%0A
-        if (this == obj)%0A            return true;%0A        if (obj == null)%0A            return false;%0A        if (getClass() != obj.getClass())%0A            return false;%0A        final Entry%3C?%3E other = (Entry%3C?%3E) obj;%0A        if (geometry == null) %7B%0A            if (other.geometry() != null)%0A                return false;%0A        %7D else if (!geometry.equals(other.geometry()))%0A            return false;%0A        if (value == null) %7B%0A            if (other.value() != null)%0A                return false;%0A        %7D else if (!value.equals(other.value()))%0A            return false;%0A        return true;%0A    
+%09%09Optional%3CEntry%3E other = ObjectsHelper.asClass(obj, Entry.class);%0A%09%09if (other.isPresent()) %7B%0A%09%09%09return Objects.equal(value, other.get().value)%0A%09%09%09%09%09&& Objects.equal(geometry, other.get().geometry);%0A%09%09%7D else%0A%09%09%09return false;%0A%09
 %7D%0A%0A%7D

use guava Objects equals and hashcode