Compare commits
No commits in common. "29ddc5594756ec5421da192f83f50b28c58c31b1" and "867b3b4d9a6030ca77c31b0883598ed06bbd22fc" have entirely different histories.
29ddc55947
...
867b3b4d9a
@ -6,6 +6,12 @@
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/test" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="test"/>
|
||||
|
||||
@ -6,14 +6,8 @@
|
||||
- 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 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.
|
||||
- Fixed: Supplier was using the wrong dataType in their function name.
|
||||
- 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
|
||||
|
||||
@ -50,7 +50,7 @@ repositories {
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation 'com.github.Speiger:Primitive-Collections:0.9.0'
|
||||
implementation 'com.github.Speiger:Primitive-Collections:0.7.0'
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ repositories {
|
||||
}
|
||||
|
||||
archivesBaseName = 'Primitive Collections'
|
||||
version = '0.9.0';
|
||||
version = '0.8.0';
|
||||
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
||||
|
||||
@ -46,7 +46,7 @@ configurations {
|
||||
|
||||
dependencies {
|
||||
builderImplementation 'com.google.code.gson:gson:2.10'
|
||||
builderImplementation 'de.speiger:Simple-Code-Generator:1.3.0'
|
||||
builderImplementation 'de.speiger:Simple-Code-Generator:1.2.2'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'com.google.guava:guava-testlib:31.0.1-jre'
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
|
||||
maxMemory = 2048m
|
||||
testThreads = 4
|
||||
maxMemory = 1024m
|
||||
testThreads = 2
|
||||
@ -45,19 +45,23 @@ 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);
|
||||
}
|
||||
|
||||
@ -84,24 +88,42 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFileValid(Path fileName) { return true; }
|
||||
@Override
|
||||
protected boolean relativePackages() { return true; }
|
||||
@Override
|
||||
protected boolean debugUnusedMappers() { return false; }
|
||||
protected boolean isFileValid(Path fileName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterFinish() {
|
||||
if((flags & SPECIAL) == 0 && getVersion() > 8) {
|
||||
protected boolean relativePackages()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean debugUnusedMappers()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
@ -117,32 +139,38 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
manager.resolve();
|
||||
for(int i = 0,m=modules.size();i<m;i++) {
|
||||
biPackages.forEach(modules.get(i)::init);
|
||||
}
|
||||
modules.forEach(BaseModule::cleanup);
|
||||
for(int i = 0,m=modules.size();i<m;i++) {
|
||||
modules.get(i).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);
|
||||
@ -151,9 +179,11 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@ -167,7 +197,8 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
|
||||
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)
|
||||
@ -175,7 +206,8 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
.map(this::sanitize)
|
||||
.forEach(T -> joiner.add("\texports "+T+";"));
|
||||
}
|
||||
catch(Exception e) {
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -186,26 +218,34 @@ public class PrimitiveCollectionsBuilder extends TemplateProcessor
|
||||
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));
|
||||
|
||||
@ -1,100 +1,54 @@
|
||||
package speiger.src.builder;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.internal.Streams;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.IDependency.LoadingState;
|
||||
import speiger.src.builder.modules.BaseModule;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class SettingsManager
|
||||
{
|
||||
boolean loaded;
|
||||
Map<String, LoadingState> parsedData = new TreeMap<>();
|
||||
JsonObject data = new JsonObject();
|
||||
Set<String> moduleNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||
Set<IDependency> allDependencies = new LinkedHashSet<>();
|
||||
|
||||
public void resolve() {
|
||||
if(!loaded) return;
|
||||
Set<IDependency> roots = new LinkedHashSet<>();
|
||||
Set<IDependency> leafs = new LinkedHashSet<>();
|
||||
for(IDependency entry : allDependencies) {
|
||||
if(entry.isRoot()) {
|
||||
roots.add(entry);
|
||||
}
|
||||
if(entry.isLeaf()) {
|
||||
leafs.add(entry);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This has to be 2 iteration passes.
|
||||
* Due to Key Value Pairs, first pass does all initials keys, and the second pass processes the values.
|
||||
* May require more passes but extremely unlikely
|
||||
*/
|
||||
for(int i = 0;i<2;i++) {
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
for(IDependency entry : roots) {
|
||||
entry.resolveRequirements(keyType, valueType);
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean isModuleEnabled(BaseModule base, ClassType keyType, ClassType valueType) {
|
||||
if(!loaded) return true;
|
||||
if(!isEnabled(data, base.getModuleName())) return false;
|
||||
JsonObject result = getObject(data, keyType.getClassPath(), false);
|
||||
if(!isEnabled(result, "Enabled")) return false;
|
||||
if(base.isBiModule()) {
|
||||
result = getObject(result, valueType.getClassPath(), false);
|
||||
if(!isEnabled(result, "Enabled")) return false;
|
||||
}
|
||||
result = getObject(result, base.getModuleName(), false);
|
||||
return (result.size() <= 0 || isEnabled(result, "Enabled")) && base.areDependenciesLoaded();
|
||||
}
|
||||
|
||||
List<String> errors = new ArrayList<>();
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
for(IDependency entry : leafs) {
|
||||
entry.validateDependency(errors::add, keyType, valueType);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(errors.size() > 0) {
|
||||
throw new IllegalStateException("Issues with dependencies found: "+String.join("\n", errors));
|
||||
public boolean isModuleEnabled(BaseModule base, ClassType keyType, ClassType valueType, String entry)
|
||||
{
|
||||
if(!loaded) return true;
|
||||
if(!isEnabled(data, base.getModuleName())) return false;
|
||||
JsonObject result = getObject(data, keyType.getClassPath(), false);
|
||||
if(!isEnabled(result, "Enabled")) return false;
|
||||
if(base.isBiModule()) {
|
||||
result = getObject(result, valueType.getClassPath(), false);
|
||||
if(!isEnabled(result, "Enabled")) return false;
|
||||
}
|
||||
result = getObject(result, base.getModuleName(), false);
|
||||
return (result.size() <= 0 || (isEnabled(result, "Enabled") && isEnabled(result, entry))) && base.areDependenciesLoaded();
|
||||
}
|
||||
|
||||
public void addModule(BaseModule module) {
|
||||
if(loaded) {
|
||||
if(module.isBiModule()) {
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, valueType)) continue;
|
||||
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
|
||||
dependency.set(parsedData);
|
||||
allDependencies.add(dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, keyType)) continue;
|
||||
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
|
||||
dependency.set(parsedData);
|
||||
allDependencies.add(dependency);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(loaded) return;
|
||||
String moduleName = module.getModuleName();
|
||||
moduleNames.add(moduleName);
|
||||
data.addProperty(moduleName, true);
|
||||
@ -103,9 +57,9 @@ public class SettingsManager
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, valueType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, true);
|
||||
obj.addProperty("Enabled", true);
|
||||
for(String key : module.getModuleKeys(keyType, valueType)) {
|
||||
obj.addProperty(key, true);
|
||||
}
|
||||
addModule(keyType, valueType, true, moduleName, obj);
|
||||
}
|
||||
@ -115,61 +69,18 @@ public class SettingsManager
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, keyType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, true);
|
||||
obj.addProperty("Enabled", true);
|
||||
for(String key : module.getModuleKeys(keyType, keyType)) {
|
||||
obj.addProperty(key, true);
|
||||
}
|
||||
addModule(keyType, keyType, false, moduleName, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public void printModuleSettings(List<BaseModule> modules) {
|
||||
JsonObject data = new JsonObject();
|
||||
for(BaseModule module : modules) {
|
||||
String moduleName = module.getModuleName();
|
||||
if(module.isBiModule()) {
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
for(ClassType valueType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, valueType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
for(IDependency dependency : module.getDependencies(keyType, valueType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, dependency.isLoaded(keyType, valueType).getJsonResult());
|
||||
}
|
||||
addModule(data, keyType, valueType, true, moduleName, obj);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for(ClassType keyType : ModulePackage.TYPE) {
|
||||
if(!module.isModuleValid(keyType, keyType)) continue;
|
||||
JsonObject obj = new JsonObject();
|
||||
for(IDependency dependency : module.getDependencies(keyType, keyType)) {
|
||||
String key = dependency.getName();
|
||||
if(key != null) obj.addProperty(key, dependency.isLoaded(keyType, keyType).getJsonResult());
|
||||
}
|
||||
addModule(data, keyType, keyType, false, moduleName, obj);
|
||||
}
|
||||
}
|
||||
try {
|
||||
System.out.println();
|
||||
JsonWriter writer = new JsonWriter(new OutputStreamWriter(System.out));
|
||||
writer.setIndent("\t");
|
||||
Streams.write(data, writer);
|
||||
writer.flush();
|
||||
System.out.println();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
try(BufferedReader reader = Files.newBufferedReader(Paths.get("ModulSettings.json"))) {
|
||||
data = JsonParser.parseReader(reader).getAsJsonObject();
|
||||
loaded = true;
|
||||
IDependency.flatten("", false, data, parsedData);
|
||||
JsonElement element = data.get("Default");
|
||||
LoadingState.setOptionalResolver(LoadingState.of(element == null ? true : element.getAsBoolean()));
|
||||
}
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
@ -189,14 +100,6 @@ public class SettingsManager
|
||||
catch(Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
private void addModule(JsonObject data, ClassType keyType, ClassType valueType, boolean bi, String moduleName, JsonObject obj) {
|
||||
JsonObject result = getObject(data, keyType.getClassPath(), true);
|
||||
if(bi) {
|
||||
result = getObject(result, valueType.getClassPath(), true);
|
||||
}
|
||||
result.add(moduleName, obj);
|
||||
}
|
||||
|
||||
private void addModule(ClassType keyType, ClassType valueType, boolean bi, String moduleName, JsonObject obj) {
|
||||
JsonObject result = getObject(data, keyType.getClassPath(), true);
|
||||
if(bi) {
|
||||
@ -214,4 +117,9 @@ public class SettingsManager
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
private boolean isEnabled(JsonObject obj, String key) {
|
||||
if(obj.has(key)) return obj.getAsJsonPrimitive(key).getAsBoolean();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,137 +0,0 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.Requirements.Requirement;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public abstract class BaseDependency implements IDependency {
|
||||
protected static boolean FETCH_FAILURES = false;
|
||||
protected static Set<String> FAILURE_KEYS = new TreeSet<>();
|
||||
|
||||
protected final String name;
|
||||
protected final boolean biType;
|
||||
protected Map<String, LoadingState> dependencies;
|
||||
protected List<IDependency> children = new ArrayList<>();
|
||||
protected List<Requirement> requirements = new ArrayList<>();
|
||||
protected ClassType keyType;
|
||||
protected ClassType valueType;
|
||||
|
||||
public BaseDependency(String name, boolean biType) {
|
||||
this.name = name;
|
||||
this.biType = biType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Map<String, LoadingState> dependency) {
|
||||
dependencies = dependency;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDependency addDependency(Requirement require) {
|
||||
requirements.add(require);
|
||||
require.dependency.addChild(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChild(IDependency child) {
|
||||
children.add(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaf() {
|
||||
return children.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot() {
|
||||
return requirements.isEmpty();
|
||||
}
|
||||
|
||||
protected LoadingState getGlobalState() {
|
||||
return dependencies.getOrDefault(name, LoadingState.OPTIONAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalStateKey(ClassType keyType, ClassType valueType) {
|
||||
return (biType ? keyType.getClassPath()+"-"+valueType.getClassPath() : keyType.getClassPath())+"-"+name;
|
||||
}
|
||||
|
||||
protected LoadingState getLocalState(ClassType keyType, ClassType valueType) {
|
||||
return dependencies.getOrDefault(getLocalStateKey(keyType, valueType), LoadingState.OPTIONAL);
|
||||
}
|
||||
|
||||
protected LoadingState getReqirementState(ClassType keyType, ClassType valueType) {
|
||||
LoadingState state = requirements.isEmpty() ? LoadingState.REQUIRED : LoadingState.OPTIONAL;
|
||||
for(int i = 0,m=requirements.size();i<m;i++) {
|
||||
state = state.merge(requirements.get(i).test(keyType, valueType));
|
||||
}
|
||||
return state.resolveIfUndefined();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveRequirements(ClassType keyType, ClassType valueType) {
|
||||
if(!children.isEmpty()) {
|
||||
for(IDependency child : children) {
|
||||
if(child == this) continue;
|
||||
child.resolveRequirements(keyType, valueType);
|
||||
}
|
||||
}
|
||||
if(getLocalState(keyType, valueType) == LoadingState.REQUIRED) {
|
||||
for(Requirement req : requirements) {
|
||||
dependencies.putIfAbsent(req.key(keyType, valueType), LoadingState.REQUIRED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateDependency(Consumer<String> result, ClassType keyType, ClassType valueType) {
|
||||
if(getLocalState(keyType, valueType) == LoadingState.REQUIRED) {
|
||||
FETCH_FAILURES = true;
|
||||
for(Requirement req : requirements) {
|
||||
req.test(keyType, valueType);
|
||||
}
|
||||
FETCH_FAILURES = false;
|
||||
if(FAILURE_KEYS.size() > 0) {
|
||||
int size = FAILURE_KEYS.size();
|
||||
StringJoiner joiner = new StringJoiner("], [", "[", "]");
|
||||
FAILURE_KEYS.forEach(joiner::add);
|
||||
FAILURE_KEYS.clear();
|
||||
String joins = size > 1 ? "["+joiner.toString()+"]" : joiner.toString();
|
||||
|
||||
result.accept("["+getLocalStateKey(keyType, valueType)+"] Requires "+joins+" but it specifically has been disabled!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(ClassType key, ClassType value) {
|
||||
this.keyType = key;
|
||||
this.valueType = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
if(keyType == null || keyType == null) return false;
|
||||
return isLoaded(keyType, valueType).getJsonResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FunctionDependency extends BaseDependency {
|
||||
ModuleDependency owner;
|
||||
|
||||
public FunctionDependency(ModuleDependency owner, String name) {
|
||||
super(name, owner.biType);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadingState isLoaded(ClassType key, ClassType value) {
|
||||
if(dependencies == null) return LoadingState.REQUIRED;
|
||||
LoadingState result = getLocalState(key, value);
|
||||
if(FETCH_FAILURES && result == LoadingState.REJECTED) {
|
||||
FAILURE_KEYS.add(getLocalStateKey(key, value));
|
||||
}
|
||||
return result.resolveIfUndefined().merge(getReqirementState(key, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalStateKey(ClassType keyType, ClassType valueType) {
|
||||
return (biType ? keyType.getClassPath()+"-"+valueType.getClassPath() : keyType.getClassPath())+"-"+owner.getName()+"-"+name;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,104 +0,0 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.Requirements.Requirement;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public interface IDependency {
|
||||
|
||||
|
||||
public void set(Map<String, LoadingState> dependency);
|
||||
public void set(ClassType key, ClassType value);
|
||||
public LoadingState isLoaded(ClassType key, ClassType value);
|
||||
public String getLocalStateKey(ClassType keyType, ClassType valueType);
|
||||
public boolean isEnabled();
|
||||
public boolean isLeaf();
|
||||
public boolean isRoot();
|
||||
|
||||
public String getName();
|
||||
public void validateDependency(Consumer<String> result, ClassType keyType, ClassType valueType);
|
||||
public void resolveRequirements(ClassType keyType, ClassType valueType);
|
||||
|
||||
public void addChild(IDependency child);
|
||||
public <T extends IDependency> T addDependency(Requirement require);
|
||||
public default <T extends IDependency> T addKeyDependency(IDependency dependency) { return addDependency(new Requirement(dependency, Requirements.KEY_TEST, Requirements.KEY_GETTER)); }
|
||||
public default <T extends IDependency> T addValueDependency(IDependency dependency) { return addDependency(new Requirement(dependency, Requirements.VALUE_TEST, Requirements.VALUE_GETTER)); }
|
||||
public default <T extends IDependency> T addEntryDependency(IDependency dependency) { return addDependency(new Requirement(dependency, Requirements.ENTRY_TEST, Requirements.ENTRY_GETTER)); }
|
||||
public default <T extends IDependency> T addTypeDependency(IDependency dependency, ClassType type) { return addDependency(new Requirement(dependency, Requirements.typedTest(type), Requirements.typedKey(type))); }
|
||||
public default <T extends IDependency> T addOptionalTypeDependency(IDependency dependency, ClassType type, boolean key) { return addDependency(new Requirement(dependency, Requirements.optionalTest(type, key), Requirements.optionalKey(type, key))); }
|
||||
public default <T extends IDependency> T addOptionalTypeDependency(ClassType type, boolean key) { return addDependency(new Requirement(this, Requirements.optionalTest(type, key), Requirements.optionalKey(type, key))); }
|
||||
|
||||
|
||||
public static void flatten(String prefix, boolean applyMiddle, JsonObject object, Map<String, LoadingState> result) {
|
||||
if(applyMiddle) prefix+="-";
|
||||
for(Entry<String, JsonElement> entry : object.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
JsonElement value = entry.getValue();
|
||||
if(value instanceof JsonPrimitive) {
|
||||
String entryKey = prefix+key;
|
||||
if("Enabled".equalsIgnoreCase(key)) {
|
||||
entryKey = prefix.substring(0, prefix.length()-1);
|
||||
}
|
||||
result.put(entryKey, LoadingState.of(((JsonPrimitive)value).getAsBoolean()));
|
||||
}
|
||||
if(value instanceof JsonObject) {
|
||||
flatten(prefix+key, true, (JsonObject)value, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum LoadingState {
|
||||
OPTIONAL,
|
||||
REQUIRED,
|
||||
REJECTED;
|
||||
|
||||
private static LoadingState RESOLVED = LoadingState.REQUIRED;
|
||||
|
||||
public static LoadingState of(boolean value) {
|
||||
return value ? REQUIRED : REJECTED;
|
||||
}
|
||||
|
||||
public LoadingState merge(LoadingState merge) {
|
||||
return ordinal() > merge.ordinal() ? this : merge;
|
||||
}
|
||||
|
||||
public LoadingState replaceIfUndefined(LoadingState state) {
|
||||
return this == OPTIONAL ? state : this;
|
||||
}
|
||||
|
||||
public LoadingState resolveIfUndefined() {
|
||||
return this == OPTIONAL ? RESOLVED : this;
|
||||
}
|
||||
|
||||
public LoadingState mergeDown(LoadingState merge) {
|
||||
if(merge == REJECTED || ordinal() > merge.ordinal()) {
|
||||
return this;
|
||||
}
|
||||
return merge;
|
||||
}
|
||||
|
||||
public LoadingState mergeUp(LoadingState merge) {
|
||||
if(merge == REQUIRED || ordinal() > merge.ordinal()) {
|
||||
return this;
|
||||
}
|
||||
return merge;
|
||||
}
|
||||
|
||||
public static void setOptionalResolver(LoadingState state) {
|
||||
RESOLVED = state;
|
||||
}
|
||||
|
||||
public boolean getJsonResult() {
|
||||
LoadingState state = this == OPTIONAL ? RESOLVED : this;
|
||||
return state == REQUIRED;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.modules.BaseModule;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ModuleDependency extends BaseDependency {
|
||||
BaseModule owner;
|
||||
|
||||
public ModuleDependency(BaseModule owner, boolean biType) {
|
||||
super(owner.getModuleName(), biType);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public FunctionDependency createDependency(String name) {
|
||||
FunctionDependency result = new FunctionDependency(this, name);
|
||||
if(biType) result.addEntryDependency(this);
|
||||
else result.addKeyDependency(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadingState isLoaded(ClassType key, ClassType value) {
|
||||
if(dependencies == null) return LoadingState.REQUIRED;
|
||||
LoadingState result = getLocalState(key, value);
|
||||
if(FETCH_FAILURES && result == LoadingState.REJECTED) {
|
||||
FAILURE_KEYS.add(getLocalStateKey(key, value));
|
||||
}
|
||||
return result.replaceIfUndefined(getGlobalState()).resolveIfUndefined().merge(getReqirementState(key, value));
|
||||
}
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
package speiger.src.builder.dependencies;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.IDependency.LoadingState;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Requirements {
|
||||
public static final RequirementTest KEY_TEST = (T, K, V) -> T.isLoaded(K, K);
|
||||
public static final RequirementTest VALUE_TEST = (T, K, V) -> T.isLoaded(V, V);
|
||||
public static final RequirementTest ENTRY_TEST = (T, K, V) -> T.isLoaded(K, V);
|
||||
|
||||
public static RequirementTest typedTest(ClassType type) {
|
||||
return (T, K, V) -> T.isLoaded(type, type);
|
||||
}
|
||||
|
||||
public static RequirementTest optionalTest(ClassType type, boolean key) {
|
||||
return (T, K, V) -> (key ? K : V) != type ? T.isLoaded(type, type) : LoadingState.REQUIRED;
|
||||
}
|
||||
|
||||
public static final RequirementKey KEY_GETTER = (T, K, V) -> T.getLocalStateKey(K, K);
|
||||
public static final RequirementKey VALUE_GETTER = (T, K, V) -> T.getLocalStateKey(V, V);
|
||||
public static final RequirementKey ENTRY_GETTER = (T, K, V) -> T.getLocalStateKey(K, V);
|
||||
|
||||
public static RequirementKey typedKey(ClassType type) {
|
||||
return (T, K, V) -> T.getLocalStateKey(type, type);
|
||||
}
|
||||
|
||||
public static RequirementKey optionalKey(ClassType type, boolean key) {
|
||||
return (T, K, V) -> (key ? K : V) != type ? T.getLocalStateKey(type, type) : "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public interface RequirementTest {
|
||||
public LoadingState test(IDependency test, ClassType keyType, ClassType valueType);
|
||||
}
|
||||
|
||||
public static interface RequirementKey {
|
||||
public String key(IDependency test, ClassType keyType, ClassType valueType);
|
||||
}
|
||||
|
||||
public static interface RequirementResolver {
|
||||
public void resolve(IDependency test, Consumer<String> result, ClassType keyType, ClassType valueType);
|
||||
}
|
||||
|
||||
public static class Requirement {
|
||||
IDependency dependency;
|
||||
RequirementTest test;
|
||||
RequirementKey key;
|
||||
|
||||
public Requirement(IDependency dependency, RequirementTest test, RequirementKey key) {
|
||||
this.dependency = dependency;
|
||||
this.test = test;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public LoadingState test(ClassType keyType, ClassType valueType) {
|
||||
return test.test(dependency, keyType, valueType);
|
||||
}
|
||||
|
||||
public String key(ClassType keyType, ClassType valueType) {
|
||||
return key.key(dependency, keyType, valueType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,9 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class AsyncModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new AsyncModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(JavaModule.MODULE);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Async"; }
|
||||
@ -24,16 +16,16 @@ public class AsyncModule extends BaseModule
|
||||
@Override
|
||||
protected void loadFunctions() {}
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE); }
|
||||
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!MODULE.isEnabled()) {
|
||||
if(!isModuleEnabled()) {
|
||||
addBlockedFiles("AsyncBuilder", "Task");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(MODULE.isEnabled()) {
|
||||
if(isModuleEnabled()) {
|
||||
addKeyFlag("ASYNC_MODULE");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,13 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.ModulePackage;
|
||||
import speiger.src.builder.RequiredType;
|
||||
import speiger.src.builder.SettingsManager;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.mappers.ArgumentMapper;
|
||||
import speiger.src.builder.mappers.InjectMapper;
|
||||
import speiger.src.builder.mappers.LineMapper;
|
||||
@ -32,9 +30,6 @@ public abstract class BaseModule
|
||||
this.entry = entry;
|
||||
keyType = entry.getKeyType();
|
||||
valueType = entry.getValueType();
|
||||
for(IDependency dependency : getDependencies(keyType, valueType)) {
|
||||
dependency.set(keyType, valueType);
|
||||
}
|
||||
loadVariables();
|
||||
loadClasses();
|
||||
loadTestClasses();
|
||||
@ -61,11 +56,28 @@ public abstract class BaseModule
|
||||
|
||||
public abstract String getModuleName();
|
||||
public boolean isBiModule() { return false; }
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Collections.emptyList(); }
|
||||
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);
|
||||
}
|
||||
|
||||
protected boolean isModuleEnabled(String name) {
|
||||
return manager == null || manager.isModuleEnabled(this, keyType, valueType, name);
|
||||
}
|
||||
|
||||
protected boolean isDependencyLoaded(BaseModule module) {
|
||||
return isDependencyLoaded(module, true);
|
||||
}
|
||||
|
||||
protected boolean isDependencyLoaded(BaseModule module, boolean key) {
|
||||
return manager == null || (module.isBiModule() ? manager.isModuleEnabled(module, keyType, valueType) : (key ? manager.isModuleEnabled(module, keyType, keyType) : manager.isModuleEnabled(module, valueType, valueType)));
|
||||
}
|
||||
|
||||
public boolean areDependenciesLoaded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void addFlag(String name) {
|
||||
entry.addFlag(name);
|
||||
@ -190,9 +202,4 @@ public abstract class BaseModule
|
||||
entry.addMapper(mapper);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
public static <T> T make(T input, Consumer<T> processor) {
|
||||
processor.accept(input);
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,59 +1,52 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class CollectionModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new CollectionModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false)
|
||||
.addKeyDependency(FunctionModule.MODULE)
|
||||
.addOptionalTypeDependency(FunctionModule.MODULE, ClassType.OBJECT, true)
|
||||
.addOptionalTypeDependency(FunctionModule.MODULE, ClassType.INT, true)
|
||||
.addOptionalTypeDependency(ClassType.OBJECT, true);
|
||||
public static final FunctionDependency STREAMS = MODULE.createDependency("Streams");
|
||||
public static final FunctionDependency SPLIT_ITERATORS = MODULE.createDependency("Splititerators").addKeyDependency(STREAMS);
|
||||
public static final FunctionDependency IARRAY = MODULE.createDependency("IArray");
|
||||
public static final FunctionDependency STRATEGY = MODULE.createDependency("Strategy");
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Collection"; }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, STREAMS, SPLIT_ITERATORS, IARRAY, STRATEGY); }
|
||||
public boolean areDependenciesLoaded(){ return isDependencyLoaded(JavaModule.INSTANCE); }
|
||||
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType)
|
||||
{
|
||||
return new TreeSet<>(Arrays.asList("Streams", "Splititerators", "IArray", "Strategy"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(MODULE.isEnabled()) addKeyFlag("COLLECTION_MODULE");
|
||||
if(STREAMS.isEnabled()) addKeyFlag("STREAM_FEATURE");
|
||||
if(SPLIT_ITERATORS.isEnabled()) addKeyFlag("SPLIT_ITERATOR_FEATURE");
|
||||
if(IARRAY.isEnabled()) addKeyFlag("IARRAY_FEATURE");
|
||||
if(isModuleEnabled()) addKeyFlag("COLLECTION_MODULE");
|
||||
if(isModuleEnabled("Streams")) addKeyFlag("STREAM_FEATURE");
|
||||
if(isModuleEnabled("Splititerators")) addKeyFlag("SPLIT_ITERATOR_FEATURE");
|
||||
if(isModuleEnabled("IArray")) addKeyFlag("IARRAY_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!MODULE.isEnabled()) {
|
||||
if(!isModuleEnabled()) {
|
||||
addBlockedFiles("Iterable", "Iterables", "Iterator", "Iterators", "BidirectionalIterator", "ListIterator");
|
||||
addBlockedFiles("Arrays", "Collection", "OrderedCollection", "AbstractCollection", "Collections", "Stack");
|
||||
addBlockedFiles("Arrays", "Collection", "AbstractCollection", "Collections", "Stack");
|
||||
}
|
||||
if(!SPLIT_ITERATORS.isEnabled()) addBlockedFiles("Splititerator", "Splititerators");
|
||||
if(!IARRAY.isEnabled()) addBlockedFiles("IArray");
|
||||
if(!STRATEGY.isEnabled()) addBlockedFiles("Strategy");
|
||||
if(!isModuleEnabled("Splititerators")) addBlockedFiles("Splititerator", "Splititerators");
|
||||
if(!isModuleEnabled("IArray")) addBlockedFiles("IArray");
|
||||
if(!isModuleEnabled("Strategy")) addBlockedFiles("Strategy");
|
||||
|
||||
if(keyType.isObject())
|
||||
{
|
||||
if(keyType.isObject()) {
|
||||
addBlockedFiles("Stack");
|
||||
addBlockedFiles("CollectionStreamTester");
|
||||
}
|
||||
if(keyType == ClassType.BOOLEAN)
|
||||
{
|
||||
if(keyType == ClassType.BOOLEAN) {
|
||||
addBlockedFiles("CollectionRemoveIfTester", "CollectionStreamTester");
|
||||
addBlockedFilter(T -> T.endsWith("Tester") && T.startsWith("Iterable"));
|
||||
}
|
||||
@ -91,7 +84,6 @@ public class CollectionModule extends BaseModule
|
||||
{
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_COLLECTION", "Abstract%sCollection");
|
||||
addAbstractMapper("REVERSED_ORDERED_COLLECTION", "Reverse%sOrderedCollection");
|
||||
|
||||
//Helper Classes
|
||||
addClassMapper("ARRAYS", "Arrays");
|
||||
@ -102,7 +94,6 @@ public class CollectionModule extends BaseModule
|
||||
|
||||
//Interfaces
|
||||
addClassMapper("COLLECTION", "Collection");
|
||||
addClassMapper("ORDERED_COLLECTION", "OrderedCollection");
|
||||
addClassMapper("ITERABLE", "Iterable");
|
||||
addClassMapper("SPLIT_ITERATOR", "Splititerator");
|
||||
addClassMapper("LIST_ITERATOR", "ListIterator");
|
||||
|
||||
@ -1,18 +1,12 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.RequiredType;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FunctionModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new FunctionModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(JavaModule.MODULE);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Function"; }
|
||||
@ -25,16 +19,10 @@ public class FunctionModule extends BaseModule
|
||||
@Override
|
||||
protected void loadTestClasses() {}
|
||||
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
|
||||
return Arrays.asList(MODULE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(keyType.isObject()) addBlockedFiles("Consumer", "Comparator");
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Consumer", "BiConsumer", "Comparator", "Supplier", "Function", "UnaryOperator");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,8 +54,8 @@ public class FunctionModule extends BaseModule
|
||||
protected void loadFunctions()
|
||||
{
|
||||
addSimpleMapper("APPLY", keyType.getApply(valueType));
|
||||
addSimpleMapper("SUPPLY_GET", keyType.isObject() ? "get" : "getAs"+keyType.getNonFileType());
|
||||
addSimpleMapper("VALUE_SUPPLY_GET", valueType.isObject() ? "get" : "getAs"+valueType.getNonFileType());
|
||||
addSimpleMapper("SUPPLY_GET", keyType.isObject() ? "get" : "getAs"+keyType.getCustomJDKType().getNonFileType());
|
||||
addSimpleMapper("VALUE_SUPPLY_GET", valueType.isObject() ? "get" : "getAs"+valueType.getCustomJDKType().getNonFileType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,17 +1,11 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class JavaModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new JavaModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Base"; }
|
||||
@ -23,11 +17,6 @@ public class JavaModule extends BaseModule
|
||||
loadBaseVariables();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
|
||||
return Arrays.asList(MODULE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFlags()
|
||||
{
|
||||
@ -196,7 +185,6 @@ public class JavaModule extends BaseModule
|
||||
addComment("@Type", "@param <%s> the keyType of elements maintained by this Collection");
|
||||
addValueComment("@ValueArrayType", "@param <%s> the keyType of array that the operation should be applied");
|
||||
addValueComment("@ValueType", "@param <%s> the keyType of elements maintained by this Collection");
|
||||
addSimpleMapper("@Java21", getVersion() >= 21 ? "@Override" : "");
|
||||
addAnnontion("@PrimitiveOverride", "@Override");
|
||||
addSimpleMapper("@PrimitiveDoc", "");
|
||||
addAnnontion("@Primitive", "@Deprecated");
|
||||
|
||||
@ -1,57 +1,55 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ListModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new ListModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(CollectionModule.MODULE).addKeyDependency(CollectionModule.SPLIT_ITERATORS);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers");
|
||||
public static final FunctionDependency ARRAY_LIST = MODULE.createDependency("ArrayList").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_LIST = MODULE.createDependency("LinkedList").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency IMMUTABLE_LIST = MODULE.createDependency("ImmutableList").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency COPY_ON_WRITE_LIST = MODULE.createDependency("CopyOnWriteList").addKeyDependency(IMPLEMENTATION);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "List"; }
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, IMPLEMENTATION, WRAPPERS, ARRAY_LIST, LINKED_LIST, IMMUTABLE_LIST, COPY_ON_WRITE_LIST); }
|
||||
@Override
|
||||
protected void loadVariables() {}
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(MODULE.isEnabled()) addKeyFlag("LIST_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addKeyFlag("LISTS_FEATURE");
|
||||
if(ARRAY_LIST.isEnabled()) addKeyFlag("ARRAY_LIST_FEATURE");
|
||||
if(LINKED_LIST.isEnabled()) addKeyFlag("LINKED_LIST_FEATURE");
|
||||
if(IMMUTABLE_LIST.isEnabled()) addKeyFlag("IMMUTABLE_LIST_FEATURE");
|
||||
if(COPY_ON_WRITE_LIST.isEnabled()) addKeyFlag("COPY_ON_WRITE_LIST_FEATURE");
|
||||
if(isModuleEnabled()) addKeyFlag("LIST_MODULE");
|
||||
if(isModuleEnabled("Wrappers")) addKeyFlag("LISTS_FEATURE");
|
||||
boolean implementations = isModuleEnabled("Implementations");
|
||||
if(implementations && isModuleEnabled("ArrayList")) addKeyFlag("ARRAY_LIST_FEATURE");
|
||||
if(implementations && isModuleEnabled("LinkedList")) addKeyFlag("LINKED_LIST_FEATURE");
|
||||
if(implementations && isModuleEnabled("ImmutableList")) addKeyFlag("IMMUTABLE_LIST_FEATURE");
|
||||
if(implementations && isModuleEnabled("CopyOnWriteList")) addKeyFlag("COPY_ON_WRITE_LIST_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("Lists");
|
||||
if(!ARRAY_LIST.isEnabled()) addBlockedFiles("ArrayList");
|
||||
if(!LINKED_LIST.isEnabled()) addBlockedFiles("LinkedList");
|
||||
if(!IMMUTABLE_LIST.isEnabled()) addBlockedFiles("ImmutableList");
|
||||
if(!COPY_ON_WRITE_LIST.isEnabled()) addBlockedFiles("CopyOnWriteList");
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("List", "AbstractList");
|
||||
|
||||
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Lists");
|
||||
boolean implementations = !isModuleEnabled("Implementations");
|
||||
if(implementations || !isModuleEnabled("ArrayList")) addBlockedFiles("ArrayList");
|
||||
if(implementations || !isModuleEnabled("LinkedList")) addBlockedFiles("LinkedList");
|
||||
if(implementations || !isModuleEnabled("ImmutableList")) addBlockedFiles("ImmutableList");
|
||||
if(implementations || !isModuleEnabled("CopyOnWriteList")) addBlockedFiles("CopyOnWriteList");
|
||||
if(!isModuleEnabled()) addBlockedFiles("List", "AbstractList");
|
||||
|
||||
if(keyType.isObject()) addBlockedFiles("ListFillBufferTester");
|
||||
if(keyType == ClassType.BOOLEAN) addBlockedFiles("ListFillBufferTester", "ListReplaceAllTester");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||
return new TreeSet<>(Arrays.asList("Implementations", "Wrappers", "ArrayList", "LinkedList", "ImmutableList", "CopyOnWriteList"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areDependenciesLoaded() {
|
||||
return isDependencyLoaded(CollectionModule.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadRemappers()
|
||||
|
||||
@ -1,44 +1,15 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class MapModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new MapModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, true)
|
||||
.addKeyDependency(SetModule.MODULE)
|
||||
.addValueDependency(CollectionModule.MODULE)
|
||||
.addEntryDependency(SetModule.MODULE)
|
||||
.addTypeDependency(SetModule.MODULE, ClassType.OBJECT);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers").addKeyDependency(SetModule.WRAPPERS).addOptionalTypeDependency(SetModule.WRAPPERS, ClassType.OBJECT, true);
|
||||
|
||||
public static final FunctionDependency ORDERED_MAP = MODULE.createDependency("OrderedMap").addKeyDependency(SetModule.ORDERED_SET).addOptionalTypeDependency(SetModule.ORDERED_SET, ClassType.OBJECT, true);
|
||||
public static final FunctionDependency SORTED_MAP = MODULE.createDependency("SortedMap").addKeyDependency(SetModule.SORTED_SET).addOptionalTypeDependency(SetModule.SORTED_SET, ClassType.OBJECT, true);
|
||||
|
||||
public static final FunctionDependency ARRAY_MAP = MODULE.createDependency("ArrayMap").addEntryDependency(ORDERED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency IMMUTABLE_MAP = MODULE.createDependency("ImmutableMap").addEntryDependency(IMPLEMENTATION);
|
||||
|
||||
public static final FunctionDependency HASH_MAP = MODULE.createDependency("HashMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_MAP = MODULE.createDependency("LinkedHashMap").addEntryDependency(HASH_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
public static final FunctionDependency CUSTOM_MAP = MODULE.createDependency("CustomHashMap").addEntryDependency(IMPLEMENTATION).addKeyDependency(CollectionModule.STRATEGY);
|
||||
public static final FunctionDependency LINKED_CUSTOM_MAP = MODULE.createDependency("LinkedCustomHashMap").addEntryDependency(CUSTOM_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
public static final FunctionDependency ENUM_MAP = MODULE.createDependency("EnumMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_ENUM_MAP = MODULE.createDependency("LinkedEnumMap").addEntryDependency(ENUM_MAP).addEntryDependency(ORDERED_MAP);
|
||||
|
||||
public static final FunctionDependency CONCURRENT_MAP = MODULE.createDependency("ConcurrentMap").addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency AVL_TREE_MAP = MODULE.createDependency("AVLTreeMap").addEntryDependency(SORTED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency RB_TREE_MAP = MODULE.createDependency("RBTreeMap").addEntryDependency(SORTED_MAP).addEntryDependency(IMPLEMENTATION);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Map"; }
|
||||
@ -49,52 +20,79 @@ public class MapModule extends BaseModule
|
||||
@Override
|
||||
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; }
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) {
|
||||
List<IDependency> dependencies = new ArrayList<>(Arrays.asList(MODULE, ORDERED_MAP, SORTED_MAP, IMPLEMENTATION, WRAPPERS, ARRAY_MAP, IMMUTABLE_MAP, HASH_MAP, LINKED_MAP, CUSTOM_MAP, LINKED_CUSTOM_MAP, CONCURRENT_MAP, AVL_TREE_MAP, RB_TREE_MAP));
|
||||
if(keyType == ClassType.OBJECT) dependencies.addAll(Arrays.asList(ENUM_MAP, LINKED_ENUM_MAP));
|
||||
return dependencies;
|
||||
public boolean areDependenciesLoaded() { return isDependencyLoaded(SetModule.INSTANCE) && isDependencyLoaded(CollectionModule.INSTANCE, false); }
|
||||
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||
Set<String> sets = new TreeSet<>();
|
||||
sets.addAll(Arrays.asList("Wrappers", "Implementations"));
|
||||
sets.addAll(Arrays.asList("OrderedMap", "SortedMap"));
|
||||
sets.addAll(Arrays.asList("ArrayMap", "ConcurrentMap", "ImmutableMap"));
|
||||
sets.addAll(Arrays.asList("HashMap", "LinkedHashMap"));
|
||||
sets.addAll(Arrays.asList("CustomHashMap", "LinkedCustomHashMap"));
|
||||
sets.addAll(Arrays.asList("EnumMap", "LinkedEnumMap"));
|
||||
sets.addAll(Arrays.asList("AVLTreeMap", "RBTreeMap"));
|
||||
return sets;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFlags()
|
||||
{
|
||||
if(MODULE.isEnabled()) addFlag("MAP_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addFlag("MAPS_FEATURE");
|
||||
if(ORDERED_MAP.isEnabled()) addFlag("ORDERED_MAP_FEATURE");
|
||||
if(ARRAY_MAP.isEnabled()) addFlag("ARRAY_MAP_FEATURE");
|
||||
if(LINKED_MAP.isEnabled()) addFlag("LINKED_MAP_FEATURE");
|
||||
if(LINKED_CUSTOM_MAP.isEnabled()) addFlag("LINKED_CUSTOM_MAP_FEATURE");
|
||||
if(LINKED_ENUM_MAP.isEnabled()) addFlag("LINKED_ENUM_MAP_FEATURE");
|
||||
if(isModuleEnabled()) addFlag("MAP_MODULE");
|
||||
if(isModuleEnabled("Wrappers")) addFlag("MAPS_FEATURE");
|
||||
boolean implementations = isModuleEnabled("Implementations");
|
||||
boolean hashMap = implementations && isModuleEnabled("HashMap");
|
||||
boolean customHashMap = implementations && isModuleEnabled("CustomHashMap");
|
||||
boolean enumMap = implementations && isModuleEnabled("EnumMap");
|
||||
|
||||
if(SORTED_MAP.isEnabled()) addFlag("SORTED_MAP_FEATURE");
|
||||
if(AVL_TREE_MAP.isEnabled()) addFlag("AVL_TREE_MAP_FEATURE");
|
||||
if(RB_TREE_MAP.isEnabled()) addFlag("RB_TREE_MAP_FEATURE");
|
||||
|
||||
if(CONCURRENT_MAP.isEnabled()) addFlag("CONCURRENT_MAP_FEATURE");
|
||||
if(IMMUTABLE_MAP.isEnabled()) addFlag("IMMUTABLE_MAP_FEATURE");
|
||||
if(HASH_MAP.isEnabled()) addFlag("MAP_FEATURE");
|
||||
if(CUSTOM_MAP.isEnabled()) addFlag("CUSTOM_MAP_FEATURE");
|
||||
if(ENUM_MAP.isEnabled()) addFlag("ENUM_MAP_FEATURE");
|
||||
if(isModuleEnabled("OrderedMap")) {
|
||||
addFlag("ORDERED_MAP_FEATURE");
|
||||
if(isModuleEnabled("ArrayMap")) addFlag("ARRAY_MAP_FEATURE");
|
||||
if(hashMap && isModuleEnabled("LinkedHashMap")) addFlag("LINKED_MAP_FEATURE");
|
||||
if(customHashMap && isModuleEnabled("LinkedCustomHashMap")) addFlag("LINKED_CUSTOM_MAP_FEATURE");
|
||||
if(enumMap && isModuleEnabled("LinkedEnumMap")) addFlag("LINKED_ENUM_MAP_FEATURE");
|
||||
}
|
||||
if(isModuleEnabled("SortedMap")) {
|
||||
addFlag("SORTED_MAP_FEATURE");
|
||||
if(implementations && isModuleEnabled("AVLTreeMap")) addFlag("AVL_TREE_MAP_FEATURE");
|
||||
if(implementations && isModuleEnabled("RBTreeMap")) addFlag("RB_TREE_MAP_FEATURE");
|
||||
}
|
||||
if(implementations && isModuleEnabled("ConcurrentMap")) addFlag("CONCURRENT_MAP_FEATURE");
|
||||
if(implementations && isModuleEnabled("ImmutableMap")) addFlag("IMMUTABLE_MAP_FEATURE");
|
||||
if(hashMap) addFlag("MAP_FEATURE");
|
||||
if(customHashMap) addFlag("CUSTOM_MAP_FEATURE");
|
||||
if(enumMap) addFlag("ENUM_MAP_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Map", "AbstractMap");
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("Maps");
|
||||
if(!IMMUTABLE_MAP.isEnabled()) addBlockedFiles("ImmutableOpenHashMap");
|
||||
if(!CONCURRENT_MAP.isEnabled()) addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
|
||||
if(!ORDERED_MAP.isEnabled()) addBlockedFiles("OrderedMap");
|
||||
if(!HASH_MAP.isEnabled()) addBlockedFiles("OpenHashMap");
|
||||
if(!LINKED_MAP.isEnabled()) addBlockedFiles("LinkedOpenHashMap");
|
||||
if(!CUSTOM_MAP.isEnabled()) addBlockedFiles("OpenCustomHashMap");
|
||||
if(!LINKED_CUSTOM_MAP.isEnabled()) addBlockedFiles("LinkedOpenCustomHashMap");
|
||||
if(!ENUM_MAP.isEnabled()) addBlockedFiles("EnumMap");
|
||||
if(!LINKED_ENUM_MAP.isEnabled()) addBlockedFiles("LinkedEnumMap");
|
||||
if(!ARRAY_MAP.isEnabled()) addBlockedFiles("ArrayMap");
|
||||
if(!SORTED_MAP.isEnabled()) addBlockedFiles("SortedMap", "NavigableMap");
|
||||
if(!AVL_TREE_MAP.isEnabled()) addBlockedFiles("AVLTreeMap");
|
||||
if(!RB_TREE_MAP.isEnabled()) addBlockedFiles("RBTreeMap");
|
||||
if(!isModuleEnabled()) addBlockedFiles("Map", "AbstractMap");
|
||||
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Maps");
|
||||
boolean implementations = !isModuleEnabled("Implementations");
|
||||
if(implementations || !isModuleEnabled("ImmutableMap")) addBlockedFiles("ImmutableOpenHashMap");
|
||||
if(implementations || !isModuleEnabled("ConcurrentMap")) addBlockedFiles("ConcurrentMap", "ConcurrentOpenHashMap");
|
||||
|
||||
boolean ordered = !isModuleEnabled("OrderedMap");
|
||||
if(ordered) addBlockedFiles("OrderedMap");
|
||||
boolean hashMap = implementations || !isModuleEnabled("HashMap");
|
||||
if(hashMap) addBlockedFiles("OpenHashMap");
|
||||
if(hashMap || ordered || !isModuleEnabled("LinkedHashMap")) addBlockedFiles("LinkedOpenHashMap");
|
||||
|
||||
boolean customHashMap = implementations || !isModuleEnabled("CustomHashMap");
|
||||
if(customHashMap) addBlockedFiles("OpenCustomHashMap");
|
||||
if(customHashMap || ordered || !isModuleEnabled("LinkedCustomHashMap")) addBlockedFiles("LinkedOpenCustomHashMap");
|
||||
|
||||
boolean enumMap = implementations || !isModuleEnabled("EnumMap");
|
||||
if(enumMap) addBlockedFiles("EnumMap");
|
||||
if(enumMap || ordered || !isModuleEnabled("LinkedEnumMap")) addBlockedFiles("LinkedEnumMap");
|
||||
|
||||
if(ordered || !isModuleEnabled("ArrayMap")) addBlockedFiles("ArrayMap");
|
||||
|
||||
boolean sorted = !isModuleEnabled("SortedMap");
|
||||
if(sorted) addBlockedFiles("SortedMap", "NavigableMap");
|
||||
if(implementations || sorted || !isModuleEnabled("AVLTreeMap")) addBlockedFiles("AVLTreeMap");
|
||||
if(implementations || sorted || !isModuleEnabled("RBTreeMap")) addBlockedFiles("RBTreeMap");
|
||||
|
||||
if(keyType == ClassType.BOOLEAN)
|
||||
{
|
||||
@ -110,9 +108,6 @@ public class MapModule extends BaseModule
|
||||
addBlockedFiles("TestOrderedMapGenerator");
|
||||
addBlockedFilter(T -> T.endsWith("Tester") && (T.startsWith("Map") || T.startsWith("OrderedMap") || T.startsWith("SortedMap") || T.startsWith("NavigableMap")));
|
||||
}
|
||||
if(valueType == ClassType.OBJECT) {
|
||||
addBlockedFiles("MapComputeIfAbsentNonDefaultTester", "MapComputeIfPresentNonDefaultTester", "MapComputeNonDefaultTester", "MapSupplyIfAbsentNonDefaultTester");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -163,9 +158,6 @@ public class MapModule extends BaseModule
|
||||
addBiRequirement("MapComputeIfAbsentTester");
|
||||
addBiRequirement("MapComputeIfPresentTester");
|
||||
addBiRequirement("MapComputeTester");
|
||||
addBiRequirement("MapComputeIfAbsentNonDefaultTester");
|
||||
addBiRequirement("MapComputeIfPresentNonDefaultTester");
|
||||
addBiRequirement("MapComputeNonDefaultTester");
|
||||
addBiRequirement("MapCopyTester");
|
||||
addBiRequirement("MapContainsTester");
|
||||
addBiRequirement("MapContainsKeyTester");
|
||||
@ -192,7 +184,6 @@ public class MapModule extends BaseModule
|
||||
addBiRequirement("MapReplaceTester");
|
||||
addBiRequirement("MapSizeTester");
|
||||
addBiRequirement("MapSupplyIfAbsentTester");
|
||||
addBiRequirement("MapSupplyIfAbsentNonDefaultTester");
|
||||
addBiRequirement("MapToStringTester");
|
||||
addBiRequirement("NavigableMapNavigationTester");
|
||||
addBiRequirement("SortedMapNavigationTester");
|
||||
@ -253,7 +244,6 @@ public class MapModule extends BaseModule
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractBiMapper("ABSTRACT_MAP", "Abstract%sMap", "2");
|
||||
addAbstractBiMapper("REVERSED_ORDERED_MAP", "Reversed%sOrderedMap", "2");
|
||||
|
||||
//Helper Classes
|
||||
addBiClassMapper("MAPS", "Maps", "2");
|
||||
|
||||
@ -1,26 +1,15 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class PairModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new PairModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, true).addKeyDependency(JavaModule.MODULE);
|
||||
public static final FunctionDependency IMMUTABLE = MODULE.createDependency("Immutable");
|
||||
public static final FunctionDependency MUTABLE = MODULE.createDependency("Mutable");
|
||||
|
||||
|
||||
// public static final DependencyModule MODULE = new BiTypeModule(INSTANCE);
|
||||
// public static final DependencyFunction IMMUTABLE = MODULE.createFunction("Immutable");
|
||||
// public static final DependencyFunction MUTABLE = MODULE.createFunction("Mutable");
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Pair"; }
|
||||
@Override
|
||||
@ -32,20 +21,20 @@ public class PairModule extends BaseModule
|
||||
@Override
|
||||
protected void loadTestClasses() {}
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, IMMUTABLE, MUTABLE); }
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) { return new TreeSet<>(Arrays.asList("Mutable", "Immutable")); }
|
||||
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(MODULE.isEnabled()) addFlag("PAIR_MODULE");
|
||||
if(MUTABLE.isEnabled()) addFlag("MUTABLE_PAIR");
|
||||
if(IMMUTABLE.isEnabled()) addFlag("IMMUTABLE_PAIR");
|
||||
if(isModuleEnabled()) addFlag("PAIR_MODULE");
|
||||
if(isModuleEnabled("Mutable")) addFlag("MUTABLE_PAIR");
|
||||
if(isModuleEnabled("Immutable")) addFlag("IMMUTABLE_PAIR");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Pair");
|
||||
if(!MUTABLE.isEnabled()) addBlockedFiles("MutablePair");
|
||||
if(!IMMUTABLE.isEnabled()) addBlockedFiles("ImmutablePair");
|
||||
if(!isModuleEnabled()) addBlockedFiles("Pair");
|
||||
if(!isModuleEnabled("Mutable")) addBlockedFiles("MutablePair");
|
||||
if(!isModuleEnabled("Immutable")) addBlockedFiles("ImmutablePair");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,26 +1,15 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class PrioQueueModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new PrioQueueModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(CollectionModule.MODULE);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers");
|
||||
public static final FunctionDependency DEQUEUE = MODULE.createDependency("Dequeue");
|
||||
|
||||
public static final FunctionDependency FIFO_QUEUE = MODULE.createDependency("FiFoQueue").addKeyDependency(DEQUEUE).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency HEAP_QUEUE = MODULE.createDependency("HeapQueue").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency ARRAY_PRIO_QUEUE = MODULE.createDependency("ArrayPrioQueue").addKeyDependency(IMPLEMENTATION);
|
||||
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "PriorityQueue"; }
|
||||
@ -29,26 +18,36 @@ public class PrioQueueModule extends BaseModule
|
||||
@Override
|
||||
protected void loadFunctions() {}
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, WRAPPERS, IMPLEMENTATION, DEQUEUE, FIFO_QUEUE, HEAP_QUEUE, ARRAY_PRIO_QUEUE); }
|
||||
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
|
||||
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||
return new TreeSet<>(Arrays.asList("Wrappers", "Implementations", "Dequeue", "FiFoQueue", "HeapQueue", "ArrayPrioQueue"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFlags() {
|
||||
if(MODULE.isEnabled()) addFlag("QUEUE_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addKeyFlag("QUEUES_FEATURE");
|
||||
if(DEQUEUE.isEnabled()) addKeyFlag("DEQUEUE_FEATURE");
|
||||
if(FIFO_QUEUE.isEnabled()) addKeyFlag("FIFO_QUEUE_FEATURE");
|
||||
if(HEAP_QUEUE.isEnabled()) addKeyFlag("HEAP_QUEUE_FEATURE");
|
||||
if(ARRAY_PRIO_QUEUE.isEnabled()) addKeyFlag("ARRAY_QUEUE_FEATURE");
|
||||
if(isModuleEnabled()) addFlag("QUEUE_MODULE");
|
||||
if(isModuleEnabled("Wrappers")) addKeyFlag("QUEUES_FEATURE");
|
||||
boolean implementations = isModuleEnabled("Implementations");
|
||||
if(isModuleEnabled("Dequeue")) {
|
||||
addKeyFlag("DEQUEUE_FEATURE");
|
||||
if(implementations && isModuleEnabled("FiFoQueue")) addKeyFlag("FIFO_QUEUE_FEATURE");
|
||||
}
|
||||
if(implementations && isModuleEnabled("HeapQueue")) addKeyFlag("HEAP_QUEUE_FEATURE");
|
||||
if(implementations && isModuleEnabled("ArrayPrioQueue")) addKeyFlag("ARRAY_QUEUE_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades() {
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("PriorityQueue", "AbstractPriorityQueue");
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("PriorityQueues");
|
||||
if(!DEQUEUE.isEnabled()) addBlockedFiles("PriorityDequeue");
|
||||
if(!FIFO_QUEUE.isEnabled()) addBlockedFiles("ArrayFIFOQueue");
|
||||
if(!HEAP_QUEUE.isEnabled()) addBlockedFiles("HeapPriorityQueue");
|
||||
if(!ARRAY_PRIO_QUEUE.isEnabled()) addBlockedFiles("ArrayPriorityQueue");
|
||||
if(!isModuleEnabled()) addBlockedFiles("PriorityQueue", "AbstractPriorityQueue");
|
||||
if(!isModuleEnabled("Wrappers")) addBlockedFiles("PriorityQueues");
|
||||
boolean implementations = !isModuleEnabled("Implementations");
|
||||
boolean dequeue = !isModuleEnabled("Dequeue");
|
||||
if(dequeue) addBlockedFiles("PriorityDequeue");
|
||||
if(dequeue || implementations || !isModuleEnabled("FiFoQueue")) addBlockedFiles("ArrayFIFOQueue");
|
||||
if(implementations || !isModuleEnabled("HeapQueue")) addBlockedFiles("HeapPriorityQueue");
|
||||
if(implementations || !isModuleEnabled("ArrayPrioQueue")) addBlockedFiles("ArrayPriorityQueue");
|
||||
|
||||
if(keyType == ClassType.BOOLEAN) {
|
||||
addBlockedFiles("QueueTests");
|
||||
|
||||
@ -1,30 +1,15 @@
|
||||
package speiger.src.builder.modules;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import speiger.src.builder.ClassType;
|
||||
import speiger.src.builder.dependencies.FunctionDependency;
|
||||
import speiger.src.builder.dependencies.IDependency;
|
||||
import speiger.src.builder.dependencies.ModuleDependency;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class SetModule extends BaseModule
|
||||
{
|
||||
public static final BaseModule INSTANCE = new SetModule();
|
||||
public static final ModuleDependency MODULE = new ModuleDependency(INSTANCE, false).addKeyDependency(CollectionModule.MODULE).addKeyDependency(CollectionModule.SPLIT_ITERATORS);
|
||||
public static final FunctionDependency IMPLEMENTATION = MODULE.createDependency("Implementations");
|
||||
public static final FunctionDependency WRAPPERS = MODULE.createDependency("Wrappers");
|
||||
public static final FunctionDependency ORDERED_SET = MODULE.createDependency("OrderedSet");
|
||||
public static final FunctionDependency SORTED_SET = MODULE.createDependency("SortedSet");
|
||||
public static final FunctionDependency ARRAY_SET = MODULE.createDependency("ArraySet").addKeyDependency(ORDERED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency IMMUTABLE_SET = MODULE.createDependency("ImmutableSet").addKeyDependency(ORDERED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency HASH_SET = MODULE.createDependency("HashSet").addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency LINKED_SET = MODULE.createDependency("LinkedHashSet").addKeyDependency(ORDERED_SET).addKeyDependency(HASH_SET);
|
||||
public static final FunctionDependency CUSTOM_SET = MODULE.createDependency("CustomHashSet").addKeyDependency(IMPLEMENTATION).addKeyDependency(CollectionModule.STRATEGY);
|
||||
public static final FunctionDependency LINKED_CUSTOM_SET = MODULE.createDependency("LinkedCustomHashSet").addKeyDependency(ORDERED_SET).addKeyDependency(CUSTOM_SET);
|
||||
public static final FunctionDependency AVL_TREE_SET = MODULE.createDependency("AVLTreeSet").addKeyDependency(SORTED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
public static final FunctionDependency RB_TREE_SET = MODULE.createDependency("RBTreeSet").addKeyDependency(SORTED_SET).addKeyDependency(IMPLEMENTATION);
|
||||
|
||||
@Override
|
||||
public String getModuleName() { return "Set"; }
|
||||
@ -34,40 +19,68 @@ public class SetModule extends BaseModule
|
||||
@Override
|
||||
public boolean isModuleValid(ClassType keyType, ClassType valueType) { return keyType != ClassType.BOOLEAN; }
|
||||
@Override
|
||||
public List<IDependency> getDependencies(ClassType keyType, ClassType valueType) { return Arrays.asList(MODULE, WRAPPERS, ORDERED_SET, SORTED_SET, IMPLEMENTATION, ARRAY_SET, IMMUTABLE_SET, HASH_SET, LINKED_SET, CUSTOM_SET, LINKED_CUSTOM_SET, AVL_TREE_SET, RB_TREE_SET); }
|
||||
public boolean areDependenciesLoaded() { return isDependencyLoaded(CollectionModule.INSTANCE); }
|
||||
@Override
|
||||
public Set<String> getModuleKeys(ClassType keyType, ClassType valueType) {
|
||||
Set<String> sets = new TreeSet<>();
|
||||
sets.addAll(Arrays.asList("Wrappers", "Implementations"));
|
||||
sets.addAll(Arrays.asList("OrderedSet", "SortedSet"));
|
||||
sets.addAll(Arrays.asList("ArraySet", "ImmutableSet"));
|
||||
sets.addAll(Arrays.asList("HashSet", "LinkedHashSet"));
|
||||
sets.addAll(Arrays.asList("CustomHashSet", "LinkedCustomHashSet"));
|
||||
sets.addAll(Arrays.asList("AVLTreeSet", "RBTreeSet"));
|
||||
return sets;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadFlags()
|
||||
{
|
||||
if(MODULE.isEnabled()) addFlag("SET_MODULE");
|
||||
if(WRAPPERS.isEnabled()) addFlag("SETS_FEATURE");
|
||||
if(ORDERED_SET.isEnabled()) addFlag("ORDERED_SET_FEATURE");
|
||||
if(SORTED_SET.isEnabled()) addFlag("SORTED_SET_FEATURE");
|
||||
if(IMMUTABLE_SET.isEnabled()) addFlag("IMMUTABLE_SET_FEATURE");
|
||||
if(ARRAY_SET.isEnabled()) addFlag("ARRAY_SET_FEATURE");
|
||||
if(HASH_SET.isEnabled()) addFlag("HASH_SET_FEATURE");
|
||||
if(LINKED_SET.isEnabled()) addFlag("LINKED_SET_FEATURE");
|
||||
if(CUSTOM_SET.isEnabled()) addFlag("CUSTOM_HASH_SET_FEATURE");
|
||||
if(LINKED_CUSTOM_SET.isEnabled()) addFlag("LINKED_CUSTOM_SET_FEATURE");
|
||||
if(AVL_TREE_SET.isEnabled()) addFlag("AVL_TREE_SET_FEATURE");
|
||||
if(RB_TREE_SET.isEnabled()) addFlag("RB_TREE_SET_FEATURE");
|
||||
if(isModuleEnabled()) addFlag("SET_MODULE");
|
||||
if(isModuleEnabled("Wrappers")) addFlag("SETS_FEATURE");
|
||||
boolean implementations = isModuleEnabled("Implementations");
|
||||
boolean hashSet = implementations && isModuleEnabled("HashSet");
|
||||
boolean customHashSet = implementations && isModuleEnabled("CustomHashSet");
|
||||
|
||||
if(isModuleEnabled("OrderedSet")) {
|
||||
addFlag("ORDERED_SET_FEATURE");
|
||||
if(implementations && isModuleEnabled("ArraySet")) addFlag("ARRAY_SET_FEATURE");
|
||||
if(hashSet && isModuleEnabled("LinkedHashSet")) addFlag("LINKED_SET_FEATURE");
|
||||
if(customHashSet && isModuleEnabled("LinkedCustomHashSet")) addFlag("LINKED_CUSTOM_SET_FEATURE");
|
||||
}
|
||||
if(isModuleEnabled("SortedSet")) {
|
||||
addFlag("SORTED_SET_FEATURE");
|
||||
if(implementations && isModuleEnabled("AVLTreeSet")) addFlag("AVL_TREE_SET_FEATURE");
|
||||
if(implementations && isModuleEnabled("RBTreeSet")) addFlag("RB_TREE_SET_FEATURE");
|
||||
}
|
||||
if(implementations && isModuleEnabled("ImmutableSet")) addFlag("IMMUTABLE_SET_FEATURE");
|
||||
if(hashSet) addFlag("HASH_SET_FEATURE");
|
||||
if(customHashSet) addFlag("CUSTOM_HASH_SET_FEATURE");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadBlockades()
|
||||
{
|
||||
if(!MODULE.isEnabled()) addBlockedFiles("Set", "AbstractSet");
|
||||
if(!WRAPPERS.isEnabled()) addBlockedFiles("Sets");
|
||||
if(!IMMUTABLE_SET.isEnabled()) addBlockedFiles("ImmutableOpenHashSet");
|
||||
if(!ORDERED_SET.isEnabled()) addBlockedFiles("OrderedSet");
|
||||
if(!HASH_SET.isEnabled()) addBlockedFiles("OpenHashSet");
|
||||
if(!LINKED_SET.isEnabled()) addBlockedFiles("LinkedOpenHashSet");
|
||||
if(!CUSTOM_SET.isEnabled()) addBlockedFiles("OpenCustomHashSet");
|
||||
if(!LINKED_CUSTOM_SET.isEnabled()) addBlockedFiles("LinkedOpenCustomHashSet");
|
||||
if(!ARRAY_SET.isEnabled()) addBlockedFiles("ArraySet");
|
||||
if(!SORTED_SET.isEnabled()) addBlockedFiles("SortedSet", "NavigableSet");
|
||||
if(!AVL_TREE_SET.isEnabled()) addBlockedFiles("AVLTreeSet");
|
||||
if(!RB_TREE_SET.isEnabled()) addBlockedFiles("RBTreeSet");
|
||||
if(!isModuleEnabled()) addBlockedFiles("Set", "AbstractSet");
|
||||
if(!isModuleEnabled("Wrappers")) addBlockedFiles("Sets");
|
||||
boolean implementations = !isModuleEnabled("Implementations");
|
||||
if(implementations || !isModuleEnabled("ImmutableSet")) addBlockedFiles("ImmutableOpenHashSet");
|
||||
|
||||
boolean ordered = !isModuleEnabled("OrderedSet");
|
||||
if(ordered) addBlockedFiles("OrderedSet");
|
||||
boolean hashSet = implementations || !isModuleEnabled("HashSet");
|
||||
if(hashSet) addBlockedFiles("OpenHashSet");
|
||||
if(hashSet || ordered || !isModuleEnabled("LinkedHashSet")) addBlockedFiles("LinkedOpenHashSet");
|
||||
|
||||
boolean customHashSet = implementations || !isModuleEnabled("CustomHashSet");
|
||||
if(customHashSet) addBlockedFiles("OpenCustomHashSet");
|
||||
if(customHashSet || ordered || !isModuleEnabled("LinkedCustomHashSet")) addBlockedFiles("LinkedOpenCustomHashSet");
|
||||
|
||||
if(implementations || ordered || !isModuleEnabled("ArraySet")) addBlockedFiles("ArraySet");
|
||||
|
||||
boolean sorted = !isModuleEnabled("SortedSet");
|
||||
if(sorted) addBlockedFiles("SortedSet", "NavigableSet");
|
||||
if(implementations || sorted || !isModuleEnabled("AVLTreeSet")) addBlockedFiles("AVLTreeSet");
|
||||
if(implementations || sorted || !isModuleEnabled("RBTreeSet")) addBlockedFiles("RBTreeSet");
|
||||
|
||||
if(keyType == ClassType.BOOLEAN)
|
||||
{
|
||||
@ -148,7 +161,6 @@ public class SetModule extends BaseModule
|
||||
|
||||
//Abstract Classes
|
||||
addAbstractMapper("ABSTRACT_SET", "Abstract%sSet");
|
||||
addAbstractMapper("REVERSED_ORDERED_SET", "Reversed%sOrderedSet");
|
||||
|
||||
//Helper Classes
|
||||
addClassMapper("SETS", "Sets");
|
||||
|
||||
@ -1,18 +1,12 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import java.util.function.Supplier;
|
||||
#endif
|
||||
import java.util.Objects;
|
||||
import java.util.AbstractCollection;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
@ -268,79 +262,5 @@ public abstract class ABSTRACT_COLLECTION KEY_GENERIC_TYPE extends AbstractColle
|
||||
if (a.length > size()) a[size()] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if ORDERED_MAP_FEATURE
|
||||
public static class REVERSED_ORDERED_COLLECTION KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements ORDERED_COLLECTION KEY_GENERIC_TYPE {
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE collection;
|
||||
Supplier<ITERATOR KEY_GENERIC_TYPE> reverseIterator;
|
||||
|
||||
public REVERSED_ORDERED_COLLECTION(ORDERED_COLLECTION KEY_GENERIC_TYPE collection, Supplier<ITERATOR KEY_GENERIC_TYPE> reverseIterator) {
|
||||
this.collection = collection;
|
||||
this.reverseIterator = reverseIterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) { return collection.add(o); }
|
||||
@Override
|
||||
public ORDERED_COLLECTION KEY_GENERIC_TYPE reversed() { return collection; }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE e) { collection.addLast(e); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE e) { collection.addFirst(e); }
|
||||
@Override
|
||||
#if !TYPE_OBJECT
|
||||
public boolean contains(KEY_TYPE e) { return collection.contains(e); }
|
||||
#else
|
||||
public boolean contains(Object e) { return collection.contains(e); }
|
||||
#endif
|
||||
@Override
|
||||
#if !TYPE_OBJECT
|
||||
public boolean REMOVE_KEY(KEY_TYPE e) { return collection.REMOVE_KEY(e); }
|
||||
#else
|
||||
public boolean remove(Object e) { return collection.remove(e); }
|
||||
#endif
|
||||
@Override
|
||||
public void clear() { collection.clear(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { return collection.GET_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { return collection.REMOVE_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { return collection.GET_FIRST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { return collection.REMOVE_FIRST_KEY(); }
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() { return reverseIterator.get(); }
|
||||
@Override
|
||||
public int size() { return collection.size(); }
|
||||
}
|
||||
|
||||
public static class ReverseBiIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE it;
|
||||
|
||||
public ReverseBiIterator(LIST_ITERATOR KEY_GENERIC_TYPE it) {
|
||||
this.it = it;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() { return it.PREVIOUS(); }
|
||||
@Override
|
||||
public boolean hasNext() { return it.hasPrevious(); }
|
||||
@Override
|
||||
public boolean hasPrevious() { return it.hasNext(); }
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() { return it.NEXT(); }
|
||||
@Override
|
||||
public void remove() { it.remove(); }
|
||||
@Override
|
||||
public int nextIndex() { return it.previousIndex(); }
|
||||
@Override
|
||||
public int previousIndex() { return it.nextIndex(); }
|
||||
@Override
|
||||
public void set(KEY_TYPE e) { it.set(e); }
|
||||
@Override
|
||||
public void add(KEY_TYPE e) { it.add(e); }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1,11 +1,19 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
/**
|
||||
* A Type-Specific {@link ObjectBidirectionalIterator} to reduce (un)boxing
|
||||
*/
|
||||
public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE, ObjectBidirectionalIterator<CLASS_TYPE>
|
||||
#else
|
||||
/**
|
||||
* This is a basically a {@link java.util.ListIterator} without the index functions.
|
||||
* Allowing to have a simple Bidirectional Iterator without having to keep track of the Iteration index.
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* Returns true if the Iterator has a Previous element
|
||||
@ -21,11 +29,11 @@ public interface BI_ITERATOR KEY_GENERIC_TYPE extends ITERATOR KEY_GENERIC_TYPE
|
||||
public KEY_TYPE PREVIOUS();
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
* @return the Previous element of the iterator.+
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_TYPE previous() {
|
||||
return KEY_TO_OBJ(PREVIOUS());
|
||||
|
||||
@ -16,19 +16,6 @@ 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;
|
||||
@ -178,25 +165,6 @@ 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
|
||||
|
||||
@ -1,83 +0,0 @@
|
||||
package speiger.src.collections.PACKAGE.collections;
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
import java.util.SequencedCollection;
|
||||
|
||||
public interface ORDERED_COLLECTION KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, SequencedCollection<CLASS_TYPE> {
|
||||
#else
|
||||
public interface ORDERED_COLLECTION KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE {
|
||||
#endif
|
||||
@Java21
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE reversed();
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a collection
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
public void addFirst(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a collection
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
public void addLast(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* A method to get the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public KEY_TYPE GET_FIRST_KEY();
|
||||
/**
|
||||
* A method to get and remove the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public KEY_TYPE REMOVE_FIRST_KEY();
|
||||
/**
|
||||
* A method to get the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public KEY_TYPE GET_LAST_KEY();
|
||||
/**
|
||||
* A method to get and remove the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public KEY_TYPE REMOVE_LAST_KEY();
|
||||
|
||||
#if JAVA_VERSION>=21 && !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addFirst(CLASS_TYPE e) {
|
||||
addFirst(OBJ_TO_KEY(e));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addLast(CLASS_TYPE e) {
|
||||
addLast(OBJ_TO_KEY(e));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getFirst() {
|
||||
return KEY_TO_OBJ(GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getLast() {
|
||||
return KEY_TO_OBJ(GET_LAST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeFirst() {
|
||||
return KEY_TO_OBJ(REMOVE_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeLast() {
|
||||
return KEY_TO_OBJ(REMOVE_LAST_KEY());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -11,15 +11,8 @@ import java.util.RandomAccess;
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#endif
|
||||
#if INT_LIST_MODULE && !TYPE_INT
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
@ -250,18 +243,6 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
return new LIST_ITER(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
|
||||
return new IndexedIterator(indecies);
|
||||
}
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
|
||||
return new ListIndexedIterator(indecies);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void size(int size) {
|
||||
while(size > size()) add(EMPTY_KEY_VALUE);
|
||||
@ -536,10 +517,9 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 16464); }
|
||||
#endif
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index) {
|
||||
@ -649,154 +629,6 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
}
|
||||
}
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
private class ListIndexedIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
IntList indecies;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
ListIndexedIterator(IntList indecies) {
|
||||
this.indecies = indecies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < indecies.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int i = index++;
|
||||
return GET_KEY((lastReturned = indecies.getInt(i)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
index--;
|
||||
return GET_KEY((lastReturned = indecies.getInt(index)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void set(KEY_TYPE e) {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
ABSTRACT_LIST.this.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, indecies.size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
private class IndexedIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
int[] indecies;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
IndexedIterator(int[] indecies) {
|
||||
this.indecies = indecies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < indecies.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int i = index++;
|
||||
return GET_KEY((lastReturned = indecies[i]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
index--;
|
||||
return GET_KEY((lastReturned = indecies[index]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void set(KEY_TYPE e) {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
ABSTRACT_LIST.this.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, indecies.length - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
private class LIST_ITER implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
@ -874,7 +706,7 @@ public abstract class ABSTRACT_LIST KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
@ -535,7 +535,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
* @return if the element was found.
|
||||
*/
|
||||
@Override
|
||||
@Primitive
|
||||
@Deprecated
|
||||
public boolean contains(Object o) {
|
||||
return indexOf(o) != -1;
|
||||
}
|
||||
@ -546,7 +546,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
* @return the index of the element if found. (if not found then -1)
|
||||
*/
|
||||
@Override
|
||||
@Primitive
|
||||
@Deprecated
|
||||
public int indexOf(Object o) {
|
||||
KEY_TYPE[] data = this.data;
|
||||
#if TYPE_OBJECT
|
||||
@ -570,7 +570,7 @@ public class COPY_ON_WRITE_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENER
|
||||
* @return the last index of the element if found. (if not found then -1)
|
||||
*/
|
||||
@Override
|
||||
@Primitive
|
||||
@Deprecated
|
||||
public int lastIndexOf(Object o) {
|
||||
KEY_TYPE[] data = this.data;
|
||||
#if TYPE_OBJECT
|
||||
|
||||
@ -13,13 +13,11 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.NoSuchElementException;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import java.util.Spliterator;
|
||||
#if PRIMITIVES
|
||||
import java.util.Spliterator.JAVA_SPLIT_ITERATOR;
|
||||
#endif
|
||||
import java.util.function.Consumer;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.IntFunction;
|
||||
@ -62,14 +60,12 @@ import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.utils.Stack;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES
|
||||
import java.util.stream.JAVA_STREAM;
|
||||
import java.util.stream.StreamSupport;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
@ -420,7 +416,6 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
return new ListIter(getNode(index), index);
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
#if PRIMITIVES
|
||||
/**
|
||||
* Returns a Java-Type-Specific Stream to reduce boxing/unboxing.
|
||||
@ -441,7 +436,6 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return new TypeSplitIteratorBRACES(this, first, 0); }
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1259,7 +1253,6 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
private static class TypeSplitIterator KEY_GENERIC_TYPE implements SPLIT_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
static final int BATCH_UNIT = 1 << 10;
|
||||
@ -1404,5 +1397,4 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@ -15,10 +15,7 @@ import java.util.function.UnaryOperator;
|
||||
#endif
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#endif
|
||||
import speiger.src.collections.ints.functions.consumer.BI_FROM_INT_CONSUMER;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
@ -27,12 +24,7 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
#if LISTS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.LISTS;
|
||||
#endif
|
||||
#if INT_LIST_MODULE && !TYPE_INT
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
#if TYPE_BYTE || TYPE_SHORT || TYPE_CHAR || TYPE_FLOAT
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
#endif
|
||||
@ -41,7 +33,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
* A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface LIST KEY_GENERIC_TYPE extends ORDERED_COLLECTION KEY_GENERIC_TYPE, List<CLASS_TYPE>
|
||||
public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List<CLASS_TYPE>
|
||||
{
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
@ -106,24 +98,6 @@ public interface LIST KEY_GENERIC_TYPE extends ORDERED_COLLECTION KEY_GENERIC_TY
|
||||
*/
|
||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c);
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a list
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
@Override
|
||||
public default void addFirst(KEY_TYPE e) {
|
||||
add(0, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a list
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
@Override
|
||||
public default void addLast(KEY_TYPE e) {
|
||||
add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns the first element of a List.
|
||||
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||
@ -451,26 +425,6 @@ public interface LIST KEY_GENERIC_TYPE extends ORDERED_COLLECTION KEY_GENERIC_TY
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE listIterator(int index);
|
||||
|
||||
/**
|
||||
* Creates a Iterator that follows the indecies provided.<br>
|
||||
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
|
||||
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
|
||||
* @param indecies that should be used for the iteration.
|
||||
* @return a custom indexed iterator
|
||||
*/
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies);
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
/**
|
||||
* Creates a Iterator that follows the indecies provided.<br>
|
||||
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
|
||||
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
|
||||
* @param indecies that should be used for the iteration.
|
||||
* @return a custom indexed iterator
|
||||
*/
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies);
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A Type-Specific List of subList
|
||||
* @see java.util.List#subList(int, int)
|
||||
@ -527,56 +481,9 @@ public interface LIST KEY_GENERIC_TYPE extends ORDERED_COLLECTION KEY_GENERIC_TY
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean add(CLASS_TYPE e) {
|
||||
return ORDERED_COLLECTION.super.add(e);
|
||||
return COLLECTION.super.add(e);
|
||||
}
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
#if !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addFirst(CLASS_TYPE e) {
|
||||
addFirst(OBJ_TO_KEY(e));
|
||||
}
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addLast(CLASS_TYPE e) {
|
||||
addLast(OBJ_TO_KEY(e));
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getFirst() {
|
||||
return KEY_TO_OBJ(GET_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getLast() {
|
||||
return KEY_TO_OBJ(GET_LAST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeFirst() {
|
||||
return KEY_TO_OBJ(REMOVE_FIRST_KEY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeLast() {
|
||||
return KEY_TO_OBJ(REMOVE_LAST_KEY());
|
||||
}
|
||||
|
||||
#endif
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
@ -624,7 +531,7 @@ public interface LIST KEY_GENERIC_TYPE extends ORDERED_COLLECTION KEY_GENERIC_TY
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean contains(Object o) {
|
||||
return ORDERED_COLLECTION.super.contains(o);
|
||||
return COLLECTION.super.contains(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -634,7 +541,7 @@ public interface LIST KEY_GENERIC_TYPE extends ORDERED_COLLECTION KEY_GENERIC_TY
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object o) {
|
||||
return ORDERED_COLLECTION.super.remove(o);
|
||||
return COLLECTION.super.remove(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -664,12 +571,10 @@ public interface LIST KEY_GENERIC_TYPE extends ORDERED_COLLECTION KEY_GENERIC_TY
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
#endif
|
||||
}
|
||||
@ -14,15 +14,6 @@ import speiger.src.collections.PACKAGE.functions.function.FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.sets.AbstractObjectSet;
|
||||
import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
#if MAPS_FEATURE
|
||||
@ -51,7 +42,7 @@ import speiger.src.collections.utils.SanityChecks;
|
||||
*/
|
||||
public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CLASS_TYPE, CLASS_VALUE_TYPE> implements MAP KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
protected VALUE_TYPE defaultReturnValue = INVALID_VALUE;
|
||||
protected VALUE_TYPE defaultReturnValue = EMPTY_VALUE;
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE getDefaultReturnValue() {
|
||||
@ -128,7 +119,7 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
public void putAll(CLASS_TYPE[] keys, CLASS_VALUE_TYPE[] values, int offset, int size) {
|
||||
SanityChecks.checkArrayCapacity(keys.length, offset, size);
|
||||
SanityChecks.checkArrayCapacity(values.length, offset, size);
|
||||
for(int i = 0;i<size;i++) put(OBJ_TO_KEY(keys[i]), OBJ_TO_VALUE(values[i]));
|
||||
for(int i = 0;i<size;i++) put(keys[i], values[i]);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -227,6 +218,22 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE value = GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(VALUE_EQUALS_NOT(value, getDefaultReturnValue()) || containsKey(key)) {
|
||||
remove(key);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -250,6 +257,20 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE value;
|
||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -273,6 +294,20 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
VALUE_TYPE value;
|
||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -296,51 +331,6 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE value = GET_VALUE(key);
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
if(VALUE_EQUALS_NOT(value, getDefaultReturnValue()) || containsKey(key)) {
|
||||
remove(key);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
VALUE_TYPE value;
|
||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
VALUE_TYPE value;
|
||||
if((value = GET_VALUE(key)) == getDefaultReturnValue() || !containsKey(key)) {
|
||||
VALUE_TYPE newValue = valueProvider.VALUE_SUPPLY_GET();
|
||||
if(VALUE_EQUALS_NOT(newValue, getDefaultReturnValue())) {
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -356,7 +346,6 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -552,132 +541,6 @@ public abstract class ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE extends AbstractMap<CL
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static class REVERSED_ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE implements ORDERED_MAP KEY_VALUE_GENERIC_TYPE {
|
||||
ORDERED_MAP KEY_VALUE_GENERIC_TYPE map;
|
||||
|
||||
public REVERSED_ORDERED_MAP(ORDERED_MAP KEY_VALUE_GENERIC_TYPE map) {
|
||||
this.map = map;
|
||||
}
|
||||
@Override
|
||||
public ABSTRACT_MAP KEY_VALUE_GENERIC_TYPE setDefaultReturnValue(VALUE_TYPE v) {
|
||||
map.setDefaultReturnValue(v);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public VALUE_TYPE getDefaultReturnValue() { return map.getDefaultReturnValue(); }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE put(KEY_TYPE key, VALUE_TYPE value) { return map.put(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putIfAbsent(KEY_TYPE key, VALUE_TYPE value) { return map.putIfAbsent(key, value); }
|
||||
#if VALUE_PRIMITIVES
|
||||
@Override
|
||||
public VALUE_TYPE addTo(KEY_TYPE key, VALUE_TYPE value) { return map.addTo(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE subFrom(KEY_TYPE key, VALUE_TYPE value) { return map.subFrom(key, value); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) { return map.REMOVE_VALUE(key); }
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public boolean remove(KEY_TYPE key, VALUE_TYPE value) { return map.remove(key, value); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.REMOVE_VALUEOrDefault(key, defaultValue); }
|
||||
@Override
|
||||
#if TYPE_OBJECT
|
||||
public boolean containsKey(Object key) { return map.containsKey(key); }
|
||||
#else
|
||||
public boolean containsKey(KEY_TYPE key) { return map.containsKey(key); }
|
||||
#endif
|
||||
@Override
|
||||
#if VALUE_OBJECT
|
||||
public boolean containsValue(Object value) { return map.containsValue(value); }
|
||||
#else
|
||||
public boolean containsValue(VALUE_TYPE value) { return map.containsValue(value); }
|
||||
#endif
|
||||
@Override
|
||||
public boolean replace(KEY_TYPE key, VALUE_TYPE oldValue, VALUE_TYPE newValue) { return map.replace(key, oldValue, newValue); }
|
||||
@Override
|
||||
public VALUE_TYPE replace(KEY_TYPE key, VALUE_TYPE value) { return map.replace(key, value); }
|
||||
@Override
|
||||
public void REPLACE_VALUES(MAP KEY_VALUE_GENERIC_TYPE m) { map.REPLACE_VALUES(m); }
|
||||
@Override
|
||||
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { map.REPLACE_VALUES(mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_ABSENT(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { return map.SUPPLY_IF_ABSENT(key, valueProvider); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_PRESENT(key, mappingFunction); }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTENonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_ABSENTNonDefault(key, mappingFunction); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { return map.SUPPLY_IF_ABSENTNonDefault(key, valueProvider); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { return map.COMPUTE_IF_PRESENTNonDefault(key, mappingFunction); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { return map.MERGE(key, value, mappingFunction); }
|
||||
#if !TYPE_OBJECT || !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE getOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) { return map.getOrDefault(key, defaultValue); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE GET_VALUE(KEY_TYPE key) { return map.GET_VALUE(key); }
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToFirst(KEY_TYPE key, VALUE_TYPE value) { return map.putAndMoveToLast(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { return map.putAndMoveToFirst(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { return map.putLast(key, value); }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { return map.putFirst(key, value); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { return map.moveToLast(key); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { return map.moveToFirst(key); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToFirst(KEY_TYPE key) { return map.getAndMoveToLast(key); }
|
||||
@Override
|
||||
public VALUE_TYPE getAndMoveToLast(KEY_TYPE key) { return map.getAndMoveToFirst(key); }
|
||||
@Override
|
||||
public KEY_TYPE FIRST_ENTRY_KEY() { return map.LAST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() { return map.POLL_LAST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE LAST_ENTRY_KEY() { return map.FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public VALUE_TYPE FIRST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { return map.pollLastEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { return map.pollFirstEntry(); }
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() { return new AbstractObjectSet.ReversedObjectOrderedSet<>(map.ENTRY_SET()); }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() { return new ABSTRACT_SET.REVERSED_ORDERED_SETBRACES(map.keySet()); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() { return map.values().reversed(); }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE reversed() { return map; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Simple Type Specific Entry class to reduce boxing/unboxing
|
||||
* @Type(T)
|
||||
|
||||
@ -518,28 +518,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
return getSegment(hash).compute(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).computeIfAbsent(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).supplyIfAbsent(hash, key, valueProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).computeIfPresent(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -547,6 +525,13 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
return getSegment(hash).computeNonDefault(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).computeIfAbsent(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -554,6 +539,13 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).supplyIfAbsent(hash, key, valueProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -561,6 +553,13 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int hash = getHashCode(key);
|
||||
return getSegment(hash).computeIfPresent(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -568,7 +567,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -2271,6 +2269,29 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeNonDefault(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfAbsent(int hash, KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
@ -2298,6 +2319,29 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfAbsentNonDefault(int hash, KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE supplyIfAbsent(int hash, KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
@ -2325,76 +2369,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfPresent(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
#if !VALUE_OBJECT
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeNonDefault(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
protected VALUE_TYPE computeIfAbsentNonDefault(int hash, KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE supplyIfAbsentNonDefault(int hash, KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
@ -2418,6 +2392,29 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfPresent(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
int index = findIndex(hash, key);
|
||||
#if !VALUE_OBJECT
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
finally {
|
||||
unlockWrite(stamp);
|
||||
}
|
||||
}
|
||||
|
||||
protected VALUE_TYPE computeIfPresentNonDefault(int hash, KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
@ -2436,7 +2433,6 @@ public class CONCURRENT_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
protected VALUE_TYPE merge(int hash, KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
long stamp = writeLock();
|
||||
try {
|
||||
|
||||
@ -40,7 +40,7 @@ import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.PACKAGE.utils.STRATEGY;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
@ -295,54 +295,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(strategy.equals(key, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(strategy.hashCode(key)) & mask;
|
||||
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
|
||||
if(strategy.equals(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) {
|
||||
if(isEmpty() || strategy.equals(FIRST_ENTRY_KEY(), key)) return false;
|
||||
@ -478,52 +430,6 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.ENTRY_KEY(), EMPTY_KEY_VALUE)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(strategy.equals(result.ENTRY_KEY(), EMPTY_KEY_VALUE)) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -537,9 +443,9 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)valuesC;
|
||||
return valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -724,24 +630,24 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@ -749,12 +655,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
return new EntryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -764,7 +665,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator(true);
|
||||
return new FastEntryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1018,12 +919,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
return new KeyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1045,22 +941,22 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
return POLL_FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
return POLL_LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@ -1204,47 +1100,39 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return LINKED_CUSTOM_HASH_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() { LINKED_CUSTOM_HASH_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
public int size() {
|
||||
return LINKED_CUSTOM_HASH_MAP.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
public void clear() {
|
||||
LINKED_CUSTOM_HASH_MAP.this.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1390,7 +1278,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1417,7 +1305,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1447,7 +1335,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1469,7 +1357,7 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
public ValueIterator() {}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@ -1490,20 +1378,16 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -1531,11 +1415,11 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return (forward ? next : previous) != -1;
|
||||
return next != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return (forward ? previous : next) != -1;
|
||||
return previous != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1595,30 +1479,20 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -554,6 +554,25 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -577,6 +596,25 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -600,64 +638,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -677,6 +657,25 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -691,7 +690,6 @@ public class CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VAL
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
|
||||
@ -39,7 +39,7 @@ import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
@ -272,54 +272,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToFirstIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NULL(key)) {
|
||||
if(KEY_EQUALS(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToFirstIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) {
|
||||
if(KEY_EQUALS_NULL(key)) {
|
||||
if(containsNull) return values[nullIndex];
|
||||
values[nullIndex] = value;
|
||||
containsNull = true;
|
||||
onNodeAdded(nullIndex);
|
||||
moveToLastIndex(nullIndex);
|
||||
}
|
||||
else {
|
||||
int pos = HashUtil.mix(KEY_TO_HASH(key)) & mask;
|
||||
while(KEY_EQUALS_NULL(key)) {
|
||||
if(KEY_EQUALS(keys[pos], key)) return values[pos];
|
||||
pos = ++pos & mask;
|
||||
}
|
||||
keys[pos] = key;
|
||||
values[pos] = value;
|
||||
onNodeAdded(pos);
|
||||
moveToLastIndex(pos);
|
||||
}
|
||||
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) {
|
||||
if(isEmpty() || KEY_EQUALS(FIRST_ENTRY_KEY(), key)) return false;
|
||||
@ -482,52 +434,6 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(KEY_EQUALS_NULL(result.ENTRY_KEY())) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
if(KEY_EQUALS_NULL(result.ENTRY_KEY())) {
|
||||
containsNull = false;
|
||||
keys[nullIndex] = EMPTY_KEY_VALUE;
|
||||
values[nullIndex] = EMPTY_VALUE;
|
||||
}
|
||||
else shiftKeys(pos);
|
||||
if(nullIndex > minCapacity && size < maxFill / 4 && nullIndex > HashUtil.DEFAULT_MIN_CAPACITY) rehash(nullIndex / 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -541,9 +447,9 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)valuesC;
|
||||
return valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -728,24 +634,24 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@ -753,12 +659,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
return new EntryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -768,7 +669,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator(true);
|
||||
return new FastEntryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1017,12 +918,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
return new KeyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1044,22 +940,22 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
return POLL_FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
return POLL_LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@ -1203,50 +1099,41 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return LINKED_HASH_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() { LINKED_HASH_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
public int size() {
|
||||
return LINKED_HASH_MAP.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
LINKED_HASH_MAP.this.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1391,7 +1278,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1418,7 +1305,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1448,7 +1335,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1470,7 +1357,7 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
public ValueIterator() {}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@ -1490,16 +1377,13 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE from) {
|
||||
@ -1530,11 +1414,11 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return (forward ? next : previous) != -1;
|
||||
return next != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return (forward ? previous : next) != -1;
|
||||
return previous != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1594,30 +1478,20 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -514,6 +514,25 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -537,6 +556,25 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -560,64 +598,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insert(-index-1, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -637,6 +617,25 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(index < 0) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index < 0 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -651,7 +650,6 @@ public class HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GENE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
|
||||
@ -65,7 +65,7 @@ import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
@ -119,7 +119,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
/** KeySet cache */
|
||||
protected transient ORDERED_SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values cache */
|
||||
protected transient VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
protected transient VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
|
||||
/** Amount of Elements stored in the HashMap */
|
||||
protected int size;
|
||||
@ -320,10 +320,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@ -447,23 +443,6 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -477,7 +456,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
@ -514,22 +493,21 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@ -642,29 +620,24 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
public boolean moveToLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
return new EntryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -674,7 +647,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator(true);
|
||||
return new FastEntryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -901,12 +874,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
return new KeyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -926,20 +894,20 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
@ -1081,42 +1049,39 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() { return IMMUTABLE_HASH_MAP.this.size(); }
|
||||
public int size() {
|
||||
return IMMUTABLE_HASH_MAP.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
}
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) {
|
||||
int index = firstIndex;
|
||||
@ -1260,7 +1225,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1286,7 +1251,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1313,7 +1278,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(KEY_TYPE from) {
|
||||
super(from);
|
||||
}
|
||||
@ -1335,7 +1300,7 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
public ValueIterator() {}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@ -1356,16 +1321,13 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE from) {
|
||||
@ -1396,11 +1358,11 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return (forward ? next : previous) != -1;
|
||||
return next != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return (forward ? previous : next) != -1;
|
||||
return previous != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -1417,30 +1379,20 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -46,7 +46,7 @@ import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_SUPPLIER;
|
||||
#if !SAME_TYPE
|
||||
@ -105,7 +105,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
/** KeySet cache */
|
||||
protected ORDERED_SET KEY_GENERIC_TYPE keySet;
|
||||
/** Values cache */
|
||||
protected VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
protected VALUE_COLLECTION VALUE_GENERIC_TYPE valuesC;
|
||||
/** EntrySet cache */
|
||||
protected FastOrderedSet KEY_VALUE_GENERIC_TYPE entrySet;
|
||||
|
||||
@ -275,27 +275,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return lastValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
insertIndex(0, key, value);
|
||||
size++;
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) {
|
||||
int index = findIndex(key);
|
||||
if(index < 0) {
|
||||
insertIndex(size++, key, value);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
return values[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
@ -423,34 +402,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[0], values[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[size-1], values[size-1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[0], values[0]);
|
||||
removeIndex(0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[size-1], values[size-1]);
|
||||
removeIndex(size-1);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE REMOVE_VALUE(KEY_TYPE key) {
|
||||
int index = findIndex(key);
|
||||
@ -510,7 +461,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return valuesC;
|
||||
}
|
||||
@ -561,6 +512,25 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insertIndex(size++, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -584,6 +554,25 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insertIndex(size++, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -607,64 +596,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(index == -1) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index == -1 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insertIndex(size++, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
if(index == -1) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
insertIndex(size++, key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -684,6 +615,25 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
int index = findIndex(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(index == -1) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(index == -1 || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeIndex(index);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -698,7 +648,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -877,24 +826,24 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@ -902,12 +851,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
return new EntryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -917,7 +861,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator(true);
|
||||
return new FastEntryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1127,9 +1071,7 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) { return ARRAY_MAP.this.moveToLast(o); }
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() { return new KeyIterator(true); }
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() { return new KeyIterator(false); }
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() { return new KeyIterator(); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return new KeyIterator(fromElement); }
|
||||
@Override
|
||||
@ -1137,13 +1079,13 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
@Override
|
||||
public void clear() { ARRAY_MAP.this.clear(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { return FIRST_ENTRY_KEY(); }
|
||||
public KEY_TYPE FIRST_KEY() { return FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { return POLL_FIRST_ENTRY_KEY(); }
|
||||
public KEY_TYPE POLL_FIRST_KEY() { return POLL_FIRST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { return LAST_ENTRY_KEY(); }
|
||||
public KEY_TYPE LAST_KEY() { return LAST_ENTRY_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); }
|
||||
public KEY_TYPE POLL_LAST_KEY() { return POLL_LAST_ENTRY_KEY(); }
|
||||
|
||||
@Override
|
||||
public KeySet copy() { throw new UnsupportedOperationException(); }
|
||||
@ -1253,49 +1195,40 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return ARRAY_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() { ARRAY_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
public int size() {
|
||||
return ARRAY_MAP.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
ARRAY_MAP.this.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(VALUE_CONSUMER VALUE_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
@ -1397,8 +1330,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator(KEY_TYPE element) { super(element); }
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(KEY_TYPE from) {
|
||||
index = findIndex(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
@ -1421,8 +1356,11 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = null;
|
||||
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator(KEY_TYPE element) { super(element); }
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(KEY_TYPE from) {
|
||||
index = findIndex(from);
|
||||
if(index == -1) throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE next() {
|
||||
@ -1449,8 +1387,11 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator(KEY_TYPE element) { super(element); }
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(KEY_TYPE element) {
|
||||
index = findIndex(element);
|
||||
if(index == -1) throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
@ -1470,9 +1411,6 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
public ValueIterator(KEY_TYPE element) { super(element); }
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
return values[previousEntry()];
|
||||
@ -1491,37 +1429,23 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
this.index = start ? 0 : size;
|
||||
}
|
||||
|
||||
MapIterator(KEY_TYPE element) {
|
||||
this.forward = true;
|
||||
index = findIndex(element);
|
||||
if(index == -1) throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return forward ? index < size : index > 0;
|
||||
return index < size;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return forward ? index > 0 : index < size;
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
return index;
|
||||
}
|
||||
|
||||
public int previousIndex() {
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
return index-1;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
@ -1534,42 +1458,26 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
if(forward) {
|
||||
index--;
|
||||
return (lastReturned = index);
|
||||
}
|
||||
lastReturned = index;
|
||||
return index++;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) {
|
||||
lastReturned = index;
|
||||
return index++;
|
||||
}
|
||||
index--;
|
||||
return (lastReturned = index);
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
lastReturned = index;
|
||||
return index++;
|
||||
}
|
||||
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
return forward ? moveForward(amount) : moveBackwards(amount);
|
||||
}
|
||||
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
return forward ? moveBackwards(amount) : moveForward(amount);
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int steps = Math.min(amount, size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
|
||||
@ -382,6 +382,26 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
clear(index);
|
||||
values[index] = EMPTY_VALUE;
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(T key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
@ -405,6 +425,25 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(T key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(T key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
int index = key.ordinal();
|
||||
@ -428,65 +467,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
#if !VALUE_OBJECT
|
||||
if(!isSet(index)) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(!isSet(index) || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
clear(index);
|
||||
values[index] = EMPTY_VALUE;
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
clear(index);
|
||||
values[index] = EMPTY_VALUE;
|
||||
return newValue;
|
||||
}
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(T key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
if(!isSet(index)) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
set(index);
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = values[index];
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
values[index] = newValue;
|
||||
}
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(T key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
int index = key.ordinal();
|
||||
@ -506,6 +486,25 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
#if !VALUE_OBJECT
|
||||
if(!isSet(index)) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
#else
|
||||
if(!isSet(index) || VALUE_EQUALS(values[index], getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, values[index]);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
clear(index);
|
||||
values[index] = EMPTY_VALUE;
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
values[index] = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(T key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
@ -520,7 +519,6 @@ public class ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(T key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
int index = key.ordinal();
|
||||
|
||||
@ -18,7 +18,7 @@ import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ITERATOR;
|
||||
#if !VALUE_OBJECT && !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.VALUE_CONSUMER;
|
||||
@ -216,28 +216,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
if(isSet(index)) return values[index];
|
||||
set(index);
|
||||
values[index] = value;
|
||||
onNodeAdded(index);
|
||||
moveToFirstIndex(index);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE putLast(T key, VALUE_TYPE value) {
|
||||
int index = key.ordinal();
|
||||
if(isSet(index)) return values[index];
|
||||
set(index);
|
||||
values[index] = value;
|
||||
onNodeAdded(index);
|
||||
moveToLastIndex(index);
|
||||
return getDefaultReturnValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(T key) {
|
||||
int index = key.ordinal();
|
||||
@ -334,42 +312,6 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
return values[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[firstIndex], values[firstIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return new BasicEntryKV_BRACES(keys[lastIndex], values[lastIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
firstIndex = (int)links[pos];
|
||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
values[result.ENTRY_KEY().ordinal()] = EMPTY_VALUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
firstIndex = (int)links[pos];
|
||||
if(0 <= firstIndex) links[firstIndex] |= 0xFFFFFFFF00000000L;
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE result = new BasicEntryKV_BRACES(keys[pos], values[pos]);
|
||||
size--;
|
||||
values[result.ENTRY_KEY().ordinal()] = EMPTY_VALUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new MapEntrySet();
|
||||
@ -383,9 +325,9 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
public VALUE_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(valuesC == null) valuesC = new Values();
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)valuesC;
|
||||
return valuesC;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -489,24 +431,24 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() {
|
||||
return new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() {
|
||||
return new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(FIRST_ENTRY_KEY(), FIRST_ENTRY_VALUE());
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() {
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() {
|
||||
BasicEntry KEY_VALUE_GENERIC_TYPE entry = new BasicEntryKV_BRACES(LAST_ENTRY_KEY(), LAST_ENTRY_VALUE());
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return entry;
|
||||
@ -514,12 +456,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() {
|
||||
return new EntryIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() {
|
||||
return new EntryIterator(false);
|
||||
return new EntryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -529,7 +466,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> fastIterator() {
|
||||
return new FastEntryIterator(true);
|
||||
return new FastEntryIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -656,12 +593,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new KeyIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new KeyIterator(false);
|
||||
return new KeyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -682,22 +614,22 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
@Override
|
||||
public T GET_FIRST_KEY() {
|
||||
public T FIRST_KEY() {
|
||||
return FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T REMOVE_FIRST_KEY() {
|
||||
public T POLL_FIRST_KEY() {
|
||||
return POLL_FIRST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T GET_LAST_KEY() {
|
||||
public T LAST_KEY() {
|
||||
return LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T REMOVE_LAST_KEY() {
|
||||
public T POLL_LAST_KEY() {
|
||||
return POLL_LAST_ENTRY_KEY();
|
||||
}
|
||||
|
||||
@ -724,50 +656,41 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
#endif
|
||||
}
|
||||
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE implements VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE {
|
||||
private class Values extends VALUE_ABSTRACT_COLLECTION VALUE_GENERIC_TYPE {
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean contains(Object e) { return containsValue(e); }
|
||||
public boolean contains(Object e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean contains(VALUE_TYPE e) { return containsValue(e); }
|
||||
public boolean contains(VALUE_TYPE e) {
|
||||
return containsValue(e);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public boolean add(VALUE_TYPE o) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() { return new ValueIterator(true); }
|
||||
@Override
|
||||
public int size() { return LINKED_ENUM_MAP.this.size(); }
|
||||
@Override
|
||||
public void clear() { LINKED_ENUM_MAP.this.clear(); }
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE reversed() { return new VALUE_ABSTRACT_COLLECTION.VALUE_REVERSED_ORDERED_COLLECTIONVALUE_BRACES(this, this::reverseIterator); }
|
||||
private VALUE_ITERATOR VALUE_GENERIC_TYPE reverseIterator() {
|
||||
return new ValueIterator(false);
|
||||
public boolean add(VALUE_TYPE o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFirst(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(VALUE_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_FIRST_KEY() { return FIRST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_FIRST_KEY() {
|
||||
VALUE_TYPE result = FIRST_ENTRY_VALUE();
|
||||
POLL_FIRST_ENTRY_KEY();
|
||||
return result;
|
||||
public VALUE_ITERATOR VALUE_GENERIC_TYPE iterator() {
|
||||
return new ValueIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_GET_LAST_KEY() { return LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_REMOVE_LAST_KEY() {
|
||||
VALUE_TYPE result = LAST_ENTRY_VALUE();
|
||||
POLL_LAST_ENTRY_KEY();
|
||||
return result;
|
||||
public int size() {
|
||||
return LINKED_ENUM_MAP.this.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
LINKED_ENUM_MAP.this.clear();
|
||||
}
|
||||
|
||||
#if VALUE_OBJECT
|
||||
@Override
|
||||
public void forEach(Consumer VALUE_SUPER_GENERIC_TYPE action) {
|
||||
@ -792,7 +715,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
private class FastEntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry = new MapEntry();
|
||||
|
||||
public FastEntryIterator(boolean start) { super(start); }
|
||||
public FastEntryIterator() {}
|
||||
public FastEntryIterator(T from) {
|
||||
super(from);
|
||||
}
|
||||
@ -819,7 +742,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
private class EntryIterator extends MapIterator implements ObjectListIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> {
|
||||
MapEntry entry;
|
||||
|
||||
public EntryIterator(boolean start) { super(start); }
|
||||
public EntryIterator() {}
|
||||
public EntryIterator(T from) {
|
||||
super(from);
|
||||
}
|
||||
@ -849,7 +772,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
private class KeyIterator extends MapIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
|
||||
public KeyIterator(boolean start) { super(start); }
|
||||
public KeyIterator() {}
|
||||
public KeyIterator(T from) {
|
||||
super(from);
|
||||
}
|
||||
@ -871,7 +794,7 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
private class ValueIterator extends MapIterator implements VALUE_LIST_ITERATOR VALUE_GENERIC_TYPE {
|
||||
public ValueIterator(boolean start) { super(start); }
|
||||
public ValueIterator() {}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE VALUE_PREVIOUS() {
|
||||
@ -892,20 +815,16 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
private class MapIterator {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = 0;
|
||||
|
||||
MapIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
MapIterator() {
|
||||
next = firstIndex;
|
||||
}
|
||||
|
||||
MapIterator(T from) {
|
||||
this.forward = true;
|
||||
previous = from.ordinal() - 1;
|
||||
index = from.ordinal();
|
||||
next = from.ordinal();
|
||||
@ -913,11 +832,11 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return (forward ? next : previous) != -1;
|
||||
return next != -1;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return (forward ? previous : next) != -1;
|
||||
return previous != -1;
|
||||
}
|
||||
|
||||
public int nextIndex() {
|
||||
@ -952,30 +871,20 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
|
||||
|
||||
public int previousEntry() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
if(index >= 0) index--;
|
||||
return current;
|
||||
}
|
||||
|
||||
public int nextEntry() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
next = current;
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = next;
|
||||
next = (int)(links[current]);
|
||||
previous = current;
|
||||
if(index >= 0) index++;
|
||||
return current;
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -567,6 +567,28 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -592,6 +614,27 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
if(Objects.equals(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -617,72 +660,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
#else
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
if(Objects.equals(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -704,6 +681,28 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
#else
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -721,7 +720,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -1771,7 +1769,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
#endif
|
||||
if(!inRange(key)) return getDefaultReturnValue();
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = map.findNode(key);
|
||||
#if VALUE_OBJECT
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.apply(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
@ -1780,11 +1777,6 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
#else
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
entry.value = mappingFunction.apply(key, entry.value);
|
||||
return entry.value;
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -569,6 +569,28 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -594,6 +616,27 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
if(Objects.equals(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -619,72 +662,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
#else
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, getDefaultReturnValue());
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
if(entry == null) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
put(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
if(Objects.equals(entry.value, getDefaultReturnValue())) {
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY(key);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) return newValue;
|
||||
entry.value = newValue;
|
||||
}
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) {
|
||||
Objects.requireNonNull(valueProvider);
|
||||
@ -706,6 +683,28 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return entry.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
#if TYPE_OBJECT
|
||||
validate(key);
|
||||
#endif
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = findNode(key);
|
||||
#if !VALUE_OBJECT
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
#else
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.APPLY_VALUE(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
removeNode(entry);
|
||||
return newValue;
|
||||
}
|
||||
#endif
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -723,7 +722,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) {
|
||||
Objects.requireNonNull(mappingFunction);
|
||||
@ -1837,7 +1835,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
#endif
|
||||
if(!inRange(key)) return getDefaultReturnValue();
|
||||
Node KEY_VALUE_GENERIC_TYPE entry = map.findNode(key);
|
||||
#if VALUE_OBJECT
|
||||
if(entry == null || VALUE_EQUALS(entry.value, getDefaultReturnValue())) return getDefaultReturnValue();
|
||||
VALUE_TYPE newValue = mappingFunction.apply(key, entry.value);
|
||||
if(VALUE_EQUALS(newValue, getDefaultReturnValue())) {
|
||||
@ -1846,11 +1843,6 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||
}
|
||||
entry.value = newValue;
|
||||
return newValue;
|
||||
#else
|
||||
if(entry == null) return getDefaultReturnValue();
|
||||
entry.value = mappingFunction.apply(key, entry.value);
|
||||
return entry.value;
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -154,7 +154,7 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* @return the last present value or default return value.
|
||||
*/
|
||||
public default CLASS_VALUE_TYPE put(Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE> entry) {
|
||||
return put(OBJ_TO_KEY(entry.getKey()), OBJ_TO_VALUE(entry.getValue()));
|
||||
return put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -389,35 +389,6 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* @return the result of the computation
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Type Specific computeIfAbsent method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value if not present
|
||||
* @return the result of the computed value or present value
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Supplier based computeIfAbsent function to fill the most used usecase of this function
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param valueProvider the value if not present
|
||||
* @return the result of the computed value or present value
|
||||
*/
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value if present
|
||||
* @return the result of the default return value or present value
|
||||
* @note if not present then compute is not executed
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
#if !VALUE_OBJECT
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
@ -427,6 +398,15 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* @return the result of the computation
|
||||
*/
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Type Specific computeIfAbsent method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value if not present
|
||||
* @return the result of the computed value or present value
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Type Specific computeIfAbsent method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
@ -436,6 +416,15 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* @return the result of the computed value or present value
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Supplier based computeIfAbsent function to fill the most used usecase of this function
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param valueProvider the value if not present
|
||||
* @return the result of the computed value or present value
|
||||
*/
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
|
||||
/**
|
||||
* A Supplier based computeIfAbsent function to fill the most used usecase of this function
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
@ -445,6 +434,16 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* @return the result of the computed value or present value
|
||||
*/
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider);
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
* A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it.
|
||||
* @param key the key that should be computed
|
||||
* @param mappingFunction the operator that should generate the value if present
|
||||
* @return the result of the default return value or present value
|
||||
* @note if not present then compute is not executed
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
/**
|
||||
* A Type Specific compute method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
@ -455,7 +454,6 @@ public interface MAP KEY_VALUE_GENERIC_TYPE extends Map<CLASS_TYPE, CLASS_VALUE_
|
||||
* @note if not present then compute is not executed
|
||||
*/
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction);
|
||||
#endif
|
||||
/**
|
||||
* A Type Specific merge method to reduce boxing/unboxing
|
||||
* If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null".
|
||||
|
||||
@ -1,15 +1,8 @@
|
||||
package speiger.src.collections.PACKAGE.maps.interfaces;
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
import java.util.Map;
|
||||
import java.util.SequencedMap;
|
||||
|
||||
#endif
|
||||
#if MAPS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.maps.MAPS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
#endif
|
||||
@ -24,11 +17,7 @@ import speiger.src.collections.objects.sets.ObjectOrderedSet;
|
||||
* @Type(T)
|
||||
* @ValueType(V)
|
||||
*/
|
||||
#if JAVA_VERSION>=21
|
||||
public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERIC_TYPE, SequencedMap<CLASS_TYPE, CLASS_VALUE_TYPE>
|
||||
#else
|
||||
public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* A customized put method that allows you to insert into the first index.
|
||||
@ -48,26 +37,6 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
*/
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A alternative to putAndMoveToFirst.
|
||||
* This method simply puts an entry at the first spot of the Map but only if the entry is missing.
|
||||
* @param key the key that should be inserted
|
||||
* @param value the value that should be inserted
|
||||
* @return the previous present or default return value
|
||||
* @see java.util.Map#put(Object, Object)
|
||||
*/
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A alternative to putAndMoveToLast.
|
||||
* This method simply puts an entry at the last spot of the Map but only if the entry is missing.
|
||||
* @param key the key that should be inserted
|
||||
* @param value the value that should be inserted
|
||||
* @return the previous present or default return value
|
||||
* @see java.util.Map#put(Object, Object)
|
||||
*/
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value);
|
||||
|
||||
/**
|
||||
* A specific move method to move a given key/value to the first index.
|
||||
* @param key that should be moved to the first index
|
||||
@ -128,34 +97,13 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
*/
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE();
|
||||
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry();
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry();
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry();
|
||||
@Java21
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry();
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy();
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet();
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values();
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET();
|
||||
@Java21
|
||||
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE reversed() { return new ABSTRACT_MAP.REVERSED_ORDERED_MAPKV_BRACES(this); }
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
@Override
|
||||
default ORDERED_SET KEY_GENERIC_TYPE sequencedKeySet() { return keySet(); }
|
||||
@Override
|
||||
default VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE sequencedValues() { return values(); }
|
||||
@Override
|
||||
default ObjectOrderedSet<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>> sequencedEntrySet() { return (ObjectOrderedSet<Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>)(Object)ENTRY_SET(); }
|
||||
|
||||
#endif
|
||||
#if MAPS_FEATURE
|
||||
/**
|
||||
* Creates a Wrapped SortedMap that is Synchronized
|
||||
@ -182,22 +130,6 @@ public interface ORDERED_MAP KEY_VALUE_GENERIC_TYPE extends MAP KEY_VALUE_GENERI
|
||||
@Override
|
||||
public default ORDERED_MAP KEY_VALUE_GENERIC_TYPE unmodifiable() { return MAPS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if JAVA_VERSION>=21
|
||||
#if !SAME_TYPE || !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_VALUE_TYPE putFirst(CLASS_TYPE k, CLASS_VALUE_TYPE v) {
|
||||
return putFirst(OBJ_TO_KEY(k), OBJ_TO_VALUE(v));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public default CLASS_VALUE_TYPE putLast(CLASS_TYPE k, CLASS_VALUE_TYPE v) {
|
||||
return putLast(OBJ_TO_KEY(k), OBJ_TO_VALUE(v));
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* Fast Ordered Entry Set that allows for a faster Entry Iterator by recycling the Entry Object and just exchanging 1 internal value
|
||||
|
||||
@ -168,15 +168,6 @@ public class ARRAY_FIFO_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEUE K
|
||||
return index >= array.length ? array[index-array.length] : array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) {
|
||||
if(first == last) return false;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(e == array[(first + i) % array.length]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) {
|
||||
if(first == last) return false;
|
||||
|
||||
@ -228,13 +228,6 @@ public class ARRAY_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUE
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
if(KEY_EQUALS(e, array[i])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
|
||||
@ -236,13 +236,6 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC_TYPE extends ABSTRACT_PRIORITY_QUEU
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
if(KEY_EQUALS(e, array[i])) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
|
||||
@ -111,13 +111,6 @@ public interface PRIORITY_QUEUE KEY_GENERIC_TYPE extends ITERABLE KEY_GENERIC_TY
|
||||
*/
|
||||
public default KEY_TYPE first() { return peek(0); }
|
||||
|
||||
/**
|
||||
* Method to find out if a element is part of the queue
|
||||
* @param e the element that is searched for
|
||||
* @return true if the element is in the queue
|
||||
*/
|
||||
public boolean contains(KEY_TYPE e);
|
||||
|
||||
/**
|
||||
* Removes the first found element in the queue
|
||||
* @param e the element that should be removed
|
||||
|
||||
@ -6,7 +6,6 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
|
||||
/**
|
||||
@ -48,95 +47,4 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if ORDERED_SET_FEATURE
|
||||
public static class REVERSED_ORDERED_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE implements ORDERED_SET KEY_GENERIC_TYPE {
|
||||
protected ORDERED_SET KEY_GENERIC_TYPE set;
|
||||
|
||||
public REVERSED_ORDERED_SET(ORDERED_SET KEY_GENERIC_TYPE set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public REVERSED_ORDERED_SET KEY_GENERIC_TYPE copy() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
||||
return set.iterator(fromElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return set.reverseIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return set.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
#if !TYPE_OBJECT
|
||||
public boolean remove(KEY_TYPE o) {
|
||||
#else
|
||||
public boolean remove(Object o) {
|
||||
#endif
|
||||
return set.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
return set.add(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToFirst(KEY_TYPE o) {
|
||||
return set.addAndMoveToLast(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAndMoveToLast(KEY_TYPE o) {
|
||||
return set.addAndMoveToFirst(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
return set.moveToLast(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
return set.moveToFirst(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
return set.GET_LAST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
return set.REMOVE_LAST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
return set.GET_FIRST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
return set.REMOVE_FIRST_KEY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE reversed() {
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return set.size();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -219,13 +219,13 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return data[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return data[size - 1];
|
||||
}
|
||||
@ -354,7 +354,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
KEY_TYPE result = data[0];
|
||||
System.arraycopy(data, 1, data, 0, --size);
|
||||
@ -365,7 +365,7 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
size--;
|
||||
#if TYPE_OBJECT
|
||||
@ -511,18 +511,13 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator(true, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false, size);
|
||||
return new SetIterator(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) {
|
||||
int index = findIndex(fromElement);
|
||||
if(index != -1) return new SetIterator(true, index);
|
||||
if(index != -1) return new SetIterator(index);
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@ -575,57 +570,45 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
public SetIterator(boolean forward, int index) {
|
||||
this.forward = forward;
|
||||
public SetIterator(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return forward ? index < size() : index > 0;
|
||||
return index < size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) {
|
||||
lastReturned = index;
|
||||
return data[index++];
|
||||
}
|
||||
index--;
|
||||
return data[(lastReturned = index)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return forward ? index > 0 : index < size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
if(forward) {
|
||||
index--;
|
||||
return data[(lastReturned = index)];
|
||||
}
|
||||
lastReturned = index;
|
||||
return data[index++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
--index;
|
||||
return data[(lastReturned = index)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -654,23 +637,15 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
return forward ? moveForward(amount) : moveBackwards(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
return forward ? moveBackwards(amount) : moveForward(amount);
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int steps = Math.min(amount, size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
|
||||
@ -285,22 +285,22 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[firstIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean remove(Object o) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@ -455,12 +455,7 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false);
|
||||
return new SetIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -526,20 +521,16 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = -1;
|
||||
int index = 0;
|
||||
|
||||
SetIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
SetIterator() {
|
||||
next = firstIndex;
|
||||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(KEY_EQUALS_NULL(from)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -568,60 +559,48 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = forward ? moveForward(amount) : moveBackwards(amount);
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = forward ? moveBackwards(amount) : moveForward(amount);
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return (forward ? next : previous) != -1;
|
||||
return next != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return (forward ? previous : next) != -1;
|
||||
return previous != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
ensureIndexKnown();
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
ensureIndexKnown();
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
return index - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -630,8 +609,8 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@ -639,20 +618,10 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -291,7 +291,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
if(isEmpty() || strategy.equals(GET_FIRST_KEY(), o)) return false;
|
||||
if(isEmpty() || strategy.equals(FIRST_KEY(), o)) return false;
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
@ -313,7 +313,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
if(isEmpty() || strategy.equals(GET_LAST_KEY(), o)) return false;
|
||||
if(isEmpty() || strategy.equals(LAST_KEY(), o)) return false;
|
||||
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
@ -370,13 +370,13 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[firstIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
@ -392,13 +392,13 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
@ -697,12 +697,7 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false);
|
||||
return new SetIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -727,20 +722,16 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = -1;
|
||||
int index = 0;
|
||||
|
||||
SetIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
SetIterator() {
|
||||
next = firstIndex;
|
||||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(strategy.equals(from, EMPTY_KEY_VALUE)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -769,60 +760,48 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return (forward ? next : previous) != -1;
|
||||
return next != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return (forward ? previous : next) != -1;
|
||||
return previous != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = forward ? moveForward(amount) : moveBackwards(amount);
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = forward ? moveBackwards(amount) : moveForward(amount);
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
ensureIndexKnown();
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
ensureIndexKnown();
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
return index - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -871,8 +850,8 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@ -880,20 +859,10 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -262,7 +262,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE o) {
|
||||
if(isEmpty() || KEY_EQUALS(GET_FIRST_KEY(), o)) return false;
|
||||
if(isEmpty() || KEY_EQUALS(FIRST_KEY(), o)) return false;
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToFirstIndex(nullIndex);
|
||||
@ -284,7 +284,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE o) {
|
||||
if(isEmpty() || KEY_EQUALS(GET_LAST_KEY(), o)) return false;
|
||||
if(isEmpty() || KEY_EQUALS(LAST_KEY(), o)) return false;
|
||||
if(KEY_EQUALS_NULL(o)) {
|
||||
if(containsNull) {
|
||||
moveToLastIndex(nullIndex);
|
||||
@ -341,13 +341,13 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() {
|
||||
public KEY_TYPE FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[firstIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||
public KEY_TYPE POLL_FIRST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = firstIndex;
|
||||
onNodeRemoved(pos);
|
||||
@ -363,13 +363,13 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() {
|
||||
public KEY_TYPE LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
return keys[lastIndex];
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||
public KEY_TYPE POLL_LAST_KEY() {
|
||||
if(size == 0) throw new NoSuchElementException();
|
||||
int pos = lastIndex;
|
||||
onNodeRemoved(pos);
|
||||
@ -668,12 +668,7 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new SetIterator(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
|
||||
return new SetIterator(false);
|
||||
return new SetIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -698,20 +693,16 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
}
|
||||
|
||||
private class SetIterator implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
boolean forward;
|
||||
int previous = -1;
|
||||
int next = -1;
|
||||
int current = -1;
|
||||
int index = -1;
|
||||
int index = 0;
|
||||
|
||||
SetIterator(boolean start) {
|
||||
this.forward = start;
|
||||
if(start) next = firstIndex;
|
||||
else previous = lastIndex;
|
||||
SetIterator() {
|
||||
next = firstIndex;
|
||||
}
|
||||
|
||||
SetIterator(KEY_TYPE from) {
|
||||
this.forward = true;
|
||||
if(KEY_EQUALS_NULL(from)) {
|
||||
if(containsNull) {
|
||||
next = (int) links[nullIndex];
|
||||
@ -740,60 +731,48 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
int result = forward ? moveForward(amount) : moveBackwards(amount);
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = forward ? moveBackwards(amount) : moveForward(amount);
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveForward(int amount) {
|
||||
int result = 0;
|
||||
while(next != -1 && result != amount) {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index+=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int moveBackwards(int amount) {
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
int result = 0;
|
||||
while(previous != -1 && result != amount) {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
result++;
|
||||
}
|
||||
if(index >= 0) index-=result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return (forward ? next : previous) != -1;
|
||||
return next != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return (forward ? previous : next) != -1;
|
||||
return previous != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
ensureIndexKnown();
|
||||
if(forward) return index;
|
||||
return size - index;
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
ensureIndexKnown();
|
||||
if(forward) return index-1;
|
||||
return (size - index)-1;
|
||||
return index - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -842,8 +821,8 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
if(forward) moveBackwards();
|
||||
else moveForwards();
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
if(index >= 0) index--;
|
||||
return keys[current];
|
||||
}
|
||||
@ -851,20 +830,10 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
if(forward) moveForwards();
|
||||
else moveBackwards();
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void moveBackwards() {
|
||||
current = next = previous;
|
||||
previous = (int)(links[current] >> 32);
|
||||
}
|
||||
|
||||
private void moveForwards() {
|
||||
current = previous = next;
|
||||
next = (int)(links[current]);
|
||||
if(index >= 0) index++;
|
||||
return keys[current];
|
||||
}
|
||||
|
||||
private void ensureIndexKnown() {
|
||||
|
||||
@ -3,13 +3,11 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
import java.util.NavigableSet;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
|
||||
/**
|
||||
* A Type Specific Navigable Set interface with a couple helper methods
|
||||
@ -147,7 +145,6 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
||||
public default NAVIGABLE_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
@ -155,7 +152,6 @@ public interface NAVIGABLE_SET KEY_GENERIC_TYPE extends NavigableSet<CLASS_TYPE>
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
@Deprecated
|
||||
|
||||
@ -1,18 +1,11 @@
|
||||
package speiger.src.collections.PACKAGE.sets;
|
||||
|
||||
#if JAVA_VERSION>=21
|
||||
import java.util.SequencedSet;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.sets.ABSTRACT_SET.REVERSED_ORDERED_SET;
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
|
||||
/**
|
||||
* A Special Set Interface giving Access to some really usefull functions
|
||||
@ -22,11 +15,7 @@ import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
*
|
||||
* @Type(T)
|
||||
*/
|
||||
#if JAVA_VERSION>=21
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SequencedSet<CLASS_TYPE>
|
||||
#else
|
||||
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
#endif
|
||||
{
|
||||
/**
|
||||
* A customized add method that allows you to insert into the first index.
|
||||
@ -63,7 +52,6 @@ public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator();
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator();
|
||||
|
||||
/**
|
||||
* A type Specific Iterator starting from a given key
|
||||
@ -73,7 +61,6 @@ public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
*/
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement);
|
||||
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
@ -81,80 +68,26 @@ public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
|
||||
#endif
|
||||
/**
|
||||
* A method to get the first element in the set
|
||||
* @return first element in the set
|
||||
*/
|
||||
public KEY_TYPE GET_FIRST_KEY();
|
||||
public KEY_TYPE FIRST_KEY();
|
||||
/**
|
||||
* A method to get and remove the first element in the set
|
||||
* @return first element in the set
|
||||
*/
|
||||
public KEY_TYPE REMOVE_FIRST_KEY();
|
||||
public KEY_TYPE POLL_FIRST_KEY();
|
||||
/**
|
||||
* A method to get the last element in the set
|
||||
* @return last element in the set
|
||||
*/
|
||||
public KEY_TYPE GET_LAST_KEY();
|
||||
public KEY_TYPE LAST_KEY();
|
||||
/**
|
||||
* A method to get and remove the last element in the set
|
||||
* @return last element in the set
|
||||
*/
|
||||
public KEY_TYPE REMOVE_LAST_KEY();
|
||||
|
||||
#if JAVA_VERSION>=21 && !TYPE_OBJECT
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addFirst(CLASS_TYPE e) { addAndMoveToFirst(OBJ_TO_KEY(e)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default void addLast(CLASS_TYPE e) { addAndMoveToLast(OBJ_TO_KEY(e)); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getFirst() { return GET_FIRST_KEY(); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE getLast() { return GET_LAST_KEY(); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeFirst() { return REMOVE_FIRST_KEY(); }
|
||||
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
default CLASS_TYPE removeLast() { return REMOVE_LAST_KEY(); }
|
||||
|
||||
#endif
|
||||
@Java21
|
||||
public default ORDERED_SET KEY_GENERIC_TYPE reversed() { return new REVERSED_ORDERED_SETBRACES(this); }
|
||||
public KEY_TYPE POLL_LAST_KEY();
|
||||
|
||||
#if SETS_FEATURE
|
||||
/**
|
||||
|
||||
@ -4,13 +4,11 @@ import java.util.Set;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
|
||||
|
||||
/**
|
||||
@ -90,12 +88,10 @@ public interface SET KEY_GENERIC_TYPE extends Set<CLASS_TYPE>, COLLECTION KEY_GE
|
||||
public default SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
#endif
|
||||
}
|
||||
@ -3,9 +3,7 @@ package speiger.src.collections.PACKAGE.sets;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#else
|
||||
@ -14,9 +12,7 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#if SETS_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Type Specific SortedSet implementation to reduce boxing/unboxing
|
||||
@ -71,7 +67,6 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
||||
public default SORTED_SET KEY_GENERIC_TYPE unmodifiable() { return SETS.unmodifiable(this); }
|
||||
|
||||
#endif
|
||||
#if SPLIT_ITERATOR_FEATURE
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
@ -79,7 +74,6 @@ public interface SORTED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, Sorte
|
||||
@Override
|
||||
default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createSplititerator(this, 0); }
|
||||
|
||||
#endif
|
||||
#if !TYPE_OBJECT
|
||||
/**
|
||||
* A Type Specific SubSet method to reduce boxing/unboxing
|
||||
|
||||
@ -16,16 +16,6 @@ import java.util.function.IntFunction;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Comparator;
|
||||
|
||||
#iterate
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument BUILDER BooleanAsyncBuilder ByteAsyncBuilder ShortAsyncBuilder IntAsyncBuilder LongAsyncBuilder FloatAsyncBuilder DoubleAsyncBuilder
|
||||
#argument PACKAGE booleans bytes shorts ints longs floats doubles
|
||||
#argument CHECK BOOLEAN_ASYNC_MODULE BYTE_ASYNC_MODULE SHORT_ASYNC_MODULE INT_ASYNC_MODULE LONG_ASYNC_MODULE FLOAT_ASYNC_MODULE DOUBLE_ASYNC_MODULE
|
||||
#if CHECK
|
||||
import speiger.src.collections.objects.functions.function.MAPPER;
|
||||
import speiger.src.collections.PACKAGE.utils.BUILDER;
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
@ -33,9 +23,7 @@ import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.TASK;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
#endif
|
||||
@ -71,9 +59,7 @@ import speiger.src.collections.PACKAGE.sets.ARRAY_SET;
|
||||
#endif
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN && BOOLEAN_ASYNC_MODULE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder;
|
||||
#endif
|
||||
import speiger.src.collections.booleans.utils.BooleanAsyncBuilder.BaseBooleanTask;
|
||||
#endif
|
||||
#if !TYPE_OBJECT && OBJECT_ASYNC_MODULE
|
||||
@ -81,9 +67,7 @@ import speiger.src.collections.objects.utils.ObjectAsyncBuilder;
|
||||
import speiger.src.collections.objects.utils.ObjectAsyncBuilder.BaseObjectTask;
|
||||
#endif
|
||||
#if !TYPE_INT && INT_ASYNC_MODULE
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.ints.utils.IntAsyncBuilder;
|
||||
#endif
|
||||
import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
|
||||
#endif
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
@ -203,25 +187,6 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return new ObjectAsyncBuilder<>(ITERABLES.arrayFlatMap(iterable, mapper));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument BUILDER BooleanAsyncBuilder ByteAsyncBuilder ShortAsyncBuilder IntAsyncBuilder LongAsyncBuilder FloatAsyncBuilder DoubleAsyncBuilder
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument TYPE Boolean Byte Short Int Long Float Double
|
||||
#argument CHECK BOOLEAN_ASYNC_MODULE BYTE_ASYNC_MODULE SHORT_ASYNC_MODULE INT_ASYNC_MODULE LONG_ASYNC_MODULE FLOAT_ASYNC_MODULE DOUBLE_ASYNC_MODULE
|
||||
#if CHECK
|
||||
/**
|
||||
* Maps the elements to something else
|
||||
* @param mapper the mapping function
|
||||
* @return a new Builder Object with the mapped Iterable
|
||||
*/
|
||||
public BUILDER mapToTYPE(MAPPER<T> mapper) {
|
||||
return new BUILDER(ITERABLES.mapToTYPE(iterable, mapper));
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
/**
|
||||
* Filters out the unwanted elements out of the Iterable
|
||||
|
||||
@ -23,9 +23,6 @@ import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
@ -79,37 +76,6 @@ public class COLLECTIONS
|
||||
return c instanceof UnmodifiableCollection ? c : new UnmodifiableCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Immutable Ordered Collection instance based on the instance given.
|
||||
* @param c that should be made immutable/unmodifiable
|
||||
* @Type(T)
|
||||
* @return a unmodifiable Ordered collection wrapper. If the Collection already a unmodifiable wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ORDERED_COLLECTION KEY_GENERIC_TYPE unmodifiable(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return c instanceof UnmodifiableOrderedCollection ? c : new UnmodifiableOrderedCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized ordered Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
* @Type(T)
|
||||
* @return a synchronized ordered collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ORDERED_COLLECTION KEY_GENERIC_TYPE synchronize(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
return c instanceof SynchronizedOrderedCollection ? c : new SynchronizedOrderedCollectionBRACES(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized ordered Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
* @param mutex is the controller of the synchronization block.
|
||||
* @Type(T)
|
||||
* @return a synchronized ordered collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ORDERED_COLLECTION KEY_GENERIC_TYPE synchronize(ORDERED_COLLECTION KEY_GENERIC_TYPE c, Object mutex) {
|
||||
return c instanceof SynchronizedOrderedCollection ? c : new SynchronizedOrderedCollectionBRACES(c, mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
@ -702,38 +668,6 @@ public class COLLECTIONS
|
||||
@Override
|
||||
public SingletonCollection KEY_GENERIC_TYPE copy() { return new SingletonCollectionBRACES(element); }
|
||||
}
|
||||
/**
|
||||
* Synchronized Ordered Collection Wrapper for the synchronizedCollection function
|
||||
* @Type(T)
|
||||
*/
|
||||
public static class SynchronizedOrderedCollection KEY_GENERIC_TYPE extends SynchronizedCollection KEY_GENERIC_TYPE implements ORDERED_COLLECTION KEY_GENERIC_TYPE {
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE c;
|
||||
|
||||
SynchronizedOrderedCollection(ORDERED_COLLECTION KEY_GENERIC_TYPE c, Object mutex) {
|
||||
super(c, mutex);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
SynchronizedOrderedCollection(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_COLLECTION KEY_GENERIC_TYPE reversed() { return COLLECTIONS.synchronize(c.reversed(), mutex); }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE e) { synchronized(mutex) { this.c.addFirst(e); } }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE e) { synchronized(mutex) { this.c.addLast(e); } }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { synchronized(mutex) { return this.c.GET_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { synchronized(mutex) { return this.c.REMOVE_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { synchronized(mutex) { return this.c.GET_LAST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { synchronized(mutex) { return this.c.REMOVE_LAST_KEY(); } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronized Collection Wrapper for the synchronizedCollection function
|
||||
@ -876,34 +810,6 @@ public class COLLECTIONS
|
||||
public int count(PREDICATE KEY_GENERIC_TYPE filter) { synchronized(mutex) { return c.count(filter); } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmodifyable Ordered Collection Wrapper for the unmodifyableCollection method
|
||||
* @Type(T)
|
||||
*/
|
||||
public static class UnmodifiableOrderedCollection KEY_GENERIC_TYPE extends UnmodifiableCollection KEY_GENERIC_TYPE implements ORDERED_COLLECTION KEY_GENERIC_TYPE {
|
||||
ORDERED_COLLECTION KEY_GENERIC_TYPE c;
|
||||
|
||||
UnmodifiableOrderedCollection(ORDERED_COLLECTION KEY_GENERIC_TYPE c) {
|
||||
super(c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_COLLECTION KEY_GENERIC_TYPE reversed() { return COLLECTIONS.unmodifiable(c.reversed()); }
|
||||
@Override
|
||||
public void addFirst(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { return c.GET_FIRST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { return c.GET_LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmodifyable Collection Wrapper for the unmodifyableCollection method
|
||||
* @Type(T)
|
||||
|
||||
@ -19,26 +19,6 @@ import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#else
|
||||
#if BOOLEAN_COLLECTION_MODULE
|
||||
import speiger.src.collections.booleans.functions.BooleanConsumer;
|
||||
import speiger.src.collections.booleans.collections.BooleanIterable;
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
#endif
|
||||
#iterate
|
||||
#argument FILTER_TYPE BYTE_COLLECTION_MODULE SHORT_COLLECTION_MODULE INT_COLLECTION_MODULE LONG_COLLECTION_MODULE FLOAT_COLLECTION_MODULE DOUBLE_COLLECTION_MODULE
|
||||
#argument CONSUMER ByteConsumer ShortConsumer IntConsumer LongConsumer FloatConsumer DoubleConsumer
|
||||
#argument OUTPUT_ITERABLE ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
|
||||
#argument OUTPUT_ITERATOR ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
|
||||
#argument MAPPER ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument PACKAGE bytes shorts ints longs floats doubles
|
||||
#if FILTER_TYPE
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.objects.functions.function.MAPPER;
|
||||
import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.collections.OUTPUT_ITERATOR;
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
@ -76,39 +56,6 @@ public class ITERABLES
|
||||
return new MappedIterable<>(iterable, mapper);
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
|
||||
#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 that maps a Java-Iterable into a new Type.
|
||||
* @param iterable the iterable that should be mapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @return a iterable that is mapped to a new result
|
||||
*/
|
||||
public static <T> OUTPUT_ITERABLE mapToDATA_TYPE(Iterable<? extends CLASS_TYPE> iterable, MAPPER<T> mapper) {
|
||||
return new MAPPED_TYPEIterable<>(wrap(iterable), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a Iterable into a new Type.
|
||||
* @param iterable the iterable that should be mapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @return a iterable that is mapped to a new result
|
||||
*/
|
||||
public static <T> OUTPUT_ITERABLE mapToDATA_TYPE(ITERABLE KEY_GENERIC_TYPE iterable, MAPPER<T> mapper) {
|
||||
return new MAPPED_TYPEIterable<>(iterable, mapper);
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterable into a new Type.
|
||||
* @param iterable the iterable that should be flatMapped
|
||||
@ -333,47 +280,6 @@ public class ITERABLES
|
||||
#endif
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument CONSUMER BooleanConsumer ByteConsumer ShortConsumer IntConsumer LongConsumer FloatConsumer DoubleConsumer
|
||||
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
|
||||
#argument OUTPUT_ITERABLE BooleanIterable ByteIterable ShortIterable IntIterable LongIterable FloatIterable DoubleIterable
|
||||
#argument OUTPUT_ITERATOR BooleanIterator ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument APPLY test applyAsByte applyAsShort applyAsInt applyAsLong applyAsFloat applyAsDouble
|
||||
#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
|
||||
private static class MAPPED_TYPEIterable<E> implements OUTPUT_ITERABLE, ISizeProvider
|
||||
{
|
||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||
MAPPER<E> mapper;
|
||||
|
||||
MAPPED_TYPEIterable(ITERABLE<E> iterable, MAPPER<E> mapper) {
|
||||
this.iterable = iterable;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public OUTPUT_ITERATOR iterator() {
|
||||
return ITERATORS.mapToDATA_TYPE(iterable.iterator(), mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
ISizeProvider prov = ISizeProvider.of(this);
|
||||
return prov == null ? -1 : prov.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
iterable.forEach(E -> action.accept(mapper.APPLY(E)));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>, ISizeProvider
|
||||
{
|
||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||
|
||||
@ -4,8 +4,8 @@ import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.CONSUMER;
|
||||
#endif
|
||||
import java.util.function.Consumer;
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
@ -16,23 +16,8 @@ import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#else
|
||||
#if BOOLEAN_COLLECTION_MODULE
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
#endif
|
||||
#iterate
|
||||
#argument ITERATOR ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
|
||||
#argument PACKAGE bytes shorts ints longs floats doubles
|
||||
#argument MAPPER ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#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.ITERATOR;
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
@ -48,7 +33,6 @@ import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.CollectionWrapper;
|
||||
|
||||
/**
|
||||
* A Helper class for Iterators
|
||||
@ -65,7 +49,7 @@ public class ITERATORS
|
||||
* @Type(T)
|
||||
* @return an empty iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST_ITERATOR KEY_GENERIC_TYPE empty() {
|
||||
public static GENERIC_KEY_BRACES EmptyIterator KEY_GENERIC_TYPE empty() {
|
||||
#if TYPE_OBJECT
|
||||
return (EmptyIterator<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
@ -123,7 +107,6 @@ public class ITERATORS
|
||||
return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
#if OBJECT_COLLECTION_MODULE
|
||||
/**
|
||||
* A Helper function that maps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be mapped
|
||||
@ -148,40 +131,6 @@ public class ITERATORS
|
||||
return new MappedIterator<>(iterator, mapper);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
|
||||
#argument OUTPUT_ITERATOR BooleanIterator ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
|
||||
#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 that maps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be mapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @return a iterator that is mapped to a new result
|
||||
*/
|
||||
public static <T> OUTPUT_ITERATOR mapToDATA_TYPE(Iterator<? extends CLASS_TYPE> iterator, MAPPER<T> mapper) {
|
||||
return new MAPPED_TYPEIterator<>(wrap(iterator), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a Iterator into a new Type.
|
||||
* @param iterator that should be mapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @return a iterator that is mapped to a new result
|
||||
*/
|
||||
public static <T> OUTPUT_ITERATOR mapToDATA_TYPE(ITERATOR KEY_GENERIC_TYPE iterator, MAPPER<T> mapper) {
|
||||
return new MAPPED_TYPEIterator<>(iterator, mapper);
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
@ -296,26 +245,6 @@ public class ITERATORS
|
||||
return new RepeatingIteratorBRACES(wrap(iterator), repeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that creates a infinitely looping iterator
|
||||
* @param iterator that should be looping infinitely
|
||||
* @Type(T)
|
||||
* @return a infinitely looping iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE infinite(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
return new InfiniteIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that creates a infinitely looping iterator from a Java Iterator
|
||||
* @param iterator that should be looping infinitely
|
||||
* @Type(T)
|
||||
* @return a infinitely looping iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE infinite(Iterator<? extends CLASS_TYPE> iterator) {
|
||||
return new InfiniteIteratorBRACES(wrap(iterator));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that hard limits the Iterator to a specific size
|
||||
* @param iterator that should be limited
|
||||
@ -400,7 +329,7 @@ public class ITERATORS
|
||||
* @ArrayType(T)
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE wrap(KEY_TYPE... a) {
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE... a) {
|
||||
return wrap(a, 0, a.length);
|
||||
}
|
||||
|
||||
@ -412,7 +341,7 @@ public class ITERATORS
|
||||
* @ArrayType(T)
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
||||
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
||||
return new ArrayIteratorBRACES(a, start, end);
|
||||
}
|
||||
|
||||
@ -917,45 +846,6 @@ public class ITERATORS
|
||||
}
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
#iterate
|
||||
#argument MAPPED_TYPE MappedBoolean MappedByte MappedShort MappedInt MappedLong MappedFloat MappedDouble
|
||||
#argument NEXT_TYPE nextBoolean nextByte nextShort nextInt nextLong nextFloat nextDouble
|
||||
#argument OUTPUT_ITERATOR BooleanIterator ByteIterator ShortIterator IntIterator LongIterator FloatIterator DoubleIterator
|
||||
#argument MAPPER Predicate ToByteFunction ToShortFunction ToIntFunction ToLongFunction ToFloatFunction ToDoubleFunction
|
||||
#argument APPLY test applyAsByte applyAsShort applyAsInt applyAsLong applyAsFloat applyAsDouble
|
||||
#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
|
||||
private static class MAPPED_TYPEIterator<E> implements OUTPUT_ITERATOR
|
||||
{
|
||||
ITERATOR<E> iterator;
|
||||
MAPPER<E> mapper;
|
||||
|
||||
MAPPED_TYPEIterator(ITERATOR KEY_SPECIAL_GENERIC_TYPE<E> iterator, MAPPER<E> mapper) {
|
||||
this.iterator = iterator;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DATA_TYPE NEXT_TYPE() {
|
||||
return mapper.APPLY(iterator.NEXT());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
return iterator.skip(amount);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#enditerate
|
||||
#endif
|
||||
private static class FlatMappedIterator KSS_GENERIC_TYPE<E, T,[SPACE]V extends Iterable<T>> implements ObjectIterator<T>
|
||||
{
|
||||
ITERATOR KEY_SPECIAL_GENERIC_TYPE<E> iterator;
|
||||
@ -1028,42 +918,6 @@ public class ITERATORS
|
||||
}
|
||||
}
|
||||
|
||||
private static class InfiniteIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
CollectionWrapper KEY_GENERIC_TYPE looper = COLLECTIONS.wrapper();
|
||||
int index = 0;
|
||||
|
||||
public InfiniteIterator(ITERATOR KEY_GENERIC_TYPE iter) {
|
||||
this.iter = iter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(iter != null) {
|
||||
if(iter.hasNext()) {
|
||||
KEY_TYPE value = iter.NEXT();
|
||||
looper.add(value);
|
||||
return value;
|
||||
}
|
||||
else iter = null;
|
||||
}
|
||||
return looper.GET_KEY((index++) % looper.size());
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEachRemaining(CONSUMER action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
#endif
|
||||
public void forEachRemaining(Consumer<? super CLASS_TYPE> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
public <E> void forEachRemaining(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
}
|
||||
|
||||
private static class RepeatingIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
final int repeats;
|
||||
|
||||
@ -24,9 +24,6 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.ABSTRACT_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if INT_LIST_MODULE && !TYPE_INT
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
@ -45,7 +42,7 @@ public class LISTS
|
||||
* @Type(T)
|
||||
* @return an empty list
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE empty() {
|
||||
public static GENERIC_KEY_BRACES EmptyList KEY_GENERIC_TYPE empty() {
|
||||
#if TYPE_OBJECT
|
||||
return (EmptyList<KEY_TYPE>)EMPTY;
|
||||
#else
|
||||
@ -411,18 +408,6 @@ public class LISTS
|
||||
return l.listIterator(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
|
||||
return l.indexedIterator(indecies);
|
||||
}
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
|
||||
return l.indexedIterator(indecies);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
|
||||
return LISTS.synchronize(l.subList(from, to));
|
||||
@ -550,18 +535,6 @@ public class LISTS
|
||||
return ITERATORS.unmodifiable(l.listIterator(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
|
||||
return ITERATORS.unmodifiable(l.indexedIterator(indecies));
|
||||
}
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
|
||||
return ITERATORS.unmodifiable(l.indexedIterator(indecies));
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public LIST KEY_GENERIC_TYPE subList(int from, int to) {
|
||||
return LISTS.unmodifiable(l.subList(from, to));
|
||||
@ -660,18 +633,6 @@ public class LISTS
|
||||
return ITERATORS.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(int...indecies) {
|
||||
return ITERATORS.empty();
|
||||
}
|
||||
|
||||
#if INT_LIST_MODULE
|
||||
@Override
|
||||
public LIST_ITERATOR KEY_GENERIC_TYPE indexedIterator(IntList indecies) {
|
||||
return ITERATORS.empty();
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public int hashCode() { return 1; }
|
||||
|
||||
|
||||
@ -116,8 +116,6 @@ public class PRIORITY_QUEUES
|
||||
@Override
|
||||
public KEY_TYPE peek(int index) { synchronized(mutex) { return queue.peek(index); } }
|
||||
@Override
|
||||
public boolean contains(KEY_TYPE e) { synchronized(mutex) { return queue.contains(e); } }
|
||||
@Override
|
||||
public boolean removeFirst(KEY_TYPE e) { synchronized(mutex) { return queue.removeFirst(e); } }
|
||||
@Override
|
||||
public boolean removeLast(KEY_TYPE e) { synchronized(mutex) { return queue.removeLast(e); } }
|
||||
|
||||
@ -371,19 +371,17 @@ public class SETS
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { return ITERATORS.unmodifiable(s.iterator()); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() { return ITERATORS.unmodifiable(s.reverseIterator()); }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { return ITERATORS.unmodifiable(s.iterator(fromElement)); }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE copy() { return s.copy(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { return s.GET_FIRST_KEY(); }
|
||||
public KEY_TYPE FIRST_KEY() { return s.FIRST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE POLL_FIRST_KEY() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { return s.GET_LAST_KEY(); }
|
||||
public KEY_TYPE LAST_KEY() { return s.LAST_KEY(); }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
public KEY_TYPE POLL_LAST_KEY() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -662,19 +660,17 @@ public class SETS
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator() { synchronized(mutex) { return s.iterator(); } }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() { synchronized(mutex) { return s.reverseIterator(); } }
|
||||
@Override
|
||||
public BI_ITERATOR KEY_GENERIC_TYPE iterator(KEY_TYPE fromElement) { synchronized(mutex) { return s.iterator(fromElement); } }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE copy() { synchronized(mutex) { return s.copy(); } }
|
||||
@Override
|
||||
public KEY_TYPE GET_FIRST_KEY() { synchronized(mutex) { return s.GET_FIRST_KEY(); } }
|
||||
public KEY_TYPE FIRST_KEY() { synchronized(mutex) { return s.FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_FIRST_KEY() { synchronized(mutex) { return s.REMOVE_FIRST_KEY(); } }
|
||||
public KEY_TYPE POLL_FIRST_KEY() { synchronized(mutex) { return s.POLL_FIRST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE GET_LAST_KEY() { synchronized(mutex) { return s.GET_LAST_KEY(); } }
|
||||
public KEY_TYPE LAST_KEY() { synchronized(mutex) { return s.LAST_KEY(); } }
|
||||
@Override
|
||||
public KEY_TYPE REMOVE_LAST_KEY() { synchronized(mutex) { return s.REMOVE_LAST_KEY(); } }
|
||||
public KEY_TYPE POLL_LAST_KEY() { synchronized(mutex) { return s.POLL_LAST_KEY(); } }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -56,9 +56,6 @@ import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.utils.SETS;
|
||||
#endif
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_COLLECTION;
|
||||
#if ORDERED_MAP_FEATURE
|
||||
import speiger.src.collections.VALUE_PACKAGE.collections.VALUE_ORDERED_COLLECTION;
|
||||
#endif
|
||||
#if !SAME_TYPE
|
||||
import speiger.src.collections.VALUE_PACKAGE.functions.function.VALUE_UNARY_OPERATOR;
|
||||
#endif
|
||||
@ -343,22 +340,20 @@ public class MAPS
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@ -415,22 +410,20 @@ public class MAPS
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@ -556,10 +549,6 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { throw new UnsupportedOperationException(); }
|
||||
@ -580,25 +569,13 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { return map.LAST_ENTRY_VALUE(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { return map.firstEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { return map.lastEntry(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { return map.copy(); }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.unmodifiable(map.keySet());
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keys;
|
||||
}
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(values == null) values = VALUE_COLLECTIONS.unmodifiable(map.values());
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = new UnmodifyableOrderedEntrySetKV_BRACES(map.ENTRY_SET());
|
||||
@ -692,22 +669,20 @@ public class MAPS
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { throw new UnsupportedOperationException(); }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
@ -768,17 +743,15 @@ public class MAPS
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator() { return ObjectIterators.unmodifiable(set.iterator()); }
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> reverseIterator() { return ObjectIterators.unmodifiable(set.reverseIterator()); }
|
||||
@Override
|
||||
public ObjectBidirectionalIterator<MAP.Entry KEY_VALUE_GENERIC_TYPE> iterator(MAP.Entry KEY_VALUE_GENERIC_TYPE fromElement) { return ObjectIterators.unmodifiable(set.iterator(fromElement)); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getFirst() { return set.getFirst(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE first() { return set.first(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeFirst() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirst() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE getLast() { return set.getLast(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE last() { return set.last(); }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE removeLast() { throw new UnsupportedOperationException(); }
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLast() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -959,10 +932,6 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE putAndMoveToLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putAndMoveToLast(key, value); } }
|
||||
@Override
|
||||
public VALUE_TYPE putFirst(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putFirst(key, value); } }
|
||||
@Override
|
||||
public VALUE_TYPE putLast(KEY_TYPE key, VALUE_TYPE value) { synchronized(mutex) { return map.putLast(key, value); } }
|
||||
@Override
|
||||
public boolean moveToFirst(KEY_TYPE key) { synchronized(mutex) { return map.moveToFirst(key); } }
|
||||
@Override
|
||||
public boolean moveToLast(KEY_TYPE key) { synchronized(mutex) { return map.moveToLast(key); } }
|
||||
@ -983,25 +952,13 @@ public class MAPS
|
||||
@Override
|
||||
public VALUE_TYPE LAST_ENTRY_VALUE() { synchronized(mutex) { return map.LAST_ENTRY_VALUE(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE firstEntry() { synchronized(mutex) { return map.firstEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE lastEntry() { synchronized(mutex) { return map.lastEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollFirstEntry() { synchronized(mutex) { return map.pollFirstEntry(); } }
|
||||
@Override
|
||||
public MAP.Entry KEY_VALUE_GENERIC_TYPE pollLastEntry() { synchronized(mutex) { return map.pollLastEntry(); } }
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE copy() { synchronized(mutex) { return map.copy(); } }
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE keySet() {
|
||||
if(keys == null) keys = SETS.synchronize(map.keySet(), mutex);
|
||||
return (ORDERED_SET KEY_GENERIC_TYPE)keys;
|
||||
}
|
||||
@Override
|
||||
public VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE values() {
|
||||
if(values == null) values = VALUE_COLLECTIONS.synchronize(map.values(), mutex);
|
||||
return (VALUE_ORDERED_COLLECTION VALUE_GENERIC_TYPE)values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectOrderedSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> ENTRY_SET() {
|
||||
if(entrySet == null) entrySet = ObjectSets.synchronize(map.ENTRY_SET(), mutex);
|
||||
@ -1152,22 +1109,20 @@ public class MAPS
|
||||
public void REPLACE_VALUES(UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { map.REPLACE_VALUES(mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_ABSENT(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_PRESENT(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { synchronized(mutex) { return map.SUPPLY_IF_ABSENT(key, valueProvider); } }
|
||||
#if !VALUE_OBJECT
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTENonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTENonDefault(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENT(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_ABSENT(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_ABSENTNonDefault(KEY_TYPE key, FUNCTION KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_ABSENTNonDefault(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENT(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_PRESENT(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE COMPUTE_IF_PRESENTNonDefault(KEY_TYPE key, UNARY_OPERATOR KEY_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.COMPUTE_IF_PRESENTNonDefault(key, mappingFunction); } }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENT(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { synchronized(mutex) { return map.SUPPLY_IF_ABSENT(key, valueProvider); } }
|
||||
@Override
|
||||
public VALUE_TYPE SUPPLY_IF_ABSENTNonDefault(KEY_TYPE key, VALUE_SUPPLIER VALUE_GENERIC_TYPE valueProvider) { synchronized(mutex) { return map.SUPPLY_IF_ABSENTNonDefault(key, valueProvider); } }
|
||||
#endif
|
||||
@Override
|
||||
public VALUE_TYPE MERGE(KEY_TYPE key, VALUE_TYPE value, VALUE_UNARY_OPERATOR VALUE_VALUE_GENERIC_TYPE mappingFunction) { synchronized(mutex) { return map.MERGE(key, value, mappingFunction); } }
|
||||
@Override
|
||||
|
||||
@ -1,29 +1,16 @@
|
||||
package speiger.src.testers.PACKAGE.builder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.testing.AbstractTester;
|
||||
import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.Helpers;
|
||||
import com.google.common.collect.testing.OneSizeTestContainerGenerator;
|
||||
import com.google.common.collect.testing.SampleElements;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.Feature;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.sets.ORDERED_SET;
|
||||
import speiger.src.collections.PACKAGE.utils.LISTS;
|
||||
import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR;
|
||||
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetMoveTester;
|
||||
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetIterationTester;
|
||||
import speiger.src.testers.PACKAGE.tests.set.FILE_KEY_TYPEOrderedSetNavigationTester;
|
||||
import speiger.src.testers.PACKAGE.utils.SAMPLE_ELEMENTS;
|
||||
import speiger.src.testers.utils.SpecialFeature;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE extends SET_TEST_BUILDER KEY_GENERIC_TYPE {
|
||||
@ -48,68 +35,4 @@ public class ORDERED_SET_TEST_BUILDER KEY_GENERIC_TYPE extends SET_TEST_BUILDER
|
||||
#endignore
|
||||
return super.createTestSuite();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TestSuite> createDerivedSuites(
|
||||
FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE>> parentBuilder) {
|
||||
List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
|
||||
|
||||
if (!parentBuilder.getFeatures().contains(SpecialFeature.REVERSE)) {
|
||||
derivedSuites.add(createReverseSuite(parentBuilder));
|
||||
}
|
||||
|
||||
return derivedSuites;
|
||||
}
|
||||
|
||||
private TestSuite createReverseSuite(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Collection<CLASS_TYPE>, CLASS_TYPE>> parentBuilder) {
|
||||
TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE delegate = (TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator();
|
||||
|
||||
List<Feature<?>> features = new ArrayList<>();
|
||||
features.add(SpecialFeature.REVERSE);
|
||||
features.addAll(parentBuilder.getFeatures());
|
||||
features.remove(SpecialFeature.COPYING);
|
||||
features.remove(SpecialFeature.CHILDREN_COPY);
|
||||
|
||||
return ORDERED_SET_TEST_BUILDER.using(new TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE() {
|
||||
@Override
|
||||
public SampleElements<CLASS_TYPE> samples() {
|
||||
return delegate.samples();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SAMPLE_ELEMENTS KEY_GENERIC_TYPE getSamples() {
|
||||
return delegate.getSamples();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERABLE KEY_GENERIC_TYPE order(LIST KEY_GENERIC_TYPE insertionOrder) {
|
||||
return insertionOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<CLASS_TYPE> order(List<CLASS_TYPE> insertionOrder) {
|
||||
return insertionOrder;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE create(KEY_TYPE... elements) {
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES(elements);
|
||||
LISTS.reverse(list);
|
||||
return delegate.create(list.TO_ARRAY()).reversed();
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public ORDERED_SET KEY_GENERIC_TYPE create(Object... elements) {
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
for (Object e : elements) {
|
||||
list.add(CLASS_TO_KEY(e));
|
||||
}
|
||||
LISTS.reverse(list);
|
||||
return delegate.create(list.toArray()).reversed();
|
||||
}
|
||||
}).named(parentBuilder.getName() + " reversing").withFeatures(features)
|
||||
.suppressing(parentBuilder.getSuppressedTests()).createTestSuite();
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,11 +53,6 @@ import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapCl
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester;
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentNonDefaultTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentNonDefaultTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeNonDefaultTester;
|
||||
#endif
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapCopyTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsKeyTester;
|
||||
@ -83,9 +78,6 @@ import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapRe
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapReplaceTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSizeTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester;
|
||||
#if !VALUE_OBJECT
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentNonDefaultTester;
|
||||
#endif
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEMapToStringTester;
|
||||
import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder;
|
||||
import speiger.src.testers.objects.generators.TestObjectSetGenerator;
|
||||
@ -113,12 +105,6 @@ public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder
|
||||
protected List<Class<? extends AbstractTester>> getTesters() {
|
||||
List<Class<? extends AbstractTester>> testers = new ArrayList<>();
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapClearTester.class);
|
||||
#if !VALUE_OBJECT
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeNonDefaultTester.class);
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentNonDefaultTester.class);
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentNonDefaultTester.class);
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentNonDefaultTester.class);
|
||||
#endif
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester.class);
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester.class);
|
||||
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester.class);
|
||||
@ -238,17 +224,21 @@ public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder
|
||||
private static Set<Feature<?>> computeEntrySetFeatures(Set<Feature<?>> mapFeatures) {
|
||||
Set<Feature<?>> entrySetFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures);
|
||||
#ignore
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_ENTRY_QUERIES)) entrySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) entrySetFeatures.add(SpecialFeature.COPYING);
|
||||
else entrySetFeatures.remove(SpecialFeature.COPYING);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) entrySetFeatures.add(SpecialFeature.MODIFIABLE);
|
||||
else entrySetFeatures.remove(SpecialFeature.MODIFIABLE);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.REVERSE)) entrySetFeatures.add(SpecialFeature.REVERSE);
|
||||
else entrySetFeatures.remove(SpecialFeature.REVERSE);
|
||||
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_ENTRY_QUERIES)) {
|
||||
entrySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
}
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) {
|
||||
entrySetFeatures.add(SpecialFeature.COPYING);
|
||||
}
|
||||
else {
|
||||
entrySetFeatures.remove(SpecialFeature.COPYING);
|
||||
}
|
||||
if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) {
|
||||
entrySetFeatures.add(SpecialFeature.MODIFIABLE);
|
||||
}
|
||||
else {
|
||||
entrySetFeatures.remove(SpecialFeature.MODIFIABLE);
|
||||
}
|
||||
entrySetFeatures.add(SpecialFeature.MAP_ENTRY);
|
||||
#endignore
|
||||
return entrySetFeatures;
|
||||
@ -258,17 +248,23 @@ public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder
|
||||
Set<Feature<?>> keySetFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures);
|
||||
#ignore
|
||||
keySetFeatures.add(CollectionFeature.SUBSET_VIEW);
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) keySetFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
else if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEY_QUERIES)) keySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) keySetFeatures.add(SpecialFeature.COPYING);
|
||||
else keySetFeatures.remove(SpecialFeature.COPYING);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) keySetFeatures.add(SpecialFeature.MODIFIABLE);
|
||||
else keySetFeatures.remove(SpecialFeature.MODIFIABLE);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.REVERSE)) keySetFeatures.add(SpecialFeature.REVERSE);
|
||||
else keySetFeatures.remove(SpecialFeature.REVERSE);
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEYS)) {
|
||||
keySetFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
} else if (mapFeatures.contains(MapFeature.ALLOWS_NULL_KEY_QUERIES)) {
|
||||
keySetFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
}
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) {
|
||||
keySetFeatures.add(SpecialFeature.COPYING);
|
||||
}
|
||||
else {
|
||||
keySetFeatures.remove(SpecialFeature.COPYING);
|
||||
}
|
||||
if(mapFeatures.contains(SpecialFeature.MODIFIABLE)) {
|
||||
keySetFeatures.add(SpecialFeature.MODIFIABLE);
|
||||
}
|
||||
else {
|
||||
keySetFeatures.remove(SpecialFeature.MODIFIABLE);
|
||||
}
|
||||
#endignore
|
||||
return keySetFeatures;
|
||||
}
|
||||
@ -277,15 +273,18 @@ public class MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MapTestSuiteBuilder
|
||||
private static Set<Feature<?>> computeValuesCollectionFeatures(Set<Feature<?>> mapFeatures) {
|
||||
Set<Feature<?>> valuesCollectionFeatures = MapTestSuiteBuilder.computeCommonDerivedCollectionFeatures(mapFeatures);
|
||||
#ignore
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) valuesCollectionFeatures.add(SpecialFeature.COPYING);
|
||||
else valuesCollectionFeatures.remove(SpecialFeature.COPYING);
|
||||
|
||||
if(mapFeatures.contains(SpecialFeature.REVERSE)) valuesCollectionFeatures.add(SpecialFeature.REVERSE);
|
||||
else valuesCollectionFeatures.remove(SpecialFeature.REVERSE);
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUE_QUERIES)) {
|
||||
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_QUERIES);
|
||||
}
|
||||
if (mapFeatures.contains(MapFeature.ALLOWS_NULL_VALUES)) {
|
||||
valuesCollectionFeatures.add(CollectionFeature.ALLOWS_NULL_VALUES);
|
||||
}
|
||||
if(mapFeatures.contains(SpecialFeature.CHILDREN_COPY)) {
|
||||
valuesCollectionFeatures.add(SpecialFeature.COPYING);
|
||||
}
|
||||
else {
|
||||
valuesCollectionFeatures.remove(SpecialFeature.COPYING);
|
||||
}
|
||||
#endignore
|
||||
return valuesCollectionFeatures;
|
||||
}
|
||||
|
||||
@ -1,14 +1,9 @@
|
||||
package speiger.src.testers.PACKAGE.builder.maps;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.testing.AbstractTester;
|
||||
import com.google.common.collect.testing.FeatureSpecificTestSuiteBuilder;
|
||||
import com.google.common.collect.testing.OneSizeTestContainerGenerator;
|
||||
import com.google.common.collect.testing.features.CollectionFeature;
|
||||
import com.google.common.collect.testing.features.Feature;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
@ -17,7 +12,6 @@ import speiger.src.testers.PACKAGE.builder.SET_TEST_BUILDER;
|
||||
import speiger.src.testers.PACKAGE.generators.TEST_ORDERED_SET_GENERATOR;
|
||||
import speiger.src.testers.PACKAGE.generators.TEST_SET_GENERATOR;
|
||||
import speiger.src.testers.PACKAGE.generators.maps.TEST_ORDERED_MAP_GENERATOR;
|
||||
import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester;
|
||||
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester;
|
||||
#if !TYPE_OBJECT
|
||||
@ -26,7 +20,6 @@ import speiger.src.testers.objects.generators.TestObjectSetGenerator;
|
||||
import speiger.src.testers.objects.builder.ObjectOrderedSetTestSuiteBuilder;
|
||||
import speiger.src.testers.objects.generators.TestObjectOrderedSetGenerator;
|
||||
#endif
|
||||
import speiger.src.testers.utils.SpecialFeature;
|
||||
|
||||
@SuppressWarnings("javadoc")
|
||||
public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE
|
||||
@ -52,15 +45,6 @@ public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BU
|
||||
return super.createTestSuite();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TestSuite> createDerivedSuites(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>> parentBuilder) {
|
||||
List<TestSuite> derivedSuites = super.createDerivedSuites(parentBuilder);
|
||||
if (!parentBuilder.getFeatures().contains(SpecialFeature.REVERSE)) {
|
||||
derivedSuites.add(createReverseSuite(parentBuilder));
|
||||
}
|
||||
return derivedSuites;
|
||||
}
|
||||
|
||||
protected ObjectSetTestSuiteBuilder<MAP.Entry KEY_VALUE_GENERIC_TYPE> createDerivedEntrySetSuite(TestObjectSetGenerator<MAP.Entry KEY_VALUE_GENERIC_TYPE> entrySetGenerator) {
|
||||
return ObjectOrderedSetTestSuiteBuilder.using((TestObjectOrderedSetGenerator<MAP.Entry KEY_VALUE_GENERIC_TYPE>)entrySetGenerator);
|
||||
}
|
||||
@ -68,17 +52,4 @@ public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BU
|
||||
protected SET_TEST_BUILDER KEY_GENERIC_TYPE createDerivedKeySetSuite(TEST_SET_GENERATOR KEY_GENERIC_TYPE generator) {
|
||||
return ORDERED_SET_TEST_BUILDER.using((TEST_ORDERED_SET_GENERATOR KEY_GENERIC_TYPE)generator);
|
||||
}
|
||||
|
||||
private TestSuite createReverseSuite(FeatureSpecificTestSuiteBuilder<?, ? extends OneSizeTestContainerGenerator<Map<CLASS_TYPE, CLASS_VALUE_TYPE>, Map.Entry<CLASS_TYPE, CLASS_VALUE_TYPE>>> parentBuilder) {
|
||||
TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE delegate = (TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE) parentBuilder.getSubjectGenerator().getInnerGenerator();
|
||||
|
||||
List<Feature<?>> features = new ArrayList<>();
|
||||
features.add(SpecialFeature.REVERSE);
|
||||
features.addAll(parentBuilder.getFeatures());
|
||||
features.remove(SpecialFeature.COPYING);
|
||||
features.remove(SpecialFeature.CHILDREN_COPY);
|
||||
return ORDERED_MAP_TEST_BUILDER.using(new DERIVED_MAP_GENERATORS.ReverseTestOrderedMapGenerator(delegate))
|
||||
.named(parentBuilder.getName() + " reversed").withFeatures(features)
|
||||
.suppressing(parentBuilder.getSuppressedTests()).createTestSuite();
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,6 @@ import speiger.src.collections.PACKAGE.maps.abstracts.ABSTRACT_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.MAP.Entry;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.NAVIGABLE_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
|
||||
import speiger.src.collections.PACKAGE.maps.interfaces.SORTED_MAP;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
@ -207,22 +206,6 @@ public class DERIVED_MAP_GENERATORS {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ReverseTestOrderedMapGenerator KEY_VALUE_GENERIC_TYPE extends MapGenerator KEY_VALUE_GENERIC_TYPE implements TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE {
|
||||
TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent;
|
||||
|
||||
public ReverseTestOrderedMapGenerator(TEST_ORDERED_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent) {
|
||||
super(parent);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORDERED_MAP KEY_VALUE_GENERIC_TYPE create(Entry KEY_VALUE_GENERIC_TYPE... elements) {
|
||||
ObjectList<Entry KEY_VALUE_GENERIC_TYPE> entries = new ObjectArrayList<Entry KEY_VALUE_GENERIC_TYPE>(elements);
|
||||
ObjectLists.reverse(entries);
|
||||
return ((ORDERED_MAP KEY_VALUE_GENERIC_TYPE)parent.create(entries.toArray(Entry[]::new))).reversed();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MapGenerator KEY_VALUE_GENERIC_TYPE implements TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
TEST_MAP_GENERATOR KEY_VALUE_GENERIC_TYPE parent;
|
||||
|
||||
@ -1,153 +0,0 @@
|
||||
package speiger.src.testers.PACKAGE.tests.maps;
|
||||
|
||||
#ignore
|
||||
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
|
||||
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
|
||||
#endignore
|
||||
#if !VALUE_BOOLEAN
|
||||
#ignore
|
||||
import static com.google.common.collect.testing.features.CollectionSize.ONE;
|
||||
#endignore
|
||||
#endif
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.MapFeature;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
|
||||
|
||||
@Ignore
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_supportedAbsent() {
|
||||
#if VALUE_BOOLEAN
|
||||
getMap().setDefaultReturnValue(true);
|
||||
#endif
|
||||
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
|
||||
assertEquals(k3(), k);
|
||||
return v3();
|
||||
}));
|
||||
expectAdded(e3());
|
||||
}
|
||||
|
||||
#if !VALUE_BOOLEAN
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_supportedAbsentFirst() {
|
||||
getMap().setDefaultReturnValue(v0());
|
||||
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
|
||||
assertEquals(k0(), k);
|
||||
return v3();
|
||||
}));
|
||||
expectContents(entry(k0(), v3()));
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_supportedAbsentSameResult() {
|
||||
getMap().setDefaultReturnValue(v0());
|
||||
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
|
||||
assertEquals(k0(), k);
|
||||
return v0();
|
||||
}));
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#endif
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_supportedPresent() {
|
||||
assertEquals("COMPUTE_IF_ABSENT(present, function) should return existing value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
|
||||
throw new AssertionFailedError();
|
||||
}));
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_functionReturnsNullNotInserted() {
|
||||
assertEquals("COMPUTE_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
|
||||
assertEquals(k3(), k);
|
||||
return INVALID_VALUE;
|
||||
}));
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
static class ExpectedException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_functionThrows() {
|
||||
try {
|
||||
getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
|
||||
assertEquals(k3(), k);
|
||||
throw new ExpectedException();
|
||||
});
|
||||
fail("Expected ExpectedException");
|
||||
} catch (ExpectedException expected) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_unsupportedAbsent() {
|
||||
try {
|
||||
getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
|
||||
// allowed to be called
|
||||
assertEquals(k3(), k);
|
||||
return v3();
|
||||
});
|
||||
fail("COMPUTE_IF_ABSENT(notPresent, function) should throw");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_unsupportedPresentExistingValue() {
|
||||
try {
|
||||
assertEquals("COMPUTE_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
|
||||
assertEquals(k0(), k);
|
||||
return v0();
|
||||
}));
|
||||
} catch (UnsupportedOperationException tolerated) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_unsupportedPresentDifferentValue() {
|
||||
try {
|
||||
assertEquals("COMPUTE_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
|
||||
assertEquals(k0(), k);
|
||||
return v3();
|
||||
}));
|
||||
} catch (UnsupportedOperationException tolerated) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_supportedAbsent() {
|
||||
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENT(k3(), k -> {
|
||||
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
|
||||
assertEquals(k3(), k);
|
||||
return v3();
|
||||
}));
|
||||
@ -40,19 +40,11 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
|
||||
#endignore
|
||||
public void testComputeIfAbsent_supportedAbsentFirst() {
|
||||
getMap().setDefaultReturnValue(v0());
|
||||
#if VALUE_OBJECT
|
||||
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
|
||||
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
|
||||
assertEquals(k0(), k);
|
||||
return v3();
|
||||
}));
|
||||
expectContents(entry(k0(), v3()));
|
||||
#else
|
||||
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
|
||||
assertEquals(k0(), k);
|
||||
return v3();
|
||||
}));
|
||||
expectUnchanged();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -61,7 +53,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
|
||||
#endignore
|
||||
public void testComputeIfAbsent_supportedAbsentSameResult() {
|
||||
getMap().setDefaultReturnValue(v0());
|
||||
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
|
||||
assertEquals("COMPUTE_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
|
||||
assertEquals(k0(), k);
|
||||
return v0();
|
||||
}));
|
||||
@ -74,7 +66,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_supportedPresent() {
|
||||
assertEquals("COMPUTE_IF_ABSENT(present, function) should return existing value", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
|
||||
assertEquals("COMPUTE_IF_ABSENT(present, function) should return existing value", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
|
||||
throw new AssertionFailedError();
|
||||
}));
|
||||
expectUnchanged();
|
||||
@ -84,15 +76,11 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testComputeIfAbsent_functionReturnsNullNotInserted() {
|
||||
assertEquals("COMPUTE_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_ABSENT(k3(), k -> {
|
||||
assertEquals("COMPUTE_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
|
||||
assertEquals(k3(), k);
|
||||
return INVALID_VALUE;
|
||||
}));
|
||||
#if VALUE_OBJECT
|
||||
expectUnchanged();
|
||||
#else
|
||||
expectAdded(entry(k3(), INVALID_VALUE));
|
||||
#endif
|
||||
}
|
||||
|
||||
static class ExpectedException extends RuntimeException {
|
||||
@ -104,7 +92,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
|
||||
#endignore
|
||||
public void testComputeIfAbsent_functionThrows() {
|
||||
try {
|
||||
getMap().COMPUTE_IF_ABSENT(k3(), k -> {
|
||||
getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
|
||||
assertEquals(k3(), k);
|
||||
throw new ExpectedException();
|
||||
});
|
||||
@ -119,7 +107,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
|
||||
#endignore
|
||||
public void testComputeIfAbsent_unsupportedAbsent() {
|
||||
try {
|
||||
getMap().COMPUTE_IF_ABSENT(k3(), k -> {
|
||||
getMap().COMPUTE_IF_ABSENTNonDefault(k3(), k -> {
|
||||
// allowed to be called
|
||||
assertEquals(k3(), k);
|
||||
return v3();
|
||||
@ -136,7 +124,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
|
||||
#endignore
|
||||
public void testComputeIfAbsent_unsupportedPresentExistingValue() {
|
||||
try {
|
||||
assertEquals("COMPUTE_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
|
||||
assertEquals("COMPUTE_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
|
||||
assertEquals(k0(), k);
|
||||
return v0();
|
||||
}));
|
||||
@ -151,7 +139,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfAbsentTester KEY_VALUE_GEN
|
||||
#endignore
|
||||
public void testComputeIfAbsent_unsupportedPresentDifferentValue() {
|
||||
try {
|
||||
assertEquals("COMPUTE_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENT(k0(), k -> {
|
||||
assertEquals("COMPUTE_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().COMPUTE_IF_ABSENTNonDefault(k0(), k -> {
|
||||
assertEquals(k0(), k);
|
||||
return v3();
|
||||
}));
|
||||
|
||||
@ -1,104 +0,0 @@
|
||||
package speiger.src.testers.PACKAGE.tests.maps;
|
||||
|
||||
#ignore
|
||||
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
|
||||
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
|
||||
#endignore
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.MapFeature;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
|
||||
|
||||
@Ignore
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testComputeIfPresent_supportedAbsent() {
|
||||
assertEquals("COMPUTE_IF_PRESENT(notPresent, function) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> {
|
||||
throw new AssertionFailedError();
|
||||
}));
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#if !VALUE_BOOLEAN
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testComputeIfPresent_supportedPresent() {
|
||||
assertEquals("COMPUTE_IF_PRESENT(present, function) should return new value", v3(), getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
return v3();
|
||||
}));
|
||||
expectReplacement(entry(k0(), v3()));
|
||||
}
|
||||
|
||||
#endif
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testComputeIfPresent_functionReturnsNull() {
|
||||
assertEquals("COMPUTE_IF_PRESENT(present, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
return INVALID_VALUE;
|
||||
}));
|
||||
expectMissing(e0());
|
||||
}
|
||||
|
||||
static class ExpectedException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testComputeIfPresent_functionThrows() {
|
||||
try {
|
||||
getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
throw new ExpectedException();
|
||||
});
|
||||
fail("Expected ExpectedException");
|
||||
} catch (ExpectedException expected) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testComputeIfPresent_unsupportedAbsent() {
|
||||
try {
|
||||
getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> {
|
||||
throw new AssertionFailedError();
|
||||
});
|
||||
} catch (UnsupportedOperationException tolerated) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testComputeIfPresent_unsupportedPresent() {
|
||||
try {
|
||||
getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> v3());
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testComputeIfPresent_supportedAbsent() {
|
||||
assertEquals("COMPUTE_IF_PRESENT(notPresent, function) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENT(k3(), (k, v) -> {
|
||||
assertEquals("COMPUTE_IF_PRESENT(notPresent, function) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> {
|
||||
throw new AssertionFailedError();
|
||||
}));
|
||||
expectUnchanged();
|
||||
@ -32,7 +32,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testComputeIfPresent_supportedPresent() {
|
||||
assertEquals("COMPUTE_IF_PRESENT(present, function) should return new value", v3(), getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> {
|
||||
assertEquals("COMPUTE_IF_PRESENT(present, function) should return new value", v3(), getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
return v3();
|
||||
@ -45,7 +45,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testComputeIfPresent_functionReturnsNull() {
|
||||
assertEquals("COMPUTE_IF_PRESENT(present, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> {
|
||||
assertEquals("COMPUTE_IF_PRESENT(present, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
return INVALID_VALUE;
|
||||
@ -63,7 +63,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
|
||||
#endignore
|
||||
public void testComputeIfPresent_functionThrows() {
|
||||
try {
|
||||
getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> {
|
||||
getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
throw new ExpectedException();
|
||||
@ -79,7 +79,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
|
||||
#endignore
|
||||
public void testComputeIfPresent_unsupportedAbsent() {
|
||||
try {
|
||||
getMap().COMPUTE_IF_PRESENT(k3(), (k, v) -> {
|
||||
getMap().COMPUTE_IF_PRESENTNonDefault(k3(), (k, v) -> {
|
||||
throw new AssertionFailedError();
|
||||
});
|
||||
} catch (UnsupportedOperationException tolerated) {
|
||||
@ -93,7 +93,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeIfPresentTester KEY_VALUE_GE
|
||||
#endignore
|
||||
public void testComputeIfPresent_unsupportedPresent() {
|
||||
try {
|
||||
getMap().COMPUTE_IF_PRESENT(k0(), (k, v) -> v3());
|
||||
getMap().COMPUTE_IF_PRESENTNonDefault(k0(), (k, v) -> v3());
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
}
|
||||
|
||||
@ -1,148 +0,0 @@
|
||||
package speiger.src.testers.PACKAGE.tests.maps;
|
||||
|
||||
#ignore
|
||||
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
|
||||
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
|
||||
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
|
||||
#endignore
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.MapFeature;
|
||||
|
||||
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
|
||||
|
||||
@Ignore
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
#if !VALUE_BOOLEAN
|
||||
#ignore
|
||||
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
|
||||
#endignore
|
||||
public void testCompute_absentToPresent() {
|
||||
assertEquals("Map.COMPUTE(absent, functionReturningValue) should return value", v3(), getMap().COMPUTENonDefault(k3(), (k, v) -> {
|
||||
assertEquals(k3(), k);
|
||||
assertEquals(INVALID_VALUE, v);
|
||||
return v3();
|
||||
}));
|
||||
expectAdded(e3());
|
||||
assertEquals(getNumElements() + 1, getMap().size());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
|
||||
#endignore
|
||||
public void testCompute_absentToAbsent() {
|
||||
assertEquals("Map.COMPUTE(absent, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k3(), (k, v) -> {
|
||||
assertEquals(k3(), k);
|
||||
assertEquals(INVALID_VALUE, v);
|
||||
return INVALID_VALUE;
|
||||
}));
|
||||
expectUnchanged();
|
||||
assertEquals(getNumElements(), getMap().size());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testCompute_presentToPresent() {
|
||||
#if VALUE_BOOLEAN
|
||||
getMap().setDefaultReturnValue(true);
|
||||
#endif
|
||||
assertEquals("Map.COMPUTE(present, functionReturningValue) should return new value", v3(), getMap().COMPUTENonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
return v3();
|
||||
}));
|
||||
expectReplacement(entry(k0(), v3()));
|
||||
assertEquals(getNumElements(), getMap().size());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testCompute_presentToAbsent() {
|
||||
assertEquals("Map.COMPUTE(present, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
return INVALID_VALUE;
|
||||
}));
|
||||
expectMissing(e0());
|
||||
expectMissingKeys(k0());
|
||||
assertEquals(getNumElements() - 1, getMap().size());
|
||||
}
|
||||
|
||||
static class ExpectedException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testCompute_presentFunctionThrows() {
|
||||
try {
|
||||
getMap().COMPUTENonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
throw new ExpectedException();
|
||||
});
|
||||
fail("Expected ExpectedException");
|
||||
} catch (ExpectedException expected) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
|
||||
#endignore
|
||||
public void testCompute_absentFunctionThrows() {
|
||||
try {
|
||||
getMap().COMPUTENonDefault(k3(), (k, v) -> {
|
||||
assertEquals(k3(), k);
|
||||
assertEquals(INVALID_VALUE, v);
|
||||
throw new ExpectedException();
|
||||
});
|
||||
fail("Expected ExpectedException");
|
||||
} catch (ExpectedException expected) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_REMOVE)
|
||||
#endignore
|
||||
public void testCompute_removeAbsent() {
|
||||
try {
|
||||
getMap().COMPUTENonDefault(k3(), (k, v) -> {
|
||||
assertEquals(k3(), k);
|
||||
assertEquals(INVALID_VALUE, v);
|
||||
return INVALID_VALUE;
|
||||
});
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testCompute_putAbsent() {
|
||||
try {
|
||||
getMap().COMPUTENonDefault(k3(), (k, v) -> {
|
||||
assertEquals(k3(), k);
|
||||
assertEquals(INVALID_VALUE, v);
|
||||
return INVALID_VALUE;
|
||||
});
|
||||
fail("Expected UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
|
||||
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
|
||||
#endignore
|
||||
public void testCompute_absentToPresent() {
|
||||
assertEquals("Map.COMPUTE(absent, functionReturningValue) should return value", v3(), getMap().COMPUTE(k3(), (k, v) -> {
|
||||
assertEquals("Map.COMPUTE(absent, functionReturningValue) should return value", v3(), getMap().COMPUTENonDefault(k3(), (k, v) -> {
|
||||
assertEquals(k3(), k);
|
||||
assertEquals(INVALID_VALUE, v);
|
||||
return v3();
|
||||
@ -34,18 +34,13 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
|
||||
@MapFeature.Require({ SUPPORTS_PUT, SUPPORTS_REMOVE })
|
||||
#endignore
|
||||
public void testCompute_absentToAbsent() {
|
||||
assertEquals("Map.COMPUTE(absent, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE(k3(), (k, v) -> {
|
||||
assertEquals("Map.COMPUTE(absent, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k3(), (k, v) -> {
|
||||
assertEquals(k3(), k);
|
||||
assertEquals(INVALID_VALUE, v);
|
||||
return INVALID_VALUE;
|
||||
}));
|
||||
#if VALUE_OBJECT
|
||||
expectUnchanged();
|
||||
assertEquals(getNumElements(), getMap().size());
|
||||
#else
|
||||
expectAdded(entry(k3(), INVALID_VALUE));
|
||||
assertEquals(getNumElements()+1, getMap().size());
|
||||
#endif
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -53,7 +48,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testCompute_presentToPresent() {
|
||||
assertEquals("Map.COMPUTE(present, functionReturningValue) should return new value", v3(), getMap().COMPUTE(k0(), (k, v) -> {
|
||||
assertEquals("Map.COMPUTE(present, functionReturningValue) should return new value", v3(), getMap().COMPUTENonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
return v3();
|
||||
@ -67,19 +62,14 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testCompute_presentToAbsent() {
|
||||
assertEquals("Map.COMPUTE(present, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTE(k0(), (k, v) -> {
|
||||
assertEquals("Map.COMPUTE(present, functionReturningNull) should return INVALID_VALUE", INVALID_VALUE, getMap().COMPUTENonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
return INVALID_VALUE;
|
||||
}));
|
||||
#if VALUE_OBJECT
|
||||
expectMissing(e0());
|
||||
expectMissingKeys(k0());
|
||||
assertEquals(getNumElements() - 1, getMap().size());
|
||||
#else
|
||||
expectReplacement(entry(k0(), INVALID_VALUE));
|
||||
assertEquals(getNumElements(), getMap().size());
|
||||
#endif
|
||||
}
|
||||
|
||||
static class ExpectedException extends RuntimeException {
|
||||
@ -92,7 +82,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
|
||||
#endignore
|
||||
public void testCompute_presentFunctionThrows() {
|
||||
try {
|
||||
getMap().COMPUTE(k0(), (k, v) -> {
|
||||
getMap().COMPUTENonDefault(k0(), (k, v) -> {
|
||||
assertEquals(k0(), k);
|
||||
assertEquals(v0(), v);
|
||||
throw new ExpectedException();
|
||||
@ -108,7 +98,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
|
||||
#endignore
|
||||
public void testCompute_absentFunctionThrows() {
|
||||
try {
|
||||
getMap().COMPUTE(k3(), (k, v) -> {
|
||||
getMap().COMPUTENonDefault(k3(), (k, v) -> {
|
||||
assertEquals(k3(), k);
|
||||
assertEquals(INVALID_VALUE, v);
|
||||
throw new ExpectedException();
|
||||
@ -124,7 +114,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
|
||||
#endignore
|
||||
public void testCompute_removeAbsent() {
|
||||
try {
|
||||
getMap().COMPUTE(k3(), (k, v) -> {
|
||||
getMap().COMPUTENonDefault(k3(), (k, v) -> {
|
||||
assertEquals(k3(), k);
|
||||
assertEquals(INVALID_VALUE, v);
|
||||
return INVALID_VALUE;
|
||||
@ -140,7 +130,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapComputeTester KEY_VALUE_GENERIC_TYP
|
||||
#endignore
|
||||
public void testCompute_putAbsent() {
|
||||
try {
|
||||
getMap().COMPUTE(k3(), (k, v) -> {
|
||||
getMap().COMPUTENonDefault(k3(), (k, v) -> {
|
||||
assertEquals(k3(), k);
|
||||
assertEquals(INVALID_VALUE, v);
|
||||
return INVALID_VALUE;
|
||||
|
||||
@ -1,130 +0,0 @@
|
||||
package speiger.src.testers.PACKAGE.tests.maps;
|
||||
|
||||
#ignore
|
||||
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
|
||||
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
|
||||
#endignore
|
||||
#if !VALUE_BOOLEAN
|
||||
#ignore
|
||||
import static com.google.common.collect.testing.features.CollectionSize.ONE;
|
||||
#endignore
|
||||
#endif
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
import com.google.common.collect.testing.features.CollectionSize;
|
||||
import com.google.common.collect.testing.features.MapFeature;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
|
||||
|
||||
@Ignore
|
||||
@SuppressWarnings("javadoc")
|
||||
public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentNonDefaultTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
|
||||
{
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_supportedAbsent() {
|
||||
#if VALUE_BOOLEAN
|
||||
getMap().setDefaultReturnValue(true);
|
||||
#endif
|
||||
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3));
|
||||
expectAdded(e3());
|
||||
}
|
||||
|
||||
#if !VALUE_BOOLEAN
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_supportedAbsentFirst() {
|
||||
getMap().setDefaultReturnValue(v0());
|
||||
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3));
|
||||
expectContents(entry(k0(), v3()));
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_supportedAbsentSameResult() {
|
||||
getMap().setDefaultReturnValue(v0());
|
||||
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0));
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#endif
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_supportedPresent() {
|
||||
assertEquals("SUPPLY_IF_ABSENT(present, function) should return existing value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), () -> {
|
||||
throw new AssertionFailedError();
|
||||
}));
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_functionReturnsNullNotInserted() {
|
||||
assertEquals("SUPPLY_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> INVALID_VALUE));
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
static class ExpectedException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_functionThrows() {
|
||||
try {
|
||||
getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> {
|
||||
throw new ExpectedException();
|
||||
});
|
||||
fail("Expected ExpectedException");
|
||||
} catch (ExpectedException expected) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_unsupportedAbsent() {
|
||||
try {
|
||||
getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3);
|
||||
fail("SUPPLY_IF_ABSENT(notPresent, function) should throw");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_unsupportedPresentExistingValue() {
|
||||
try {
|
||||
assertEquals("SUPPLY_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0));
|
||||
} catch (UnsupportedOperationException tolerated) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
#ignore
|
||||
@MapFeature.Require(absent = SUPPORTS_PUT)
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_unsupportedPresentDifferentValue() {
|
||||
try {
|
||||
assertEquals("SUPPLY_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3));
|
||||
} catch (UnsupportedOperationException tolerated) {
|
||||
}
|
||||
expectUnchanged();
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_supportedAbsent() {
|
||||
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENT(k3(), this::v3));
|
||||
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3));
|
||||
expectAdded(e3());
|
||||
}
|
||||
|
||||
@ -37,13 +37,8 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_supportedAbsentFirst() {
|
||||
getMap().setDefaultReturnValue(v0());
|
||||
#if VALUE_OBJECT
|
||||
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENT(k0(), this::v3));
|
||||
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v3(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3));
|
||||
expectContents(entry(k0(), v3()));
|
||||
#else
|
||||
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v3));
|
||||
expectUnchanged();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -52,7 +47,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_supportedAbsentSameResult() {
|
||||
getMap().setDefaultReturnValue(v0());
|
||||
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v0));
|
||||
assertEquals("SUPPLY_IF_ABSENT(notPresent, function) should return new value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0));
|
||||
expectUnchanged();
|
||||
}
|
||||
|
||||
@ -62,7 +57,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
|
||||
@CollectionSize.Require(absent = ZERO)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_supportedPresent() {
|
||||
assertEquals("SUPPLY_IF_ABSENT(present, function) should return existing value", v0(), getMap().SUPPLY_IF_ABSENT(k0(), () -> {
|
||||
assertEquals("SUPPLY_IF_ABSENT(present, function) should return existing value", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), () -> {
|
||||
throw new AssertionFailedError();
|
||||
}));
|
||||
expectUnchanged();
|
||||
@ -72,12 +67,8 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
|
||||
@MapFeature.Require(SUPPORTS_PUT)
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_functionReturnsNullNotInserted() {
|
||||
assertEquals("SUPPLY_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().SUPPLY_IF_ABSENT(k3(), () -> INVALID_VALUE));
|
||||
#if VALUE_OBJECT
|
||||
assertEquals("SUPPLY_IF_ABSENT(absent, returnsNull) should return INVALID_VALUE", INVALID_VALUE, getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> INVALID_VALUE));
|
||||
expectUnchanged();
|
||||
#else
|
||||
expectAdded(entry(k3(), INVALID_VALUE));
|
||||
#endif
|
||||
}
|
||||
|
||||
static class ExpectedException extends RuntimeException {
|
||||
@ -89,7 +80,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_functionThrows() {
|
||||
try {
|
||||
getMap().SUPPLY_IF_ABSENT(k3(), () -> {
|
||||
getMap().SUPPLY_IF_ABSENTNonDefault(k3(), () -> {
|
||||
throw new ExpectedException();
|
||||
});
|
||||
fail("Expected ExpectedException");
|
||||
@ -103,7 +94,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_unsupportedAbsent() {
|
||||
try {
|
||||
getMap().SUPPLY_IF_ABSENT(k3(), this::v3);
|
||||
getMap().SUPPLY_IF_ABSENTNonDefault(k3(), this::v3);
|
||||
fail("SUPPLY_IF_ABSENT(notPresent, function) should throw");
|
||||
} catch (UnsupportedOperationException expected) {
|
||||
}
|
||||
@ -116,7 +107,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_unsupportedPresentExistingValue() {
|
||||
try {
|
||||
assertEquals("SUPPLY_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v0));
|
||||
assertEquals("SUPPLY_IF_ABSENT(present, returnsCurrentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v0));
|
||||
} catch (UnsupportedOperationException tolerated) {
|
||||
}
|
||||
expectUnchanged();
|
||||
@ -128,7 +119,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapSupplyIfAbsentTester KEY_VALUE_GENE
|
||||
#endignore
|
||||
public void testSupplyIfAbsent_unsupportedPresentDifferentValue() {
|
||||
try {
|
||||
assertEquals("SUPPLY_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENT(k0(), this::v3));
|
||||
assertEquals("SUPPLY_IF_ABSENT(present, returnsDifferentValue) should return present or throw", v0(), getMap().SUPPLY_IF_ABSENTNonDefault(k0(), this::v3));
|
||||
} catch (UnsupportedOperationException tolerated) {
|
||||
}
|
||||
expectUnchanged();
|
||||
|
||||
@ -45,10 +45,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testaddMoveToFirstMissing()
|
||||
{
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(true, orderedSet.addAndMoveToFirst(e4()));
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(e4(), orderedSet.GET_FIRST_KEY());
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(e4(), orderedSet.FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -57,10 +57,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testaddMoveToFirstPreset()
|
||||
{
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(false, orderedSet.addAndMoveToFirst(c));
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(c, orderedSet.GET_FIRST_KEY());
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(c, orderedSet.FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -69,10 +69,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testaddMoveToLastMissing()
|
||||
{
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(true, orderedSet.addAndMoveToLast(e4()));
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(e4(), orderedSet.GET_LAST_KEY());
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(e4(), orderedSet.LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -81,10 +81,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testaddMoveToLastPreset()
|
||||
{
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(false, orderedSet.addAndMoveToLast(a));
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(a, orderedSet.GET_LAST_KEY());
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(a, orderedSet.LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -93,9 +93,9 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveToFirstMissing()
|
||||
{
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(false, orderedSet.moveToFirst(e4()));
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -104,10 +104,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveToFirstPreset()
|
||||
{
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(true, orderedSet.moveToFirst(c));
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(c, orderedSet.GET_FIRST_KEY());
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(c, orderedSet.FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -116,9 +116,9 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveToLastMissing()
|
||||
{
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(false, orderedSet.moveToLast(e4()));
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -127,10 +127,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveToLastPreset()
|
||||
{
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(true, orderedSet.moveToLast(a));
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(a, orderedSet.GET_LAST_KEY());
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(a, orderedSet.LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -139,10 +139,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveCenterToLast()
|
||||
{
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertTrue(orderedSet.moveToLast(e1()));
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(e1(), orderedSet.GET_LAST_KEY());
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(e1(), orderedSet.LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -151,10 +151,10 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveCenterToFirst()
|
||||
{
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertTrue(orderedSet.moveToFirst(e1()));
|
||||
assertNotEquals(c, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(e1(), orderedSet.GET_FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.FIRST_KEY());
|
||||
assertEquals(e1(), orderedSet.FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -163,13 +163,13 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveForthAndBack()
|
||||
{
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertTrue(orderedSet.moveToLast(e0()));
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(a, orderedSet.GET_LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(a, orderedSet.LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertTrue(orderedSet.moveToFirst(e0()));
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -178,13 +178,13 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testMoveBackAndForth()
|
||||
{
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertTrue(orderedSet.moveToFirst(e2()));
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(c, orderedSet.GET_FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(c, orderedSet.FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertTrue(orderedSet.moveToLast(e2()));
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -193,13 +193,13 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testAddForthAndBack()
|
||||
{
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
assertFalse(orderedSet.addAndMoveToLast(e0()));
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(a, orderedSet.GET_LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertEquals(a, orderedSet.LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertFalse(orderedSet.addAndMoveToFirst(e0()));
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@ -208,13 +208,13 @@ public class FILE_KEY_TYPEOrderedSetMoveTester KEY_GENERIC_TYPE extends ABSTRACT
|
||||
#endignore
|
||||
public void testAddBackAndForth()
|
||||
{
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
assertFalse(orderedSet.addAndMoveToFirst(e2()));
|
||||
assertNotEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(c, orderedSet.GET_FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertNotEquals(a, orderedSet.FIRST_KEY());
|
||||
assertEquals(c, orderedSet.FIRST_KEY());
|
||||
assertNotEquals(c, orderedSet.LAST_KEY());
|
||||
assertFalse(orderedSet.addAndMoveToLast(e2()));
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
|
||||
@ -68,7 +68,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
int polled = 0;
|
||||
int expectedPolls = orderedSet.size();
|
||||
while(polled < expectedPolls) {
|
||||
orderedSet.REMOVE_FIRST_KEY();
|
||||
orderedSet.POLL_FIRST_KEY();
|
||||
polled++;
|
||||
}
|
||||
assertTrue("Map should be empty", orderedSet.isEmpty());
|
||||
@ -82,7 +82,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
int polled = 0;
|
||||
int expectedPolls = orderedSet.size();
|
||||
while(polled < expectedPolls) {
|
||||
orderedSet.REMOVE_LAST_KEY();
|
||||
orderedSet.POLL_LAST_KEY();
|
||||
polled++;
|
||||
}
|
||||
assertTrue("Map should be empty", orderedSet.isEmpty());
|
||||
@ -94,8 +94,8 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testEmptySetPollFirst() {
|
||||
try {
|
||||
orderedSet.REMOVE_FIRST_KEY();
|
||||
fail("OrderedSet.REMOVE_FIRST_KEY should throw NoSuchElementException");
|
||||
orderedSet.POLL_FIRST_KEY();
|
||||
fail("OrderedSet.POLL_FIRST_KEY should throw NoSuchElementException");
|
||||
} catch (NoSuchElementException e) {
|
||||
}
|
||||
expectUnchanged();
|
||||
@ -107,8 +107,8 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testEmptySetPollLast() {
|
||||
try {
|
||||
orderedSet.REMOVE_LAST_KEY();
|
||||
fail("OrderedSet.REMOVE_LAST_KEY should throw NoSuchElementException");
|
||||
orderedSet.POLL_LAST_KEY();
|
||||
fail("OrderedSet.POLL_LAST_KEY should throw NoSuchElementException");
|
||||
} catch (NoSuchElementException e) {
|
||||
}
|
||||
expectUnchanged();
|
||||
@ -119,8 +119,8 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testUnsupportedSetPollFirst() {
|
||||
try {
|
||||
orderedSet.REMOVE_FIRST_KEY();
|
||||
fail("OrderedSet.REMOVE_FIRST_KEY should throw UnsupportedOperationException");
|
||||
orderedSet.POLL_FIRST_KEY();
|
||||
fail("OrderedSet.POLL_FIRST_KEY should throw UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
expectUnchanged();
|
||||
@ -131,8 +131,8 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testUnsupportedSetPollLast() {
|
||||
try {
|
||||
orderedSet.REMOVE_LAST_KEY();
|
||||
fail("OrderedSet.REMOVE_LAST_KEY should throw UnsupportedOperationException");
|
||||
orderedSet.POLL_LAST_KEY();
|
||||
fail("OrderedSet.POLL_LAST_KEY should throw UnsupportedOperationException");
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
expectUnchanged();
|
||||
@ -143,7 +143,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testSingletonSetPollFirst() {
|
||||
assertEquals(a, orderedSet.REMOVE_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.POLL_FIRST_KEY());
|
||||
assertTrue(orderedSet.isEmpty());
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testSingletonSetPollLast() {
|
||||
assertEquals(a, orderedSet.REMOVE_LAST_KEY());
|
||||
assertEquals(a, orderedSet.POLL_LAST_KEY());
|
||||
assertTrue(orderedSet.isEmpty());
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
@CollectionSize.Require(SEVERAL)
|
||||
#endignore
|
||||
public void testPollFirst() {
|
||||
assertEquals(a, orderedSet.REMOVE_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.POLL_FIRST_KEY());
|
||||
assertEquals(values.subList(1, values.size()), HELPERS.copyToList(orderedSet));
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
@CollectionSize.Require(SEVERAL)
|
||||
#endignore
|
||||
public void testPollLast() {
|
||||
assertEquals(c, orderedSet.REMOVE_LAST_KEY());
|
||||
assertEquals(c, orderedSet.POLL_LAST_KEY());
|
||||
assertEquals(values.subList(0, values.size()-1), HELPERS.copyToList(orderedSet));
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testPollFirstUnsupported() {
|
||||
try {
|
||||
orderedSet.REMOVE_FIRST_KEY();
|
||||
orderedSet.POLL_FIRST_KEY();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
@ -190,7 +190,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testPollLastUnsupported() {
|
||||
try {
|
||||
orderedSet.REMOVE_LAST_KEY();
|
||||
orderedSet.POLL_LAST_KEY();
|
||||
fail();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
@ -201,7 +201,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testEmptySetFirst() {
|
||||
try {
|
||||
orderedSet.GET_FIRST_KEY();
|
||||
orderedSet.FIRST_KEY();
|
||||
fail();
|
||||
} catch (NoSuchElementException e) {
|
||||
}
|
||||
@ -212,7 +212,7 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
#endignore
|
||||
public void testEmptySetLast() {
|
||||
try {
|
||||
orderedSet.GET_LAST_KEY();
|
||||
orderedSet.LAST_KEY();
|
||||
fail();
|
||||
} catch (NoSuchElementException e) {
|
||||
}
|
||||
@ -222,27 +222,27 @@ public class FILE_KEY_TYPEOrderedSetNavigationTester KEY_GENERIC_TYPE extends AB
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testSingletonSetFirst() {
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@CollectionSize.Require(ONE)
|
||||
#endignore
|
||||
public void testSingletonSetLast() {
|
||||
assertEquals(a, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(a, orderedSet.LAST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@CollectionSize.Require(SEVERAL)
|
||||
#endignore
|
||||
public void testFirst() {
|
||||
assertEquals(a, orderedSet.GET_FIRST_KEY());
|
||||
assertEquals(a, orderedSet.FIRST_KEY());
|
||||
}
|
||||
|
||||
#ignore
|
||||
@CollectionSize.Require(SEVERAL)
|
||||
#endignore
|
||||
public void testLast() {
|
||||
assertEquals(c, orderedSet.GET_LAST_KEY());
|
||||
assertEquals(c, orderedSet.LAST_KEY());
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,9 @@
|
||||
package speiger.src.collections.booleans.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.Objects;
|
||||
import java.util.AbstractCollection;
|
||||
|
||||
import speiger.src.collections.booleans.lists.BooleanListIterator;
|
||||
import speiger.src.collections.booleans.functions.BooleanConsumer;
|
||||
import speiger.src.collections.booleans.utils.BooleanIterators;
|
||||
import speiger.src.collections.booleans.utils.BooleanArrays;
|
||||
@ -251,68 +249,4 @@ public abstract class AbstractBooleanCollection extends AbstractCollection<Boole
|
||||
if (a.length > size()) a[size()] = false;
|
||||
return a;
|
||||
}
|
||||
|
||||
public static class ReverseBooleanOrderedCollection extends AbstractBooleanCollection implements BooleanOrderedCollection {
|
||||
BooleanOrderedCollection collection;
|
||||
Supplier<BooleanIterator> reverseIterator;
|
||||
|
||||
public ReverseBooleanOrderedCollection(BooleanOrderedCollection collection, Supplier<BooleanIterator> reverseIterator) {
|
||||
this.collection = collection;
|
||||
this.reverseIterator = reverseIterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(boolean o) { return collection.add(o); }
|
||||
@Override
|
||||
public BooleanOrderedCollection reversed() { return collection; }
|
||||
@Override
|
||||
public void addFirst(boolean e) { collection.addLast(e); }
|
||||
@Override
|
||||
public void addLast(boolean e) { collection.addFirst(e); }
|
||||
@Override
|
||||
public boolean contains(boolean e) { return collection.contains(e); }
|
||||
@Override
|
||||
public boolean remBoolean(boolean e) { return collection.remBoolean(e); }
|
||||
@Override
|
||||
public void clear() { collection.clear(); }
|
||||
@Override
|
||||
public boolean getFirstBoolean() { return collection.getLastBoolean(); }
|
||||
@Override
|
||||
public boolean removeFirstBoolean() { return collection.removeLastBoolean(); }
|
||||
@Override
|
||||
public boolean getLastBoolean() { return collection.getFirstBoolean(); }
|
||||
@Override
|
||||
public boolean removeLastBoolean() { return collection.removeFirstBoolean(); }
|
||||
@Override
|
||||
public BooleanIterator iterator() { return reverseIterator.get(); }
|
||||
@Override
|
||||
public int size() { return collection.size(); }
|
||||
}
|
||||
|
||||
public static class ReverseBiIterator implements BooleanListIterator {
|
||||
BooleanListIterator it;
|
||||
|
||||
public ReverseBiIterator(BooleanListIterator it) {
|
||||
this.it = it;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() { return it.previousBoolean(); }
|
||||
@Override
|
||||
public boolean hasNext() { return it.hasPrevious(); }
|
||||
@Override
|
||||
public boolean hasPrevious() { return it.hasNext(); }
|
||||
@Override
|
||||
public boolean previousBoolean() { return it.nextBoolean(); }
|
||||
@Override
|
||||
public void remove() { it.remove(); }
|
||||
@Override
|
||||
public int nextIndex() { return it.previousIndex(); }
|
||||
@Override
|
||||
public int previousIndex() { return it.nextIndex(); }
|
||||
@Override
|
||||
public void set(boolean e) { it.set(e); }
|
||||
@Override
|
||||
public void add(boolean e) { it.add(e); }
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
package speiger.src.collections.booleans.collections;
|
||||
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
/**
|
||||
* This is a basically a {@link java.util.ListIterator} without the index functions.
|
||||
* Allowing to have a simple Bidirectional Iterator without having to keep track of the Iteration index.
|
||||
* A Type-Specific {@link ObjectBidirectionalIterator} to reduce (un)boxing
|
||||
*/
|
||||
public interface BooleanBidirectionalIterator extends BooleanIterator
|
||||
public interface BooleanBidirectionalIterator extends BooleanIterator, ObjectBidirectionalIterator<Boolean>
|
||||
{
|
||||
/**
|
||||
* Returns true if the Iterator has a Previous element
|
||||
@ -19,11 +19,11 @@ public interface BooleanBidirectionalIterator extends BooleanIterator
|
||||
*/
|
||||
public boolean previousBoolean();
|
||||
|
||||
/**
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
* @return the Previous element of the iterator.+
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default Boolean previous() {
|
||||
return Boolean.valueOf(previousBoolean());
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
package speiger.src.collections.booleans.collections;
|
||||
|
||||
public interface BooleanOrderedCollection extends BooleanCollection {
|
||||
|
||||
BooleanOrderedCollection reversed();
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a collection
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
public void addFirst(boolean e);
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a collection
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
public void addLast(boolean e);
|
||||
|
||||
/**
|
||||
* A method to get the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public boolean getFirstBoolean();
|
||||
/**
|
||||
* A method to get and remove the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public boolean removeFirstBoolean();
|
||||
/**
|
||||
* A method to get the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public boolean getLastBoolean();
|
||||
/**
|
||||
* A method to get and remove the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public boolean removeLastBoolean();
|
||||
|
||||
}
|
||||
@ -12,7 +12,6 @@ import speiger.src.collections.booleans.collections.AbstractBooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
import speiger.src.collections.booleans.collections.BooleanSplititerator;
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
import speiger.src.collections.booleans.utils.BooleanSplititerators;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
@ -213,16 +212,6 @@ public abstract class AbstractBooleanList extends AbstractBooleanCollection impl
|
||||
return new BooleanListIter(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanListIterator indexedIterator(int...indecies) {
|
||||
return new IndexedIterator(indecies);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanListIterator indexedIterator(IntList indecies) {
|
||||
return new ListIndexedIterator(indecies);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void size(int size) {
|
||||
while(size > size()) add(false);
|
||||
@ -466,6 +455,7 @@ public abstract class AbstractBooleanList extends AbstractBooleanCollection impl
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanSplititerator spliterator() { return BooleanSplititerators.createSplititerator(this, 16464); }
|
||||
|
||||
@ -577,152 +567,6 @@ public abstract class AbstractBooleanList extends AbstractBooleanCollection impl
|
||||
}
|
||||
}
|
||||
|
||||
private class ListIndexedIterator implements BooleanListIterator {
|
||||
IntList indecies;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
ListIndexedIterator(IntList indecies) {
|
||||
this.indecies = indecies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < indecies.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int i = index++;
|
||||
return getBoolean((lastReturned = indecies.getInt(i)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean previousBoolean() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
index--;
|
||||
return getBoolean((lastReturned = indecies.getInt(index)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void add(boolean e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void set(boolean e) {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
AbstractBooleanList.this.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, indecies.size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
private class IndexedIterator implements BooleanListIterator {
|
||||
int[] indecies;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
IndexedIterator(int[] indecies) {
|
||||
this.indecies = indecies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < indecies.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int i = index++;
|
||||
return getBoolean((lastReturned = indecies[i]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean previousBoolean() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
index--;
|
||||
return getBoolean((lastReturned = indecies[index]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void add(boolean e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void set(boolean e) {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
AbstractBooleanList.this.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, indecies.length - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
private class BooleanListIter implements BooleanListIterator {
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
@ -800,7 +644,7 @@ public abstract class AbstractBooleanList extends AbstractBooleanCollection impl
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,19 +6,17 @@ import java.util.Objects;
|
||||
import java.util.Comparator;
|
||||
|
||||
import speiger.src.collections.booleans.collections.BooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanOrderedCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanSplititerator;
|
||||
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
|
||||
import speiger.src.collections.booleans.functions.BooleanComparator;
|
||||
import speiger.src.collections.booleans.utils.BooleanArrays;
|
||||
import speiger.src.collections.booleans.utils.BooleanLists;
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
import speiger.src.collections.booleans.utils.BooleanSplititerators;
|
||||
|
||||
/**
|
||||
* A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features
|
||||
*/
|
||||
public interface BooleanList extends BooleanOrderedCollection, List<Boolean>
|
||||
public interface BooleanList extends BooleanCollection, List<Boolean>
|
||||
{
|
||||
/**
|
||||
* A Type-Specific add Function to reduce (un)boxing
|
||||
@ -81,24 +79,6 @@ public interface BooleanList extends BooleanOrderedCollection, List<Boolean>
|
||||
*/
|
||||
public boolean addAll(int index, BooleanList c);
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a list
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
@Override
|
||||
public default void addFirst(boolean e) {
|
||||
add(0, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a list
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
@Override
|
||||
public default void addLast(boolean e) {
|
||||
add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns the first element of a List.
|
||||
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||
@ -340,24 +320,6 @@ public interface BooleanList extends BooleanOrderedCollection, List<Boolean>
|
||||
@Override
|
||||
public BooleanListIterator listIterator(int index);
|
||||
|
||||
/**
|
||||
* Creates a Iterator that follows the indecies provided.<br>
|
||||
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
|
||||
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
|
||||
* @param indecies that should be used for the iteration.
|
||||
* @return a custom indexed iterator
|
||||
*/
|
||||
public BooleanListIterator indexedIterator(int...indecies);
|
||||
|
||||
/**
|
||||
* Creates a Iterator that follows the indecies provided.<br>
|
||||
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
|
||||
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
|
||||
* @param indecies that should be used for the iteration.
|
||||
* @return a custom indexed iterator
|
||||
*/
|
||||
public BooleanListIterator indexedIterator(IntList indecies);
|
||||
|
||||
/**
|
||||
* A Type-Specific List of subList
|
||||
* @see java.util.List#subList(int, int)
|
||||
@ -411,7 +373,7 @@ public interface BooleanList extends BooleanOrderedCollection, List<Boolean>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean add(Boolean e) {
|
||||
return BooleanOrderedCollection.super.add(e);
|
||||
return BooleanCollection.super.add(e);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -461,7 +423,7 @@ public interface BooleanList extends BooleanOrderedCollection, List<Boolean>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean contains(Object o) {
|
||||
return BooleanOrderedCollection.super.contains(o);
|
||||
return BooleanCollection.super.contains(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -471,7 +433,7 @@ public interface BooleanList extends BooleanOrderedCollection, List<Boolean>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object o) {
|
||||
return BooleanOrderedCollection.super.remove(o);
|
||||
return BooleanCollection.super.remove(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
||||
@ -146,15 +146,6 @@ public class BooleanArrayFIFOQueue extends AbstractBooleanPriorityQueue implemen
|
||||
return index >= array.length ? array[index-array.length] : array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(boolean e) {
|
||||
if(first == last) return false;
|
||||
for(int i = 0,m=size();i<m;i++) {
|
||||
if(e == array[(first + i) % array.length]) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFirst(boolean e) {
|
||||
if(first == last) return false;
|
||||
|
||||
@ -208,13 +208,6 @@ public class BooleanArrayPriorityQueue extends AbstractBooleanPriorityQueue
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(boolean e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
if(e == array[i]) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFirst(boolean e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
|
||||
@ -213,13 +213,6 @@ public class BooleanHeapPriorityQueue extends AbstractBooleanPriorityQueue
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(boolean e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
if(e == array[i]) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFirst(boolean e) {
|
||||
for(int i = 0;i<size;i++)
|
||||
|
||||
@ -89,13 +89,6 @@ public interface BooleanPriorityQueue extends BooleanIterable
|
||||
*/
|
||||
public default boolean first() { return peek(0); }
|
||||
|
||||
/**
|
||||
* Method to find out if a element is part of the queue
|
||||
* @param e the element that is searched for
|
||||
* @return true if the element is in the queue
|
||||
*/
|
||||
public boolean contains(boolean e);
|
||||
|
||||
/**
|
||||
* Removes the first found element in the queue
|
||||
* @param e the element that should be removed
|
||||
|
||||
@ -21,7 +21,8 @@ import speiger.src.collections.booleans.lists.BooleanList;
|
||||
import speiger.src.collections.booleans.lists.BooleanArrayList;
|
||||
import speiger.src.collections.objects.utils.ObjectAsyncBuilder;
|
||||
import speiger.src.collections.objects.utils.ObjectAsyncBuilder.BaseObjectTask;
|
||||
import speiger.src.collections.ints.utils.IntAsyncBuilder;import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
|
||||
import speiger.src.collections.ints.utils.IntAsyncBuilder;
|
||||
import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
|
||||
import speiger.src.collections.utils.ISizeProvider;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@ import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.booleans.collections.AbstractBooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanOrderedCollection;
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
import speiger.src.collections.booleans.functions.BooleanComparator;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
@ -49,34 +48,6 @@ public class BooleanCollections
|
||||
return c instanceof UnmodifiableCollection ? c : new UnmodifiableCollection(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Immutable Ordered Collection instance based on the instance given.
|
||||
* @param c that should be made immutable/unmodifiable
|
||||
* @return a unmodifiable Ordered collection wrapper. If the Collection already a unmodifiable wrapper then it just returns itself.
|
||||
*/
|
||||
public static BooleanOrderedCollection unmodifiable(BooleanOrderedCollection c) {
|
||||
return c instanceof UnmodifiableOrderedCollection ? c : new UnmodifiableOrderedCollection(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized ordered Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
* @return a synchronized ordered collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static BooleanOrderedCollection synchronize(BooleanOrderedCollection c) {
|
||||
return c instanceof SynchronizedOrderedCollection ? c : new SynchronizedOrderedCollection(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized ordered Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
* @param mutex is the controller of the synchronization block.
|
||||
* @return a synchronized ordered collection wrapper. If the Collection already a synchronized wrapper then it just returns itself.
|
||||
*/
|
||||
public static BooleanOrderedCollection synchronize(BooleanOrderedCollection c, Object mutex) {
|
||||
return c instanceof SynchronizedOrderedCollection ? c : new SynchronizedOrderedCollection(c, mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a synchronized Collection instance based on the instance given.
|
||||
* @param c that should be synchronized
|
||||
@ -317,37 +288,6 @@ public class BooleanCollections
|
||||
@Override
|
||||
public SingletonCollection copy() { return new SingletonCollection(element); }
|
||||
}
|
||||
/**
|
||||
* Synchronized Ordered Collection Wrapper for the synchronizedCollection function
|
||||
*/
|
||||
public static class SynchronizedOrderedCollection extends SynchronizedCollection implements BooleanOrderedCollection {
|
||||
BooleanOrderedCollection c;
|
||||
|
||||
SynchronizedOrderedCollection(BooleanOrderedCollection c, Object mutex) {
|
||||
super(c, mutex);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
SynchronizedOrderedCollection(BooleanOrderedCollection c) {
|
||||
super(c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanOrderedCollection reversed() { return BooleanCollections.synchronize(c.reversed(), mutex); }
|
||||
@Override
|
||||
public void addFirst(boolean e) { synchronized(mutex) { this.c.addFirst(e); } }
|
||||
@Override
|
||||
public void addLast(boolean e) { synchronized(mutex) { this.c.addLast(e); } }
|
||||
@Override
|
||||
public boolean getFirstBoolean() { synchronized(mutex) { return this.c.getFirstBoolean(); } }
|
||||
@Override
|
||||
public boolean removeFirstBoolean() { synchronized(mutex) { return this.c.removeFirstBoolean(); } }
|
||||
@Override
|
||||
public boolean getLastBoolean() { synchronized(mutex) { return this.c.getLastBoolean(); } }
|
||||
@Override
|
||||
public boolean removeLastBoolean() { synchronized(mutex) { return this.c.removeLastBoolean(); } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronized Collection Wrapper for the synchronizedCollection function
|
||||
@ -467,33 +407,6 @@ public class BooleanCollections
|
||||
public int count(BooleanPredicate filter) { synchronized(mutex) { return c.count(filter); } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmodifyable Ordered Collection Wrapper for the unmodifyableCollection method
|
||||
*/
|
||||
public static class UnmodifiableOrderedCollection extends UnmodifiableCollection implements BooleanOrderedCollection {
|
||||
BooleanOrderedCollection c;
|
||||
|
||||
UnmodifiableOrderedCollection(BooleanOrderedCollection c) {
|
||||
super(c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanOrderedCollection reversed() { return BooleanCollections.unmodifiable(c.reversed()); }
|
||||
@Override
|
||||
public void addFirst(boolean e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void addLast(boolean e) { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean getFirstBoolean() { return c.getFirstBoolean(); }
|
||||
@Override
|
||||
public boolean removeFirstBoolean() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public boolean getLastBoolean() { return c.getLastBoolean(); }
|
||||
@Override
|
||||
public boolean removeLastBoolean() { throw new UnsupportedOperationException(); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmodifyable Collection Wrapper for the unmodifyableCollection method
|
||||
*/
|
||||
|
||||
@ -2,7 +2,6 @@ package speiger.src.collections.booleans.utils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.booleans.collections.BooleanIterator;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
@ -10,7 +9,6 @@ import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
import speiger.src.collections.booleans.functions.BooleanConsumer;
|
||||
import speiger.src.collections.booleans.functions.BooleanComparator;
|
||||
import speiger.src.collections.booleans.functions.function.BooleanFunction;
|
||||
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
|
||||
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
|
||||
import speiger.src.collections.booleans.lists.BooleanList;
|
||||
import speiger.src.collections.booleans.lists.BooleanArrayList;
|
||||
@ -18,7 +16,6 @@ import speiger.src.collections.booleans.lists.BooleanArrayList;
|
||||
import speiger.src.collections.booleans.lists.BooleanListIterator;
|
||||
import speiger.src.collections.booleans.collections.BooleanBidirectionalIterator;
|
||||
import speiger.src.collections.booleans.collections.BooleanCollection;
|
||||
import speiger.src.collections.booleans.utils.BooleanCollections.CollectionWrapper;
|
||||
|
||||
/**
|
||||
* A Helper class for Iterators
|
||||
@ -34,7 +31,7 @@ public class BooleanIterators
|
||||
* Returns a Immutable EmptyIterator instance that is automatically casted.
|
||||
* @return an empty iterator
|
||||
*/
|
||||
public static BooleanListIterator empty() {
|
||||
public static EmptyIterator empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@ -209,24 +206,6 @@ public class BooleanIterators
|
||||
return new RepeatingIterator(wrap(iterator), repeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that creates a infinitely looping iterator
|
||||
* @param iterator that should be looping infinitely
|
||||
* @return a infinitely looping iterator
|
||||
*/
|
||||
public static BooleanIterator infinite(BooleanIterator iterator) {
|
||||
return new InfiniteIterator(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that creates a infinitely looping iterator from a Java Iterator
|
||||
* @param iterator that should be looping infinitely
|
||||
* @return a infinitely looping iterator
|
||||
*/
|
||||
public static BooleanIterator infinite(Iterator<? extends Boolean> iterator) {
|
||||
return new InfiniteIterator(wrap(iterator));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that hard limits the Iterator to a specific size
|
||||
* @param iterator that should be limited
|
||||
@ -303,7 +282,7 @@ public class BooleanIterators
|
||||
* @param a the array that should be wrapped
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static BooleanIterator wrap(boolean... a) {
|
||||
public static ArrayIterator wrap(boolean... a) {
|
||||
return wrap(a, 0, a.length);
|
||||
}
|
||||
|
||||
@ -314,7 +293,7 @@ public class BooleanIterators
|
||||
* @param end the index that should be ended.
|
||||
* @return a Iterator that is wrapping a array.
|
||||
*/
|
||||
public static BooleanIterator wrap(boolean[] a, int start, int end) {
|
||||
public static ArrayIterator wrap(boolean[] a, int start, int end) {
|
||||
return new ArrayIterator(a, start, end);
|
||||
}
|
||||
|
||||
@ -862,40 +841,6 @@ public class BooleanIterators
|
||||
}
|
||||
}
|
||||
|
||||
private static class InfiniteIterator implements BooleanIterator
|
||||
{
|
||||
BooleanIterator iter;
|
||||
CollectionWrapper looper = BooleanCollections.wrapper();
|
||||
int index = 0;
|
||||
|
||||
public InfiniteIterator(BooleanIterator iter) {
|
||||
this.iter = iter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextBoolean() {
|
||||
if(iter != null) {
|
||||
if(iter.hasNext()) {
|
||||
boolean value = iter.nextBoolean();
|
||||
looper.add(value);
|
||||
return value;
|
||||
}
|
||||
else iter = null;
|
||||
}
|
||||
return looper.getBoolean((index++) % looper.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachRemaining(BooleanConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
public void forEachRemaining(Consumer<? super Boolean> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
public <E> void forEachRemaining(E input, ObjectBooleanConsumer<E> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
}
|
||||
|
||||
private static class RepeatingIterator implements BooleanIterator
|
||||
{
|
||||
final int repeats;
|
||||
|
||||
@ -11,7 +11,6 @@ import speiger.src.collections.booleans.collections.BooleanCollection;
|
||||
import speiger.src.collections.booleans.functions.BooleanConsumer;
|
||||
import speiger.src.collections.booleans.lists.AbstractBooleanList;
|
||||
import speiger.src.collections.booleans.lists.BooleanList;
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
import speiger.src.collections.booleans.lists.BooleanListIterator;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
@ -29,7 +28,7 @@ public class BooleanLists
|
||||
* Returns a Immutable EmptyList instance that is automatically casted.
|
||||
* @return an empty list
|
||||
*/
|
||||
public static BooleanList empty() {
|
||||
public static EmptyList empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@ -314,16 +313,6 @@ public class BooleanLists
|
||||
return l.listIterator(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanListIterator indexedIterator(int...indecies) {
|
||||
return l.indexedIterator(indecies);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanListIterator indexedIterator(IntList indecies) {
|
||||
return l.indexedIterator(indecies);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanList subList(int from, int to) {
|
||||
return BooleanLists.synchronize(l.subList(from, to));
|
||||
@ -431,16 +420,6 @@ public class BooleanLists
|
||||
return BooleanIterators.unmodifiable(l.listIterator(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanListIterator indexedIterator(int...indecies) {
|
||||
return BooleanIterators.unmodifiable(l.indexedIterator(indecies));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanListIterator indexedIterator(IntList indecies) {
|
||||
return BooleanIterators.unmodifiable(l.indexedIterator(indecies));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanList subList(int from, int to) {
|
||||
return BooleanLists.unmodifiable(l.subList(from, to));
|
||||
@ -529,16 +508,6 @@ public class BooleanLists
|
||||
return BooleanIterators.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanListIterator indexedIterator(int...indecies) {
|
||||
return BooleanIterators.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BooleanListIterator indexedIterator(IntList indecies) {
|
||||
return BooleanIterators.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() { return 1; }
|
||||
|
||||
|
||||
@ -89,8 +89,6 @@ public class BooleanPriorityQueues
|
||||
@Override
|
||||
public boolean peek(int index) { synchronized(mutex) { return queue.peek(index); } }
|
||||
@Override
|
||||
public boolean contains(boolean e) { synchronized(mutex) { return queue.contains(e); } }
|
||||
@Override
|
||||
public boolean removeFirst(boolean e) { synchronized(mutex) { return queue.removeFirst(e); } }
|
||||
@Override
|
||||
public boolean removeLast(boolean e) { synchronized(mutex) { return queue.removeLast(e); } }
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
package speiger.src.collections.bytes.collections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.Objects;
|
||||
import java.util.AbstractCollection;
|
||||
|
||||
import speiger.src.collections.bytes.lists.ByteListIterator;
|
||||
import speiger.src.collections.bytes.functions.ByteConsumer;
|
||||
import speiger.src.collections.bytes.utils.ByteIterators;
|
||||
import speiger.src.collections.bytes.utils.ByteArrays;
|
||||
@ -251,68 +249,4 @@ public abstract class AbstractByteCollection extends AbstractCollection<Byte> im
|
||||
if (a.length > size()) a[size()] = (byte)0;
|
||||
return a;
|
||||
}
|
||||
|
||||
public static class ReverseByteOrderedCollection extends AbstractByteCollection implements ByteOrderedCollection {
|
||||
ByteOrderedCollection collection;
|
||||
Supplier<ByteIterator> reverseIterator;
|
||||
|
||||
public ReverseByteOrderedCollection(ByteOrderedCollection collection, Supplier<ByteIterator> reverseIterator) {
|
||||
this.collection = collection;
|
||||
this.reverseIterator = reverseIterator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(byte o) { return collection.add(o); }
|
||||
@Override
|
||||
public ByteOrderedCollection reversed() { return collection; }
|
||||
@Override
|
||||
public void addFirst(byte e) { collection.addLast(e); }
|
||||
@Override
|
||||
public void addLast(byte e) { collection.addFirst(e); }
|
||||
@Override
|
||||
public boolean contains(byte e) { return collection.contains(e); }
|
||||
@Override
|
||||
public boolean remByte(byte e) { return collection.remByte(e); }
|
||||
@Override
|
||||
public void clear() { collection.clear(); }
|
||||
@Override
|
||||
public byte getFirstByte() { return collection.getLastByte(); }
|
||||
@Override
|
||||
public byte removeFirstByte() { return collection.removeLastByte(); }
|
||||
@Override
|
||||
public byte getLastByte() { return collection.getFirstByte(); }
|
||||
@Override
|
||||
public byte removeLastByte() { return collection.removeFirstByte(); }
|
||||
@Override
|
||||
public ByteIterator iterator() { return reverseIterator.get(); }
|
||||
@Override
|
||||
public int size() { return collection.size(); }
|
||||
}
|
||||
|
||||
public static class ReverseBiIterator implements ByteListIterator {
|
||||
ByteListIterator it;
|
||||
|
||||
public ReverseBiIterator(ByteListIterator it) {
|
||||
this.it = it;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte nextByte() { return it.previousByte(); }
|
||||
@Override
|
||||
public boolean hasNext() { return it.hasPrevious(); }
|
||||
@Override
|
||||
public boolean hasPrevious() { return it.hasNext(); }
|
||||
@Override
|
||||
public byte previousByte() { return it.nextByte(); }
|
||||
@Override
|
||||
public void remove() { it.remove(); }
|
||||
@Override
|
||||
public int nextIndex() { return it.previousIndex(); }
|
||||
@Override
|
||||
public int previousIndex() { return it.nextIndex(); }
|
||||
@Override
|
||||
public void set(byte e) { it.set(e); }
|
||||
@Override
|
||||
public void add(byte e) { it.add(e); }
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
package speiger.src.collections.bytes.collections;
|
||||
|
||||
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
|
||||
/**
|
||||
* This is a basically a {@link java.util.ListIterator} without the index functions.
|
||||
* Allowing to have a simple Bidirectional Iterator without having to keep track of the Iteration index.
|
||||
* A Type-Specific {@link ObjectBidirectionalIterator} to reduce (un)boxing
|
||||
*/
|
||||
public interface ByteBidirectionalIterator extends ByteIterator
|
||||
public interface ByteBidirectionalIterator extends ByteIterator, ObjectBidirectionalIterator<Byte>
|
||||
{
|
||||
/**
|
||||
* Returns true if the Iterator has a Previous element
|
||||
@ -19,11 +19,11 @@ public interface ByteBidirectionalIterator extends ByteIterator
|
||||
*/
|
||||
public byte previousByte();
|
||||
|
||||
/**
|
||||
/** {@inheritDoc}
|
||||
* <p>This default implementation delegates to the corresponding type-specific function.
|
||||
* @deprecated Please use the corresponding type-specific function instead.
|
||||
* @return the Previous element of the iterator.+
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public default Byte previous() {
|
||||
return Byte.valueOf(previousByte());
|
||||
|
||||
@ -1,40 +0,0 @@
|
||||
package speiger.src.collections.bytes.collections;
|
||||
|
||||
public interface ByteOrderedCollection extends ByteCollection {
|
||||
|
||||
ByteOrderedCollection reversed();
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a collection
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
public void addFirst(byte e);
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a collection
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
public void addLast(byte e);
|
||||
|
||||
/**
|
||||
* A method to get the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public byte getFirstByte();
|
||||
/**
|
||||
* A method to get and remove the first element in the collection
|
||||
* @return first element in the collection
|
||||
*/
|
||||
public byte removeFirstByte();
|
||||
/**
|
||||
* A method to get the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public byte getLastByte();
|
||||
/**
|
||||
* A method to get and remove the last element in the collection
|
||||
* @return last element in the collection
|
||||
*/
|
||||
public byte removeLastByte();
|
||||
|
||||
}
|
||||
@ -8,5 +8,5 @@ public interface ByteSupplier
|
||||
/**
|
||||
* @return the supplied value
|
||||
*/
|
||||
public byte getAsByte();
|
||||
public byte getAsInt();
|
||||
}
|
||||
@ -12,7 +12,6 @@ import speiger.src.collections.bytes.collections.AbstractByteCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteIterator;
|
||||
import speiger.src.collections.bytes.collections.ByteSplititerator;
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
import speiger.src.collections.bytes.utils.ByteSplititerators;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
@ -213,16 +212,6 @@ public abstract class AbstractByteList extends AbstractByteCollection implements
|
||||
return new ByteListIter(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator indexedIterator(int...indecies) {
|
||||
return new IndexedIterator(indecies);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteListIterator indexedIterator(IntList indecies) {
|
||||
return new ListIndexedIterator(indecies);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void size(int size) {
|
||||
while(size > size()) add((byte)0);
|
||||
@ -466,6 +455,7 @@ public abstract class AbstractByteList extends AbstractByteCollection implements
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteSplititerator spliterator() { return ByteSplititerators.createSplititerator(this, 16464); }
|
||||
|
||||
@ -577,152 +567,6 @@ public abstract class AbstractByteList extends AbstractByteCollection implements
|
||||
}
|
||||
}
|
||||
|
||||
private class ListIndexedIterator implements ByteListIterator {
|
||||
IntList indecies;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
ListIndexedIterator(IntList indecies) {
|
||||
this.indecies = indecies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < indecies.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte nextByte() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int i = index++;
|
||||
return getByte((lastReturned = indecies.getInt(i)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte previousByte() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
index--;
|
||||
return getByte((lastReturned = indecies.getInt(index)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void add(byte e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void set(byte e) {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
AbstractByteList.this.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, indecies.size() - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
private class IndexedIterator implements ByteListIterator {
|
||||
int[] indecies;
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
|
||||
IndexedIterator(int[] indecies) {
|
||||
this.indecies = indecies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < indecies.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte nextByte() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
int i = index++;
|
||||
return getByte((lastReturned = indecies[i]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return index > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte previousByte() {
|
||||
if(!hasPrevious()) throw new NoSuchElementException();
|
||||
index--;
|
||||
return getByte((lastReturned = indecies[index]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return index-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() { throw new UnsupportedOperationException(); }
|
||||
@Override
|
||||
public void add(byte e) { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void set(byte e) {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
AbstractByteList.this.set(lastReturned, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int skip(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, indecies.length - index);
|
||||
index += steps;
|
||||
if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1);
|
||||
return steps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int back(int amount) {
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
private class ByteListIter implements ByteListIterator {
|
||||
int index;
|
||||
int lastReturned = -1;
|
||||
@ -800,7 +644,7 @@ public abstract class AbstractByteList extends AbstractByteCollection implements
|
||||
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
||||
int steps = Math.min(amount, index);
|
||||
index -= steps;
|
||||
if(steps > 0) lastReturned = Math.max(index, 0);
|
||||
if(steps > 0) lastReturned = Math.min(index, size()-1);
|
||||
return steps;
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,8 @@ import speiger.src.collections.bytes.functions.ByteConsumer;
|
||||
import speiger.src.collections.bytes.utils.ByteArrays;
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.StreamSupport;import speiger.src.collections.bytes.collections.ByteSplititerator;
|
||||
import java.util.stream.StreamSupport;
|
||||
import speiger.src.collections.bytes.collections.ByteSplititerator;
|
||||
import speiger.src.collections.bytes.utils.ByteSplititerators;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
@ -371,7 +372,8 @@ public class ByteLinkedList extends AbstractByteList implements BytePriorityDequ
|
||||
* Returns a Java-Type-Specific Parallel Stream to reduce boxing/unboxing.
|
||||
* @return a Stream of the closest java type
|
||||
*/
|
||||
public IntStream parallelPrimitiveStream() { return StreamSupport.intStream(new SplitIterator(this, first, 0), true); } /**
|
||||
public IntStream parallelPrimitiveStream() { return StreamSupport.intStream(new SplitIterator(this, first, 0), true); }
|
||||
/**
|
||||
* A Type Specific Type Splititerator to reduce boxing/unboxing
|
||||
* @return type specific splititerator
|
||||
*/
|
||||
|
||||
@ -9,20 +9,18 @@ import java.util.Comparator;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import speiger.src.collections.bytes.collections.ByteCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteOrderedCollection;
|
||||
import speiger.src.collections.bytes.collections.ByteSplititerator;
|
||||
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
|
||||
import speiger.src.collections.bytes.functions.ByteComparator;
|
||||
import speiger.src.collections.bytes.utils.ByteArrays;
|
||||
import speiger.src.collections.bytes.utils.ByteLists;
|
||||
import speiger.src.collections.ints.lists.IntList;
|
||||
import speiger.src.collections.bytes.utils.ByteSplititerators;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
* A Type Specific List interface that reduces boxing/unboxing and adds a couple extra quality of life features
|
||||
*/
|
||||
public interface ByteList extends ByteOrderedCollection, List<Byte>
|
||||
public interface ByteList extends ByteCollection, List<Byte>
|
||||
{
|
||||
/**
|
||||
* A Type-Specific add Function to reduce (un)boxing
|
||||
@ -85,24 +83,6 @@ public interface ByteList extends ByteOrderedCollection, List<Byte>
|
||||
*/
|
||||
public boolean addAll(int index, ByteList c);
|
||||
|
||||
/**
|
||||
* A method to add an element to the start of a list
|
||||
* @param e that should be added at the start.
|
||||
*/
|
||||
@Override
|
||||
public default void addFirst(byte e) {
|
||||
add(0, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to add an element to the end of a list
|
||||
* @param e that should be added at the end.
|
||||
*/
|
||||
@Override
|
||||
public default void addLast(byte e) {
|
||||
add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns the first element of a List.
|
||||
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||
@ -362,24 +342,6 @@ public interface ByteList extends ByteOrderedCollection, List<Byte>
|
||||
@Override
|
||||
public ByteListIterator listIterator(int index);
|
||||
|
||||
/**
|
||||
* Creates a Iterator that follows the indecies provided.<br>
|
||||
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
|
||||
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
|
||||
* @param indecies that should be used for the iteration.
|
||||
* @return a custom indexed iterator
|
||||
*/
|
||||
public ByteListIterator indexedIterator(int...indecies);
|
||||
|
||||
/**
|
||||
* Creates a Iterator that follows the indecies provided.<br>
|
||||
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
|
||||
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
|
||||
* @param indecies that should be used for the iteration.
|
||||
* @return a custom indexed iterator
|
||||
*/
|
||||
public ByteListIterator indexedIterator(IntList indecies);
|
||||
|
||||
/**
|
||||
* A Type-Specific List of subList
|
||||
* @see java.util.List#subList(int, int)
|
||||
@ -433,7 +395,7 @@ public interface ByteList extends ByteOrderedCollection, List<Byte>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean add(Byte e) {
|
||||
return ByteOrderedCollection.super.add(e);
|
||||
return ByteCollection.super.add(e);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -483,7 +445,7 @@ public interface ByteList extends ByteOrderedCollection, List<Byte>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean contains(Object o) {
|
||||
return ByteOrderedCollection.super.contains(o);
|
||||
return ByteCollection.super.contains(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
@ -493,7 +455,7 @@ public interface ByteList extends ByteOrderedCollection, List<Byte>
|
||||
@Override
|
||||
@Deprecated
|
||||
public default boolean remove(Object o) {
|
||||
return ByteOrderedCollection.super.remove(o);
|
||||
return ByteCollection.super.remove(o);
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user