Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: run autoformatter #8

Merged
merged 1 commit into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
30 changes: 30 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@
<url>https://github.com/TomerAberbach/mano-simulator</url>
<build>
<plugins>
<plugin>
<groupId>com.cosium.code</groupId>
<artifactId>git-code-format-maven-plugin</artifactId>
<version>3.4</version>
<executions>
<execution>
<goals>
<goal>install-hooks</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>[3.5.4,)</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.0</version>
Expand Down
32 changes: 32 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,38 @@

<build>
<plugins>

<plugin>
<groupId>com.cosium.code</groupId>
<artifactId>git-code-format-maven-plugin</artifactId>
<version>3.4</version>
<executions>
<execution>
<goals>
<goal>install-hooks</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>[3.5.4,)</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
99 changes: 50 additions & 49 deletions src/main/java/com/tomeraberbach/mano/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,57 @@

import java.util.Collection;


/**
* Class containing general methods.
*/
/** Class containing general methods. */
public class Utilities {
/**
* Empty private constructor to block instantiation.
*/
private Utilities() {
}


/**
* @param value Integer to convert to a hexadecimal {@link String}.
* @param digits Integer number of hexadecimal digits the hexadecimal {@link String} should contain.
* @return {@link String} which is the {@code digits} long hexadecimal representation of {@code value}.
*/
public static String hex(int value, int digits) {
return padLeft(Integer.toHexString(value), '0', digits).toUpperCase();
}

/**
* @param text {@link String} text to pad with characters from the left.
* @param c Character to pad {@code text} with from the left.
* @param length Integer length the resulting padded {@link String} should be.
* @return {@code text} padded with {@code c} characters from the left such that its length is {@code length}.
*/
public static String padLeft(String text, char c, int length) {
StringBuilder builder = new StringBuilder();

// Loops to padLeft the given text with characters from the left if it is less than the desired length
while (builder.length() + text.length() < length) {
builder.append(c);
}

builder.append(text);

return builder.toString();
/** Empty private constructor to block instantiation. */
private Utilities() {}

/**
* @param value Integer to convert to a hexadecimal {@link String}.
* @param digits Integer number of hexadecimal digits the hexadecimal {@link String} should
* contain.
* @return {@link String} which is the {@code digits} long hexadecimal representation of {@code
* value}.
*/
public static String hex(int value, int digits) {
return padLeft(Integer.toHexString(value), '0', digits).toUpperCase();
}

/**
* @param text {@link String} text to pad with characters from the left.
* @param c Character to pad {@code text} with from the left.
* @param length Integer length the resulting padded {@link String} should be.
* @return {@code text} padded with {@code c} characters from the left such that its length is
* {@code length}.
*/
public static String padLeft(String text, char c, int length) {
StringBuilder builder = new StringBuilder();

// Loops to padLeft the given text with characters from the left if it is less than the desired
// length
while (builder.length() + text.length() < length) {
builder.append(c);
}

/**
* @param collections {@link Collection} of {@code T} instances to union.
* @param <T> Type of {@link Collection} instances which will be unioned.
* @param <U> Type of instance which the {@code T} instances contain.
* @return {@code T} at the first index of {@code collections} and which now contains the contents of all the other {@code T} instances in {@code collections}.
*/
public static <T extends Collection<U>, U> T union(Collection<T> collections) {
return collections.stream().reduce((collection1, collection2) -> {
collection1.addAll(collection2);
return collection1;
}).orElse(null);
}
builder.append(text);

return builder.toString();
}

/**
* @param collections {@link Collection} of {@code T} instances to union.
* @param <T> Type of {@link Collection} instances which will be unioned.
* @param <U> Type of instance which the {@code T} instances contain.
* @return {@code T} at the first index of {@code collections} and which now contains the contents
* of all the other {@code T} instances in {@code collections}.
*/
public static <T extends Collection<U>, U> T union(Collection<T> collections) {
return collections.stream()
.reduce(
(collection1, collection2) -> {
collection1.addAll(collection2);
return collection1;
})
.orElse(null);
}
}
Loading