input
stringlengths
10
828
output
stringlengths
5
107
public boolean is in range byte value byte min byte max return value min value max
check if the value is within a specified range
protected format get format string pattern locale locale number format formatter null boolean use pattern pattern null pattern length 0 if use pattern formatter number format get format locale else if locale null formatter new decimal format pattern else decimal format symbols symbols new decimal format symbols locale formatter new decimal format pattern symbols if determine scale formatter 0 formatter set parse integer only true return formatter
p returns a code number format code for the specified i pattern i
public boolean is in range byte value byte min byte max return is in range value byte value min max
check if the value is within a specified range
protected int determine scale number format format if is strict return 1 if is allow fractions format is parse integer only return 0 int minimum fraction format get minimum fraction digits int maximum fraction format get maximum fraction digits if minimum fraction maximum fraction return 1 int scale minimum fraction if format instanceof decimal format int multiplier decimal format format get multiplier if multiplier 100 scale 2 else if multiplier 1000 scale 3 else if format type percent format scale 2 return scale
p returns the i multiplier i of the code number format code
public boolean min value byte value byte min return value min
check if the value is greater than or equal to a minimum
public boolean min value byte value byte min return min value value byte value min
check if the value is greater than or equal to a minimum
protected format get format locale locale number format formatter null switch format type case currency format if locale null formatter number format get currency instance else formatter number format get currency instance locale break case percent format if locale null formatter number format get percent instance else formatter number format get percent instance locale break default if locale null formatter number format get instance else formatter number format get instance locale break return formatter
p returns a code number format code for the specified locale
public boolean max value byte value byte max return value max
check if the value is less than or equal to a maximum
public boolean max value byte value byte max return max value value byte value max
check if the value is less than or equal to a maximum
protected object process parsed value object value format formatter long long value number value long value if long value byte min value long value byte max value return null else return new byte byte long value
p perform further validation and convert the code number code to
protected boolean is valid path string path if path null return false if path pattern matcher path matches return false int slash2 count count token path if is off allow 2 slashes slash2 count 0 return false int slash count count token path int dot2 count count token path if dot2 count 0 if slash count slash2 count 1 dot2 count return false return true
returns true if the path is valid
protected boolean is valid fragment string fragment if fragment null return true return is off no fragments
returns true if the given fragment is null or fragments are allowed
protected int count token string token string target int token index 0 int count 0 while token index 1 token index target index of token token index if token index 1 token index count return count
returns the number of times the token appears in the target
private boolean is on long flag return this options flag 0
tests whether the given flag is on
public long get flags return this flags
returns the current flags
public boolean is on long flag return this flags flag 0
tests whether the given flag is on
private boolean is off long flag return this options flag 0
tests whether the given flag is off
public boolean is off long flag return this flags flag 0
tests whether the given flag is off
public boolean is valid string isbn return org apache commons validator routines isbnvalidator get instance is valid isbn10 isbn
if the isbn is formatted with space or dash separators its format is
public void turn on long flag this flags flag
turns on the given flag
public void turn off long flag this flags flag
turns off the given flag
public void merge validator results results this h results put all results h results
merge another validator results into mine
public void turn off all this flags 0
turn off all flags
public void add field field string validator name boolean result this add field validator name result null
add a the result of a validator action
public void clear this flags 0
turn off all flags
public void turn on all this flags long max value
turn on all 64 flags
public void clear this h results clear
clear all results recorded by this object
public object clone try return super clone catch clone not supported exception e throw new runtime exception couldn t clone flags object
clone this flags object
public boolean is empty return this h results is empty
return code true code if there are no messages recorded
public boolean equals object obj if obj instanceof flags return false if obj this return true flags f flags obj return this flags f flags
tests if two flags objects are in the same state
public validator result get validator result string key return validator result this h results get key
gets the code validator result code associated
public int hash code return int this flags
the hash code is based on the current state of the flags
public set get property names return collections unmodifiable set this h results key set
return the set of property names for which at least one message has
public map get result value map map results new hash map for iterator i h results key set iterator i has next string property key string i next validator result vr this get validator result property key for iterator x vr get actions x has next string action key string x next object result vr get result action key if result null result instanceof boolean results put property key result return results
get a code map code of any code object code s returned from
public void add field field f this l fields add f this h fields put f get key f
add a code field code to the code form code
public boolean contains field string field name return this h fields contains key field name
returns true if this form contains a field with the given name
public string to string string buffer results new string buffer results append form results append name results append n for iterator i l fields iterator i has next results append t field n results append i next results append n return results to string
returns a string representation of the object
public string get extends return inherit
gets the name key of the parent set of validation rules
public void set extends string inherit this inherit inherit
sets the name key of the parent set of validation rules
protected map get field map return h fields
returns a map of string field keys to field objects
public boolean is valid string card if card null card length 13 card length 19 return false if this luhn check card return false iterator types this card types iterator while types has next credit card type type credit card type types next if type matches card return true return false
checks if the field is a valid credit card number
public void add allowed card type credit card type type this card types add type
add an allowed credit card type that participates in the card
protected boolean luhn check string card number number must be validated as 0 9 numeric first int digits card number length int odd or even digits 1 long sum 0 for int count 0 count digits count int digit 0 try digit integer parse int card number char at count catch number format exception e return false if count 1 odd or even 0 not digit 2 if digit 9 digit 9 sum digit return sum 0 false sum 10 0
checks for a valid credit card number
public string to string string buffer results new string buffer results append msg name results append name results append key results append key results append resource results append resource results append bundle results append bundle results append n return results to string
returns a string representation of the object
public boolean is valid string value string date pattern boolean strict if value null date pattern null date pattern length 0 return false simple date format formatter new simple date format date pattern formatter set lenient false try formatter parse value catch parse exception e return false if strict date pattern length value length return false return true
p checks if the field is a valid date
public boolean is valid string value locale locale if value null return false date format formatter null if locale null formatter date format get date instance date format short locale else formatter date format get date instance date format short locale get default formatter set lenient false try formatter parse value catch parse exception e return false return true
p checks if the field is a valid date
protected boolean is valid path string path if path null return false if path pattern matcher path matches return false int slash2 count count token path if this options is off allow 2 slashes slash2 count 0 return false int slash count count token path int dot2 count count token path if dot2 count 0 if slash count slash2 count 1 dot2 count return false return true
returns true if the path is valid
protected boolean is valid fragment string fragment if fragment null return true return this options is off no fragments
returns true if the given fragment is null or fragments are allowed
public void add constant string name string value if get log is debug enabled get log debug adding global constant name value this h constants put name value
add a global constant to the resource
public void add validator action validator action va va init this h actions put va get name va if get log is debug enabled get log debug add validator action va get name va get classname
add a code validator action code to the resource
public validator action get validator action string key return validator action h actions get key
get a code validator action code based on its name
public map get validator actions return collections unmodifiable map h actions
get an unmodifiable code map code of the code validator action code s
private string build locale string lang string country string variant string key lang null lang length 0 lang key country null country length 0 country key variant null variant length 0 variant return key
assembles a locale code from the given parts
public void process h form sets set fast true h constants set fast true h actions set fast true this process forms
process the code validator resources code object
protected map get form sets return h form sets
returns a map of string locale keys to lists of their form sets
protected map get constants return h constants
returns a map of string constant names to their string values
public void test uslocale throws validator exception create bean to run test on type bean info new type bean info set byte 12 info set short 129 info set integer 144 info set long 88000 info set float 12 1555 info set double 129 1551511111 info set date 12 21 2010 locale test info locale us
tests the us locale
public void test frlocale throws validator exception create bean to run test on type bean info new type bean info set byte 12 info set short 129 info set integer 1443 info set long 88000 info set float 12 1555 info set double 129 1551511111 info set date 21 12 2010 map map locale test info locale french assert true float value not correct float map get float int value 12 assert true double value not correct double map get double int value 129
tests the fr locale
protected map get actions return h actions
returns a map of string validator action names to their validator action
public void test valid date throws validator exception create bean to run test on value bean info new value bean info set value 12 01 2005 value test info true
tests the date validation
public void test invalid date throws validator exception create bean to run test on value bean info new value bean info set value 12 01as 2005 value test info false
tests the date validation
private log get log if log null log log factory get log validator resources class return log
accessor method for log instance
public void test null input stream throws exception try new validator resources input stream null fail expected illegal argument exception catch illegal argument exception e expected result system out println exception e
test null input stream for validator resources
public void test long throws validator exception create bean to run test on value bean info new value bean info set value 0 value test info true
tests the long validation
public void test long min throws validator exception create bean to run test on value bean info new value bean info set value new long long min value to string value test info true
tests the long validation
public void test long max throws validator exception create bean to run test on value bean info new value bean info set value new long long max value to string value test info true
tests the long validation
public void test long failure throws validator exception create bean to run test on value bean info new value bean value test info false
tests the long validation failure
public void test long beyond min throws validator exception create bean to run test on value bean info new value bean info set value long min value 1 value test info false
tests the long validation failure
public void test long beyond max throws validator exception create bean to run test on value bean info new value bean info set value long max value 1 value test info false
tests the long validation failure
public void test int throws validator exception create bean to run test on value bean info new value bean info set value 0 value test info true
tests the int validation
public void test int min throws validator exception create bean to run test on value bean info new value bean info set value new integer integer min value to string value test info true
tests the int validation
public void test integer max throws validator exception create bean to run test on value bean info new value bean info set value new integer integer max value to string value test info true
tests the int validation
public void test int failure throws validator exception create bean to run test on value bean info new value bean value test info false
tests the int validation failure
public void test int beyond min throws validator exception create bean to run test on value bean info new value bean info set value integer min value 1 value test info false
tests the int validation failure
public void test int beyond max throws validator exception create bean to run test on value bean info new value bean info set value integer max value 1 value test info false
tests the int validation failure
public void test short min throws validator exception create bean to run test on value bean info new value bean info set value new short short min value to string value test info true
tests the short validation
public void test short max throws validator exception create bean to run test on value bean info new value bean info set value new short short max value to string value test info true
tests the short validation
public void test short beyond min throws validator exception create bean to run test on value bean info new value bean info set value short min value 1 value test info false
tests the short validation failure
public void test short beyond max throws validator exception create bean to run test on value bean info new value bean info set value short max value 1 value test info false
tests the short validation failure
public void test email throws validator exception create bean to run test on value bean info new value bean info set value jsmith apache org value test info true
tests the e mail validation
public void test email with numeric address throws validator exception value bean info new value bean info set value someone 216 109 118 76 value test info true info set value someone yahoo com value test info true
tests the email validation with numeric domains
private name bean create name bean name bean name new name bean name set first name first name name set middle name middle name name set last name last name return name
create a name bean
public void test email extension throws validator exception create bean to run test on value bean info new value bean info set value jsmith apache org value test info true info set value jsmith apache com value test info true info set value jsmith apache net value test info true info set value jsmith apache info value test info true info set value jsmith apache value test info false info set value jsmith apache c value test info false info set value someone yahoo museum value test info true info set value someone yahoo mu seum value test info false
tests the e mail validation
public void test email with dash throws validator exception create bean to run test on value bean info new value bean info set value andy noble data workshop com value test info true info set value andy noble data workshop com value test info false info set value andy noble data workshop c om value test info false info set value andy noble data workshop co m value test info false
p tests the e mail validation with a dash in
public void test email with dot end throws validator exception create bean to run test on value bean info new value bean info set value andy noble data workshop com value test info false
tests the e mail validation with a dot at the end of
public void test email with bogus character throws validator exception create bean to run test on value bean info new value bean info set value andy noble u008fdata workshop com value test info false the character is valid in an email username info set value andy o reilly data workshop com value test info true but not in the domain name info set value andy o reilly data workshop com value test info false info set value foo bar i am not in us example com value test info true
tests the e mail validation with an rcs noncompliant character in
public void test email with commas throws validator exception value bean info new value bean info set value joeblow apa che org value test info false info set value joeblow apache o rg value test info false info set value joeblow apache org value test info false
tests the email validation with commas
public void test byte throws validator exception create bean to run test on value bean info new value bean info set value 0 value test info true
tests the byte validation
public void test byte min throws validator exception create bean to run test on value bean info new value bean info set value new byte byte min value to string value test info true
tests the byte validation
public void test byte max throws validator exception create bean to run test on value bean info new value bean info set value new byte byte max value to string value test info true
tests the byte validation
public void test byte failure throws validator exception create bean to run test on value bean info new value bean value test info false
tests the byte validation failure
public void test byte beyond min throws validator exception create bean to run test on value bean info new value bean info set value byte min value 1 value test info false
tests the byte validation failure
public void test email with spaces throws validator exception value bean info new value bean info set value joeblow apache org value test info false info set value joeblow apache org value test info false info set value joeblow apache org value test info true info set value joeblow apache org value test info true info set value joe blow apache org value test info false info set value joeblow apa che org value test info false
tests the email validation with spaces
public void test byte beyond max throws validator exception create bean to run test on value bean info new value bean info set value byte max value 1 value test info false
tests the byte validation failure
public void test validator exception create bean to run test on value bean info new value bean info set value validator construct validator based on the loaded resources and the form key validator validator new validator resources form key add the name bean to the validator as a resource for the validations to be performed on validator set parameter validator bean param info get results of the validation which can throw validator exception try validator validate fail validator exception should occur here catch validator exception expected assert true validator exception equals expected get message
tests handling of checked exceptions should become
public void test email with control chars email validator validator new email validator for char c 0 c 32 c assert false test control char int c validator is valid foo c bar domain com assert false test control char 127 validator is valid foo char 127 bar domain com
tests the email validation with ascii control characters
public void test entity import throws exception url url get class get resource entity import test config xml validator resources resources new validator resources url to external form assert not null form should be found resources get form locale get default byte form
tests the entity import loading the code byte form code form
public void test parse url throws exception url url get class get resource entity import test config xml validator resources resources new validator resources url assert not null form should be found resources get form locale get default byte form
tests loading validator resources from a url
public void test number throws validator exception create bean to run test on value bean info new value bean info set value 0 value test info true
tests the number validation
public void test number failure throws validator exception create bean to run test on value bean info new value bean value test info false
tests the float validation failure