summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnitsGUI/ViewBot.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/sevenUnitsGUI/ViewBot.java')
-rw-r--r--src/main/java/sevenUnitsGUI/ViewBot.java200
1 files changed, 199 insertions, 1 deletions
diff --git a/src/main/java/sevenUnitsGUI/ViewBot.java b/src/main/java/sevenUnitsGUI/ViewBot.java
index 9f9a524..988d1bc 100644
--- a/src/main/java/sevenUnitsGUI/ViewBot.java
+++ b/src/main/java/sevenUnitsGUI/ViewBot.java
@@ -25,6 +25,7 @@ import java.util.Set;
import sevenUnits.unit.UnitType;
import sevenUnits.utils.NameSymbol;
+import sevenUnits.utils.Nameable;
/**
* A class that simulates a View (supports both unit and expression conversion)
@@ -34,6 +35,163 @@ import sevenUnits.utils.NameSymbol;
* @since 2022-01-29
*/
final class ViewBot implements UnitConversionView, ExpressionConversionView {
+ /**
+ * A record of the parameters given to
+ * {@link View#showPrefix(NameSymbol, String)}, for testing.
+ *
+ * @since 2022-04-16
+ */
+ public static final class PrefixViewingRecord implements Nameable {
+ private final NameSymbol nameSymbol;
+ private final String multiplierString;
+
+ /**
+ * @param nameSymbol
+ * @param multiplierString
+ * @since 2022-04-16
+ */
+ public PrefixViewingRecord(NameSymbol nameSymbol,
+ String multiplierString) {
+ this.nameSymbol = nameSymbol;
+ this.multiplierString = multiplierString;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof PrefixViewingRecord))
+ return false;
+ final PrefixViewingRecord other = (PrefixViewingRecord) obj;
+ return Objects.equals(this.multiplierString, other.multiplierString)
+ && Objects.equals(this.nameSymbol, other.nameSymbol);
+ }
+
+ @Override
+ public NameSymbol getNameSymbol() {
+ return this.nameSymbol;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.multiplierString, this.nameSymbol);
+ }
+
+ public String multiplierString() {
+ return this.multiplierString;
+ }
+
+ public NameSymbol nameSymbol() {
+ return this.nameSymbol;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("PrefixViewingRecord [nameSymbol=");
+ builder.append(this.nameSymbol);
+ builder.append(", multiplierString=");
+ builder.append(this.multiplierString);
+ builder.append("]");
+ return builder.toString();
+ }
+ }
+
+ /**
+ * A record of the parameters given to
+ * {@link View#showUnit(NameSymbol, String, String, UnitType)}, for testing.
+ *
+ * @since 2022-04-16
+ */
+ public static final class UnitViewingRecord implements Nameable {
+ private final NameSymbol nameSymbol;
+ private final String definition;
+ private final String dimensionName;
+ private final UnitType unitType;
+
+ /**
+ * @since 2022-04-16
+ */
+ public UnitViewingRecord(NameSymbol nameSymbol, String definition,
+ String dimensionName, UnitType unitType) {
+ this.nameSymbol = nameSymbol;
+ this.definition = definition;
+ this.dimensionName = dimensionName;
+ this.unitType = unitType;
+ }
+
+ /**
+ * @return the definition
+ * @since 2022-04-16
+ */
+ public String definition() {
+ return this.definition;
+ }
+
+ /**
+ * @return the dimensionName
+ * @since 2022-04-16
+ */
+ public String dimensionName() {
+ return this.dimensionName;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!(obj instanceof UnitViewingRecord))
+ return false;
+ final UnitViewingRecord other = (UnitViewingRecord) obj;
+ return Objects.equals(this.definition, other.definition)
+ && Objects.equals(this.dimensionName, other.dimensionName)
+ && Objects.equals(this.nameSymbol, other.nameSymbol)
+ && this.unitType == other.unitType;
+ }
+
+ /**
+ * @return the nameSymbol
+ * @since 2022-04-16
+ */
+ @Override
+ public NameSymbol getNameSymbol() {
+ return this.nameSymbol;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.definition, this.dimensionName,
+ this.nameSymbol, this.unitType);
+ }
+
+ public NameSymbol nameSymbol() {
+ return this.nameSymbol;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("UnitViewingRecord [nameSymbol=");
+ builder.append(this.nameSymbol);
+ builder.append(", definition=");
+ builder.append(this.definition);
+ builder.append(", dimensionName=");
+ builder.append(this.dimensionName);
+ builder.append(", unitType=");
+ builder.append(this.unitType);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ /**
+ * @return the unitType
+ * @since 2022-04-16
+ */
+ public UnitType unitType() {
+ return this.unitType;
+ }
+ }
+
/** The presenter that works with this ViewBot */
private final Presenter presenter;
@@ -62,6 +220,10 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView {
private final List<UnitConversionRecord> unitConversions;
/** Saved outputs of all unit expressions */
private final List<UnitConversionRecord> expressionConversions;
+ /** Saved outputs of all unit viewings */
+ private final List<UnitViewingRecord> unitViewingRecords;
+ /** Saved outputs of all prefix viewings */
+ private final List<PrefixViewingRecord> prefixViewingRecords;
/**
* Creates a new {@code ViewBot} with a new presenter.
@@ -73,6 +235,8 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView {
this.unitConversions = new ArrayList<>();
this.expressionConversions = new ArrayList<>();
+ this.unitViewingRecords = new ArrayList<>();
+ this.prefixViewingRecords = new ArrayList<>();
}
/**
@@ -80,7 +244,7 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView {
* @since 2022-04-09
*/
public List<UnitConversionRecord> expressionConversionList() {
- return this.expressionConversions;
+ return Collections.unmodifiableList(this.expressionConversions);
}
/**
@@ -158,6 +322,14 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView {
throw new UnsupportedOperationException("Not implemented yet");
}
+ /**
+ * @return list of records of this viewBot's prefix views
+ * @since 2022-04-16
+ */
+ public List<PrefixViewingRecord> prefixViewList() {
+ return Collections.unmodifiableList(this.prefixViewingRecords);
+ }
+
@Override
public void setDimensionNames(Set<String> dimensionNames) {
this.dimensionNames = Objects.requireNonNull(dimensionNames,
@@ -259,6 +431,24 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView {
throw new UnsupportedOperationException("Not implemented yet");
}
+ public void setViewedPrefixName(
+ @SuppressWarnings("unused") Optional<String> viewedPrefixName) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ public void setViewedPrefixName(String viewedPrefixName) {
+ this.setViewedPrefixName(Optional.of(viewedPrefixName));
+ }
+
+ public void setViewedUnitName(
+ @SuppressWarnings("unused") Optional<String> viewedUnitName) {
+ throw new UnsupportedOperationException("Not implemented yet");
+ }
+
+ public void setViewedUnitName(String viewedUnitName) {
+ this.setViewedUnitName(Optional.of(viewedUnitName));
+ }
+
@Override
public void showErrorMessage(String title, String message) {
System.err.printf("%s: %s%n", title, message);
@@ -299,4 +489,12 @@ final class ViewBot implements UnitConversionView, ExpressionConversionView {
public List<UnitConversionRecord> unitConversionList() {
return Collections.unmodifiableList(this.unitConversions);
}
+
+ /**
+ * @return list of records of unit viewings made by this bot
+ * @since 2022-04-16
+ */
+ public List<UnitViewingRecord> unitViewList() {
+ return Collections.unmodifiableList(this.unitViewingRecords);
+ }
}