@Override public boolean overlaps(LikeCondition condition) { // If either condition is a constant then the other condition must contain the the condition's string to overlap. // For example, "door" overlaps "d*r" if (!hasWildcards()) { return condition.matches(getCondition()); } else if (!condition.hasWildcards()) { return matches(condition.getCondition()); } // Any internal wildcards surrounded by constants can match any other internal values, so determining overlap // only depends on the prefixes and suffixes. String prefix = getPrefix(); String otherPrefix = condition.getPrefix(); String suffix = getSuffix(); String otherSuffix = condition.getSuffix(); return (prefix == null || otherPrefix == null || prefix.startsWith(otherPrefix) || otherPrefix.startsWith(prefix)) && (suffix == null || otherSuffix == null || suffix.endsWith(otherSuffix) || otherSuffix.endsWith(suffix)); }