package me.iwf.photopicker.entity;

import android.util.SparseBooleanArray;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by donglua on 15/6/28.
 */
public class PhotoDirectory {

  private String id;
  private String coverPath;
  private String name;
  private long   dateAdded;
  private List<Photo> photos = new ArrayList<>();

  @Override public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof PhotoDirectory)) return false;

    PhotoDirectory directory = (PhotoDirectory) o;

    if (!id.equals(directory.id)) return false;
    return name.equals(directory.name);
  }

  @Override public int hashCode() {
    int result = id.hashCode();
    result = 31 * result + name.hashCode();
    return result;
  }

  public String getId() {
    return id;
  }

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

  public String getCoverPath() {
    return coverPath;
  }

  public void setCoverPath(String coverPath) {
    this.coverPath = coverPath;
  }

  public String getName() {
    return name;
  }

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

  public long getDateAdded() {
    return dateAdded;
  }

  public void setDateAdded(long dateAdded) {
    this.dateAdded = dateAdded;
  }

  public List<Photo> getPhotos() {
    return photos;
  }

  public void setPhotos(List<Photo> photos) {
    this.photos = photos;
  }

  public List<String> getPhotoPaths() {
    List<String> paths = new ArrayList<>(photos.size());
    for (Photo photo : photos) {
      paths.add(photo.getPath());
    }
    return paths;
  }

  public void addPhoto(int id, String path) {
    photos.add(new Photo(id, path));
  }

}

@@ -48,32 +48,24 @@
 oid.
-util.SparseBooleanArray;
+text.TextUtils;%0A
 %0Aimp
@@ -93,33 +93,8 @@
 st;%0A
-import java.util.Arrays;%0A
 impo
@@ -530,23 +530,167 @@
     
-if (!id
+boolean hasId = !TextUtils.isEmpty(id);%0A    boolean otherHasId = !TextUtils.isEmpty(directory.id);%0A%0A    if (hasId && otherHasId) %7B%0A      if (!TextUtils
 .equals(
 dire
@@ -677,32 +677,36 @@
 extUtils.equals(
+id, 
 directory.id)) r
@@ -703,16 +703,26 @@
 ory.id))
+ %7B%0A       
  return 
@@ -736,27 +736,43 @@
     
-return name
+  %7D%0A%0A      return TextUtils
 .equals(
 dire
@@ -767,16 +767,22 @@
 .equals(
+name, 
 director
@@ -790,16 +790,41 @@
 .name);%0A
+    %7D%0A%0A    return false;%0A
   %7D%0A%0A  @
@@ -865,34 +865,232 @@
    i
-nt result = id.hashCode();
+f (TextUtils.isEmpty(id)) %7B%0A      if (TextUtils.isEmpty(name)) %7B%0A        return 0;%0A      %7D%0A%0A      return name.hashCode();%0A    %7D%0A%0A    int result = id.hashCode();%0A%0A    if (TextUtils.isEmpty(name)) %7B%0A      return result;%0A    %7D%0A
 %0A   

Handle missing id / name in PhotoDirectory