1f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescupackage com.android.gallery3d.ingest.data;
2f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu
3f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescuimport android.annotation.TargetApi;
4f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescuimport android.os.Build;
5f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu
6f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu/**
7f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu * Date bucket for {@link MtpDeviceIndex}.
8f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu * See {@link MtpDeviceIndexRunnable} for implementation notes.
9f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu */
10f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
11f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescuclass DateBucket implements Comparable<DateBucket> {
12f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  final SimpleDate date;
13f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  final int unifiedStartIndex;
14f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  final int unifiedEndIndex;
15f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  final int itemsStartIndex;
16f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  final int numItems;
17f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu
18f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  public DateBucket(SimpleDate date, int unifiedStartIndex, int unifiedEndIndex,
19f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu      int itemsStartIndex, int numItems) {
20f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    this.date = date;
21f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    this.unifiedStartIndex = unifiedStartIndex;
22f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    this.unifiedEndIndex = unifiedEndIndex;
23f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    this.itemsStartIndex = itemsStartIndex;
24f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    this.numItems = numItems;
25f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  }
26f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu
27f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  @Override
28f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  public String toString() {
29f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    return date.toString();
30f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  }
31f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu
32f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  @Override
33f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  public int hashCode() {
34f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    return date.hashCode();
35f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  }
36f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu
37f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  @Override
38f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  public boolean equals(Object obj) {
39f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    if (this == obj) {
40f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu      return true;
41f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    }
42f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    if (obj == null) {
43f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu      return false;
44f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    }
45f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    if (!(obj instanceof DateBucket)) {
46f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu      return false;
47f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    }
48f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    DateBucket other = (DateBucket) obj;
49f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    if (date == null) {
50f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu      if (other.date != null) {
51f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu        return false;
52f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu      }
53f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    } else if (!date.equals(other.date)) {
54f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu      return false;
55f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    }
56f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    return true;
57f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  }
58f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu
59f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  @Override
60f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  public int compareTo(DateBucket another) {
61f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu    return this.date.compareTo(another.date);
62f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu  }
63f640d379259bb114a50e3200f49961b89d60f2c2Bobby Georgescu}