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

com.hecloud.runtime.database.state.machine.AbstractStateMachine Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
package com.hecloud.runtime.database.state.machine;

import com.hecloud.runtime.common.collections.Lists;
import lombok.Data;

import java.util.List;

/**
 * 抽象状态机
 *
 * @author LoveInBJ-1024
 * @version 1.0
 */
@Data
public abstract class AbstractStateMachine {
    private T state;
    private List next;

    /**
     * 改变状态为给定值
     *
     * @param target 目标状态
     * @param next   下一节点
     */
    public void change(T target, T... next) {
        if (isNext(target)) {
            this.setState(target);
            this.setNext(com.google.common.collect.Lists.newArrayList(next));
        }
    }

    @SafeVarargs
    public final void next(T... next) {
        this.next = com.google.common.collect.Lists.newArrayList(next);
    }

    /**
     * 状态next 是否可以作为当前状态current的下一个状态
     *
     * @param next 下一状态节点
     * @return 是否满足:true 表示满足,false 表示不满足
     */
    public boolean isNext(T next) {

        if (Lists.allNull(this.getNext())) {
            return false;
        } else {
            return this.getNext().contains(next);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy