Browse Source

Java Doc + Readme

TomTroppmann 2 years ago
parent
commit
530cd74cde

+ 18 - 29
README.md

@@ -2,10 +2,6 @@
 
 Cyber-physical systems simulation software following a Holon-based smart grid system.
 
-## Prerequisites
-
-* Java 1.8 compatible VM
-
 ## Introduction and User Manual
 
 The Wiki contains some
@@ -21,37 +17,39 @@ for some Instructions
 
 ## License
 
-This project is licensed under a modified MIT License - see
+This project is licensed under a modified MIT License, see
 the [LICENSE.md](https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons/src/master/license.md)
-file for details
+file for details.
 
 ## Built With
-
-* [JUnit](http://junit.org) - The used test system
+* [Gradle](https://gradle.org/) - Build tool
+* [Java 17](https://openjdk.java.net/projects/jdk/17/) - Java SE version
+* [JUnit](http://junit.org) - Test system
 * [Gson](https://github.com/google/gson) - Used for Saving/Loading
-* [Apache Common Compress ](https://rometools.github.io/rome/) - Creates zip/tar Archives
+* [MigLayout](https://github.com/mikaelgrev/miglayout) - Extends Swing
+* [XChart](https://github.com/knowm/XChart) - For data visualization
 
+## Code Style
+This project uses [Google Code Style](https://google.github.io/styleguide/javaguide.html) and corresponding [Code Schema](https://github.com/google/styleguide).
 ## Contributors
 
-### Version 1.0 to 1.1.0
+* Rolf Egert
+* Tom Troppmann
+### Past Contributors
 
+* Andreas Tundis
+* Carlos Garcia
+* Andreas T. Meyer-Berg
+* Ludwig Tietze
+* Antonio Schneider
+* Isabella Dix
 * Kevin Julian Trometer
 * Dominik Fabio Rieder
 * Teh-Hai Julian Zheng
 * Edgardo Ernesto Palza Paredes
 * Jessey Steven Widhalm
 
-### Version 2.0
-
-* Isabella Dix
-* Carlos Garcia
-
-### Version 2.1 [Changelog](https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons/src/master/ChangelogV2_1.md)
 
-* Andreas T. Meyer-Berg
-* Ludwig Tietze
-* Antonio Schneider
-* Tom Troppmann
 
 ## Under contract from:
 
@@ -60,12 +58,3 @@ file for details
 * Hochschulstr. 10
 * Informatik Telecooperation Lab (TK)
 * D-64289 Darmstadt, Germany
-
-### Version 1.0 to 1.1.0
-
-* Andreas Tundis
-* Carlos Garcia
-
-### Version 2.1
-
-* Rolf Egert

+ 1 - 2
build.gradle

@@ -21,9 +21,8 @@ repositories {
 }
 
 dependencies {
-    implementation 'com.google.code.gson:gson:2.8.9'
+    implementation 'com.google.code.gson:gson:2.9.0'
     implementation 'org.apache.commons:commons-email:1.5'
-    implementation 'org.wso2.orbit.org.apache.commons:commons-compress:1.18.0.wso2v1'
     implementation 'org.knowm.xchart:xchart:3.8.1'
     implementation 'com.miglayout:miglayout-swing:11.0'
     testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'

+ 21 - 2
src/holeg/algorithm/topologie/GaAlgorithm.java

@@ -231,7 +231,7 @@ public class GaAlgorithm extends TopologieAlgorithmFramework {
       int index = iter.nextIndex();
       Integer intValue = iter.next();
       if (Random.nextDouble() <= probability) {
-        iter.set(Random.nextIntegerInRangeExcept(0, this.getMaximumIndexObjects(index), intValue));
+        iter.set(nextIntegerInRangeExcept(0, this.getMaximumIndexObjects(index), intValue));
       }
     }
   }
@@ -269,7 +269,7 @@ public class GaAlgorithm extends TopologieAlgorithmFramework {
       int index = iter.nextIndex();
       int intValue = iter.next();
       if (index == firstindex) {
-        iter.set(Random.nextIntegerInRangeExcept(0, this.getMaximumIndexObjects(index), intValue));
+        iter.set(nextIntegerInRangeExcept(0, this.getMaximumIndexObjects(index), intValue));
         //println("changed Value["+ index +"]");
         if (mutationLocation.isEmpty()) {
           break;
@@ -278,4 +278,23 @@ public class GaAlgorithm extends TopologieAlgorithmFramework {
       }
     }
   }
+  /**
+   * Random Int in Range [min;max[ with UniformDistribution without the value between.
+   *
+   * @param min the minimum value
+   * @param max the maximum value
+   * @param valueBetween a value between min and max
+   * @return next random integer value without a value between.
+   */
+  public static int nextIntegerInRangeExcept(int min, int max, int valueBetween) {
+    if (max - min == 1) {
+      //return the other value
+      return (valueBetween == min) ? max : min;
+    }
+    int result = Random.nextIntegerInRange(min, max -1);
+    if (result >= valueBetween) {
+      result++;
+    }
+    return result;
+  }
 }

+ 10 - 10
src/holeg/model/HolonElement.java

@@ -246,14 +246,14 @@ public class HolonElement implements TimelineDependent, PostDeserialize {
     float[] sampleCurve = new float[sampleLength];
     for (int i = 0; i < sampleLength; i++) {
       double graphX = (double) i / (double) (sampleLength - 1); //from 0.0 to 1.0
-      if (graphX > after.x) {
+      if (graphX > after.getX()) {
         before = after;
         after = iter.next();
       }
       //t to determine how many percentage the graphX is to the next Point needed to calc Bezier
       //inverseLerp(valueBetween, min, max) (valueBetween - min) / (max - min)
-      // e.g. old.x = 0.4, actual.x = 0.8 and graphX = 0.6 then t is 0.5
-      double t = (after.x - before.x > 0) ? (graphX - before.x) / (after.x - before.x) : 0.0;
+      // e.g. old.getX() = 0.4, actual.getX() = 0.8 and graphX = 0.6 then t is 0.5
+      double t = (after.getX() - before.getX() > 0) ? (graphX - before.getX()) / (after.getX() - before.getX()) : 0.0;
       sampleCurve[i] = (float) getYBetweenTwoPoints(t, before, after);
     }
     return sampleCurve;
@@ -273,10 +273,10 @@ public class HolonElement implements TimelineDependent, PostDeserialize {
    */
   private double getYBetweenTwoPoints(double t, Vec2f start, Vec2f end) {
 
-    float mitte = (start.x + end.x) * 0.5f;
-    Vec2f bezier = getBezierPoint(t, start, new Vec2f(mitte, start.y), new Vec2f(mitte, end.y),
+    float mitte = (start.getX() + end.getX()) * 0.5f;
+    Vec2f bezier = getBezierPoint(t, start, new Vec2f(mitte, start.getY()), new Vec2f(mitte, end.getY()),
         end);
-    return bezier.y;
+    return bezier.getY();
   }
 
   /**
@@ -305,10 +305,10 @@ public class HolonElement implements TimelineDependent, PostDeserialize {
     double t2 = Math.pow(t, 2);
     double t3 = Math.pow(t, 3);
 
-    bezier.x = (float) (OneSubT3 * p0.x + 3 * OneSubT2 * t * p1.x + 3 * OneSubT * t2 * p2.x
-        + t3 * p3.x);
-    bezier.y = (float) (OneSubT3 * p0.y + 3 * OneSubT2 * t * p1.y + 3 * OneSubT * t2 * p2.y
-        + t3 * p3.y);
+    bezier.setX((float) (OneSubT3 * p0.getX() + 3 * OneSubT2 * t * p1.getX() + 3 * OneSubT * t2 * p2.getX()
+        + t3 * p3.getX()));
+    bezier.setY((float) (OneSubT3 * p0.getY() + 3 * OneSubT2 * t * p1.getY() + 3 * OneSubT * t2 * p2.getY()
+        + t3 * p3.getY()));
     return bezier;
 
   }

+ 37 - 12
src/holeg/utility/math/Maths.java

@@ -1,5 +1,9 @@
 package holeg.utility.math;
 
+/**
+ * A helper class for common math operations.
+ * It's an extension for {@link java.lang.Math}.
+ */
 public class Maths {
 
   public final static double EPSILON = 1E-6;
@@ -7,22 +11,22 @@ public class Maths {
   /**
    * Linear Interpolation from first to second via alpha amount.
    *
-   * @param first
-   * @param second
-   * @param alpha
-   * @return
+   * @param first the first value
+   * @param second the second value
+   * @param alpha the alpha to calculate the double that is interpolated between first and second, normally a value between 0.0 and 1.0
+   * @return the interpolated double via alpha
    */
   public static double lerp(double first, double second, double alpha) {
     return first * (1.0 - alpha) + second * alpha;
   }
 
   /**
-   * Inverse Linear Interpolation from min to max to get the corresponding alpha from value.
+   * Inverse linear interpolation from min to max to get the corresponding alpha from value.
    *
-   * @param min
-   * @param max
-   * @param value
-   * @return
+   * @param min the minimum value
+   * @param max the maximum value
+   * @param value the value to get the alpha from
+   * @return the corresponding alpha
    */
   public static double invLerp(double min, double max, double value) {
     if (Math.abs(max - min) < EPSILON) {
@@ -32,15 +36,36 @@ public class Maths {
     }
   }
 
-  public static int Clamp(int value, int min, int max) {
+  /**
+   * Clamp a value between a minimum and a maximum.
+   * @param value the value to be clamped
+   * @param min the minimum value
+   * @param max the maximum value
+   * @return the value in Range[min;max]
+   */
+  public static int clamp(int value, int min, int max) {
     return Math.max(min, Math.min(max, value));
   }
 
-  public static float Clamp(float value, float min, float max) {
+  /**
+   * Clamp a value between a minimum and a maximum.
+   * @param value the value to be clamped
+   * @param min the minimum value
+   * @param max the maximum value
+   * @return the value in Range[min;max]
+   */
+  public static float clamp(float value, float min, float max) {
     return Math.max(min, Math.min(max, value));
   }
 
-  public static double Clamp(double value, double min, double max) {
+  /**
+   * Clamp a value between a minimum and a maximum.
+   * @param value the value to be clamped
+   * @param min the minimum value
+   * @param max the maximum value
+   * @return the value in Range[min;max]
+   */
+  public static double clamp(double value, double min, double max) {
     return Math.max(min, Math.min(max, value));
   }
 }

+ 18 - 36
src/holeg/utility/math/Random.java

@@ -1,10 +1,11 @@
 package holeg.utility.math;
 
-
+/**
+ * A Helper class to abstract the implementation of the generation of a random number.
+ */
 public class Random {
 
-
-  private static java.util.Random random = new java.util.Random();
+  private static final java.util.Random random = new java.util.Random();
 
   /**
    * True or false
@@ -32,52 +33,33 @@ public class Random {
    * Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean and
    * standard deviation from this random number generator's sequence.
    *
-   * @param mean
-   * @param deviation
-   * @return
+   * @param mean      the mean of the Gaussian distribution
+   * @param deviation the standard deviation of the Gaussian distribution
+   * @return next gaussian value
    */
   public static double nextGaussian(double mean, double deviation) {
     return mean + random.nextGaussian() * deviation;
   }
 
+  /**
+   * Random Double in Range [min;max[ with UniformDistribution
+   *
+   * @param min minimum double value
+   * @param max maximum double value
+   * @return next random double value in range
+   */
   public static double nextDoubleInRange(double min, double max) {
     return min + random.nextDouble() * Math.abs(max - min);
   }
 
   /**
-   * Random Int in Range [min;max[ with UniformDistirbution
+   * Random Int in Range [min;max[ with UniformDistribution
    *
-   * @param min
-   * @param max
-   * @return
+   * @param min minimum integer value
+   * @param max maximum integer value
+   * @return next random integer value in range
    */
   public static int nextIntegerInRange(int min, int max) {
     return min + random.nextInt(max - min);
   }
-
-  /**
-   * Random Int in Range [min;max[ with UniformDistirbution
-   *
-   * @param min
-   * @param max
-   * @param valueBetween a value between min and max
-   * @return
-   */
-  public static int nextIntegerInRangeExcept(int min, int max, int valueBetween) {
-    int result = min;
-    if (max - min == 1) {
-      //return the other value
-      return (valueBetween == min) ? max : min;
-    }
-    try {
-      result = min + random.nextInt((max - 1) - min);
-      if (result >= valueBetween) {
-        result++;
-      }
-    } catch (java.lang.IllegalArgumentException e) {
-      System.err.println("min : " + min + " max : " + max + " valueBetween:" + valueBetween);
-      System.err.println("Except max should be more then min");
-    }
-    return result;
-  }
 }

+ 1 - 1
src/holeg/utility/math/vector/Geometry.java

@@ -29,7 +29,7 @@ public class Geometry {
       }
     }
     Vec2f p2p1 = line.p2.subtract(line.p1);
-    float t = Maths.Clamp(Vec2f.dot(circle.position.subtract(line.p1), p2p1) / lineLengthSqr, 0.0f,
+    float t = Maths.clamp(Vec2f.dot(circle.position.subtract(line.p1), p2p1) / lineLengthSqr, 0.0f,
         1.0f);
     Vec2f projection = line.p1.add(p2p1.multiply(t));
     if (projection.getSquaredDistance(circle.position) < circle.radius * circle.radius) {

+ 130 - 48
src/holeg/utility/math/vector/Vec2f.java

@@ -1,31 +1,68 @@
 package holeg.utility.math.vector;
 
+import holeg.utility.math.Maths;
+
+/**
+ * A class representing a 2 dimensional vector with float entries.
+ */
 public class Vec2f {
 
-  public float x;
-  public float y;
+  /**
+   * The first entry.
+   */
+  private float x;
+  /**
+   * The second entry.
+   */
+  private float y;
 
+  /**
+   * Constructs a vector and initialized it with zeros.
+   */
   public Vec2f() {
     x = y = 0;
   }
 
+  /**
+   * Constructs a vector with x and y.
+   *
+   * @param x the first entry
+   * @param y the second entry
+   */
   public Vec2f(float x, float y) {
-    setX(x);
-    setY(y);
+    this.x = x;
+    this.y = y;
   }
 
+  /**
+   * Creates a copy of another vector.
+   *
+   * @param other the other to copy the entries from
+   */
   public Vec2f(Vec2f other) {
     x = other.x;
     y = other.y;
   }
 
+  /**
+   * Creates a copy of another integer vector but the entries stores as float.
+   *
+   * @param other the other integer vector
+   */
   public Vec2f(Vec2i other) {
     x = other.getX();
     y = other.getY();
   }
 
-  public static float dot(Vec2f p1, Vec2f p2) {
-    return p1.dot(p2);
+  /**
+   * Creates the dot product of two vectors.
+   *
+   * @param v1 the first vector
+   * @param v2 the second vector
+   * @return the dot product
+   */
+  public static float dot(Vec2f v1, Vec2f v2) {
+    return v1.dot(v2);
   }
 
   public float getX() {
@@ -44,100 +81,155 @@ public class Vec2f {
     this.y = y;
   }
 
+  /**
+   * Sets the first and second entry of the vector.
+   *
+   * @param x the first entry
+   * @param y the second entry
+   */
   public void set(float x, float y) {
-    setX(x);
-    setY(y);
+    this.x = x;
+    this.y = y;
   }
 
+  /**
+   * Creates the dot product with another vector.
+   *
+   * @param other the other vector
+   * @return the dot product
+   */
   public float dot(Vec2f other) {
     float result = 0.0f;
-    result = x * other.getX() + y * other.getY();
+    result = x * other.x + y * other.y;
     return result;
   }
 
+  /**
+   * Returns the euclidean distance to zero.
+   *
+   * @return distance to zero
+   */
   public float getLength() {
     return (float) Math.sqrt(x * x + y * y);
   }
 
   /**
-   * Return the Distance to a other Position.
+   * Return the euclidean distance to a other vector.
    *
-   * @param other the other Position.
-   * @return distance to the Position.
+   * @param other the other vector.
+   * @return distance to the vector.
    */
   public float getDistance(Vec2f other) {
     return (float) Math.sqrt(getSquaredDistance(other));
   }
 
   /**
-   * Return the Distance squared to a other Position. Faster then Distance because no Sqrt()
-   * needed.
+   * Return the squared distance to a other Position. Faster than {@link #getDistance(Vec2f)}
+   * because no {@link Math#sqrt(double)} needed.
    *
    * @param other the other Position.
    * @return squared distance to the Position
    */
   public float getSquaredDistance(Vec2f other) {
-    float xDistance = other.getX() - x;
-    float yDistance = other.getY() - y;
+    float xDistance = other.x - x;
+    float yDistance = other.x - y;
     return xDistance * xDistance + yDistance * yDistance;
   }
 
+  /**
+   * Returns a new vector that is the sum of this vector and another Vector.
+   *
+   * @param other the other vector
+   * @return the sum
+   */
   public Vec2f add(Vec2f other) {
     Vec2f result = new Vec2f();
-    result.setX(x + other.getX());
-    result.setY(y + other.getY());
+    result.x += other.x;
+    result.y += other.y;
     return result;
   }
 
+  /**
+   * Add the entries of another Vector to this vector.
+   *
+   * @param other the other vector
+   */
   public void addAssign(Vec2f other) {
-    x += other.getX();
-    y += other.getY();
+    x += other.x;
+    y += other.y;
   }
 
-
+  /**
+   * Returns a new vector that is the subtraction of this vector and another Vector.
+   *
+   * @param other the other vector
+   * @return the subtraction
+   */
   public Vec2f subtract(Vec2f other) {
     Vec2f result = new Vec2f();
-    result.setX(x - other.getX());
-    result.setY(y - other.getY());
+    result.x -= other.x;
+    result.y -= other.y;
     return result;
   }
 
+  /**
+   * Subtract the entries of another Vector to this vector.
+   *
+   * @param other the other vector
+   */
   public void subtractAssign(Vec2f other) {
-    x -= other.getX();
-    y -= other.getY();
+    x -= other.x;
+    y -= other.y;
   }
 
+  /**
+   * Returns a new vector which entries are multiplied times a scaled factor.
+   * @param scaleFactor the scale factor
+   * @return the multiplication from this vector with a scale
+   */
   public Vec2f multiply(float scaleFactor) {
     Vec2f result = new Vec2f();
-    result.setX(x * scaleFactor);
-    result.setY(y * scaleFactor);
+    x *= scaleFactor;
+    y *= scaleFactor;
     return result;
   }
 
+  /**
+   * Multiply this vector entries time a scale factor.
+   * @param scaleFactor the scale factor
+   */
   public void multiplyAssign(float scaleFactor) {
     x *= scaleFactor;
     y *= scaleFactor;
   }
 
+  /** Returns a new vector which entries are divided with a divide factor.
+   * @param divideFactor the divide factor
+   * @return the division from this vector and a divide factor
+   */
   public Vec2f divide(float divideFactor) {
     return this.multiply(1.0f / divideFactor);
   }
 
+  /**
+   * Divide this vector entries with a divide factor.
+   * @param divideFactor the divide factor
+   */
   public void divideAssign(float divideFactor) {
     multiplyAssign(1.0f / divideFactor);
   }
 
-  public Vec2f normalize() {
+  /**
+   * Normalizes this vector by dividing with the length of the vector.
+   */
+  public void normalize() {
     float len = getLength();
     if (len != 0.0f) {
-      this.setX(x / len);
-      this.setY(y / len);
+      x /= len;
+      y /= len;
     } else {
-      this.setX(0.0f);
-      this.setY(0.0f);
+      this.set(0, 0);
     }
-
-    return this;
   }
 
   /**
@@ -147,11 +239,7 @@ public class Vec2f {
    * @param max upper bound
    */
   public void clampX(float min, float max) {
-    if (x < min) {
-      setX(min);
-    } else if (x > max) {
-      setX(max);
-    }
+    x = Maths.clamp(x, min, max);
   }
 
   /**
@@ -161,17 +249,11 @@ public class Vec2f {
    * @param max upper bound
    */
   public void clampY(float min, float max) {
-    if (y < min) {
-      setY(min);
-    } else if (y > max) {
-      setY(max);
-    }
+    y = Maths.clamp(y, min, max);
   }
 
-
+  @Override
   public String toString() {
-    return "X: " + x + " Y: " + y;
+    return "Vec2f(" + x + "," + y + ")";
   }
-
-
 }

+ 92 - 36
src/holeg/utility/math/vector/Vec2i.java

@@ -1,30 +1,53 @@
 package holeg.utility.math.vector;
 
-
+import holeg.utility.math.Maths;
 import java.awt.Point;
 
 /**
- * @author Tom Troppmann
+ * A class representing a 2 dimensional vector with integer entries.
  */
 public class Vec2i {
 
+  /**
+   * The first entry.
+   */
   private int x;
+  /**
+   * The second entry.
+   */
   private int y;
 
+  /**
+   * Constructs a vector and initialized it with zeros.
+   */
   public Vec2i() {
     x = y = 0;
   }
 
+  /**
+   * Constructs a vector with x and y.
+   *
+   * @param x the first entry
+   * @param y the second entry
+   */
   public Vec2i(int x, int y) {
-    setX(x);
-    setY(y);
+    this.x = x;
+    this.y = y;
   }
-
+  /**
+   * Creates a copy of another vector.
+   *
+   * @param other the other to copy the entries from
+   */
   public Vec2i(Vec2i other) {
     x = other.x;
     y = other.y;
   }
-
+  /**
+   * Creates a vector from a point.
+   *
+   * @param point the point
+   */
   public Vec2i(Point point) {
     x = point.x;
     y = point.y;
@@ -47,37 +70,47 @@ public class Vec2i {
   }
 
   public void set(int x, int y) {
-    setX(x);
-    setY(y);
+    this.x = x;
+    this.y = y;
   }
 
   public void set(Vec2i other) {
-    setX(other.x);
-    setY(other.y);
+    x = other.x;
+    y = other.y;
   }
 
-
+  /**
+   * Creates the dot product with another vector.
+   *
+   * @param other the other vector
+   * @return the dot product
+   */
   public float dot(Vec2i other) {
     return (float) (x * other.getX() + y * other.getY());
   }
 
+  /**
+   * Returns the euclidean distance to zero.
+   *
+   * @return distance to zero
+   */
   public float getLength() {
     return (float) Math.sqrt(x * x + y * y);
   }
 
   /**
-   * Return the Distance to a other Position.
+   * Return the Distance to a other vector.
    *
-   * @param other the other Position.
-   * @return distance to the Position.
+   * @param other the other vector.
+   * @return distance to the vector.
    */
   public float getDistance(Vec2i other) {
     return (float) Math.sqrt(getSquaredDistance(other));
   }
 
   /**
-   * Return the Distance squared to a other Position. Faster then Distance because no Sqrt()
-   * needed.
+   * Return the squared distance to a other Position. Faster than {@link #getDistance(Vec2i)}
+   * because no {@link Math#sqrt(double)} needed.
    *
    * @param other the other Position.
    * @return squared distance to the Position
@@ -87,47 +120,78 @@ public class Vec2i {
     int yDistance = other.getY() - y;
     return xDistance * xDistance + yDistance * yDistance;
   }
-
+  /**
+   * Returns a new vector that is the sum of this vector and another Vector.
+   *
+   * @param other the other vector
+   * @return the sum
+   */
   public Vec2i add(Vec2i other) {
     Vec2i result = new Vec2i();
     result.setX(x + other.getX());
     result.setY(y + other.getY());
     return result;
   }
-
+  /**
+   * Add the entries of another Vector to this vector.
+   *
+   * @param other the other vector
+   */
   public void addAssign(Vec2i other) {
     x += other.getX();
     y += other.getY();
   }
-
+  /**
+   * Returns a new vector that is the subtraction of this vector and another Vector.
+   *
+   * @param other the other vector
+   * @return the subtraction
+   */
   public Vec2i subtract(Vec2i other) {
     Vec2i result = new Vec2i();
     result.setX(x - other.getX());
     result.setY(y - other.getY());
     return result;
   }
-
+  /**
+   * Subtract the entries of another Vector to this vector.
+   *
+   * @param other the other vector
+   */
   public void subtractAssign(Vec2i other) {
     x -= other.getX();
     y -= other.getY();
   }
-
+  /**
+   * Returns a new vector which entries are multiplied times a scaled factor.
+   * @param scaleFactor the scale factor
+   * @return the multiplication from this vector with a scale
+   */
   public Vec2i multiply(float scaleFactor) {
     Vec2i result = new Vec2i();
     result.setX((int) (x * scaleFactor));
     result.setY((int) (y * scaleFactor));
     return result;
   }
-
+  /**
+   * Multiply this vector entries time a scale factor.
+   * @param scaleFactor the scale factor
+   */
   public void multiplyAssign(float scaleFactor) {
     x *= scaleFactor;
     y *= scaleFactor;
   }
-
+  /** Returns a new vector which entries are divided with a divide factor.
+   * @param divideFactor the divide factor
+   * @return the division from this vector and a divide factor
+   */
   public Vec2i divide(float divideFactor) {
     return this.multiply(1.0f / divideFactor);
   }
-
+  /**
+   * Divide this vector entries with a divide factor.
+   * @param divideFactor the divide factor
+   */
   public void divideAssign(float divideFactor) {
     multiplyAssign(1.0f / divideFactor);
   }
@@ -139,11 +203,7 @@ public class Vec2i {
    * @param max upper bound
    */
   public void clampX(int min, int max) {
-    if (x < min) {
-      setX(min);
-    } else if (x > max) {
-      setX(max);
-    }
+    x = Maths.clamp(x, min, max);
   }
 
   /**
@@ -153,16 +213,12 @@ public class Vec2i {
    * @param max upper bound
    */
   public void clampY(int min, int max) {
-    if (y < min) {
-      setY(min);
-    } else if (y > max) {
-      setY(max);
-    }
+    y = Maths.clamp(y, min, max);
   }
 
-
+  @Override
   public String toString() {
-    return "X: " + x + " Y: " + y;
+    return "Vec2i(" + x + "," + y + ")";
   }
 
 }

+ 63 - 13
src/holeg/utility/pooling/Pool.java

@@ -3,7 +3,13 @@ package holeg.utility.pooling;
 import java.util.ArrayList;
 import java.util.stream.Stream;
 
-
+/**
+ * An abstract implementation of simple pooling. To reduce constructing time and garbage collection
+ * when many objects are dynamically needed. The Pool keeps track of the objects that are borrowed
+ * via the {@link #get()} Method.
+ *
+ * @param <T> Type of the pooled objects.
+ */
 public abstract class Pool<T> {
 
   int borrowedCount = 0;
@@ -11,13 +17,26 @@ public abstract class Pool<T> {
   private final ArrayList<T> poolList = new ArrayList<>(poolCapacity);
   private final ArrayList<T> borrowedList = new ArrayList<>(poolCapacity);
 
-
+  /**
+   * Constructs the Pool and populate it.
+   */
   public Pool() {
-    poppulatePool(poolCapacity);
+    populatePool(poolCapacity);
   }
 
+  /**
+   * This method is called to create an object instance for the pool. This method is abstract to
+   * handle all type of parametrized constructors of the pooled object type {@link T}.
+   *
+   * @return a new created instance of an object for pooling
+   */
   public abstract T create();
 
+  /**
+   * Returns an object from the pool.
+   *
+   * @return the pooled object
+   */
   public T get() {
     checkCapacity(borrowedCount);
     T poolObject = poolList.get(borrowedCount);
@@ -26,32 +45,63 @@ public abstract class Pool<T> {
     return poolObject;
   }
 
+  /**
+   * Resets the pool to start returning pooled objects from the beginning.
+   * <br>
+   * Attention:
+   * <br>
+   * All references to previous borrowed objects are still valid, but the {@link #get()} method will
+   * start giving objects from the start of the pool. Be sure to don't use old references after the
+   * call of this method.
+   */
   public void clear() {
     borrowedList.clear();
     borrowedCount = 0;
   }
 
+  /**
+   * Returns the amount of borrowed objects.
+   *
+   * @return the amount of borrowed objects
+   */
+  public int getBorrowedCount() {
+    return borrowedCount;
+  }
+
+  /**
+   * Returns a stream of all objects that are currently borrowed.
+   *
+   * @return stream of borrowed objects
+   */
+  public Stream<T> getBorrowedStream() {
+    return borrowedList.stream();
+  }
 
-  private void poppulatePool(int amount) {
+  /**
+   * Creates an amount of objects to the pool. The {@link #create()} method is called to instantiate
+   * the objects.
+   *
+   * @param amount amount of new created objects
+   */
+  private void populatePool(int amount) {
     for (int i = 0; i < amount; i++) {
       poolList.add(create());
     }
   }
 
+  /**
+   * This method is called to check if the current capacity can hold the requested capacity. If the
+   * current capacity cannot hold the requested capacity the actual capacity is increased to two
+   * times the requested capacity.
+   *
+   * @param requestedCapacity the requested amount of pooled objects
+   */
   private void checkCapacity(int requestedCapacity) {
     if (poolCapacity <= requestedCapacity) {
       int newSize = 2 * requestedCapacity;
-      poppulatePool(newSize - poolCapacity);
+      populatePool(newSize - poolCapacity);
       poolCapacity = 2 * requestedCapacity;
     }
   }
 
-  public int getBorrowedCount() {
-    return borrowedCount;
-  }
-
-  public Stream<T> getBorrowedStream() {
-    return borrowedList.stream();
-  }
-
 }