Skip to content

Instantly share code, notes, and snippets.

@Hadevs
Created March 15, 2023 07:05
Show Gist options
  • Save Hadevs/02c6ec31b0a9c44c95152c3c23a1353d to your computer and use it in GitHub Desktop.
Save Hadevs/02c6ec31b0a9c44c95152c3c23a1353d to your computer and use it in GitHub Desktop.
public List<String> getCommonColors(String blueprintId, List<String> printProviders) throws IOException {
List<String> commonColors = new ArrayList<String>();
for (String printProvider : printProviders) {
VariantsResponse variantsResponse = getVariants(blueprintId, printProvider);
List<Variant> variants = variantsResponse.getVariants();
for (Variant variant : variants) {
Options options = variant.getOptions();
String color = options.getColor();
if (!commonColors.contains(color)) {
boolean isCommonInAllProviders = true;
for (String otherProvider : printProviders) {
if (!otherProvider.equals(printProvider)) {
VariantsResponse otherVariantsResponse = getVariants(blueprintId, otherProvider);
List<Variant> otherVariants = otherVariantsResponse.getVariants();
boolean found = false;
for (Variant otherVariant : otherVariants) {
Options otherOptions = otherVariant.getOptions();
if (otherOptions.getColor().equals(color)) {
found = true;
break;
}
}
if (!found) {
isCommonInAllProviders = false;
break;
}
}
}
if (isCommonInAllProviders) {
commonColors.add(color);
}
}
}
}
return commonColors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment