@Test public void testValidAlphanumericStringConstrainedSet() { String[] set = {"true", "123abc", "F12G3a0", "false"}; String[] badSet = {"tr-ue", "12&3abc", "F12 G3a0", "false"}; assertTrue(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("true", set, false)); assertFalse(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("tRue", set, false)); assertTrue(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("true", set, true)); assertTrue(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("tRue", set, true)); assertTrue(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("F12G3a0", set, false)); assertFalse(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("f12G3a0", set, false)); assertTrue(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("F12G3a0", set, true)); assertTrue(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("f12G3a0", set, true)); assertFalse(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("true", badSet, false)); assertFalse(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("tr-ue", badSet, false)); assertFalse(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("truE", badSet, true)); assertFalse(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("tr-uE", badSet, true)); assertTrue(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("false", badSet, false)); assertFalse(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("fAlse", badSet, false)); assertTrue(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("false", badSet, true)); assertTrue(StringValidateEncodeUtils.validAlphanumericStringConstrainedSet("fAlse", badSet, true)); }
public static boolean validAlphanumericStringConstrainedSet(String alphNumString, String[] constrainedSet, boolean ignoreCase) { if (alphNumString == null || constrainedSet == null || constrainedSet.length == 0) return false; Matcher m = VALID_CHARACTERS_FOR_ALPHANUMERIC_STRING_PATTERN.matcher(alphNumString); if (!m.matches()) return false; for (String s : constrainedSet) { if (ignoreCase ? alphNumString.equalsIgnoreCase(s) : alphNumString.equals(s)) return true; } return false; }
StringValidateEncodeUtils { public static boolean validAlphanumericStringConstrainedSet(String alphNumString, String[] constrainedSet, boolean ignoreCase) { if (alphNumString == null || constrainedSet == null || constrainedSet.length == 0) return false; Matcher m = VALID_CHARACTERS_FOR_ALPHANUMERIC_STRING_PATTERN.matcher(alphNumString); if (!m.matches()) return false; for (String s : constrainedSet) { if (ignoreCase ? alphNumString.equalsIgnoreCase(s) : alphNumString.equals(s)) return true; } return false; } }
StringValidateEncodeUtils { public static boolean validAlphanumericStringConstrainedSet(String alphNumString, String[] constrainedSet, boolean ignoreCase) { if (alphNumString == null || constrainedSet == null || constrainedSet.length == 0) return false; Matcher m = VALID_CHARACTERS_FOR_ALPHANUMERIC_STRING_PATTERN.matcher(alphNumString); if (!m.matches()) return false; for (String s : constrainedSet) { if (ignoreCase ? alphNumString.equalsIgnoreCase(s) : alphNumString.equals(s)) return true; } return false; } private  StringValidateEncodeUtils(); }
StringValidateEncodeUtils { public static boolean validAlphanumericStringConstrainedSet(String alphNumString, String[] constrainedSet, boolean ignoreCase) { if (alphNumString == null || constrainedSet == null || constrainedSet.length == 0) return false; Matcher m = VALID_CHARACTERS_FOR_ALPHANUMERIC_STRING_PATTERN.matcher(alphNumString); if (!m.matches()) return false; for (String s : constrainedSet) { if (ignoreCase ? alphNumString.equalsIgnoreCase(s) : alphNumString.equals(s)) return true; } return false; } private  StringValidateEncodeUtils(); static boolean validSingleLineString(String singleLineString); @SuppressWarnings({"SimplifiableIfStatement"}) static boolean validPath(String path); @SuppressWarnings({"SimplifiableIfStatement"}) static boolean validFilePath(String path); @SuppressWarnings({"SimplifiableIfStatement"}) static boolean validUriString(String uri); static boolean validIdString(String id); static boolean containsAngleBracketCharacters(String string); static boolean containsAmpersandCharacters(String string); static boolean containsBackslashCharacters(String string); static boolean validDecimalNumber(String number); @SuppressWarnings({"SimplifiableIfStatement"}) static boolean validBooleanString(String boolString); static boolean validAlphanumericString(String alphNumString); static boolean validAlphanumericStringConstrainedSet(String alphNumString, String[] constrainedSet,
      boolean ignoreCase); @SuppressWarnings({"UnnecessaryContinue"}) static boolean descendOnlyFilePath(String path); static boolean validPercentHexOctetsString(String percentHexOctetsString); static String unicodeCodePoint2PercentHexString(int codePoint, String charsetName); }
StringValidateEncodeUtils { public static boolean validAlphanumericStringConstrainedSet(String alphNumString, String[] constrainedSet, boolean ignoreCase) { if (alphNumString == null || constrainedSet == null || constrainedSet.length == 0) return false; Matcher m = VALID_CHARACTERS_FOR_ALPHANUMERIC_STRING_PATTERN.matcher(alphNumString); if (!m.matches()) return false; for (String s : constrainedSet) { if (ignoreCase ? alphNumString.equalsIgnoreCase(s) : alphNumString.equals(s)) return true; } return false; } private  StringValidateEncodeUtils(); static boolean validSingleLineString(String singleLineString); @SuppressWarnings({"SimplifiableIfStatement"}) static boolean validPath(String path); @SuppressWarnings({"SimplifiableIfStatement"}) static boolean validFilePath(String path); @SuppressWarnings({"SimplifiableIfStatement"}) static boolean validUriString(String uri); static boolean validIdString(String id); static boolean containsAngleBracketCharacters(String string); static boolean containsAmpersandCharacters(String string); static boolean containsBackslashCharacters(String string); static boolean validDecimalNumber(String number); @SuppressWarnings({"SimplifiableIfStatement"}) static boolean validBooleanString(String boolString); static boolean validAlphanumericString(String alphNumString); static boolean validAlphanumericStringConstrainedSet(String alphNumString, String[] constrainedSet,
      boolean ignoreCase); @SuppressWarnings({"UnnecessaryContinue"}) static boolean descendOnlyFilePath(String path); static boolean validPercentHexOctetsString(String percentHexOctetsString); static String unicodeCodePoint2PercentHexString(int codePoint, String charsetName); final static String CHARACTER_ENCODING_UTF_8; }