public static RequestedShards getRequestedShards(FragmentationState fragmentationState,
DissectedDocument document) {
// Create a SelectedShards object to hold the shards that have been
// selected for each dissectable area.
RequestedShards requestedShards = document.createRequestedShards();
// Get the shard that has been selected for each dissectable area. This
// is done by iterating over the dissectable areas looking to see if a
// shard has been specified for them in the fragmentation state. If no
// shard has been explicitly set then the first shard is used.
int count = requestedShards.getCount();
for (int i = 0; i < count; i += 1) {
DissectableAreaIdentity identity
= document.getDissectableAreaIdentity(i);
// Get the shard index from the fragmentation state. Really we
// should push the identity into the fragmentation state but for
// now we will expand it here.
String inclusionPath = identity.getInclusionPath();
String name = identity.getName();
int shardIndex;
if (fragmentationState == null) {
shardIndex = 0;
} else {
shardIndex = fragmentationState.getShardIndex(inclusionPath,
name);
}
// Store the index in the requested shards.
requestedShards.setShard(i, shardIndex);
}
return requestedShards;
}