diff --git a/.gitignore b/.gitignore index b63da45..0e9d764 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ build/ out/ !**/src/main/**/out/ !**/src/test/**/out/ +.idea/discord-ij.xml ### Eclipse ### .apt_generated diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 84011d4..249fd75 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1 @@ -rootProject.name = 'Nixienaut' - +rootProject.name = 'Nixienaut' \ No newline at end of file diff --git a/src/main/java/net/rotgruengelb/nixienaut/Dummy.java b/src/main/java/net/rotgruengelb/nixienaut/Dummy.java index fc38271..6691356 100644 --- a/src/main/java/net/rotgruengelb/nixienaut/Dummy.java +++ b/src/main/java/net/rotgruengelb/nixienaut/Dummy.java @@ -1,5 +1,7 @@ package net.rotgruengelb.nixienaut; +import net.rotgruengelb.nixienaut.annotation.PlaceholderValue; + /** * This is a dummy class. * @@ -13,6 +15,7 @@ public class Dummy { * * @see Dummy */ + @PlaceholderValue("TODO") public static void _void() { } } diff --git a/src/main/java/net/rotgruengelb/nixienaut/RGB.java b/src/main/java/net/rotgruengelb/nixienaut/RGB.java index a9e2154..3aecb17 100644 --- a/src/main/java/net/rotgruengelb/nixienaut/RGB.java +++ b/src/main/java/net/rotgruengelb/nixienaut/RGB.java @@ -1,161 +1,176 @@ package net.rotgruengelb.nixienaut; - +/** + * This class represents an RGB color.
+ * - It can be created from an integer, a hex string or from three integers.
+ * - It can be converted to an integer, a hex string or an array.
+ * - It can also be converted to a string. + * + * @see RGB#fromInt(int) + * @see RGB#fromHex(String) + * @see RGB#toArray() + * @see RGB#toInt() + * @see RGB#toString() + * @see RGB#toHex() + */ public class RGB { - private final ClampedNum r = new ClampedNum<>(0, 255); - private final ClampedNum g = new ClampedNum<>(0, 255); - private final ClampedNum b = new ClampedNum<>(0, 255); - - /** - * Creates a new RGB object. - * - * @param r The red value. - * @param g The green value. - * @param b The blue value. - * @throws IllegalArgumentException If any of the values are out of range. - */ - public RGB(int r, int g, int b) { - this.r.setValue(r); - this.g.setValue(g); - this.b.setValue(b); - } - - /** - * Creates a new RGB object from an integer. - * - * @param color The integer to create the RGB object from. - * @see RGB#toInt() - * @see RGB#fromHex(String) - * @see RGB#toArray() - * @see RGB#toInt() - * @see RGB#toString() - */ - public static RGB fromInt(int color) { - int r = (color >> 16) & 0xFF; - int g = (color >> 8) & 0xFF; - int b = color & 0xFF; - - return new RGB(r, g, b); - } - - /** - * Creates a new RGB object from a hex string. - * - * @param hex The hex string to create the RGB object from. - * @see RGB#toHex() - * @see RGB#fromInt(int) - */ - public static RGB fromHex(String hex) { - hex = hex.replace("#", ""); - int rgbInt = Integer.parseInt(hex, 16); - return fromInt(rgbInt); - } - - /** - * Converts the RGB object to an integer. - * - * @return The integer representation of the RGB object. - * @see RGB#fromInt(int) - */ - public int toInt() { - return (this.r() << 16) | (this.g() << 8) | this.b(); - } - - /** - * Converts the RGB object to a string. - * - * @return The string representation of the RGB object. - * Format: RGB(r, g, b) - * @see RGB#toHex() - * @see RGB#toInt() - * @see RGB#fromHex(String) - */ - public String toString() { - return "RGB(" + this.r() + ", " + this.g() + ", " + this.b() + ")"; - } - - /** - * Converts the RGB object to a hex string. - * - * @return The hex string representation of the RGB object. - * Format: #RRGGBB - * @see RGB#fromHex(String) - * @see RGB#toString() - */ - public String toHex() { - return String.format("#%02X%02X%02X", this.r(), this.g(), this.b()); - } - - /** - * Converts the RGB object to an array. - * - * @return The array representation of the RGB object. - * Format: [r, g, b] - * @see RGB#toString() - * @see RGB#toHex() - */ - public int[] toArray() { - return new int[]{this.r(), this.g(), this.b()}; - } - - /** - * Gets the red value. - * - * @return The red value. - * @see RGB#r(int) - */ - public int r() { - return this.r.getValue(); - } - - /** - * Gets the green value. - * - * @return The green value. - * @see RGB#g(int) - */ - public int g() { - return this.g.getValue(); - } - - /** - * Gets the blue value. - * - * @return The blue value. - * @see RGB#b(int) - */ - public int b() { - return this.b.getValue(); - } - - /** - * Sets the red value. - * - * @param value The new red value. - * @see RGB#r() - */ - public void r(int value) { - this.r.setValue(value); - } - - /** - * Sets the green value. - * - * @param value The new green value. - * @see RGB#g() - */ - public void g(int value) { - this.g.setValue(value); - } - - /** - * Sets the blue value. - * - * @param value The new blue value. - * @see RGB#b() - */ - public void b(int value) { - this.b.setValue(value); - } + private final ClampedNum r = new ClampedNum<>(0, 255); + private final ClampedNum g = new ClampedNum<>(0, 255); + private final ClampedNum b = new ClampedNum<>(0, 255); + + /** + * Creates a new RGB object. + * + * @param r The red value. + * @param g The green value. + * @param b The blue value. + * @throws IllegalArgumentException If any of the values are out of range. + */ + public RGB(int r, int g, int b) { + this.r.setValue(r); + this.g.setValue(g); + this.b.setValue(b); + } + + /** + * Creates a new RGB object from an integer. + * + * @param color The integer to create the RGB object from. + * @return The RGB object created from the integer. + * @see RGB#toInt() + * @see RGB#fromHex(String) + * @see RGB#toArray() + * @see RGB#toInt() + * @see RGB#toString() + */ + public static RGB fromInt(int color) { + int r = (color >> 16) & 0xFF; + int g = (color >> 8) & 0xFF; + int b = color & 0xFF; + + return new RGB(r, g, b); + } + + /** + * Creates a new RGB object from a hex string. + * + * @param hex The hex string to create the RGB object from. + * @return The RGB object created from the hex string. + * @see RGB#toHex() + * @see RGB#fromInt(int) + */ + public static RGB fromHex(String hex) { + Dummy._void(); + hex = hex.replace("#", ""); + int rgbInt = Integer.parseInt(hex, 16); + return fromInt(rgbInt); + } + + /** + * Converts the RGB object to an integer. + * + * @return The integer representation of the RGB object. + * @see RGB#fromInt(int) + */ + public int toInt() { + return (this.r() << 16) | (this.g() << 8) | this.b(); + } + + /** + * Converts the RGB object to a string. + * + * @return The string representation of the RGB object. + * Format: RGB(r, g, b) + * @see RGB#toHex() + * @see RGB#toInt() + * @see RGB#fromHex(String) + */ + public String toString() { + return "RGB(" + this.r() + ", " + this.g() + ", " + this.b() + ")"; + } + + /** + * Converts the RGB object to a hex string. + * + * @return The hex string representation of the RGB object. + * Format: #RRGGBB + * @see RGB#fromHex(String) + * @see RGB#toString() + */ + public String toHex() { + return String.format("#%02X%02X%02X", this.r(), this.g(), this.b()); + } + + /** + * Converts the RGB object to an list. + * + * @return The list representation of the RGB object. + * Format: [r, g, b] + * @see RGB#toString() + * @see RGB#toHex() + */ + public int[] toArray() { + return new int[]{this.r(), this.g(), this.b()}; + } + + /** + * Gets the red value. + * + * @return The red value. + * @see RGB#r(int) + */ + public int r() { + return this.r.getValue(); + } + + /** + * Gets the green value. + * + * @return The green value. + * @see RGB#g(int) + */ + public int g() { + return this.g.getValue(); + } + + /** + * Gets the blue value. + * + * @return The blue value. + * @see RGB#b(int) + */ + public int b() { + return this.b.getValue(); + } + + /** + * Sets the red value. + * + * @param value The new red value. + * @see RGB#r() + */ + public void r(int value) { + this.r.setValue(value); + } + + /** + * Sets the green value. + * + * @param value The new green value. + * @see RGB#g() + */ + public void g(int value) { + this.g.setValue(value); + } + + /** + * Sets the blue value. + * + * @param value The new blue value. + * @see RGB#b() + */ + public void b(int value) { + this.b.setValue(value); + } } \ No newline at end of file diff --git a/src/main/java/net/rotgruengelb/nixienaut/UtilFunctions.java b/src/main/java/net/rotgruengelb/nixienaut/UtilFunctions.java deleted file mode 100644 index 2d3da17..0000000 --- a/src/main/java/net/rotgruengelb/nixienaut/UtilFunctions.java +++ /dev/null @@ -1,32 +0,0 @@ -package net.rotgruengelb.nixienaut; - -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * This class contains utility functions. - */ -public class UtilFunctions { - - /** - * Creates a set from a map. - * - * @param The type of the key. - * @param The type of the value. - * @param map The map to create the set from. - * @param useKey Whether to use the key or the value. - * @return The set. - * @see java.util.Map - * @see Map#keySet() - * @see Map#values() - * @see java.util.Set - */ - public static Set setFromMap(Map map, boolean useKey) { - if (useKey) { - return new HashSet<>(map.keySet()); - } else { - return new HashSet<>(map.values()); - } - } -} diff --git a/src/main/java/net/rotgruengelb/nixienaut/annotation/PlaceholderValue.java b/src/main/java/net/rotgruengelb/nixienaut/annotation/PlaceholderValue.java new file mode 100644 index 0000000..19ed453 --- /dev/null +++ b/src/main/java/net/rotgruengelb/nixienaut/annotation/PlaceholderValue.java @@ -0,0 +1,19 @@ +package net.rotgruengelb.nixienaut.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to indicate that the method returns a placeholder value. + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.METHOD, ElementType.PACKAGE, ElementType.PARAMETER, ElementType.TYPE}) +public @interface PlaceholderValue { + /** + * The value of the placeholder. (warning message) + * @return The value of the placeholder. (warning message) + */ + String value(); +} diff --git a/src/main/java/net/rotgruengelb/nixienaut/annotation/processor/PlaceholderValueAnnotationProcessor.java b/src/main/java/net/rotgruengelb/nixienaut/annotation/processor/PlaceholderValueAnnotationProcessor.java new file mode 100644 index 0000000..132b0b7 --- /dev/null +++ b/src/main/java/net/rotgruengelb/nixienaut/annotation/processor/PlaceholderValueAnnotationProcessor.java @@ -0,0 +1,30 @@ +package net.rotgruengelb.nixienaut.annotation.processor; + +import net.rotgruengelb.nixienaut.annotation.PlaceholderValue; + +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.Element; +import javax.tools.Diagnostic; +import java.util.Set; + +/** + * Annotation processor for {@link PlaceholderValue}. + */ +@SuppressWarnings("RedundantMethodOverride") +public class PlaceholderValueAnnotationProcessor extends TMessageAnnotationProcessor { + + private static final Class annotation = PlaceholderValue.class; + + @Override + public Diagnostic.Kind kind() { return Diagnostic.Kind.WARNING; } + + public String message(Element element) { return element.getAnnotation(annotation).value(); } + + @Override + public String annotationName() { return annotation.getName(); } + + @Override + public Set elementsAnnotatedWith(RoundEnvironment roundEnv) { + return roundEnv.getElementsAnnotatedWith(annotation); + } +} diff --git a/src/main/java/net/rotgruengelb/nixienaut/annotation/processor/TMessageAnnotationProcessor.java b/src/main/java/net/rotgruengelb/nixienaut/annotation/processor/TMessageAnnotationProcessor.java new file mode 100644 index 0000000..812ec00 --- /dev/null +++ b/src/main/java/net/rotgruengelb/nixienaut/annotation/processor/TMessageAnnotationProcessor.java @@ -0,0 +1,68 @@ +package net.rotgruengelb.nixienaut.annotation.processor; + +import net.rotgruengelb.nixienaut.annotation.PlaceholderValue; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import java.lang.annotation.Annotation; +import java.util.Collections; +import java.util.Set; + +import static javax.tools.Diagnostic.Kind.WARNING; + +/** + * Template for annotation processors. + */ +public class TMessageAnnotationProcessor extends AbstractProcessor { + + + /** + * The kind of the message. + * @return The kind of the message. + */ + public Diagnostic.Kind kind() { return WARNING; } + + /** + * The name of the annotation. + * @return The name of the annotation. + */ + public String annotationName() { return PlaceholderValue.class.getName(); } + + /** + * The message to be displayed. + * @return The message to be displayed. + * @param element The element for getting the annotation. + */ + public String message(Element element) { return element.getAnnotation(PlaceholderValue.class).value(); } + + /** + * The elements annotated with the annotation. + * @param roundEnv The round environment. + * @return Set of elements from roundEnv#getElementsAnnotatedWith. + */ + public Set elementsAnnotatedWith(RoundEnvironment roundEnv) { + return roundEnv.getElementsAnnotatedWith(PlaceholderValue.class); + } + + @Override + public SourceVersion getSupportedSourceVersion() { return SourceVersion.latestSupported(); } + + @Override + public Set getSupportedAnnotationTypes() { return Collections.singleton(annotationName()); } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + Set elements = elementsAnnotatedWith(roundEnv); + + for (Element element : elements) { + processingEnv.getMessager() + .printMessage(kind(), "@" + annotationName() + message(element), element); + } + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/net/rotgruengelb/nixienaut/exeption/NotImplementedException.java b/src/main/java/net/rotgruengelb/nixienaut/exeption/NotImplementedException.java new file mode 100644 index 0000000..0bdc6f2 --- /dev/null +++ b/src/main/java/net/rotgruengelb/nixienaut/exeption/NotImplementedException.java @@ -0,0 +1,20 @@ +package net.rotgruengelb.nixienaut.exeption; + + +/** + * This exception is thrown when a method is called that is not implemented yet. + */ +public class NotImplementedException extends RuntimeException { + + /** + * This exception is thrown when a method is called that is not implemented yet. + * @see NotImplementedException#NotImplementedException(String message) + */ + public NotImplementedException() { super("Not implemented yet!"); } + + /** + * This exception is thrown when a method is called that is not implemented yet. + * @param message The message to be displayed + */ + public NotImplementedException(String message) { super(message); } +} diff --git a/src/main/java/net/rotgruengelb/nixienaut/list/QuickArrayList.java b/src/main/java/net/rotgruengelb/nixienaut/list/QuickArrayList.java new file mode 100644 index 0000000..b205fd0 --- /dev/null +++ b/src/main/java/net/rotgruengelb/nixienaut/list/QuickArrayList.java @@ -0,0 +1,26 @@ +package net.rotgruengelb.nixienaut.list; + +import java.util.ArrayList; + + +/** + * This class is just a wrapper for ArrayList to make it easier to
+ * add elements to the list in a chain. + * and then return the list itself. + * @see QuickArrayList#qAdd(E e) + */ +public class QuickArrayList extends ArrayList { + + /** + * This class is just a wrapper for ArrayList to make it easier to
+ * add elements to the list in a chain. + * and then return the list itself. + * @param e The type of the elements in the list + * @return The list itself + * @see ArrayList#add(Object) + */ + public QuickArrayList qAdd(E e) { + super.add(e); + return this; + } +} diff --git a/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000..6537173 --- /dev/null +++ b/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +net.rotgruengelb.nixienaut.annotation.processor.PlaceholderValueAnnotationProcessor \ No newline at end of file