All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fastasyncworldedit.core.extent.filter.ForkedFilter Maven / Gradle / Ivy

Go to download

Blazingly fast Minecraft world manipulation for artists, builders and everyone else.

There is a newer version: 2.9.2
Show newest version
package com.fastasyncworldedit.core.extent.filter;

import com.fastasyncworldedit.core.queue.Filter;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public abstract class ForkedFilter> implements Filter {

    protected final Map children;

    @SuppressWarnings("unchecked")
    public ForkedFilter(T root) {
        if (root != null) {
            children = root.children;
        } else {
            children = new ConcurrentHashMap<>();
            children.put(Thread.currentThread(), (T) this);
        }
    }

    @Override
    public final Filter fork() {
        return children.computeIfAbsent(Thread.currentThread(), thread -> init());
    }

    public abstract T init();

    @Override
    public void join() {
        for (Map.Entry entry : children.entrySet()) {
            T filter = entry.getValue();
            if (filter != this) {
                join(filter);
            }
        }
        children.clear();
    }

    public abstract void join(T filter);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy