Compare commits

...

3 Commits

8 changed files with 85 additions and 49 deletions

12
.gitignore vendored
View File

@ -11,15 +11,23 @@ gradle-app.setting
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties # gradle/wrapper/gradle-wrapper.properties
.classpath .classpath
.project .project
---> Custom # IntelliJ
.idea/
out/
*.iws
*.ipr
*.iml
# ---> Custom
!/libs/ !/libs/
/.settings/ /.settings/
/bin/ /bin/
/storage/ /storage/
#Generated Code #Generated Code
/src/main/java/speiger/src/collections/booleans/* /src/main/java/speiger/src/collections/booleans/*
/src/main/java/speiger/src/collections/bytes/* /src/main/java/speiger/src/collections/bytes/*

View File

@ -1,9 +1,7 @@
plugins { buildscript {
id 'java-library' def config = new Properties()
} file('build.properties').withInputStream(config.&load)
project.ext.config = config
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
} }
apply plugin: 'java' apply plugin: 'java'
@ -12,24 +10,31 @@ apply plugin: 'maven'
repositories { repositories {
mavenCentral() mavenCentral()
google()
maven { maven {
url = "https://maven.speiger.com/repository/main" url = "https://maven.speiger.com/repository/main"
} }
} }
archivesBaseName = 'Primitive Collections' archivesBaseName = config.project_name
version = '0.4.0'; version = config.project_version
group = config.project_group
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' sourceCompatibility = config.java_source_version
targetCompatibility = config.java_target_version
javadoc { javadoc {
options.tags = [ "implSpec", "note" ] options.tags = [ "implSpec", "note" ]
failOnError = false
options.memberLevel = JavadocMemberLevel.PUBLIC
options.quiet()
} }
eclipse { eclipse {
classpath { classpath {
downloadJavadoc = true downloadJavadoc = true
downloadSources = true downloadSources = true
file { file {
whenMerged { whenMerged {
//Enforce a custom container and allowing access to the sun.misc package which is nessesary for EnumMaps //Enforce a custom container and allowing access to the sun.misc package which is nessesary for EnumMaps
@ -39,6 +44,12 @@ eclipse {
} }
} }
tasks.withType(JavaCompile) {
sourceCompatibility = config.java_source_version
targetCompatibility = config.java_target_version
options.encoding = 'UTF-8'
}
compileJava { compileJava {
options.compilerArgs << '-XDignore.symbol.file' options.compilerArgs << '-XDignore.symbol.file'
options.fork = true options.fork = true
@ -54,8 +65,11 @@ configurations {
} }
dependencies { dependencies {
builderCompile 'de.speiger:Simple-Code-Generator:1.0.4' implementation group: 'org.jetbrains', name: 'annotations', version: config.annotations_version
runtimeOnly 'de.speiger:Simple-Code-Generator:1.0.4'
builderCompile group: 'de.speiger', name: 'Simple-Code-Generator', version: config.scg_version
runtimeOnly group: 'de.speiger', name: 'Simple-Code-Generator', version: config.scg_version
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
} }
@ -84,10 +98,6 @@ task srcJar(type: Jar) {
classifier = 'sources' classifier = 'sources'
} }
javadoc.failOnError = false
javadoc.options.memberLevel = JavadocMemberLevel.PUBLIC
javadoc.options.quiet()
artifacts { artifacts {
archives javadocJar archives javadocJar
archives srcJar archives srcJar
@ -107,8 +117,8 @@ uploadArchives {
} }
pom { pom {
version = project.version version = project.version
artifactId = project.archivesBaseName.replace(" ", "-") artifactId = config.artifact_id
groupId = 'de.speiger' groupId = config.artifact_group
project { project {
licenses { licenses {
license { license {

13
build.properties Normal file
View File

@ -0,0 +1,13 @@
project_name=PrimitiveCollections
project_id=primitivecollections
project_group=speiger.src.collections
project_version=0.4.0
artifact_group=de.speiger
artifact_id=Primitive-Collections
java_source_version=11
java_target_version=8
annotations_version=22.0.0
scg_version=1.0.4

0
gradlew vendored Normal file → Executable file
View File

View File

@ -16,5 +16,5 @@ public interface IArray extends RandomAccess, ITrimmable
* *
* @param size the desired minimum capacity * @param size the desired minimum capacity
*/ */
public void ensureCapacity(int size); void ensureCapacity(int size);
} }

View File

@ -10,7 +10,7 @@ public interface ITrimmable
* Trims the original collection down to the size of the current elements * Trims the original collection down to the size of the current elements
* @return if the internal array has been trimmed. * @return if the internal array has been trimmed.
*/ */
public default boolean trim() { default boolean trim() {
return trim(0); return trim(0);
} }
@ -19,12 +19,12 @@ public interface ITrimmable
* @param size the requested trim size. * @param size the requested trim size.
* @return if the internal array has been trimmed. * @return if the internal array has been trimmed.
*/ */
public boolean trim(int size); boolean trim(int size);
/** /**
* Trims the collection down to the original size and clears all present elements with it. * Trims the collection down to the original size and clears all present elements with it.
*/ */
public default void clearAndTrim() { default void clearAndTrim() {
clearAndTrim(0); clearAndTrim(0);
} }
@ -33,5 +33,5 @@ public interface ITrimmable
* @param size the amount of elements that should be allowed * @param size the amount of elements that should be allowed
* @note this will enforce minimum size of the collection itself * @note this will enforce minimum size of the collection itself
*/ */
public void clearAndTrim(int size); void clearAndTrim(int size);
} }

View File

@ -1,5 +1,8 @@
package speiger.src.collections.utils; package speiger.src.collections.utils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask; import java.util.concurrent.ForkJoinTask;
@ -8,15 +11,15 @@ import java.util.concurrent.ForkJoinTask;
* Helper class that provides functions that are shared within the library. * Helper class that provides functions that are shared within the library.
* On top of that it provides some helper functions that allow control of some internals of the Library * On top of that it provides some helper functions that allow control of some internals of the Library
*/ */
public class SanityChecks public final class SanityChecks
{ {
/** Max Possible ArraySize without the JVM Crashing */ /** Max Possible ArraySize without the JVM Crashing */
public static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; public static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
private static ForkJoinPool WORK_POOL = ForkJoinPool.commonPool(); private static ForkJoinPool WORK_POOL = ForkJoinPool.commonPool();
private static boolean FORCE_IGNORE_PARALLELISM = false; private static boolean FORCE_IGNORE_PARALLELISM = false;
private static ThreadLocal<Random> RANDOM = ThreadLocal.withInitial(Random::new); private static final ThreadLocal<Random> RANDOM = ThreadLocal.withInitial(Random::new);
private static ThreadLocal<Boolean> FORCE_ASYNC = ThreadLocal.withInitial(() -> false); private static final ThreadLocal<Boolean> FORCE_ASYNC = ThreadLocal.withInitial(() -> false);
private static ThreadLocal<Boolean> FORCE_TASK_POOL = ThreadLocal.withInitial(() -> false); private static final ThreadLocal<Boolean> FORCE_TASK_POOL = ThreadLocal.withInitial(() -> false);
/** /**
* Internal function to cast a Integer to a Byte * Internal function to cast a Integer to a Byte
@ -90,8 +93,8 @@ public class SanityChecks
* @param task the Task to invoke * @param task the Task to invoke
* @param <T> the type of the task * @param <T> the type of the task
*/ */
public static <T> void invokeTask(ForkJoinTask<T> task) { public static <T> void invokeTask(@NotNull ForkJoinTask<T> task) {
if(FORCE_ASYNC.get().booleanValue()) invokeAsyncTask(task); if(FORCE_ASYNC.get()) invokeAsyncTask(task);
else getPool().invoke(task); else getPool().invoke(task);
} }
@ -100,7 +103,7 @@ public class SanityChecks
* @param task the Task to invoke * @param task the Task to invoke
* @param <T> the type of the task * @param <T> the type of the task
*/ */
public static <T> void invokeAsyncTask(ForkJoinTask<T> task) { public static <T> void invokeAsyncTask(@NotNull ForkJoinTask<T> task) {
getPool().execute(task); getPool().execute(task);
} }
@ -109,12 +112,12 @@ public class SanityChecks
* @note this method is not thread-save. It is only there to provide control over how Library specific Threaded tasks are handled. * @note this method is not thread-save. It is only there to provide control over how Library specific Threaded tasks are handled.
* @param pool The ForkJoinPool that should receive the tasks. If null {@link ForkJoinPool#commonPool()} is set instead * @param pool The ForkJoinPool that should receive the tasks. If null {@link ForkJoinPool#commonPool()} is set instead
*/ */
public static void setWorkPool(ForkJoinPool pool) { public static void setWorkPool(@Nullable ForkJoinPool pool) {
WORK_POOL = pool == null ? ForkJoinPool.commonPool() : pool; WORK_POOL = pool == null ? ForkJoinPool.commonPool() : pool;
} }
private static ForkJoinPool getPool() { private static @NotNull ForkJoinPool getPool() {
if(FORCE_TASK_POOL.get().booleanValue()) { if(FORCE_TASK_POOL.get()) {
ForkJoinPool pool = ForkJoinTask.getPool(); ForkJoinPool pool = ForkJoinTask.getPool();
if(pool != null) return pool; if(pool != null) return pool;
} }
@ -126,7 +129,7 @@ public class SanityChecks
* @return if the Current Thread has not to await task completion. * @return if the Current Thread has not to await task completion.
*/ */
public static boolean isForcedAsync() { public static boolean isForcedAsync() {
return FORCE_ASYNC.get().booleanValue(); return FORCE_ASYNC.get();
} }
/** /**
@ -134,7 +137,7 @@ public class SanityChecks
* @return if the task checks the current pool to be executed in if it is valid. * @return if the task checks the current pool to be executed in if it is valid.
*/ */
public static boolean isForcedTaskPool() { public static boolean isForcedTaskPool() {
return FORCE_TASK_POOL.get().booleanValue(); return FORCE_TASK_POOL.get();
} }
/** /**
@ -142,7 +145,7 @@ public class SanityChecks
* @param value it tasks should not be awaited for * @param value it tasks should not be awaited for
*/ */
public static void setForcedAsync(boolean value) { public static void setForcedAsync(boolean value) {
FORCE_ASYNC.set(Boolean.valueOf(value)); FORCE_ASYNC.set(value);
} }
/** /**
@ -150,7 +153,7 @@ public class SanityChecks
* @param value if the current thread should check if it is a ThreadPoolWorker. * @param value if the current thread should check if it is a ThreadPoolWorker.
*/ */
public static void setForcedTaskPool(boolean value) { public static void setForcedTaskPool(boolean value) {
FORCE_TASK_POOL.set(Boolean.valueOf(value)); FORCE_TASK_POOL.set(value);
} }
/** /**
@ -164,7 +167,7 @@ public class SanityChecks
/** /**
* @return Thread Specific Random needed for internal functions in this library. * @return Thread Specific Random needed for internal functions in this library.
*/ */
public static Random getRandom() { public static @NotNull Random getRandom() {
return RANDOM.get(); return RANDOM.get();
} }
} }

View File

@ -1,6 +1,8 @@
package speiger.src.collections.utils; package speiger.src.collections.utils;
import org.jetbrains.annotations.NotNull;
/** /**
* The Stack Interface represents the Last-In-First-Out layout (LIFO). * The Stack Interface represents the Last-In-First-Out layout (LIFO).
* It provides a simple {@link #push(Object)}, {@link #pop()} function, * It provides a simple {@link #push(Object)}, {@link #pop()} function,
@ -14,40 +16,40 @@ public interface Stack<T>
* Inserts a given Object on top of the stack * Inserts a given Object on top of the stack
* @param e the Object to insert * @param e the Object to insert
*/ */
public void push(T e); void push(@NotNull T e);
/** /**
* Removes the Object on top of the stack. * Removes the Object on top of the stack.
* @return the element that is on top of the stack * @return the element that is on top of the stack
* @throws ArrayIndexOutOfBoundsException if the stack is empty * @throws ArrayIndexOutOfBoundsException if the stack is empty
*/ */
public T pop(); @NotNull T pop();
/** /**
* Provides the amount of elements currently in the stack * Provides the amount of elements currently in the stack
* @return amount of elements in the list * @return amount of elements in the list
*/ */
public int size(); int size();
/** /**
* @return if the stack is empty * @return if the stack is empty
*/ */
public default boolean isEmpty() { default boolean isEmpty() {
return size() == 0; return size() == 0;
} }
/** /**
* Clears the stack * Clears the stack
*/ */
public void clear(); void clear();
/** /**
* Provides the Object on top of the stack * Provides the Object on top of the stack
* @return the element that is on top of the stack * @return the element that is on top of the stack
* @throws ArrayIndexOutOfBoundsException if the stack is empty * @throws ArrayIndexOutOfBoundsException if the stack is empty
*/ */
public default T top() { default @NotNull T top() {
return peek(0); return peek(0);
} }
@ -58,5 +60,5 @@ public interface Stack<T>
* @return the element that was requested * @return the element that was requested
* @throws ArrayIndexOutOfBoundsException if the index is out of bounds * @throws ArrayIndexOutOfBoundsException if the index is out of bounds
*/ */
public T peek(int index); @NotNull T peek(int index);
} }