Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have a limited sequence of characters following one another you can use a <code>Pattern</code>, <code>.find()</code> on a matcher on your input and just invert the test:</p> <pre><code>// Only the alternation is needed, no need for the capture private static final Pattern PATTERN = Pattern.compile("012|123|234|345|456|567|678|789|890"); // ... if (PATTERN.matcher(input).find()) // fail: illegal sequence found </code></pre> <p>But if you want to detect that code points follow one another you have to use character functions:</p> <pre><code>final CharBuffer buf = CharBuffer.wrap(input); int maxSuccessive = 0; int successive = 0; char prev = buf.get(); char next; while (buf.hasRemaining()) { next = buf.get(); if (next - prev == 1) successive++; else { maxSuccessive = Math.max(maxSuccessive, successive); successive = 0; } prev = next; } // test maxSuccessive </code></pre> <p>Note however that this will test successive characters according to "canonical ordering", not collation. In some locales, for instance, what is immediately after <code>a</code> is <code>A</code>, not <code>b</code>.</p> <hr> <p>More generally, if you want to test for password requirements and constraint evolves, you are better off splitting things a bit. For instance, consider this:</p> <pre><code>public interface PasswordChecker { boolean isValid(final String passwd); } </code></pre> <p>Implement this interface for each of your checks (for instance, length, presence/absence of certain characters, etc), and when you do check for a password, have a <code>List</code> of checkers; the password is invalid if one checker returns false:</p> <pre><code>private final List&lt;PasswordChecker&gt; checkers = ...; // then for (final PasswordChecker checker: checkers) if (!checker.isValid(passwd)) return false; return true; </code></pre> <p>If you use Guava, you can forget about <code>PasswordChecker</code> and use <code>Predicate&lt;String&gt;</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload