diff options
Diffstat (limited to 'src/main/java/sevenUnitsGUI/ViewBot.java')
-rw-r--r-- | src/main/java/sevenUnitsGUI/ViewBot.java | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/src/main/java/sevenUnitsGUI/ViewBot.java b/src/main/java/sevenUnitsGUI/ViewBot.java index e6593fb..750e2d9 100644 --- a/src/main/java/sevenUnitsGUI/ViewBot.java +++ b/src/main/java/sevenUnitsGUI/ViewBot.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2022 Adrien Hopkins + * Copyright (C) 2022, 2024, 2025 Adrien Hopkins * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -30,10 +30,10 @@ import sevenUnits.utils.Nameable; /** * A class that simulates a View (supports both unit and expression conversion) * for testing. Getters and setters work as expected. - * + * * @author Adrien Hopkins - * @since v0.4.0 * @since 2022-01-29 + * @since v0.4.0 */ public final class ViewBot implements UnitConversionView, ExpressionConversionView { @@ -42,6 +42,7 @@ public final class ViewBot * {@link View#showPrefix(NameSymbol, String)}, for testing. * * @since 2022-04-16 + * @since v0.4.0 */ public static final class PrefixViewingRecord implements Nameable { private final NameSymbol nameSymbol; @@ -51,6 +52,7 @@ public final class ViewBot * @param nameSymbol * @param multiplierString * @since 2022-04-16 + * @since v0.4.0 */ public PrefixViewingRecord(NameSymbol nameSymbol, String multiplierString) { @@ -64,7 +66,7 @@ public final class ViewBot return true; if (!(obj instanceof PrefixViewingRecord)) return false; - final PrefixViewingRecord other = (PrefixViewingRecord) obj; + final var other = (PrefixViewingRecord) obj; return Objects.equals(this.multiplierString, other.multiplierString) && Objects.equals(this.nameSymbol, other.nameSymbol); } @@ -79,17 +81,19 @@ public final class ViewBot return Objects.hash(this.multiplierString, this.nameSymbol); } + /** @return A string representation of the prefix multiplier. */ public String multiplierString() { return this.multiplierString; } + /** @return A {@code NameSymbol} describing the prefix. */ public NameSymbol nameSymbol() { return this.nameSymbol; } @Override public String toString() { - final StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); builder.append("PrefixViewingRecord [nameSymbol="); builder.append(this.nameSymbol); builder.append(", multiplierString="); @@ -104,6 +108,7 @@ public final class ViewBot * {@link View#showUnit(NameSymbol, String, String, UnitType)}, for testing. * * @since 2022-04-16 + * @since v0.4.0 */ public static final class UnitViewingRecord implements Nameable { private final NameSymbol nameSymbol; @@ -112,7 +117,12 @@ public final class ViewBot private final UnitType unitType; /** + * @param nameSymbol name(s) and symbol of unit + * @param definition unit's definition string + * @param dimensionName name of unit's dimension + * @param unitType type of unit (metric/semi-metric/non-metric) * @since 2022-04-16 + * @since v0.4.0 */ public UnitViewingRecord(NameSymbol nameSymbol, String definition, String dimensionName, UnitType unitType) { @@ -125,6 +135,7 @@ public final class ViewBot /** * @return the definition * @since 2022-04-16 + * @since v0.4.0 */ public String definition() { return this.definition; @@ -133,6 +144,7 @@ public final class ViewBot /** * @return the dimensionName * @since 2022-04-16 + * @since v0.4.0 */ public String dimensionName() { return this.dimensionName; @@ -144,7 +156,7 @@ public final class ViewBot return true; if (!(obj instanceof UnitViewingRecord)) return false; - final UnitViewingRecord other = (UnitViewingRecord) obj; + final var other = (UnitViewingRecord) obj; return Objects.equals(this.definition, other.definition) && Objects.equals(this.dimensionName, other.dimensionName) && Objects.equals(this.nameSymbol, other.nameSymbol) @@ -154,6 +166,7 @@ public final class ViewBot /** * @return the nameSymbol * @since 2022-04-16 + * @since v0.4.0 */ @Override public NameSymbol getNameSymbol() { @@ -166,13 +179,14 @@ public final class ViewBot this.nameSymbol, this.unitType); } + /** @return name(s) and symbol of unit */ public NameSymbol nameSymbol() { return this.nameSymbol; } @Override public String toString() { - final StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); builder.append("UnitViewingRecord [nameSymbol="); builder.append(this.nameSymbol); builder.append(", definition="); @@ -188,6 +202,7 @@ public final class ViewBot /** * @return the unitType * @since 2022-04-16 + * @since v0.4.0 */ public UnitType unitType() { return this.unitType; @@ -236,6 +251,7 @@ public final class ViewBot * Creates a new {@code ViewBot} with a new presenter. * * @since 2022-01-29 + * @since v0.4.0 */ public ViewBot() { this.presenter = new Presenter(this); @@ -249,6 +265,7 @@ public final class ViewBot /** * @return list of records of expression conversions done by this bot * @since 2022-04-09 + * @since v0.4.0 */ public List<UnitConversionRecord> expressionConversionList() { return Collections.unmodifiableList(this.expressionConversions); @@ -257,6 +274,7 @@ public final class ViewBot /** * @return the available dimensions * @since 2022-01-29 + * @since v0.4.0 */ @Override public Set<String> getDimensionNames() { @@ -276,6 +294,7 @@ public final class ViewBot /** * @return the units available for selection in From * @since 2022-01-29 + * @since v0.4.0 */ @Override public Set<String> getFromUnitNames() { @@ -290,6 +309,7 @@ public final class ViewBot /** * @return the presenter associated with tihs view * @since 2022-01-29 + * @since v0.4.0 */ @Override public Presenter getPresenter() { @@ -314,6 +334,7 @@ public final class ViewBot /** * @return the units available for selection in To * @since 2022-01-29 + * @since v0.4.0 */ @Override public Set<String> getToUnitNames() { @@ -333,6 +354,7 @@ public final class ViewBot /** * @return list of records of this viewBot's prefix views * @since 2022-04-16 + * @since v0.4.0 */ public List<PrefixViewingRecord> prefixViewList() { return Collections.unmodifiableList(this.prefixViewingRecords); @@ -350,6 +372,7 @@ public final class ViewBot * @param fromExpression the expression to convert from * @throws NullPointerException if {@code fromExpression} is null * @since 2022-01-29 + * @since v0.4.0 */ public void setFromExpression(String fromExpression) { this.fromExpression = Objects.requireNonNull(fromExpression, @@ -359,6 +382,7 @@ public final class ViewBot /** * @param fromSelection the fromSelection to set * @since 2022-01-29 + * @since v0.4.0 */ public void setFromSelection(Optional<String> fromSelection) { this.fromSelection = Objects.requireNonNull(fromSelection, @@ -368,6 +392,7 @@ public final class ViewBot /** * @param fromSelection the fromSelection to set * @since 2022-02-10 + * @since v0.4.0 */ public void setFromSelection(String fromSelection) { this.setFromSelection(Optional.of(fromSelection)); @@ -381,20 +406,27 @@ public final class ViewBot /** * @param inputValue the inputValue to set * @since 2022-01-29 + * @since v0.4.0 */ public void setInputValue(String inputValue) { this.inputValue = inputValue; } /** - * @param selectedDimension the selectedDimension to set + * @param selectedDimensionName the selectedDimensionName to set * @since 2022-01-29 + * @since v0.4.0 */ public void setSelectedDimensionName( Optional<String> selectedDimensionName) { this.selectedDimensionName = selectedDimensionName; } + /** + * Sets the view's selected dimension + * + * @param selectedDimensionName name of dimension to select (string) + */ public void setSelectedDimensionName(String selectedDimensionName) { this.setSelectedDimensionName(Optional.of(selectedDimensionName)); } @@ -405,6 +437,7 @@ public final class ViewBot * @param toExpression the expression to convert to * @throws NullPointerException if {@code toExpression} is null * @since 2022-01-29 + * @since v0.4.0 */ public void setToExpression(String toExpression) { this.toExpression = Objects.requireNonNull(toExpression, @@ -412,14 +445,16 @@ public final class ViewBot } /** - * @param toSelection the toSelection to set + * @param toSelection unit set in the 'To' selection * @since 2022-01-29 + * @since v0.4.0 */ public void setToSelection(Optional<String> toSelection) { this.toSelection = Objects.requireNonNull(toSelection, "toSelection cannot be null."); } + /** @param toSelection unit set in the 'To' selection */ public void setToSelection(String toSelection) { this.setToSelection(Optional.of(toSelection)); } @@ -439,18 +474,28 @@ public final class ViewBot // do nothing, ViewBot supports selecting any unit } + /** @param viewedPrefixName name of prefix being used */ public void setViewedPrefixName(Optional<String> viewedPrefixName) { this.prefixViewerSelection = viewedPrefixName; } + /** + * @param viewedPrefixName name of prefix being used (may not be null) + * @throws NullPointerException if {@code viewedPrefixName} is null + */ public void setViewedPrefixName(String viewedPrefixName) { this.setViewedPrefixName(Optional.of(viewedPrefixName)); } + /** @param viewedUnitName name of unit being used */ public void setViewedUnitName(Optional<String> viewedUnitName) { this.unitViewerSelection = viewedUnitName; } + /** + * @param viewedUnitName name of unit being used (may not be null) + * @throws NullPointerException if {@code viewedUnitName} is null + */ public void setViewedUnitName(String viewedUnitName) { this.setViewedUnitName(Optional.of(viewedUnitName)); } @@ -493,6 +538,7 @@ public final class ViewBot /** * @return list of records of every unit conversion made by this bot * @since 2022-04-09 + * @since v0.4.0 */ public List<UnitConversionRecord> unitConversionList() { return Collections.unmodifiableList(this.unitConversions); @@ -501,8 +547,14 @@ public final class ViewBot /** * @return list of records of unit viewings made by this bot * @since 2022-04-16 + * @since v0.4.0 */ public List<UnitViewingRecord> unitViewList() { return Collections.unmodifiableList(this.unitViewingRecords); } + + @Override + public void updateText() { + // do nothing, since ViewBot is not localized + } } |