Skip to content

Commit

Permalink
- get{Type}Representation() method alias with as{Type}()
Browse files Browse the repository at this point in the history
- SimpleElementOperation.fromInt() and .fromString()
  • Loading branch information
rotgruengelb committed Mar 28, 2024
1 parent 590a8f4 commit 37c12b9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/main/java/net/rotgruengelb/nixienaut/Dummy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 37c12b9

Please sign in to comment.