diff --git a/Changelog.md b/Changelog.md index daf56fc..cd59365 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ ### Version 0.8.0 - Added: getFirst/getLast/removeFirst/removeLast to Lists - Added: Dedicated implementations for toArray into TreeSets +- Fixed: forEach methods in Maps now can use "setValue" functions. ### Version 0.8.0 - Added: ISizeProvider interface (Optimization Helper) diff --git a/src/builder/java/speiger/src/builder/ModulePackage.java b/src/builder/java/speiger/src/builder/ModulePackage.java index a08c540..95ab3e2 100644 --- a/src/builder/java/speiger/src/builder/ModulePackage.java +++ b/src/builder/java/speiger/src/builder/ModulePackage.java @@ -1,155 +1,155 @@ -package speiger.src.builder; - -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; - -import speiger.src.builder.mappers.IMapper; -import speiger.src.builder.processor.TemplateProcess; - -@SuppressWarnings("javadoc") -public class ModulePackage -{ - private static final BiConsumer VOID = (K, V) -> {}; - public static final ClassType[] TYPE = ClassType.values(); - final ClassType keyType; - final ClassType valueType; - Set blocked = new HashSet<>(); - Map nameRemapper = new HashMap<>(); - Map splitters = new HashMap<>(); - List> blockedFilters = new ArrayList<>(); - List mappers = new ArrayList<>(); - Set flags = new LinkedHashSet<>(); - Set globalFlags; - Map flaggedValues = new HashMap<>(); - BiConsumer requirements = VOID; - - public ModulePackage(Set globalFlags, ClassType keyType, ClassType valueType) { - this.globalFlags = globalFlags; - this.keyType = keyType; - this.valueType = valueType; - } - - public void finish() { - requirements = VOID; - mappers.sort(Comparator.comparing(IMapper::getSearchValue, Comparator.comparingInt(String::length).reversed())); - mappers.sort(Comparator.comparing(IMapper::getSearchValue, this::sort)); - } - - public void setRequirements(BiConsumer requirements) { - this.requirements = requirements; - } - - public boolean isSame() { - return keyType == valueType; - } - - public boolean isEnumValid() { - return keyType == ClassType.OBJECT; - } - - public ClassType getKeyType() { - return keyType; - } - - public ClassType getValueType() { - return valueType; - } - - public void addFlag(String flag) { - flags.add(flag); - } - - public void addGlobalFlag(String flag) { - globalFlags.add(flag); - } - - public void addValue(String key, int value) { - flaggedValues.put(key, value); - } - - public void addRequirement(String fileName, RequiredType type) { - requirements.accept(fileName, type); - } - - public void addMapper(IMapper mapper) { - mappers.add(mapper); - } - - public void addBlockedFilter(Predicate filter) { - blockedFilters.add(filter); - } - - public void addBlockedFiles(String... names) { - blocked.addAll(Arrays.asList(names)); - } - - public void addSplitter(String fileName, String splitter) { - splitters.put(fileName, splitter); - } - - public void addRemapper(String fileName, String actualName) { - nameRemapper.put(fileName, actualName); - } - - public void process(String fileName, Consumer result) { - if(isBlocked(fileName)) return; - String splitter = String.format(splitters.getOrDefault(fileName, keyType.getFileType()), keyType.getFileType(), valueType.getFileType()); - String newName = String.format(nameRemapper.getOrDefault(fileName, "%s"+fileName), splitter); - TemplateProcess process = new TemplateProcess(newName+".java"); - process.setPathBuilder(new PathBuilder(keyType.getPathType())); - process.addFlags(flags); - process.addFlags(globalFlags); - process.addMappers(mappers); - process.addValues(flaggedValues); - result.accept(process); - } - - private boolean isBlocked(String fileName) { - if(blocked.contains(fileName)) return true; - for(int i = 0,m=blockedFilters.size();i createPackages(Set globalFlags) { - List list = new ArrayList<>(); - for(ClassType key : TYPE) { - for(ClassType value : TYPE) { - list.add(new ModulePackage(globalFlags, key, value)); - } - } - return list; - } - - private int sort(String key, String value) { - if(value.contains(key)) return 1; - else if(key.contains(value)) return -1; - return 0; - } - - class PathBuilder implements UnaryOperator { - String before; - - public PathBuilder(String before) { - this.before = before; - } - - @Override - public Path apply(Path t) { - return t.subpath(0, 6).resolve(before).resolve(t.subpath(6, t.getNameCount())); - } - } -} +package speiger.src.builder; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; + +import speiger.src.builder.mappers.IMapper; +import speiger.src.builder.processor.TemplateProcess; + +@SuppressWarnings("javadoc") +public class ModulePackage +{ + private static final BiConsumer VOID = (K, V) -> {}; + public static final ClassType[] TYPE = ClassType.values(); + final ClassType keyType; + final ClassType valueType; + Set blocked = new HashSet<>(); + Map nameRemapper = new HashMap<>(); + Map splitters = new HashMap<>(); + List> blockedFilters = new ArrayList<>(); + List mappers = new ArrayList<>(); + Set flags = new LinkedHashSet<>(); + Set globalFlags; + Map flaggedValues = new HashMap<>(); + BiConsumer requirements = VOID; + + public ModulePackage(Set globalFlags, ClassType keyType, ClassType valueType) { + this.globalFlags = globalFlags; + this.keyType = keyType; + this.valueType = valueType; + } + + public void finish() { + requirements = VOID; + mappers.sort(Comparator.comparing(IMapper::getSearchValue, Comparator.comparingInt(String::length).reversed())); + mappers.sort(Comparator.comparing(IMapper::getSearchValue, this::sort)); + } + + public void setRequirements(BiConsumer requirements) { + this.requirements = requirements; + } + + public boolean isSame() { + return keyType == valueType; + } + + public boolean isEnumValid() { + return keyType == ClassType.OBJECT; + } + + public ClassType getKeyType() { + return keyType; + } + + public ClassType getValueType() { + return valueType; + } + + public void addFlag(String flag) { + flags.add(flag); + } + + public void addGlobalFlag(String flag) { + globalFlags.add(flag); + } + + public void addValue(String key, int value) { + flaggedValues.put(key, value); + } + + public void addRequirement(String fileName, RequiredType type) { + requirements.accept(fileName, type); + } + + public void addMapper(IMapper mapper) { + mappers.add(mapper); + } + + public void addBlockedFilter(Predicate filter) { + blockedFilters.add(filter); + } + + public void addBlockedFiles(String... names) { + blocked.addAll(Arrays.asList(names)); + } + + public void addSplitter(String fileName, String splitter) { + splitters.put(fileName, splitter); + } + + public void addRemapper(String fileName, String actualName) { + nameRemapper.put(fileName, actualName); + } + + public void process(String fileName, Consumer result) { + if(isBlocked(fileName)) return; + String splitter = String.format(splitters.getOrDefault(fileName, keyType.getFileType()), keyType.getFileType(), valueType.getFileType()); + String newName = String.format(nameRemapper.getOrDefault(fileName, "%s"+fileName), splitter); + TemplateProcess process = new TemplateProcess(newName+".java"); + process.setPathBuilder(new PathBuilder(keyType.getPathType())); + process.addFlags(flags); + process.addFlags(globalFlags); + process.addMappers(mappers); + process.addValues(flaggedValues); + result.accept(process); + } + + private boolean isBlocked(String fileName) { + if(blocked.contains(fileName)) return true; + for(int i = 0,m=blockedFilters.size();i createPackages(Set globalFlags) { + List list = new ArrayList<>(); + for(ClassType key : TYPE) { + for(ClassType value : TYPE) { + list.add(new ModulePackage(globalFlags, key, value)); + } + } + return list; + } + + private int sort(String key, String value) { + if(value.contains(key)) return 1; + else if(key.contains(value)) return -1; + return 0; + } + + class PathBuilder implements UnaryOperator { + String before; + + public PathBuilder(String before) { + this.before = before; + } + + @Override + public Path apply(Path t) { + return t.subpath(0, 6).resolve(before).resolve(t.subpath(6, t.getNameCount())); + } + } +} diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/concurrent/ConcurrentOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/concurrent/ConcurrentOpenHashMap.template index d3015d7..b888a7d 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/concurrent/ConcurrentOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/concurrent/ConcurrentOpenHashMap.template @@ -652,7 +652,7 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY try { int index = seg.firstIndex; while(index != -1){ - action.accept(new BasicEntryKV_BRACES(seg.keys[index], seg.values[index])); + action.accept(new MapEntry(index, i)); index = (int)seg.links[index]; } } @@ -664,14 +664,14 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY @Override public void fastForEach(Consumer action) { - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0,m=segments.length;i filter) { Objects.requireNonNull(filter); - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0,m=segments.length;i filter) { Objects.requireNonNull(filter); - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0,m=segments.length;i filter) { Objects.requireNonNull(filter); - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0,m=segments.length;i filter) { Objects.requireNonNull(filter); - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0,m=segments.length;i filter) { Objects.requireNonNull(filter); int result = 0; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0,m=segments.length;i action) { int index = firstIndex; while(index != -1) { - action.accept(new BasicEntryKV_BRACES(keys[index], values[index])); + action.accept(new MapEntry(index)); index = (int)links[index]; } } @Override public void fastForEach(Consumer action) { - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); action.accept(entry); index = (int)links[index]; } @@ -703,7 +703,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M int count = 0; int index = firstIndex; while(index != -1) { - action.accept(count++, new BasicEntryKV_BRACES(keys[index], values[index])); + action.accept(count++, new MapEntry(index)); index = (int)links[index]; } } @@ -714,7 +714,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M if(size() <= 0) return; int index = firstIndex; while(index != -1) { - action.accept(input, new BasicEntryKV_BRACES(keys[index], values[index])); + action.accept(input, new MapEntry(index)); index = (int)links[index]; } } @@ -723,10 +723,10 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M public boolean matchesAny(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return false; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); if(filter.test(entry)) return true; index = (int)links[index]; } @@ -737,10 +737,10 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M public boolean matchesNone(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return true; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); if(filter.test(entry)) return false; index = (int)links[index]; } @@ -751,10 +751,10 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M public boolean matchesAll(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return true; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); if(!filter.test(entry)) return false; index = (int)links[index]; } @@ -767,7 +767,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M E state = identity; int index = firstIndex; while(index != -1) { - state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index])); + state = operator.apply(state, new MapEntry(index)); index = (int)links[index]; } return state; @@ -782,11 +782,11 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M while(index != -1) { if(empty) { empty = false; - state = new BasicEntryKV_BRACES(keys[index], values[index]); + state = new MapEntry(index); index = (int)links[index]; continue; } - state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index])); + state = operator.apply(state, new MapEntry(index)); index = (int)links[index]; } return state; @@ -796,10 +796,10 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return null; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); if(filter.test(entry)) return entry; index = (int)links[index]; } @@ -810,11 +810,11 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M public int count(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return 0; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int result = 0; int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); if(filter.test(entry)) result++; index = (int)links[index]; } diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template index a362ad9..d0402cc 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/customHash/OpenCustomHashMap.template @@ -797,7 +797,11 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL public MapEntry(int index) { this.index = index; } - + + void set(int index) { + this.index = index; + } + @Override public KEY_TYPE ENTRY_KEY() { return keys[index]; @@ -862,21 +866,21 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL @Override public void forEach(Consumer action) { - if(containsNull) action.accept(new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex])); + if(containsNull) action.accept(new MapEntry(nullIndex)); for(int i = nullIndex-1;i>=0;i--) - if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(new BasicEntryKV_BRACES(keys[i], values[i])); + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(new MapEntry(i)); } @Override public void fastForEach(Consumer action) { - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); action.accept(entry); } for(int i = nullIndex-1;i>=0;i--) { if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { - entry.set(keys[i], values[i]); + entry.set(i); action.accept(entry); } } @@ -886,9 +890,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL public void forEachIndexed(IntObjectConsumer action) { Objects.requireNonNull(action); if(size() <= 0) return; - if(containsNull) action.accept(0, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex])); + if(containsNull) action.accept(0, new MapEntry(nullIndex)); for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) { - if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, new BasicEntryKV_BRACES(keys[i], values[i])); + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(index++, new MapEntry(i)); } } @@ -896,9 +900,9 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL public void forEach(E input, ObjectObjectConsumer action) { Objects.requireNonNull(action); if(size() <= 0) return; - if(containsNull) action.accept(input, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex])); + if(containsNull) action.accept(input, new MapEntry(nullIndex)); for(int i = nullIndex-1;i>=0;i--) { - if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(input, new BasicEntryKV_BRACES(keys[i], values[i])); + if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) action.accept(input, new MapEntry(i)); } } @@ -906,14 +910,14 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL public boolean matchesAny(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return false; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); if(filter.test(entry)) return true; } for(int i = nullIndex-1;i>=0;i--) { if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { - entry.set(keys[i], values[i]); + entry.set(i); if(filter.test(entry)) return true; } } @@ -924,14 +928,14 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL public boolean matchesNone(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return true; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); if(filter.test(entry)) return false; } for(int i = nullIndex-1;i>=0;i--) { if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { - entry.set(keys[i], values[i]); + entry.set(i); if(filter.test(entry)) return false; } } @@ -942,14 +946,14 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL public boolean matchesAll(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return true; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); if(!filter.test(entry)) return false; } for(int i = nullIndex-1;i>=0;i--) { if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { - entry.set(keys[i], values[i]); + entry.set(i); if(!filter.test(entry)) return false; } } @@ -960,10 +964,10 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL public E reduce(E identity, BiFunction operator) { Objects.requireNonNull(operator); E state = identity; - if(containsNull) state = operator.apply(state, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex])); + if(containsNull) state = operator.apply(state, new MapEntry(nullIndex)); for(int i = nullIndex-1;i>=0;i--) { if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue; - state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i])); + state = operator.apply(state, new MapEntry(i)); } return state; } @@ -974,17 +978,17 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL MAP.Entry KEY_VALUE_GENERIC_TYPE state = null; boolean empty = true; if(containsNull) { - state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]); + state = new MapEntry(nullIndex); empty = false; } for(int i = nullIndex-1;i>=0;i--) { if(strategy.equals(keys[i], EMPTY_KEY_VALUE)) continue; if(empty) { empty = false; - state = new BasicEntryKV_BRACES(keys[i], values[i]); + state = new MapEntry(i); continue; } - state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i])); + state = operator.apply(state, new MapEntry(i)); } return state; } @@ -993,14 +997,14 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return null; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); if(filter.test(entry)) return entry; } for(int i = nullIndex-1;i>=0;i--) { if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { - entry.set(keys[i], values[i]); + entry.set(i); if(filter.test(entry)) return entry; } } @@ -1011,15 +1015,15 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL public int count(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return 0; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int result = 0; if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); if(filter.test(entry)) result++; } for(int i = nullIndex-1;i>=0;i--) { if(!strategy.equals(keys[i], EMPTY_KEY_VALUE)) { - entry.set(keys[i], values[i]); + entry.set(i); if(filter.test(entry)) result++; } } diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template index 48ebf78..057951f 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/LinkedOpenHashMap.template @@ -684,17 +684,17 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G public void forEach(Consumer action) { int index = firstIndex; while(index != -1){ - action.accept(new BasicEntryKV_BRACES(keys[index], values[index])); + action.accept(new MapEntry(index)); index = (int)links[index]; } } @Override public void fastForEach(Consumer action) { - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1){ - entry.set(keys[index], values[index]); + entry.set(index); action.accept(entry); index = (int)links[index]; } @@ -707,7 +707,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G int count = 0; int index = firstIndex; while(index != -1) { - action.accept(count++, new BasicEntryKV_BRACES(keys[index], values[index])); + action.accept(count++, new MapEntry(index)); index = (int)links[index]; } } @@ -718,7 +718,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G if(size() <= 0) return; int index = firstIndex; while(index != -1) { - action.accept(input, new BasicEntryKV_BRACES(keys[index], values[index])); + action.accept(input, new MapEntry(index)); index = (int)links[index]; } } @@ -727,10 +727,10 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G public boolean matchesAny(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return false; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); if(filter.test(entry)) return true; index = (int)links[index]; } @@ -741,10 +741,10 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G public boolean matchesNone(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return true; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); if(filter.test(entry)) return false; index = (int)links[index]; } @@ -755,10 +755,10 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G public boolean matchesAll(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return true; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); if(!filter.test(entry)) return false; index = (int)links[index]; } @@ -771,7 +771,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G E state = identity; int index = firstIndex; while(index != -1) { - state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index])); + state = operator.apply(state, new MapEntry(index)); index = (int)links[index]; } return state; @@ -786,11 +786,11 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G while(index != -1) { if(empty) { empty = false; - state = new BasicEntryKV_BRACES(keys[index], values[index]); + state = new MapEntry(index); index = (int)links[index]; continue; } - state = operator.apply(state, new BasicEntryKV_BRACES(keys[index], values[index])); + state = operator.apply(state, new MapEntry(index)); index = (int)links[index]; } return state; @@ -800,10 +800,10 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return null; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); if(filter.test(entry)) return entry; index = (int)links[index]; } @@ -815,10 +815,10 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G Objects.requireNonNull(filter); if(size() <= 0) return 0; int result = 0; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1) { - entry.set(keys[index], values[index]); + entry.set(index); if(filter.test(entry)) result++; index = (int)links[index]; } diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template index fd13e6f..7c53877 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/hash/OpenHashMap.template @@ -756,7 +756,11 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE public MapEntry(int index) { this.index = index; } - + + void set(int index) { + this.index = index; + } + @Override public KEY_TYPE ENTRY_KEY() { return keys[index]; @@ -821,21 +825,21 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE @Override public void forEach(Consumer action) { - if(containsNull) action.accept(new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex])); + if(containsNull) action.accept(new MapEntry(nullIndex)); for(int i = nullIndex-1;i>=0;i--) - if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(new BasicEntryKV_BRACES(keys[i], values[i])); + if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(new MapEntry(i)); } @Override public void fastForEach(Consumer action) { - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); action.accept(entry); } for(int i = nullIndex-1;i>=0;i--) { if(KEY_EQUALS_NOT_NULL(keys[i])) { - entry.set(keys[i], values[i]); + entry.set(i); action.accept(entry); } } @@ -845,9 +849,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE public void forEachIndexed(IntObjectConsumer action) { Objects.requireNonNull(action); if(size() <= 0) return; - if(containsNull) action.accept(0, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex])); + if(containsNull) action.accept(0, new MapEntry(nullIndex)); for(int i = nullIndex-1, index = containsNull ? 1 : 0;i>=0;i--) { - if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, new BasicEntryKV_BRACES(keys[i], values[i])); + if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(index++, new MapEntry(i)); } } @@ -855,9 +859,9 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE public void forEach(E input, ObjectObjectConsumer action) { Objects.requireNonNull(action); if(size() <= 0) return; - if(containsNull) action.accept(input, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex])); + if(containsNull) action.accept(input, new MapEntry(nullIndex)); for(int i = nullIndex-1;i>=0;i--) { - if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(input, new BasicEntryKV_BRACES(keys[i], values[i])); + if(KEY_EQUALS_NOT_NULL(keys[i])) action.accept(input, new MapEntry(i)); } } @@ -865,14 +869,14 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE public boolean matchesAny(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return false; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); if(filter.test(entry)) return true; } for(int i = nullIndex-1;i>=0;i--) { if(KEY_EQUALS_NOT_NULL(keys[i])) { - entry.set(keys[i], values[i]); + entry.set(i); if(filter.test(entry)) return true; } } @@ -883,14 +887,14 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE public boolean matchesNone(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return true; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); if(filter.test(entry)) return false; } for(int i = nullIndex-1;i>=0;i--) { if(KEY_EQUALS_NOT_NULL(keys[i])) { - entry.set(keys[i], values[i]); + entry.set(i); if(filter.test(entry)) return false; } } @@ -901,14 +905,14 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE public boolean matchesAll(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return true; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); if(!filter.test(entry)) return false; } for(int i = nullIndex-1;i>=0;i--) { if(KEY_EQUALS_NOT_NULL(keys[i])) { - entry.set(keys[i], values[i]); + entry.set(i); if(!filter.test(entry)) return false; } } @@ -919,10 +923,10 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE public E reduce(E identity, BiFunction operator) { Objects.requireNonNull(operator); E state = identity; - if(containsNull) state = operator.apply(state, new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex])); + if(containsNull) state = operator.apply(state, new MapEntry(nullIndex)); for(int i = nullIndex-1;i>=0;i--) { if(KEY_EQUALS_NULL(keys[i])) continue; - state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i])); + state = operator.apply(state, new MapEntry(i)); } return state; } @@ -933,17 +937,17 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE MAP.Entry KEY_VALUE_GENERIC_TYPE state = null; boolean empty = true; if(containsNull) { - state = new BasicEntryKV_BRACES(keys[nullIndex], values[nullIndex]); + state = new MapEntry(nullIndex); empty = false; } for(int i = nullIndex-1;i>=0;i--) { if(KEY_EQUALS_NULL(keys[i])) continue; if(empty) { empty = false; - state = new BasicEntryKV_BRACES(keys[i], values[i]); + state = new MapEntry(i); continue; } - state = operator.apply(state, new BasicEntryKV_BRACES(keys[i], values[i])); + state = operator.apply(state, new MapEntry(i)); } return state; } @@ -952,14 +956,14 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE public MAP.Entry KEY_VALUE_GENERIC_TYPE findFirst(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return null; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); if(filter.test(entry)) return entry; } for(int i = nullIndex-1;i>=0;i--) { if(KEY_EQUALS_NOT_NULL(keys[i])) { - entry.set(keys[i], values[i]); + entry.set(i); if(filter.test(entry)) return entry; } } @@ -970,15 +974,15 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE public int count(Predicate filter) { Objects.requireNonNull(filter); if(size() <= 0) return 0; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int result = 0; if(containsNull) { - entry.set(keys[nullIndex], values[nullIndex]); + entry.set(nullIndex); if(filter.test(entry)) result++; } for(int i = nullIndex-1;i>=0;i--) { if(KEY_EQUALS_NOT_NULL(keys[i])) { - entry.set(keys[i], values[i]); + entry.set(i); if(filter.test(entry)) result++; } } diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template index 11d3ae2..a631ce1 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/misc/ArrayMap.template @@ -788,16 +788,16 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN public void forEach(Consumer action) { Objects.requireNonNull(action); for(int i = 0;i action) { Objects.requireNonNull(action); if(size() <= 0) return; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0;i action) { Objects.requireNonNull(action); for(int i = 0;i void forEach(E input, ObjectObjectConsumer action) { Objects.requireNonNull(action); for(int i = 0;i filter) { Objects.requireNonNull(filter); if(size() <= 0) return false; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0;i filter) { Objects.requireNonNull(filter); if(size() <= 0) return true; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0;i filter) { Objects.requireNonNull(filter); if(size() <= 0) return true; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0;i filter) { Objects.requireNonNull(filter); if(size() <= 0) return null; - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); for(int i = 0;i action) { int index = firstIndex; while(index != -1){ - action.accept(new BasicEntryKV_BRACES(keys[index], values[index])); + action.accept(new MapEntry(index)); index = (int)links[index]; } } @Override public void fastForEach(Consumer action) { - BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(); + MapEntry entry = new MapEntry(); int index = firstIndex; while(index != -1){ - entry.set(keys[index], values[index]); + entry.set(index); action.accept(entry); index = (int)links[index]; } @@ -910,7 +910,11 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA public MapEntry(int index) { this.index = index; } - + + void set(int index) { + this.index = index; + } + @Override public KEY_TYPE ENTRY_KEY() { return keys[index];