PatchSet: Always use non-null Lists for groups
Although groups may be "missing" due to patch sets being created prior to the schema migration that added that field, the fact that these are represented in the database as null is an implementation detail. In practice we do not distinguish between empty groups and null groups, so potentially returning both of them from the API is confusing. Note that we definitely don't distinguish between these in the secondary index. Require that groups always be a non-null, and check for an empty group list to determine whether groups are "missing". This also means it's natural to use a List<String> for groups, which are naturally an ordered list. The one place where this doesn't hold is when coming out of GroupCollector, which for internal reasons needs to use a Set for deduplication. Have the few callers of that class copy the result to a list. Change-Id: I0b276e16b3ac02fd882ff1cb23d5dfd1fc7bcd20
This commit is contained in:
committed by
Edwin Kempin
parent
b3d7f7328e
commit
a714938965
@@ -19,6 +19,7 @@ import com.google.gwtorm.client.IntKey;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/** A single revision of a {@link Change}. */
|
||||
@@ -38,9 +39,9 @@ public final class PatchSet {
|
||||
return isChangeRef(name);
|
||||
}
|
||||
|
||||
public static String joinGroups(Iterable<String> groups) {
|
||||
static String joinGroups(List<String> groups) {
|
||||
if (groups == null) {
|
||||
return null;
|
||||
throw new IllegalArgumentException("groups may not be null");
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
@@ -57,7 +58,7 @@ public final class PatchSet {
|
||||
|
||||
public static List<String> splitGroups(String joinedGroups) {
|
||||
if (joinedGroups == null) {
|
||||
return null;
|
||||
throw new IllegalArgumentException("groups may not be null");
|
||||
}
|
||||
List<String> groups = new ArrayList<>();
|
||||
int i = 0;
|
||||
@@ -241,10 +242,16 @@ public final class PatchSet {
|
||||
}
|
||||
|
||||
public List<String> getGroups() {
|
||||
if (groups == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return splitGroups(groups);
|
||||
}
|
||||
|
||||
public void setGroups(Iterable<String> groups) {
|
||||
public void setGroups(List<String> groups) {
|
||||
if (groups == null) {
|
||||
groups = Collections.emptyList();
|
||||
}
|
||||
this.groups = joinGroups(groups);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user