summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnitsGUI/Presenter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/sevenUnitsGUI/Presenter.java')
-rw-r--r--src/main/java/sevenUnitsGUI/Presenter.java45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/main/java/sevenUnitsGUI/Presenter.java b/src/main/java/sevenUnitsGUI/Presenter.java
index 24a6c10..a5c4d48 100644
--- a/src/main/java/sevenUnitsGUI/Presenter.java
+++ b/src/main/java/sevenUnitsGUI/Presenter.java
@@ -200,7 +200,7 @@ public final class Presenter {
* names to prefixed versions of that unit (including the unit itself) that
* should be searchable.
*/
- private final Function<Map.Entry<String, LinearUnit>, Map<String, LinearUnit>> searchRule = PrefixSearchRule.COMMON_PREFIXES;
+ private Function<Map.Entry<String, LinearUnit>, Map<String, LinearUnit>> searchRule = PrefixSearchRule.NO_PREFIXES;
/**
* The set of units that is considered neither metric nor nonmetric for the
@@ -518,6 +518,23 @@ public final class Presenter {
}
/**
+ * @return the rule that determines which units are prefixed
+ * @since 2022-07-08
+ */
+ public Function<Map.Entry<String, LinearUnit>, Map<String, LinearUnit>> getSearchRule() {
+ return this.searchRule;
+ }
+
+ /**
+ * @return a search rule that shows all single prefixes
+ * @since 2022-07-08
+ */
+ public Function<Map.Entry<String, LinearUnit>, Map<String, LinearUnit>> getUniversalSearchRule() {
+ return PrefixSearchRule.getCoherentOnlyRule(
+ new HashSet<>(this.database.prefixMap(true).values()));
+ }
+
+ /**
* @return the view associated with this presenter
* @since 2022-04-19
*/
@@ -579,6 +596,16 @@ public final class Presenter {
case "include_duplicates":
this.showDuplicates = Boolean.valueOf(value);
break;
+ case "search_prefix_rule":
+ if (PrefixSearchRule.NO_PREFIXES.toString().equals(value)) {
+ this.searchRule = PrefixSearchRule.NO_PREFIXES;
+ } else if (PrefixSearchRule.COMMON_PREFIXES.toString()
+ .equals(value)) {
+ this.searchRule = PrefixSearchRule.COMMON_PREFIXES;
+ } else {
+ this.searchRule = this.getUniversalSearchRule();
+ }
+ break;
default:
System.err.printf("Warning: unrecognized setting \"%s\".%n",
param);
@@ -595,7 +622,7 @@ public final class Presenter {
* @return true iff the One-Way Conversion feature is available (views that
* show units as a list will have metric units removed from the From
* unit list and imperial/USC units removed from the To unit list)
- *
+ *
* @since 2022-03-30
*/
public boolean oneWayConversionEnabled() {
@@ -656,6 +683,8 @@ public final class Presenter {
String.format("one_way=%s\n", this.oneWayConversionEnabled));
writer.write(
String.format("include_duplicates=%s\n", this.showDuplicates));
+ writer.write(
+ String.format("search_prefix_rule=%s\n", this.searchRule));
} catch (final IOException e) {
e.printStackTrace();
this.view.showErrorMessage("I/O Error",
@@ -708,6 +737,18 @@ public final class Presenter {
}
/**
+ * @param searchRule A rule that accepts a prefixless name-unit pair and
+ * returns a map mapping names to prefixed versions of that
+ * unit (including the unit itself) that should be
+ * searchable.
+ * @since 2022-07-08
+ */
+ public void setSearchRule(
+ Function<Map.Entry<String, LinearUnit>, Map<String, LinearUnit>> searchRule) {
+ this.searchRule = searchRule;
+ }
+
+ /**
* @param showDuplicateUnits whether or not duplicate units should be shown
* @since 2022-03-30
*/