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

wf.utils.java.math.smooth.controller.SmoothTransformController Maven / Gradle / Ivy

There is a newer version: 3.3.4
Show newest version
package wf.utils.java.math.smooth.controller;

import java.util.ArrayList;
import java.util.List;

public class SmoothTransformController {


    private List items;

    private Thread thread;
    private int interval;



    public SmoothTransformController(int interval) {
        this(interval, new ArrayList<>());
    }

    public SmoothTransformController(int interval, List listTyped) {
        this.items = listTyped;
        this.interval = interval;
        this.thread = new Thread(() -> {
            while (true){

                items.forEach(Item::run);
                items.removeIf(Item::isEnd);

                try {Thread.sleep(interval);} catch (InterruptedException e) {throw new RuntimeException(e);}
            }
        });
        this.thread.setDaemon(true);
        this.thread.start();
    }

    public void addItem(Item item){
        items.add(item);
    }

    public List getItems() {
        return items;
    }

    public void setItems(List items) {
        this.items = items;
    }

    public Thread getThread() {
        return thread;
    }

    public void setThread(Thread thread) {
        this.thread = thread;
    }

    public int getInterval() {
        return interval;
    }

    public void setInterval(int interval) {
        this.interval = interval;
    }

    @Override
    public String toString() {
        return "SmoothTransformController{" +
                "items=" + items +
                ", thread=" + thread +
                ", interval=" + interval +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy