diff --git a/regex/src/main/java/com/florianingerl/util/regex/Pattern.java b/regex/src/main/java/com/florianingerl/util/regex/Pattern.java index 17d7896..3ba3789 100644 --- a/regex/src/main/java/com/florianingerl/util/regex/Pattern.java +++ b/regex/src/main/java/com/florianingerl/util/regex/Pattern.java @@ -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. *