if (isRename && (reference == null)) {
throw new InvalidLayoutException(String.format(
"Invalid rename: no reference locality group '%s' for family '%s'.",
getName(), refFName));
}
final FamilyLayout refFLayout =
(reference != null) ? reference.getFamilyMap().get(refFName) : null;
if (isRename && (refFLayout == null)) {
throw new InvalidLayoutException(String.format(
"Invalid rename: cannot find reference family '%s' in locality group '%s'.",
refFName, getName()));
}
final ColumnId refFId = refFIdMap.remove(refFName);
if (familyDesc.getDelete()) {
if (refFId == null) {
throw new InvalidLayoutException(String.format(
"Deleted family '%s' unknown in reference locality group '%s'.",
refFName, getName()));
}
itFamilyDesc.remove();
continue;
}
final FamilyLayout fLayout = new FamilyLayout(familyDesc, refFLayout);
families.add(fLayout);
for (String familyName : fLayout.getNames()) {
Preconditions.checkState(familyMap.put(familyName, fLayout) == null,
"Duplicate family name: " + familyName);
}
if (fLayout.getId() != null) {
final String previous = idMap.put(fLayout.getId(), fLayout.getName());
Preconditions.checkState(previous == null,
String.format("Duplicate family ID '%s' associated to '%s' and '%s'.",
fLayout.getId(), fLayout.getName(), previous));
} else {
unassigned.add(fLayout);
}
}
if (!refFIdMap.isEmpty()) {
throw new InvalidLayoutException(String.format(
"Descriptor for locality group '%s' is missing families: %s",
lgDesc.getName(), Joiner.on(",").join(refFIdMap.keySet())));
}
mFamilies = ImmutableList.copyOf(families);
mFamilyMap = ImmutableMap.copyOf(familyMap);
// Assign IDs to families:
int nextFamilyId = 1;
for (FamilyLayout fLayout : unassigned) {
Preconditions.checkState(fLayout.getId() == null);
while (true) {
final ColumnId fId = new ColumnId(nextFamilyId);
nextFamilyId += 1;
if (!idMap.containsKey(fId)) {
fLayout.setId(fId);
idMap.put(fId, fLayout.getName());
break;
}
}
}