提交 a87d56e1 编写于 作者: xindoo's avatar xindoo

reformat codes

上级 d969fd8a
......@@ -20,6 +20,7 @@ import java.util.Set;
public class Regex {
private NFAGraph nfaGraph;
private DFAGraph dfaGraph;
public static Regex compile(String regex) throws Exception {
if (regex == null || regex.length() == 0) {
throw new Exception("regex cannot be empty!");
......@@ -29,10 +30,12 @@ public class Regex {
DFAGraph dfaGraph = convertNfa2Dfa(nfaGraph);
return new Regex(nfaGraph, dfaGraph);
}
private Regex(NFAGraph nfaGraph, DFAGraph dfaGraph) {
this.nfaGraph = nfaGraph;
this.dfaGraph = dfaGraph;
}
private static NFAGraph regex2nfa(String regex) {
Reader reader = new Reader(regex);
NFAGraph nfaGraph = null;
......
......@@ -21,8 +21,8 @@ public class RegexTest {
System.out.println(regex.isMatch("a bcccdb", 1));
System.out.println(regex.isMatch("ab", 1));
System.out.println(regex.isMatch("abcd", 1));
System.out.println(regex.isMatch("a3abcd",1));
System.out.println(regex.isMatch("a33333defd",1));
System.out.println(regex.isMatch("a3abcd", 1));
System.out.println(regex.isMatch("a33333defd", 1));
System.out.println(regex.isMatch("aabcabcabcabcabcabcdb", 1));
}
}
......@@ -19,7 +19,8 @@ public class Reader {
}
return chars[cur++];
}
boolean hasNext() {
public boolean hasNext() {
return cur < chars.length;
}
......
package xyz.xindoo.re.dfa;
import xyz.xindoo.re.common.State;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
......
package xyz.xindoo.re.dfa;
import xyz.xindoo.re.common.State;
import java.util.HashSet;
import java.util.Set;
......@@ -15,6 +14,7 @@ public class DFAState extends State {
public DFAState(String allStateIds, Set<State> states) {
this.allStateIds = allStateIds;
this.nfaStates.addAll(states);
for (State state : states) {
if (state.isEndState()) {
this.stateType = 1;
......
......@@ -5,6 +5,7 @@ import xyz.xindoo.re.common.Constant;
public class NFAGraph {
public NFAState start;
public NFAState end;
public NFAGraph(NFAState start, NFAState end) {
this.start = start;
this.end = end;
......
package xyz.xindoo.re.nfa.strategy;
public class CharMatchStrategy extends MatchStrategy{
@Override
public boolean isMatch(char c, String edge) {
return edge.charAt(0) == c;
......
package xyz.xindoo.re.nfa.strategy;
public class CharSetMatchStrategy extends MatchStrategy{
public class CharSetMatchStrategy extends MatchStrategy {
@Override
public boolean isMatch(char c, String charSet) {
boolean res = false;
......
package xyz.xindoo.re.nfa.strategy;
public class DigitalMatchStrategy extends MatchStrategy{
public class DigitalMatchStrategy extends MatchStrategy {
private boolean isReverse;
public DigitalMatchStrategy(boolean isReverse) {
......
package xyz.xindoo.re.nfa.strategy;
public class DotMatchStrategy extends MatchStrategy{
public class DotMatchStrategy extends MatchStrategy {
@Override
public boolean isMatch(char c, String edge) {
return c != '\n' && c != '\r';
......
package xyz.xindoo.re.nfa.strategy;
public class EpsilonMatchStrategy extends MatchStrategy{
public class EpsilonMatchStrategy extends MatchStrategy {
@Override
public boolean isMatch(char c, String edge) {
return true;
......
......@@ -2,7 +2,8 @@ package xyz.xindoo.re.nfa.strategy;
public class MatchStrategy {
protected boolean isReverse = false;
public boolean isMatch(char c, String edge){
public boolean isMatch(char c, String edge) {
return false;
}
}
......@@ -7,6 +7,7 @@ import java.util.Map;
public class MatchStrategyManager {
private static Map<String, MatchStrategy> matchStrategyMap;
static {
matchStrategyMap = new HashMap<>();
matchStrategyMap.put("\\d", new DigitalMatchStrategy(false));
......
package xyz.xindoo.re.nfa.strategy;
public class SpaceMatchStrategy extends MatchStrategy{
public class SpaceMatchStrategy extends MatchStrategy {
private boolean isReverse;
public SpaceMatchStrategy(boolean isReverse) {
......
......@@ -2,8 +2,8 @@ package xyz.xindoo.re.nfa.strategy;
/**
* 匹配 \w和\W
* */
public class WMatchStrategy extends MatchStrategy{
*/
public class WMatchStrategy extends MatchStrategy {
public WMatchStrategy(boolean isReverse) {
this.isReverse = isReverse;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册