Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions regex/src/main/java/com/florianingerl/util/regex/Pattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,41 @@ void setNext(Node a) {
*/
private transient boolean hasSupplementary;

/**
* The TreeInfo of the complete object tree.
*/
private transient volatile TreeInfo treeInfoRoot;

private TreeInfo getTreeInfoRoot() {
// double checked locking
TreeInfo treeInfo = treeInfoRoot;
if (treeInfo == null) {
synchronized (this) {
treeInfo = treeInfoRoot;
if (treeInfo == null) {
matchRoot.study(treeInfo = new TreeInfo());
treeInfoRoot = treeInfo;
}
}
}
return treeInfo;
}

/**
* @return The minimum length of a possible match.
*/
public int getMinLength() {
return getTreeInfoRoot().minLength;
}

/**
* @return The maximum length of a possible match or {@link Integer.MAX_VALUE} if there is no maximum.
*/
public int getMaxLength() {
TreeInfo treeInfo = getTreeInfoRoot();
return treeInfo.maxValid ? treeInfo.maxLength : Integer.MAX_VALUE;
}

/**
* Compiles the given regular expression into a pattern.
*
Expand Down