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, 45 insertions, 0 deletions
diff --git a/src/main/java/sevenUnitsGUI/Presenter.java b/src/main/java/sevenUnitsGUI/Presenter.java
index 7c66d55..ff7e23c 100644
--- a/src/main/java/sevenUnitsGUI/Presenter.java
+++ b/src/main/java/sevenUnitsGUI/Presenter.java
@@ -60,6 +60,7 @@ import sevenUnitsGUI.StandardDisplayRules.UncertaintyBased;
*
* @author Adrien Hopkins
* @since 2021-12-15
+ * @since v0.4.0
*/
public final class Presenter {
/**
@@ -139,6 +140,7 @@ public final class Presenter {
* {@code maxLineLength}. If no good spot is found, returns -1.
*
* @since 2024-08-22
+ * @since v1.0.0
*/
private static int findLineSplit(String toWrap, int maxLineLength) {
for (var i = maxLineLength - 1; i >= 0; i--) {
@@ -155,6 +157,7 @@ public final class Presenter {
* @param filename filename to get resource from
* @return contents of file
* @since 2021-03-27
+ * @since v0.3.0
*/
private static List<String> getLinesFromResource(String filename) {
final List<String> lines = new ArrayList<>();
@@ -178,6 +181,7 @@ public final class Presenter {
* @param filepath file to use as resource
* @return obtained Path
* @since 2021-03-27
+ * @since v0.3.0
*/
private static InputStream inputStream(String filepath) {
return Presenter.class.getResourceAsStream(filepath);
@@ -188,6 +192,7 @@ public final class Presenter {
* the nearest integer.
*
* @since 2024-08-16
+ * @since v1.0.0
*/
private static String linearUnitValueIntToString(LinearUnitValue uv) {
return Long.toString(Math.round(uv.getValueExact())) + " " + uv.getUnit();
@@ -227,6 +232,7 @@ public final class Presenter {
/**
* @return true iff a and b have any elements in common
* @since 2022-04-19
+ * @since v0.4.0
*/
private static boolean sharesAnyElements(Set<?> a, Set<?> b) {
for (final Object e : a) {
@@ -254,6 +260,7 @@ public final class Presenter {
/**
* @return {@code line} with any comments removed.
* @since 2021-03-13
+ * @since v0.3.0
*/
private static String withoutComments(String line) {
final var index = line.indexOf('#');
@@ -264,6 +271,7 @@ public final class Presenter {
* Wraps a string, ensuring no line is longer than {@code maxLineLength}.
*
* @since 2024-08-22
+ * @since v1.0.0
*/
private static String wrapString(String toWrap, int maxLineLength) {
final var wrapped = new StringBuilder(toWrap.length());
@@ -366,6 +374,7 @@ public final class Presenter {
*
* @param view the view that this presenter communicates with
* @since 2021-12-15
+ * @since v0.4.0
*/
public Presenter(View view) {
this.view = view;
@@ -449,6 +458,7 @@ public final class Presenter {
* @param e entry
* @return stream of entries, ready for flat-mapping
* @since 2022-07-06
+ * @since v0.4.0
*/
private Stream<Map.Entry<String, Unit>> applySearchRule(
Map.Entry<String, Unit> e) {
@@ -472,6 +482,7 @@ public final class Presenter {
* not implement
* {@link ExpressionConversionView})
* @since 2021-12-15
+ * @since v0.4.0
*/
public void convertExpressions() {
if (!(this.view instanceof ExpressionConversionView))
@@ -515,6 +526,7 @@ public final class Presenter {
* returned.
*
* @since 2024-08-15
+ * @since v1.0.0
*/
private Optional<UnitConversionRecord> convertExpressionToExpression(
String fromExpression, String toExpression) {
@@ -567,6 +579,7 @@ public final class Presenter {
* the view and Optional.empty() is returned.
*
* @since 2024-08-15
+ * @since v1.0.0
*/
private Optional<UnitConversionRecord> convertExpressionToMultiUnit(
String fromExpression, String[] toExpressions) {
@@ -617,6 +630,7 @@ public final class Presenter {
* error happened, it is shown to the view and Optional.empty() is returned.
*
* @since 2024-08-15
+ * @since v1.0.0
*/
private Optional<UnitConversionRecord> convertExpressionToNamedMultiUnit(
String fromExpression, String toName) {
@@ -653,6 +667,7 @@ public final class Presenter {
* implement
* {@link UnitConversionView})
* @since 2021-12-15
+ * @since v0.4.0
*/
public void convertUnits() {
if (!(this.view instanceof UnitConversionView))
@@ -770,6 +785,7 @@ public final class Presenter {
/**
* @return true iff duplicate units are shown in unit lists
* @since 2022-03-30
+ * @since v0.4.0
*/
public boolean duplicatesShown() {
return this.showDuplicates;
@@ -778,6 +794,7 @@ public final class Presenter {
/**
* @return text in About file
* @since 2022-02-19
+ * @since v0.4.0
*/
public String getAboutText() {
final Path customFilepath = Presenter.pathFromConfig(
@@ -809,6 +826,7 @@ public final class Presenter {
/**
* @return set of all locales available to select
* @since 2025-02-21
+ * @since v1.0.0
*/
public Set<String> getAvailableLocales() {
return this.locales.keySet();
@@ -820,6 +838,7 @@ public final class Presenter {
* @param dimension dimension to name
* @return name of dimension
* @since 2022-04-16
+ * @since v0.4.0
*/
String getDimensionName(ObjectProduct<BaseDimension> dimension) {
// find this dimension in the database and get its name
@@ -847,6 +866,7 @@ public final class Presenter {
* @return the rule that is used by this presenter to convert numbers into
* strings
* @since 2022-04-10
+ * @since v0.4.0
*/
public Function<UncertainDouble, String> getNumberDisplayRule() {
return this.numberDisplayRule;
@@ -856,6 +876,7 @@ public final class Presenter {
* @return the rule that is used by this presenter to convert strings into
* numbers
* @since 2022-04-10
+ * @since v0.4.0
*/
@SuppressWarnings("unused") // not implemented yet
private Function<String, UncertainDouble> getNumberParsingRule() {
@@ -865,6 +886,7 @@ public final class Presenter {
/**
* @return the rule that determines whether a set of prefixes is valid
* @since 2022-04-19
+ * @since v0.4.0
*/
public Predicate<List<UnitPrefix>> getPrefixRepetitionRule() {
return this.prefixRepetitionRule;
@@ -873,6 +895,7 @@ public final class Presenter {
/**
* @return the rule that determines which units are prefixed
* @since 2022-07-08
+ * @since v0.4.0
*/
public Function<Map.Entry<String, LinearUnit>, Map<String, LinearUnit>> getSearchRule() {
return this.searchRule;
@@ -881,6 +904,7 @@ public final class Presenter {
/**
* @return a search rule that shows all single prefixes
* @since 2022-07-08
+ * @since v0.4.0
*/
public Function<Map.Entry<String, LinearUnit>, Map<String, LinearUnit>> getUniversalSearchRule() {
return PrefixSearchRule.getCoherentOnlyRule(
@@ -890,6 +914,7 @@ public final class Presenter {
/**
* @return user's selected locale
* @since 2025-02-21
+ * @since v1.0.0
*/
public String getUserLocale() {
return userLocale;
@@ -898,6 +923,7 @@ public final class Presenter {
/**
* @return the view associated with this presenter
* @since 2022-04-19
+ * @since v0.4.0
*/
public View getView() {
return this.view;
@@ -908,6 +934,7 @@ public final class Presenter {
* message and alerts the user.
*
* @since 2024-08-22
+ * @since v1.0.0
*/
private void handleLoadErrors(List<LoadingException> errors) {
if (!errors.isEmpty()) {
@@ -925,6 +952,7 @@ public final class Presenter {
* @return whether or not the provided unit is semi-metric (i.e. an
* exception)
* @since 2022-04-16
+ * @since v0.4.0
*/
boolean isSemiMetric(Unit u) {
// determine if u is an exception
@@ -944,6 +972,7 @@ public final class Presenter {
* number display rule.
*
* @since 2024-08-16
+ * @since v1.0.0
*/
private String linearUnitValueSumToString(List<LinearUnitValue> values) {
final var integerPart = values.subList(0, values.size() - 1).stream()
@@ -1018,6 +1047,7 @@ public final class Presenter {
*
* @param settingsFile file settings should be loaded from
* @since 2021-12-15
+ * @since v0.4.0
*/
void loadSettings(Path settingsFile) {
this.customDimensionFiles.clear();
@@ -1086,6 +1116,7 @@ public final class Presenter {
/**
* @return a message showing how much stuff has been loaded
* @since 2024-08-22
+ * @since v1.0.0
*/
private String loadStatMsg() {
return this.getLocalizedText("load_stat_msg")
@@ -1107,6 +1138,7 @@ public final class Presenter {
* unit list and imperial/USC units removed from the To unit list)
*
* @since 2022-03-30
+ * @since v0.4.0
*/
public boolean oneWayConversionEnabled() {
return this.oneWayConversionEnabled;
@@ -1118,6 +1150,7 @@ public final class Presenter {
* they depend on are not created yet.
*
* @since 2022-02-26
+ * @since v0.4.0
*/
public void postViewInitialize() {
// unit conversion specific stuff
@@ -1148,6 +1181,7 @@ public final class Presenter {
*
* @return false iff the presenter could not write to the file
* @since 2022-04-19
+ * @since v0.4.0
*/
public boolean saveSettings() {
final var configDir = CONFIG_FILE.getParent();
@@ -1187,6 +1221,7 @@ public final class Presenter {
* @param numberDisplayRule the new rule that will be used by this presenter
* to convert numbers into strings
* @since 2022-04-10
+ * @since v0.4.0
*/
public void setNumberDisplayRule(
Function<UncertainDouble, String> numberDisplayRule) {
@@ -1197,6 +1232,7 @@ public final class Presenter {
* @param numberParsingRule the new rule that will be used by this presenter
* to convert strings into numbers
* @since 2022-04-10
+ * @since v0.4.0
*/
@SuppressWarnings("unused") // not implemented yet
private void setNumberParsingRule(
@@ -1208,6 +1244,7 @@ public final class Presenter {
* @param oneWayConversionEnabled whether not one-way conversion should be
* enabled
* @since 2022-03-30
+ * @since v0.4.0
* @see #oneWayConversionEnabled
*/
public void setOneWayConversionEnabled(boolean oneWayConversionEnabled) {
@@ -1219,6 +1256,7 @@ public final class Presenter {
* @param prefixRepetitionRule the rule that determines whether a set of
* prefixes is valid
* @since 2022-04-19
+ * @since v0.4.0
*/
public void setPrefixRepetitionRule(
Predicate<List<UnitPrefix>> prefixRepetitionRule) {
@@ -1232,6 +1270,7 @@ public final class Presenter {
* unit (including the unit itself) that should be
* searchable.
* @since 2022-07-08
+ * @since v0.4.0
*/
public void setSearchRule(
Function<Map.Entry<String, LinearUnit>, Map<String, LinearUnit>> searchRule) {
@@ -1259,6 +1298,7 @@ public final class Presenter {
/**
* @param showDuplicateUnits whether or not duplicate units should be shown
* @since 2022-03-30
+ * @since v0.4.0
*/
public void setShowDuplicates(boolean showDuplicateUnits) {
this.showDuplicates = showDuplicateUnits;
@@ -1304,6 +1344,7 @@ public final class Presenter {
*
* @param u unit to show
* @since 2022-04-16
+ * @since v0.4.0
*/
private void showUnit(Unit u) {
final var nameSymbol = u.getNameSymbol();
@@ -1320,6 +1361,7 @@ public final class Presenter {
* description of a unit and displays it.
*
* @since 2022-04-10
+ * @since v0.4.0
*/
void unitNameSelected() {
// get selected unit, if it's there and valid
@@ -1335,6 +1377,7 @@ public final class Presenter {
* Updates the view's From and To units, if it has some
*
* @since 2021-12-15
+ * @since v0.4.0
*/
public void updateView() {
if (this.view instanceof UnitConversionView) {
@@ -1402,6 +1445,7 @@ public final class Presenter {
* @return AssertionError stating that an error has happened in the view's
* code
* @since 2022-04-09
+ * @since v0.4.0
*/
private AssertionError viewError(String message, Object... args) {
return new AssertionError("View Programming Error (from " + this.view
@@ -1413,6 +1457,7 @@ public final class Presenter {
*
* @param settingsFile file settings should be saved to
* @since 2021-12-15
+ * @since v0.4.0
*/
boolean writeSettings(Path settingsFile) {
try (var writer = Files.newBufferedWriter(settingsFile)) {