/** * Given a set of options selected by the user and a verson, retrieves the options that are * actually available * * @param errors the error messages * @param options the options given by the user * @param version the version of interest * @param extraVersions the secondary versions that affect feature resolution * @param trimmingExplanations the explanations of why options are being removed * @return a potentially smaller set of options that are actually possible */ private Set<LookupOption> getUserOptionsForVersion( final ResourceBundle errors, final List<LookupOption> options, final String version, final List<String> extraVersions, final List<TrimmedLookupOption> trimmingExplanations) { final Set<LookupOption> available = this.jswordMetadata.getFeatures(version, extraVersions); final Set<LookupOption> result = new HashSet<>(options.size()); // do a crazy bubble intersect, but it's tiny so that's fine for (final LookupOption loOption : options) { boolean added = false; for (final LookupOption avOption : available) { if (loOption.equals(avOption)) { result.add(loOption); added = true; break; } } // option not available in that particular version if (trimmingExplanations != null && !added) { trimmingExplanations.add( new TrimmedLookupOption(errors.getString("option_not_supported_by_version"), loOption)); } } return result; }
@Override public String optionsToString(final Collection<LookupOption> options) { StringBuilder codedOptions = new StringBuilder(); for (LookupOption o : options) { if (o.getUiName() != BibleInformationService.UNAVAILABLE_TO_UI) { codedOptions.append(o.getUiName()); } } return codedOptions.toString(); }
@Override public List<LookupOption> getLookupOptions(final String options) { final List<LookupOption> lookupOptions = new ArrayList<>(); if (isBlank(options)) { return lookupOptions; } for (int ii = 0; ii < options.length(); ii++) { lookupOptions.add(LookupOption.fromUiOption(options.charAt(ii))); } return lookupOptions; }
@Override public AvailableFeatures getAvailableFeaturesForVersion( final String version, final List<String> extraVersions, final String inputDisplayMode, final InterlinearMode finalDisplayMode) { final List<LookupOption> allLookupOptions = Arrays.asList(LookupOption.values()); final Set<LookupOption> outcome = trim( allLookupOptions, version, extraVersions, getDisplayMode(inputDisplayMode, version, extraVersions), finalDisplayMode, null); return new AvailableFeatures(new ArrayList<>(outcome), null); }