Skip to content

Commit

Permalink
New Features.
Browse files Browse the repository at this point in the history
-Added: List.indexedIterator which allows you to create a iterator with a customized iteration indecies. Useful if you want to transform lists output.
-Added: PriorityQueue.contains is now a function
-Added: Iterators/Async Builders now support MapToPrimitiveType function on the object variant. So more processing can be done. (Will be expanded upon later versions)
-Updated: SimpleCodeGenerator 1.3.0 is now being used which allows for iterative code support.
  • Loading branch information
Speiger committed Jun 29, 2023
1 parent a89c812 commit 274d37c
Show file tree
Hide file tree
Showing 31 changed files with 2,676 additions and 2,156 deletions.
6 changes: 5 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
- Added: ToArray/pushTop functions to Stack.class.
- Added: ComputeNonDefault functions which will contain the current behavior of the Compute function, while the Compute will be changed to be more java compliant!
- Added: List.reversed, which returns a SubList that has all elements in reversed order and also inserts reversed.
- Added: Iterators.infinite as an option that will create a Infinite Iterator based on the inputted one.
- Added: Iterators.infinite as an option that will create a Infinite Iterator based on the inputed one.
- Added: List.indexedIterator which allows you to create a iterator with a customized iteration indecies. Useful if you want to transform lists output.
- Added: PriorityQueue.contains is now a function
- Added: Iterators/Async Builders now support MapToPrimitiveType function on the object variant. So more processing can be done. (Will be expanded upon later versions)
- Fixed: SetValue wasn't working on forEach implementations.
- Fixed: Compute functions now perform with primitives more java compliant. Meaning that getDefaultReturnValue function no longer is seen as null.
- Updated: SimpleCodeGenerator 1.3.0 is now being used which allows for iterative code support.

### Version 0.8.0
- Added: getFirst/getLast/removeFirst/removeLast to Lists
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ configurations {

dependencies {
builderImplementation 'com.google.code.gson:gson:2.10'
builderImplementation 'de.speiger:Simple-Code-Generator:1.2.2'
builderImplementation 'de.speiger:Simple-Code-Generator:1.3.0'
testImplementation 'junit:junit:4.12'
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,19 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
SettingsManager manager = new SettingsManager();
int flags;

public PrimitiveCollectionsBuilder()
{
public PrimitiveCollectionsBuilder() {
this(false);
}

public PrimitiveCollectionsBuilder(boolean silencedSuccess)
{
public PrimitiveCollectionsBuilder(boolean silencedSuccess) {
super(silencedSuccess, 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 PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder)
{
public PrimitiveCollectionsBuilder(Path sourceFolder, Path outputFolder, Path dataFolder) {
this(false, sourceFolder, outputFolder, dataFolder);
}

public PrimitiveCollectionsBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder)
{
public PrimitiveCollectionsBuilder(boolean silencedSuccess, Path sourceFolder, Path outputFolder, Path dataFolder) {
super(silencedSuccess, sourceFolder, outputFolder, dataFolder);
}

Expand All @@ -88,42 +84,24 @@ private static PrimitiveCollectionsBuilder createTesters(boolean silent, int fla
}

@Override
protected boolean isFileValid(Path fileName)
{
return true;
}

protected boolean isFileValid(Path fileName) { return true; }
@Override
protected boolean relativePackages()
{
return true;
}

protected boolean relativePackages() { return true; }
@Override
protected boolean debugUnusedMappers()
{
return false;
}
protected boolean debugUnusedMappers() { return false; }

@Override
protected void afterFinish()
{
if((flags & SPECIAL) == 0 && getVersion() > 8)
{
protected void afterFinish() {
if((flags & SPECIAL) == 0 && getVersion() > 8) {
Path basePath = Paths.get("src/main/java");
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java")))
{
try(BufferedWriter writer = Files.newBufferedWriter(basePath.resolve("module-info.java"))) {
writer.write(getModuleInfo(basePath));
}
catch(Exception e)
{
e.printStackTrace();
}
catch(Exception e) { e.printStackTrace(); }
}
}

public List<BaseModule> createModules()
{
public List<BaseModule> createModules() {
List<BaseModule> modules = new ArrayList<>();
modules.add(JavaModule.INSTANCE);
modules.add(FunctionModule.INSTANCE);
Expand All @@ -139,38 +117,31 @@ public List<BaseModule> createModules()


@Override
protected void init()
{
protected void init() {
prepPackages();
//Init Modules here
addModules(createModules());
finishPackages();
}

public void addModules(List<BaseModule> modules)
{
public void addModules(List<BaseModule> modules) {
for(int i = 0,m=modules.size();i<m;i++) {
modules.get(i).setManager(manager);
}
for(int i = 0,m=modules.size();i<m;i++) {
biPackages.forEach(modules.get(i)::init);
}
for(int i = 0,m=modules.size();i<m;i++) {
modules.get(i).cleanup();
}
modules.forEach(BaseModule::cleanup);
}

private void finishPackages()
{
private void finishPackages() {
biPackages.forEach(ModulePackage::finish);
if((flags & SAVE) != 0) manager.save();
}

private void prepPackages()
{
private void prepPackages() {
if((flags & LOAD) != 0) manager.load();
for(ModulePackage entry : ModulePackage.createPackages(globalFlags))
{
for(ModulePackage entry : ModulePackage.createPackages(globalFlags)) {
entry.setRequirements(requirements::put);
biPackages.add(entry);
if(entry.isSame()) simplePackages.add(entry);
Expand All @@ -179,11 +150,9 @@ private void prepPackages()
}

@Override
public void createProcesses(String fileName, Consumer<TemplateProcess> process)
{
public void createProcesses(String fileName, Consumer<TemplateProcess> process) {
List<ModulePackage> packages = getPackagesByRequirement(requirements.get(fileName));
for(int i = 0,m=packages.size();i<m;i++)
{
for(int i = 0,m=packages.size();i<m;i++) {
packages.get(i).process(fileName, process);
}
}
Expand All @@ -197,17 +166,15 @@ protected List<ModulePackage> getPackagesByRequirement(RequiredType type) {

private String getModuleInfo(Path basePath) {
StringJoiner joiner = new StringJoiner("\n", "", "\n");
try(Stream<Path> stream = Files.walk(getOutputFolder()))
{
try(Stream<Path> stream = Files.walk(getOutputFolder())) {
stream.filter(Files::isDirectory)
.filter(this::containsFiles)
.map(basePath::relativize)
.map(Path::toString)
.map(this::sanitize)
.forEach(T -> joiner.add("\texports "+T+";"));
}
catch(Exception e)
{
catch(Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
Expand All @@ -218,34 +185,26 @@ private String getModuleInfo(Path basePath) {
return builder.toString();
}

private String sanitize(String input)
{
private String sanitize(String input) {
return input.replace("\\", ".").replace("/", ".");
}

private boolean containsFiles(Path path)
{
try(Stream<Path> stream = Files.walk(path, 1))
{
private boolean containsFiles(Path path) {
try(Stream<Path> stream = Files.walk(path, 1)) {
return stream.filter(Files::isRegularFile).findFirst().isPresent();
}
catch(Exception e)
{
e.printStackTrace();
}
catch(Exception e) { e.printStackTrace(); }
return false;
}

private int getVersion()
{
private int getVersion() {
String version = System.getProperty("java.version");
if(version.startsWith("1.")) return Integer.parseInt(version.substring(2, 3));
int dot = version.indexOf(".");
return Integer.parseInt(dot != -1 ? version.substring(0, dot) : version);
}

public static void main(String...args)
{
public static void main(String...args) {
try
{
Set<String> flags = new HashSet<>(Arrays.asList(args));
Expand Down
3 changes: 3 additions & 0 deletions src/builder/java/speiger/src/builder/modules/BaseModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public final void cleanup() {
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return Collections.emptySet(); }
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return true; }

public ClassType keyType() { return keyType; }
public ClassType valueType() { return valueType; }

protected boolean isModuleEnabled() {
return manager == null || manager.isModuleEnabled(this, keyType, valueType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ else if(valueType.isObject()) {
protected void loadFunctions()
{
addSimpleMapper("APPLY", keyType.getApply(valueType));
addSimpleMapper("SUPPLY_GET", keyType.isObject() ? "get" : "getAs"+keyType.getCustomJDKType().getNonFileType());
addSimpleMapper("VALUE_SUPPLY_GET", valueType.isObject() ? "get" : "getAs"+valueType.getCustomJDKType().getNonFileType());
addSimpleMapper("SUPPLY_GET", keyType.isObject() ? "get" : "getAs"+keyType.getNonFileType());
addSimpleMapper("VALUE_SUPPLY_GET", valueType.isObject() ? "get" : "getAs"+valueType.getNonFileType());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ import java.util.function.BiFunction;
import java.util.function.IntFunction;
import java.util.Comparator;

#if BOOLEAN_COLLECTION_MODULE
import speiger.src.collections.booleans.collections.BooleanIterable;
#endif
#iterate
#argument OUTPUT_ITERABLE ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
#argument MAPPER ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument PACKAGE bytes shorts ints longs floats doubles
#argument FILTER_TYPE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
#if FILTER_TYPE
import speiger.src.collections.objects.functions.function.MAPPER;
import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERABLE;
#endif
#enditerate
#endif
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
Expand Down Expand Up @@ -165,6 +178,25 @@ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable<CLASS_TYPE>
return ITERABLES.map(this, mapper);
}

#if TYPE_OBJECT
#iterate
#argument OUTPUT_ITERABLE BooleanIterable ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
#argument DATA_TYPE Boolean Byte Short Int Long Float Double
#argument FILTER_TYPE BOOLEAN_COLLECTION_MODULE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
#if FILTER_TYPE
/**
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
* @param mapper the mapping function
* @return a new Iterable that returns the desired result
*/
default OUTPUT_ITERABLE mapToDATA_TYPE(MAPPER<T> mapper) {
return ITERABLES.mapToDATA_TYPE(this, mapper);
}

#endif
#enditerate
#endif
/**
* A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else.
* @param mapper the flatMapping function
Expand Down
Loading

0 comments on commit 274d37c

Please sign in to comment.