}
static final Pattern PARTITION_PATTERN = Pattern.compile("[\\d]+||[\\d]+-[\\d]+");
public static int[] buildPartitions(String[] partitionArray) throws ConfigurationException {
IntSet partitions = new IntOpenHashSet();
try {
for (int i = 0; i < partitionArray.length; ++i) {
Matcher matcher = PARTITION_PATTERN.matcher(partitionArray[i]);
if (!matcher.matches()) {
throw new ConfigurationException("Invalid partition: " + partitionArray[i]);
}
String[] partitionRange = partitionArray[i].split("-");
int start = Integer.parseInt(partitionRange[0]);
int end;
if (partitionRange.length > 1) {
end = Integer.parseInt(partitionRange[1]);
if (end < start) {
throw new ConfigurationException("invalid partition range: " + partitionArray[i]);
}
} else {
end = start;
}
for (int k = start; k <= end; ++k) {
partitions.add(k);
}
}
} catch (Exception e) {
throw new ConfigurationException(
"Error parsing '" + SENSEI_PROPERTIES + "': " + PARTITIONS + "=" + Arrays.toString(partitionArray), e);
}
int[] ret = partitions.toIntArray();
Arrays.sort(ret);
return ret;
}