Project is now buildable.

-Moved: Code generation is in its own sourceset.
-Fixed: Bugs that caused that the project isnt buildable.
-Changed: Made build.gradle to a standard.
This commit is contained in:
Speiger 2021-01-29 11:41:48 +01:00
parent 0cb07398f9
commit aaee550ea9
57 changed files with 132 additions and 86 deletions

29
.gitignore vendored
View File

@ -14,30 +14,9 @@ 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
# ---> Java .classpath
# Compiled class file .project
*.class gradle-wrapper.jar
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
---> Custom ---> Custom
!/libs/ !/libs/
@ -56,4 +35,4 @@ hs_err_pid*
/src/main/java/speiger/src/collections/objects/* /src/main/java/speiger/src/collections/objects/*
#Cache result #Cache result
/src/main/resources/speiger/assets/collections/cache.bin /src/builder/resources/speiger/assets/collections/cache.bin

View File

@ -9,13 +9,14 @@ ArraysList, HashSet/Map (Linked & HashControl), TreeSet/Map (RB & AVL), Priority
# Guide # Guide
Project is currently not buildable due to certain design flaws that are being redone, The SourceCode can be already generated via:
but the SourceCode can be already generated via: /gradlew.bat generateSource /gradlew.bat generateSource
which will generate all the files and they shouldn't generate any errors. to build the jar
/gradlew.bat build
do not combine the commands because they can not be executed at the same time.
Current Problem: Current Problem:
EnumMaps use sun.misc package. EnumMaps use sun.misc package.
Some methods are ambiguous and need to be adjusted.
Some overhauls or missing implementations have to be added. (A couple passes) Some overhauls or missing implementations have to be added. (A couple passes)
But technically Lists/Sets/PriorityQueues are fully usable, Maps are untested and just recently added. But technically Lists/Sets/PriorityQueues are fully usable, Maps are untested and just recently added.

View File

@ -12,7 +12,7 @@ apply plugin: 'eclipse'
repositories { repositories {
jcenter() jcenter()
flatDir { flatDir {
dirs '/libs' dirs 'libs'
} }
} }
@ -31,11 +31,12 @@ eclipse {
} }
} }
task generateSource(type: JavaExec) { sourceSets {
group = 'internal' builder
description = 'Builds the sourcecode' }
classpath = sourceSets.main.runtimeClasspath
main = 'speiger.src.builder.example.TestBuilder' configurations {
builderCompile.extendsFrom compile
} }
dependencies { dependencies {
@ -43,6 +44,30 @@ dependencies {
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
} }
task generateSource(type: JavaExec) {
group = 'internal'
description = 'Builds the sourcecode'
classpath = sourceSets.builder.runtimeClasspath
main = 'speiger.src.builder.PrimitiveCollectionsBuilder'
}
task javadocJar(type: Jar) {
from javadoc
classifier = 'javadoc'
}
task srcJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
javadoc.failOnError = false
artifacts {
archives javadocJar
archives srcJar
}
test { test {
useJUnit() useJUnit()
} }

View File

@ -1,4 +1,4 @@
package speiger.src.builder.example; package speiger.src.builder;
public enum ClassType public enum ClassType
{ {

View File

@ -1,4 +1,4 @@
package speiger.src.builder.example; package speiger.src.builder;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,4 +1,4 @@
package speiger.src.builder.example; package speiger.src.builder;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
@ -15,7 +15,7 @@ import java.util.function.Consumer;
import speiger.src.builder.processor.TemplateProcess; import speiger.src.builder.processor.TemplateProcess;
import speiger.src.builder.processor.TemplateProcessor; import speiger.src.builder.processor.TemplateProcessor;
public class TestBuilder extends TemplateProcessor public class PrimitiveCollectionsBuilder extends TemplateProcessor
{ {
Map<String, EnumSet<ClassType>> blocked = new HashMap<>(); Map<String, EnumSet<ClassType>> blocked = new HashMap<>();
Map<String, String> nameRemapper = new HashMap<>(); Map<String, String> nameRemapper = new HashMap<>();
@ -26,12 +26,12 @@ public class TestBuilder extends TemplateProcessor
List<GlobalVariables> biVariables = new ArrayList<>(); List<GlobalVariables> biVariables = new ArrayList<>();
List<GlobalVariables> enumVariables = new ArrayList<>(); List<GlobalVariables> enumVariables = new ArrayList<>();
public TestBuilder() public PrimitiveCollectionsBuilder()
{ {
super(Paths.get("src/main/resources/speiger/assets/collections/templates/"), Paths.get("src/main/java/speiger/src/collections/"), Paths.get("src/main/resources/speiger/assets/collections/")); super(Paths.get("src/builder/resources/speiger/assets/collections/templates/"), Paths.get("src/main/java/speiger/src/collections/"), Paths.get("src/builder/resources/speiger/assets/collections/"));
} }
public TestBuilder(Path sourceFolder, Path outputFolder, Path dataFolder) public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder)
{ {
super(sourceFolder, outputFolder, dataFolder); super(sourceFolder, outputFolder, dataFolder);
} }
@ -145,9 +145,9 @@ public class TestBuilder extends TemplateProcessor
try try
{ {
if(args.length == 0) { if(args.length == 0) {
new TestBuilder().process(false); new PrimitiveCollectionsBuilder().process(false);
} else if(args.length == 3) { } else if(args.length == 3) {
new TestBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(false); new PrimitiveCollectionsBuilder(Paths.get(args[0]), Paths.get(args[1]), Paths.get(args[2])).process(false);
} else { } else {
System.out.println("Invalid argument count passed in"); System.out.println("Invalid argument count passed in");
System.exit(1); System.exit(1);

View File

@ -180,8 +180,8 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
} }
@Override @Override
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) { public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
VALUE_TYPE value = get(key); CLASS_VALUE_TYPE value = get(key);
return VALUE_EQUALS_NOT(value, getDefaultReturnValue()) || containsKey(key) ? value : defaultValue; return VALUE_EQUALS_NOT(value, getDefaultReturnValue()) || containsKey(key) ? value : defaultValue;
} }
@ -191,6 +191,11 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
return VALUE_TO_OBJ(key instanceof CLASS_TYPE ? GET_VALUE(CLASS_TO_KEY(key)) : getDefaultReturnValue()); return VALUE_TO_OBJ(key instanceof CLASS_TYPE ? GET_VALUE(CLASS_TO_KEY(key)) : getDefaultReturnValue());
} }
@Override
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
return VALUE_TO_OBJ(key instanceof CLASS_TYPE ? getOrDefault(CLASS_TO_KEY(key), OBJ_TO_VALUE(defaultValue)) : getDefaultReturnValue());
}
@Override @Override
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
VALUE_TYPE value = get(key); VALUE_TYPE value = get(key);

View File

@ -257,7 +257,14 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
return VALUE_TO_OBJ(slot < 0 ? getDefaultReturnValue() : values[slot]); return VALUE_TO_OBJ(slot < 0 ? getDefaultReturnValue() : values[slot]);
} }
#if !TYPE_OBJECT #if TYPE_OBJECT && VALUE_OBJECT
@Override
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
int slot = findIndex(key);
return slot < 0 ? defaultValue : values[slot];
}
#else
@Override @Override
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
int slot = findIndex(key); int slot = findIndex(key);
@ -265,12 +272,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
} }
#endif #endif
@Override
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
int slot = findIndex(key);
return slot < 0 ? defaultValue : VALUE_TO_OBJ(values[slot]);
}
@Override @Override
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() { public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
if(entrySet == null) entrySet = new MapEntrySet(); if(entrySet == null) entrySet = new MapEntrySet();

View File

@ -253,20 +253,21 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
return VALUE_TO_OBJ(slot < 0 ? getDefaultReturnValue() : values[slot]); return VALUE_TO_OBJ(slot < 0 ? getDefaultReturnValue() : values[slot]);
} }
#if !TYPE_OBJECT #if TYPE_OBJECT && VALUE_OBJECT
@Override
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
int slot = findIndex(key);
return slot < 0 ? defaultValue : values[slot];
}
#else
@Override @Override
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
int slot = findIndex(key); int slot = findIndex(key);
return slot < 0 ? defaultValue : values[slot]; return slot < 0 ? defaultValue : values[slot];
} }
#endif #endif
@Override
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
int slot = findIndex(key);
return slot < 0 ? defaultValue : VALUE_TO_OBJ(values[slot]);
}
@Override @Override
public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() { public ObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
if(entrySet == null) entrySet = new MapEntrySet(); if(entrySet == null) entrySet = new MapEntrySet();

View File

@ -153,7 +153,14 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return index < 0 ? getDefaultReturnValue() : values[index]; return index < 0 ? getDefaultReturnValue() : values[index];
} }
#if !TYPE_OBJECT #if TYPE_OBJECT
@Override
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
int index = findIndex(key);
return index < 0 ? defaultValue : values[index];
}
#else
@Override @Override
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
int index = findIndex(key); int index = findIndex(key);
@ -161,12 +168,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
} }
#endif #endif
@Override
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
int index = findIndex(key);
return index < 0 ? defaultValue : VALUE_TO_OBJ(values[index]);
}
@Override @Override
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) {
int index = findIndex(key); int index = findIndex(key);
@ -564,7 +565,14 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
return index < 0 ? getDefaultReturnValue() : values[index]; return index < 0 ? getDefaultReturnValue() : values[index];
} }
#if !TYPE_OBJECT #if TYPE_OBJECT && VALUE_OBJECT
@Override
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
int index = findIndex(key);
return index < 0 ? defaultValue : values[index];
}
#else
@Override @Override
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
int index = findIndex(key); int index = findIndex(key);
@ -572,18 +580,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
} }
#endif #endif
@Override
public CLASS_VALUE_TYPE get(Object key) {
int index = findIndex(key);
return VALUE_TO_OBJ(index < 0 ? getDefaultReturnValue() : values[index]);
}
@Override
public CLASS_VALUE_TYPE getOrDefault(Object key, CLASS_VALUE_TYPE defaultValue) {
int index = findIndex(key);
return index < 0 ? defaultValue : VALUE_TO_OBJ(values[index]);
}
@Override @Override
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) {
int index = findIndex(key); int index = findIndex(key);

View File

@ -16,7 +16,7 @@ import speiger.src.collections.objects.maps.abstracts.ABSTRACT_MAP;
import speiger.src.collections.objects.maps.interfaces.MAP; import speiger.src.collections.objects.maps.interfaces.MAP;
import speiger.src.collections.objects.sets.AbstractObjectSet; import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet; import speiger.src.collections.objects.sets.ObjectSet;
import sun.misc.SharedSecrets; //import sun.misc.SharedSecrets;
public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE
{ {
@ -182,7 +182,10 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
onNodeRemoved(index); onNodeRemoved(index);
} }
protected boolean isSet(int index) { return (present[index >> 6] & (1L << index)) != 0; } protected boolean isSet(int index) { return (present[index >> 6] & (1L << index)) != 0; }
private static <K extends Enum<K>> K[] getKeyUniverse(Class<K> keyType) { return SharedSecrets.getJavaLangAccess().getEnumConstantsShared(keyType); } private static <K extends Enum<K>> K[] getKeyUniverse(Class<K> keyType) {
return keyType.getEnumConstants();
// return SharedSecrets.getJavaLangAccess().getEnumConstantsShared(keyType);
}
class EntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> { class EntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> {

View File

@ -213,7 +213,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return node == null ? getDefaultReturnValue() : node.value; return node == null ? getDefaultReturnValue() : node.value;
} }
#if TYPE_OBJECT #if TYPE_OBJECT && VALUE_OBJECT
@Override @Override
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) { public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
Entry KEY_VALUE_GENERIC_TYPE node = findNode((CLASS_TYPE)key); Entry KEY_VALUE_GENERIC_TYPE node = findNode((CLASS_TYPE)key);
@ -918,6 +918,19 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
return inRange(key) ? m.GET_VALUE(key) : getDefaultReturnValue(); return inRange(key) ? m.GET_VALUE(key) : getDefaultReturnValue();
} }
#if TYPE_OBJECT && VALUE_OBJECT
@Override
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
return inRange((KEY_TYPE)key) ? m.getOrDefault(key, defaultValue) : getDefaultReturnValue();
}
#else
@Override
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
return inRange(key) ? m.getOrDefault(key, defaultValue) : getDefaultReturnValue();
}
#endif
@Override @Override
public VALUE_TYPE REMOVE_KEY(KEY_TYPE key) { public VALUE_TYPE REMOVE_KEY(KEY_TYPE key) {
return inRange(key) ? m.remove(key) : getDefaultReturnValue(); return inRange(key) ? m.remove(key) : getDefaultReturnValue();

View File

@ -212,7 +212,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return node == null ? getDefaultReturnValue() : node.value; return node == null ? getDefaultReturnValue() : node.value;
} }
#if TYPE_OBJECT #if TYPE_OBJECT && VALUE_OBJECT
@Override @Override
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) { public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
Entry KEY_VALUE_GENERIC_TYPE node = findNode((CLASS_TYPE)key); Entry KEY_VALUE_GENERIC_TYPE node = findNode((CLASS_TYPE)key);
@ -975,6 +975,19 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
return inRange(key) ? m.GET_VALUE(key) : getDefaultReturnValue(); return inRange(key) ? m.GET_VALUE(key) : getDefaultReturnValue();
} }
#if TYPE_OBJECT && VALUE_OBJECT
@Override
public VALUE_TYPE getOrDefault(Object key, VALUE_TYPE defaultValue) {
return inRange((KEY_TYPE)key) ? m.getOrDefault(key, defaultValue) : getDefaultReturnValue();
}
#else
@Override
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
return inRange(key) ? m.getOrDefault(key, defaultValue) : getDefaultReturnValue();
}
#endif
@Override @Override
public VALUE_TYPE REMOVE_KEY(KEY_TYPE key) { public VALUE_TYPE REMOVE_KEY(KEY_TYPE key) {
return inRange(key) ? m.remove(key) : getDefaultReturnValue(); return inRange(key) ? m.remove(key) : getDefaultReturnValue();

View File

@ -679,6 +679,9 @@ public class AVL_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
@Override @Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return set.comparator(); } public COMPARATOR KEY_GENERIC_TYPE comparator() { return set.comparator(); }
@Override
public abstract BI_ITERATOR KEY_GENERIC_TYPE iterator();
@Override @Override
public KEY_TYPE FIRST_KEY() { public KEY_TYPE FIRST_KEY() {
Entry KEY_GENERIC_TYPE entry = findLowest(); Entry KEY_GENERIC_TYPE entry = findLowest();

View File

@ -9,6 +9,9 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements SET KEY_GENERIC_TYPE
{ {
@Override
public abstract ITERATOR KEY_GENERIC_TYPE iterator();
@Override @Override
public int hashCode() { public int hashCode() {
int hashCode = 1; int hashCode = 1;

View File

@ -221,7 +221,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
boolean modified = false; boolean modified = false;
int j = 0; int j = 0;
for(int i = 0;i<data.length;i++) { for(int i = 0;i<size;i++) {
if(!filter.test(data[i])) data[j++] = data[i]; if(!filter.test(data[i])) data[j++] = data[i];
else modified = true; else modified = true;
} }

View File

@ -739,6 +739,9 @@ public class RB_TREE_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE
@Override @Override
public COMPARATOR KEY_GENERIC_TYPE comparator() { return set.comparator(); } public COMPARATOR KEY_GENERIC_TYPE comparator() { return set.comparator(); }
@Override
public abstract BI_ITERATOR KEY_GENERIC_TYPE iterator();
@Override @Override
public KEY_TYPE FIRST_KEY() { public KEY_TYPE FIRST_KEY() {
Entry KEY_GENERIC_TYPE entry = findLowest(); Entry KEY_GENERIC_TYPE entry = findLowest();