小的优化

This commit is contained in:
bryan.zhang
2017-11-29 14:35:36 +08:00
parent 4ef88abe43
commit ab8b6102e6
3 changed files with 76 additions and 0 deletions

View File

@@ -97,6 +97,14 @@
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -182,4 +182,8 @@ public class FlowParser {
}
return regexEntity;
}
public static void main(String[] args) {
System.out.println(parseNodeStr("aaaa(bbb(xxxx|yyyy)|yyyy)"));
}
}

View File

@@ -0,0 +1,64 @@
package com.thebeastshop.liteflow.parser;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 类型转换
* @author gongjun[jun.gong@thebeastshop.com]
* @since 2017-11-22 15:13
*/
@Component
public class TempConvert {
private static List<String> match(String input) {
List<String> list = new ArrayList<String>();
Stack<Character> stack = new Stack<>();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (c == '(') {
stack.push(c);
if (stack.size() == 1 && buffer.length() > 0) {
list.add(buffer.toString());
buffer = new StringBuffer();
}else {
buffer.append(c);
}
}else if (c == ')') {
if (stack.size() > 0) {
stack.pop();
if (stack.size() == 0) {
if (buffer.length() > 0) {
list.add(buffer.toString());
buffer = new StringBuffer();
}
}else {
buffer.append(c);
}
}
}else {
buffer.append(c);
}
}
if (buffer.length() > 0) {
list.add(buffer.toString());
}
return list;
}
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
String input = "aaaa(bbb(xxxxx|yyyy))";
list = match(input);
System.out.println(list);
}
}