package com.webimageloader.loader;

import com.webimageloader.transformation.Transformation;

public class LoaderRequest {
    private String url;
    private Transformation transformation;
    private Metadata metadata;

    private String cacheKey = null;

    public LoaderRequest(String url) {
        this(url, null);
    }

    public LoaderRequest(String url, Transformation transformation) {
        if (url == null) {
            throw new NullPointerException("url may not be null");
        }

        this.url = url;
        this.transformation = transformation;
    }

    public LoaderRequest withoutTransformation() {
        return new LoaderRequest(url);
    }

    public LoaderRequest withMetadata(Metadata metadata) {
        LoaderRequest r = new LoaderRequest(url, transformation);
        r.metadata = metadata;

        return r;
    }

    public String getUrl() {
        return url;
    }

    public Transformation getTransformation() {
        return transformation;
    }

    public Metadata getMetadata() {
        return metadata;
    }

    public synchronized String getCacheKey() {
        if (cacheKey == null) {
            if (transformation != null) {
                cacheKey = url + transformation.getIdentifier();
            } else {
                cacheKey = url;
            }
        }

        return cacheKey;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + getCacheKey().hashCode();
        return result;
    }

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

    @Override
    public String toString() {
        if (transformation != null) {
            return url + " with transformation " + '"' + transformation.getIdentifier() + '"';
        } else {
            return url;
        }
    }
}

@@ -1414,87 +1414,14 @@
     
-final int prime = 31;%0A        int result = 1;%0A        result = prime * result +
+return
  get
@@ -1447,31 +1447,8 @@
 ();%0A
-        return result;%0A
     
@@ -1570,70 +1570,8 @@
   %7D%0A
-        if (obj == null) %7B%0A            return false;%0A        %7D
 %0A   
@@ -1578,18 +1578,16 @@
      if 
-(!
 (obj ins
@@ -1612,48 +1612,15 @@
 est)
-)
  %7B%0A    
-        return false;%0A        %7D%0A
     
@@ -1637,21 +1637,23 @@
 Request 
-other
+request
  = (Load
@@ -1680,13 +1680,19 @@
     
-if (!
+    return 
 getC
@@ -1712,13 +1712,15 @@
 als(
-other
+request
 .get
@@ -1730,17 +1730,32 @@
 heKey())
-)
+;%0A        %7D else
  %7B%0A     
@@ -1785,37 +1785,16 @@
       %7D%0A
-        return true;%0A
     %7D%0A%0A 

Simplify hashcode and equals