001/* 002 * Copyright 2024-2025, Warm-Flow (290631660@qq.com). 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.dromara.warm.flow.core.enums; 017 018import org.dromara.warm.flow.core.utils.ObjectUtil; 019 020/** 021 * 节点类型 022 * 023 * @author warm 024 * @since 2023/3/31 12:16 025 */ 026public enum NodeType { 027 /** 028 * 开始节点 029 */ 030 START(0, "start"), 031 /** 032 * 中间节点 033 */ 034 BETWEEN(1, "between"), 035 /** 036 * 结束节点 037 */ 038 END(2, "end"), 039 040 /** 041 * 互斥网关 042 */ 043 SERIAL(3, "serial"), 044 045 /** 046 * 并行网关 047 */ 048 PARALLEL(4, "parallel"); 049 050 private Integer key; 051 private String value; 052 053 NodeType(Integer key, String value) { 054 this.key = key; 055 this.value = value; 056 } 057 058 public static Integer getKeyByValue(String value) { 059 for (NodeType item : NodeType.values()) { 060 if (item.getValue().equals(value)) { 061 return item.getKey(); 062 } 063 } 064 return null; 065 } 066 067 public static String getValueByKey(Integer Key) { 068 for (NodeType item : NodeType.values()) { 069 if (item.getKey().equals(Key)) { 070 return item.getValue(); 071 } 072 } 073 return null; 074 } 075 076 public static NodeType getByKey(String key) { 077 for (NodeType item : NodeType.values()) { 078 if (item.getKey().equals(key)) { 079 return item; 080 } 081 } 082 return null; 083 } 084 085 /** 086 * 判断是否开始节点 087 * 088 * @param Key 089 * @return 090 */ 091 public static Boolean isStart(Integer Key) { 092 return ObjectUtil.isNotNull(Key) && (NodeType.START.getKey().equals(Key)); 093 } 094 095 /** 096 * 判断是否中间节点 097 * 098 * @param Key 099 * @return 100 */ 101 public static Boolean isBetween(Integer Key) { 102 return ObjectUtil.isNotNull(Key) && (NodeType.BETWEEN.getKey().equals(Key)); 103 } 104 105 /** 106 * 判断是否结束节点 107 * 108 * @param Key 109 * @return 110 */ 111 public static Boolean isEnd(Integer Key) { 112 return ObjectUtil.isNotNull(Key) && (NodeType.END.getKey().equals(Key)); 113 } 114 115 /** 116 * 判断是否网关节点 117 * 118 * @param Key 119 * @return 120 */ 121 public static Boolean isGateWay(Integer Key) { 122 return ObjectUtil.isNotNull(Key) && (NodeType.SERIAL.getKey().equals(Key) 123 || NodeType.PARALLEL.getKey().equals(Key)); 124 } 125 126 /** 127 * 判断是否互斥网关节点 128 * 129 * @param Key 130 * @return 131 */ 132 public static Boolean isGateWaySerial(Integer Key) { 133 return ObjectUtil.isNotNull(Key) && NodeType.SERIAL.getKey().equals(Key); 134 } 135 136 /** 137 * 判断是否并行网关节点 138 * 139 * @param Key 140 * @return 141 */ 142 public static Boolean isGateWayParallel(Integer Key) { 143 return ObjectUtil.isNotNull(Key) && NodeType.PARALLEL.getKey().equals(Key); 144 } 145 146 public Integer getKey() { 147 return key; 148 } 149 150 public String getValue() { 151 return value; 152 } 153}