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

com.github.houbb.regex.support.state.State Maven / Gradle / Ivy

package com.github.houbb.regex.support.state;

import com.github.houbb.heaven.util.guava.Guavas;
import com.github.houbb.regex.api.IState;
import com.github.houbb.regex.constant.enums.StateType;

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

/**
 * 

project: regex-State

*

create on 2020/5/20 22:59

* * @author binbin.hou * @since 0.0.1 */ public class State implements IState { /** * id 生成策略 * * @since 0.0.1 */ private static int idCounter = 0; /** * id 标识 * @since 0.0.1 */ private int id; /** * 状态类型 * @since 0.0.1 */ private StateType stateType; /** * 存放后继节点信息 * * String 对应的是边 * IState 对应的是条边的节点信息 * @since 0.0.1 */ private Map> nextMap = new HashMap<>(); public State() { this.id = idCounter++; } @Override public int id() { return this.id; } /** * nextMap 中有个key-value就是一条边,edge 用来描述边的信息 * @param edge 边信息 * @param nextState 下一个节点 * @return this */ @Override public IState addNext(String edge, IState nextState) { Set set = nextMap.get(edge); if(set == null) { set = Guavas.newHashSet(); } set.add(nextState); nextMap.put(edge, set); return this; } @Override public StateType stateType() { return stateType; } @Override public Map> nextMap() { return this.nextMap; } @Override public State stateType(StateType stateType) { this.stateType = stateType; return this; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy