Genericize NC#hasSameUids

This will be used by another set of UIDs in a future patch

Test: FrameworksNetTests
Change-Id: I2c5d18ef93e73b702723814592ef3f3baf5dfbc4
This commit is contained in:
Chalard Jean
2021-12-13 21:37:12 +09:00
parent 286c0e5336
commit f4802fa4c2
4 changed files with 88 additions and 25 deletions

View File

@@ -180,4 +180,24 @@ public final class UidRange implements Parcelable {
}
return uids;
}
/**
* Compare if the given UID range sets have the same UIDs.
*
* @hide
*/
public static boolean hasSameUids(@Nullable Set<UidRange> uids1,
@Nullable Set<UidRange> uids2) {
if (null == uids1) return null == uids2;
if (null == uids2) return false;
// Make a copy so it can be mutated to check that all ranges in uids2 also are in uids.
final Set<UidRange> remainingUids = new ArraySet<>(uids2);
for (UidRange range : uids1) {
if (!remainingUids.contains(range)) {
return false;
}
remainingUids.remove(range);
}
return remainingUids.isEmpty();
}
}