From 37c12b919ad5ec57e7e8a463ddcdf9a1b06a92b9 Mon Sep 17 00:00:00 2001 From: rotgruengelb Date: Thu, 28 Mar 2024 21:15:24 +0100 Subject: [PATCH] - get{Type}Representation() method alias with as{Type}() - SimpleElementOperation.fromInt() and .fromString() --- .../java/net/rotgruengelb/nixienaut/Dummy.java | 5 ++++- .../nixienaut/object/FloatIdentifiable.java | 18 +++++++++++------- .../nixienaut/object/IntIdentifiable.java | 18 +++++++++++------- .../nixienaut/object/StringIdentifiable.java | 18 +++++++++++------- .../operation/SimpleElementOperation.java | 18 ++++++++++++++++++ 5 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/rotgruengelb/nixienaut/Dummy.java b/src/main/java/net/rotgruengelb/nixienaut/Dummy.java index 05ca24c..2601408 100644 --- a/src/main/java/net/rotgruengelb/nixienaut/Dummy.java +++ b/src/main/java/net/rotgruengelb/nixienaut/Dummy.java @@ -16,11 +16,14 @@ public class Dummy { * * @see Dummy */ - public static void _void() { + public static void _staticVoid() { } @PlaceholderValue("Not implemented yet!") public static void notImplemented() { throw new NotImplementedException(); } + + public void _void() { + } } diff --git a/src/main/java/net/rotgruengelb/nixienaut/object/FloatIdentifiable.java b/src/main/java/net/rotgruengelb/nixienaut/object/FloatIdentifiable.java index 3b83ce0..eeeea69 100644 --- a/src/main/java/net/rotgruengelb/nixienaut/object/FloatIdentifiable.java +++ b/src/main/java/net/rotgruengelb/nixienaut/object/FloatIdentifiable.java @@ -2,13 +2,6 @@ public interface FloatIdentifiable { - /** - * The float representation of the object. - * - * @return The float representation of the object. - */ - float getFloatRepresentation(); - static float getFloatRepresentation(FloatIdentifiable identifiable) { if (identifiable == null) { return Float.NaN; @@ -29,4 +22,15 @@ static float getFloatRepresentation(StringIdentifiable identifiable) { } return Float.parseFloat(identifiable.getStringRepresentation()); } + + /** + * The float representation of the object. + * + * @return The float representation of the object. + */ + float getFloatRepresentation(); + + default float asFloat() { + return getFloatRepresentation(); + } } diff --git a/src/main/java/net/rotgruengelb/nixienaut/object/IntIdentifiable.java b/src/main/java/net/rotgruengelb/nixienaut/object/IntIdentifiable.java index 23682bf..2ff66b9 100644 --- a/src/main/java/net/rotgruengelb/nixienaut/object/IntIdentifiable.java +++ b/src/main/java/net/rotgruengelb/nixienaut/object/IntIdentifiable.java @@ -2,13 +2,6 @@ public interface IntIdentifiable { - /** - * The integer representation of the object. - * - * @return The integer representation of the object. - */ - int getIntRepresentation(); - static int getIntRepresentation(IntIdentifiable identifiable) { if (identifiable == null) { return 0; @@ -22,4 +15,15 @@ static int getIntRepresentation(StringIdentifiable identifiable) { } return Integer.parseInt(identifiable.getStringRepresentation()); } + + /** + * The integer representation of the object. + * + * @return The integer representation of the object. + */ + int getIntRepresentation(); + + default int asInt() { + return getIntRepresentation(); + } } diff --git a/src/main/java/net/rotgruengelb/nixienaut/object/StringIdentifiable.java b/src/main/java/net/rotgruengelb/nixienaut/object/StringIdentifiable.java index 5e6265a..297c0d1 100644 --- a/src/main/java/net/rotgruengelb/nixienaut/object/StringIdentifiable.java +++ b/src/main/java/net/rotgruengelb/nixienaut/object/StringIdentifiable.java @@ -2,13 +2,6 @@ public interface StringIdentifiable { - /** - * The string representation of the object. - * - * @return The string representation of the object. - */ - String getStringRepresentation(); - static String getStringRepresentation(StringIdentifiable identifiable) { if (identifiable == null) { return ""; @@ -29,4 +22,15 @@ static String getStringRepresentation(FloatIdentifiable identifiable) { } return Float.toString(identifiable.getFloatRepresentation()); } + + /** + * The string representation of the object. + * + * @return The string representation of the object. + */ + String getStringRepresentation(); + + default String asString() { + return getStringRepresentation(); + } } diff --git a/src/main/java/net/rotgruengelb/nixienaut/operation/SimpleElementOperation.java b/src/main/java/net/rotgruengelb/nixienaut/operation/SimpleElementOperation.java index f147e65..126b289 100644 --- a/src/main/java/net/rotgruengelb/nixienaut/operation/SimpleElementOperation.java +++ b/src/main/java/net/rotgruengelb/nixienaut/operation/SimpleElementOperation.java @@ -17,6 +17,24 @@ public enum SimpleElementOperation implements StringIdentifiable, IntIdentifiabl this.stringRepresentation = stringRepresentation; } + public static SimpleElementOperation fromInt(int i) { + for (SimpleElementOperation operation : values()) { + if (operation.getIntRepresentation() == i) { + return operation; + } + } + return null; + } + + public static SimpleElementOperation fromString(String s) { + for (SimpleElementOperation operation : values()) { + if (operation.getStringRepresentation().equals(s)) { + return operation; + } + } + return null; + } + @Override public int getIntRepresentation() { return difference;