Fix sort orders on longs.
The int conversion narrows a long possibly inverting its sign. This may lead to broken comparator sort orders. Caught by Error Prone. Bug: 27723540 Change-Id: I53d70c25a22cdcfc496443395b170f586d259fa7
This commit is contained in:
@@ -75,14 +75,14 @@ public class UsageStatsActivity extends Activity implements OnItemSelectedListen
|
|||||||
@Override
|
@Override
|
||||||
public final int compare(UsageStats a, UsageStats b) {
|
public final int compare(UsageStats a, UsageStats b) {
|
||||||
// return by descending order
|
// return by descending order
|
||||||
return (int)(b.getLastTimeUsed() - a.getLastTimeUsed());
|
return Long.compare(b.getLastTimeUsed(), a.getLastTimeUsed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class UsageTimeComparator implements Comparator<UsageStats> {
|
public static class UsageTimeComparator implements Comparator<UsageStats> {
|
||||||
@Override
|
@Override
|
||||||
public final int compare(UsageStats a, UsageStats b) {
|
public final int compare(UsageStats a, UsageStats b) {
|
||||||
return (int)(b.getTotalTimeInForeground() - a.getTotalTimeInForeground());
|
return Long.compare(b.getTotalTimeInForeground(), a.getTotalTimeInForeground());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -133,7 +133,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
|
|||||||
@Override
|
@Override
|
||||||
public int compare(HistoricalNotificationInfo lhs,
|
public int compare(HistoricalNotificationInfo lhs,
|
||||||
HistoricalNotificationInfo rhs) {
|
HistoricalNotificationInfo rhs) {
|
||||||
return (int)(rhs.timestamp - lhs.timestamp);
|
return Long.compare(rhs.timestamp, lhs.timestamp);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user