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

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

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

import wf.utils.java.math.smooth.SmoothTransform;

import java.util.HashMap;
import java.util.Map;

public class SmoothTransformEntity {

    private Map items;


    public SmoothTransformEntity() {
        this(new HashMap<>());
    }

    public SmoothTransformEntity(Map mapTyped) {
        this.items = mapTyped;
    }

    public void setOrUpdateItem(T t, SmoothTransform transform){
        SmoothTransform currentTransform = items.get(t);
        if(currentTransform == null) items.put(t, transform);
        else {
            currentTransform.setTo(transform.getTo());
            currentTransform.setDuration(transform.getDuration());
        }
    }

    public void addOrUpdateItem(T t, SmoothTransform transform){
        SmoothTransform currentTransform = items.get(t);
        if(currentTransform == null) items.put(t, transform);
        else {
            currentTransform.setTo(currentTransform.getTo() + transform.getTo());
            currentTransform.setDuration(transform.getDuration());
        }
    }

    public double get(T t, boolean autoDelete){
        SmoothTransform transform = items.get(t);
        if(transform == null) return 0d;

        if(autoDelete && items.get(t).isEnd()) items.remove(t);
        return transform.get();
    }

    public double get(T t){
        SmoothTransform transform = items.get(t);
        if(transform == null) return 0d;

        if(items.get(t).isEnd()) items.remove(t);
        return transform.get();
    }



    public void setItem(T t, Item item){
        items.put(t, item);
    }


    public Map getItems() {
        return items;
    }

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

    @Override
    public String toString() {
        return "SmoothTransformEntity{" +
                "items=" + items +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy