private Set<String> extractStrings(ExportedWebDriverFunctions lib, Pointer rawStrings) {
IntByReference length = new IntByReference();
int result = lib.wdcGetStringCollectionLength(rawStrings, length);
if (result != SUCCESS) {
freeCollection(lib, rawStrings);
throw new IllegalStateException("Cannot extract strings from collection: " + result);
}
Set<String> toReturn = new LinkedHashSet<String>(length.getValue());
for (int i = 0; i < length.getValue(); i++) {
PointerByReference string = new PointerByReference();
result = lib.wdcGetStringAtIndex(rawStrings, i, string);
if (result != SUCCESS) {
freeCollection(lib, rawStrings);
throw new IllegalStateException(
String.format("Cannot extract string from collection at index: %d (%d)", i, result));
}
String value = new StringWrapper(lib, string).toString();
toReturn.add(value);
}
freeCollection(lib, rawStrings);
return toReturn;
}