code
stringlengths 25
201k
| docstring
stringlengths 19
96.2k
| func_name
stringlengths 0
235
| language
stringclasses 1
value | repo
stringlengths 8
51
| path
stringlengths 11
314
| url
stringlengths 62
377
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
private static ConcurrentMap<Locale, Strategy> getCache(final int field) {
synchronized (caches) {
if (caches[field] == null) {
caches[field] = new ConcurrentHashMap<>(3);
}
return caches[field];
}
}
|
Get a cache of Strategies for a particular field
@param field The Calendar field
@return a cache of Locale to Strategy
|
getCache
|
java
|
arextest/arex-agent-java
|
arex-third-party/src/main/java/io/arex/agent/thirdparty/util/time/FastDateParser.java
|
https://github.com/arextest/arex-agent-java/blob/master/arex-third-party/src/main/java/io/arex/agent/thirdparty/util/time/FastDateParser.java
|
Apache-2.0
|
private Strategy getLocaleSpecificStrategy(final int field, final Calendar definingCalendar) {
final ConcurrentMap<Locale, Strategy> cache = getCache(field);
Strategy strategy = cache.get(locale);
if (strategy == null) {
strategy = field == Calendar.ZONE_OFFSET
? new TimeZoneStrategy(locale)
: new CaseInsensitiveTextStrategy(field, definingCalendar, locale);
final Strategy inCache = cache.putIfAbsent(locale, strategy);
if (inCache != null) {
return inCache;
}
}
return strategy;
}
|
Construct a Strategy that parses a Text field
@param field The Calendar field
@param definingCalendar The calendar to obtain the short and long values
@return a TextStrategy for the field and Locale
|
getLocaleSpecificStrategy
|
java
|
arextest/arex-agent-java
|
arex-third-party/src/main/java/io/arex/agent/thirdparty/util/time/FastDateParser.java
|
https://github.com/arextest/arex-agent-java/blob/master/arex-third-party/src/main/java/io/arex/agent/thirdparty/util/time/FastDateParser.java
|
Apache-2.0
|
int modify(final FastDateParser parser, final int iValue) {
return iValue;
}
|
Make any modifications to parsed integer
@param parser The parser
@param iValue The parsed integer
@return The modified value
|
modify
|
java
|
arextest/arex-agent-java
|
arex-third-party/src/main/java/io/arex/agent/thirdparty/util/time/FastDateParser.java
|
https://github.com/arextest/arex-agent-java/blob/master/arex-third-party/src/main/java/io/arex/agent/thirdparty/util/time/FastDateParser.java
|
Apache-2.0
|
@Deprecated
protected StringBuffer applyRules(final Calendar calendar, final StringBuffer buf) {
return (StringBuffer) applyRules(calendar, (Appendable)buf);
}
|
Performs the formatting by applying the rules to the
specified calendar.
@param calendar the calendar to format
@param buf the buffer to format into
@return the specified string buffer
@deprecated use {@link #format(Calendar)} or {@link #format(Calendar, Appendable)}
|
applyRules
|
java
|
arextest/arex-agent-java
|
arex-third-party/src/main/java/io/arex/agent/thirdparty/util/time/FastDatePrinter.java
|
https://github.com/arextest/arex-agent-java/blob/master/arex-third-party/src/main/java/io/arex/agent/thirdparty/util/time/FastDatePrinter.java
|
Apache-2.0
|
private static void appendDigits(final Appendable buffer, final int value) throws IOException {
buffer.append((char)(value / 10 + '0'));
buffer.append((char)(value % 10 + '0'));
}
|
Appends two digits to the given buffer.
@param buffer the buffer to append to.
@param value the value to append digits from.
|
appendDigits
|
java
|
arextest/arex-agent-java
|
arex-third-party/src/main/java/io/arex/agent/thirdparty/util/time/FastDatePrinter.java
|
https://github.com/arextest/arex-agent-java/blob/master/arex-third-party/src/main/java/io/arex/agent/thirdparty/util/time/FastDatePrinter.java
|
Apache-2.0
|
@Override
public void onAllRulesPassed(final View view) {
boolean isTextView = view instanceof TextView;
if (isTextView) {
((TextView) view).setError(null);
}
}
|
A default implementation of the {@link com.mobsandgeeks.saripaar.Validator.ViewValidatedAction}
that clears error messages on {@link android.widget.EditText} views by calling the
{@link android.widget.TextView#setError(CharSequence)} with a {@code null} parameter.
@author Ragunath Jawahar {@literal <rj@mobsandgeeks.com>}
@since 2.0
|
onAllRulesPassed
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/DefaultViewValidatedAction.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/DefaultViewValidatedAction.java
|
Apache-2.0
|
static Method getAttributeMethod(final Class<? extends Annotation> annotationType,
final String attributeName) {
Method attributeMethod = null;
try {
attributeMethod = annotationType.getMethod(attributeName);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
return attributeMethod;
}
|
Retrieves the attribute method of the given {@link java.lang.annotation.Annotation}.
@param annotationType The {@link java.lang.annotation.Annotation}
{@link java.lang.Class} to check.
@param attributeName Attribute name.
@return The {@link java.lang.reflect.Method} if the attribute is present,
null otherwise.
|
getAttributeMethod
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
Apache-2.0
|
@SuppressWarnings("unchecked")
static <T> T getAttributeValue(final Annotation annotation, final String attributeName,
final Class<T> attributeDataType) {
T attributeValue = null;
Class<? extends Annotation> annotationType = annotation.annotationType();
Method attributeMethod = getAttributeMethod(annotationType, attributeName);
if (attributeMethod == null) {
String message = String.format("Cannot find attribute '%s' in annotation '%s'.",
attributeName, annotationType.getName());
throw new IllegalStateException(message);
} else {
try {
Object result = attributeMethod.invoke(annotation);
attributeValue = attributeDataType.isPrimitive()
? (T) result
: attributeDataType.cast(result);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
return attributeValue;
}
|
Retrieve an attribute value from an {@link java.lang.annotation.Annotation}.
@param annotation An {@link java.lang.annotation.Annotation} instance.
@param attributeName Attribute name.
@param attributeDataType {@link java.lang.Class} representing the attribute data type.
@param <T> Attribute value type.
@return The attribute value.
|
getAttributeValue
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
Apache-2.0
|
static boolean isAnnotated(final Class<? extends Annotation> inspected,
final Class<? extends Annotation> expected) {
boolean isAnnotated = false;
Annotation[] declaredAnnotations = inspected.getDeclaredAnnotations();
for (Annotation declaredAnnotation : declaredAnnotations) {
isAnnotated = expected.equals(declaredAnnotation.annotationType());
if (isAnnotated) {
break;
}
}
return isAnnotated;
}
|
Checks if an annotation was annotated with the given annotation.
@param inspected The {@link java.lang.annotation.Annotation} to be checked.
@param expected The {@link java.lang.annotation.Annotation} that we are looking for.
@return true if the annotation is present, false otherwise.
|
isAnnotated
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
Apache-2.0
|
static Method findGetDataMethod(final Class<? extends ViewDataAdapter> dataAdapterType) {
Method getDataMethod = null;
Method[] declaredMethods = dataAdapterType.getDeclaredMethods();
for (Method method : declaredMethods) {
boolean methodNameIsGetData = "getData".equals(method.getName());
if (methodNameIsGetData) {
// If we don't declare a throws clause in the method signature, the compiler
// creates an auto-generated volatile method with the java.lang.Object return type.
int modifiers = method.getModifiers();
boolean nonVolatile = !Modifier.isVolatile(modifiers);
// Single 'View' parameter
Class<?>[] parameterTypes = method.getParameterTypes();
boolean hasSingleViewParameter = parameterTypes.length == 1
&& View.class.isAssignableFrom(parameterTypes[0]);
if (nonVolatile && hasSingleViewParameter) {
getDataMethod = method;
break;
}
}
}
return getDataMethod;
}
|
Finds and returns the correct
{@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter#getData(android.view.View)}
{@link java.lang.reflect.Method}.
@param dataAdapterType The {@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter}
class whose {@code getData(View)} method is required.
@return The correct {@code getData(View)} method.
|
findGetDataMethod
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
Apache-2.0
|
static AnnotationRule instantiateRule(final Class<? extends AnnotationRule> ruleType,
final Annotation ruleAnnotation, final ValidationContext validationContext)
throws SaripaarViolationException {
AnnotationRule rule = null;
try {
if (ContextualAnnotationRule.class.isAssignableFrom(ruleType)) {
Constructor<?> constructor = ruleType.getDeclaredConstructor(
ruleAnnotation.annotationType(), ValidationContext.class);
constructor.setAccessible(true);
rule = (AnnotationRule) constructor.newInstance(ruleAnnotation, validationContext);
} else if (AnnotationRule.class.isAssignableFrom(ruleType)) {
Constructor<?> constructor = ruleType.getDeclaredConstructor(
ruleAnnotation.annotationType());
constructor.setAccessible(true);
rule = (AnnotationRule) constructor.newInstance(ruleAnnotation);
}
} catch (NoSuchMethodException e) {
String message = getMissingConstructorErrorMessage(ruleType,
ruleAnnotation.annotationType());
throw new SaripaarViolationException(message);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return rule;
}
|
Instantiates a {@link AnnotationRule} object for the given type.
@param ruleType The {@link AnnotationRule} class to be instantiated.
@param ruleAnnotation The rule {@link java.lang.annotation.Annotation} associated with
the {@link AnnotationRule}.
@return The instantiated {@link AnnotationRule} object.
@throws SaripaarViolationException if {@link AnnotationRule} does not
have a single-argument constructor that accepts a rule
{@link java.lang.annotation.Annotation} instance.
|
instantiateRule
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
Apache-2.0
|
static Class<?> getRuleDataType(final Annotation ruleAnnotation) {
ValidateUsing validateUsing = getValidateUsingAnnotation(ruleAnnotation.annotationType());
return getRuleDataType(validateUsing);
}
|
Method finds the data type of the {@link AnnotationRule} that is tied up to the given rule
annotation.
@param ruleAnnotation Rule {@link java.lang.annotation.Annotation}.
@return The expected data type for the
{@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter}s.
|
getRuleDataType
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Reflector.java
|
Apache-2.0
|
@SuppressWarnings("unchecked")
void register(final Class<? extends Annotation>... ruleAnnotations) {
for (Class<? extends Annotation> ruleAnnotation : ruleAnnotations) {
assertIsValidRuleAnnotation(ruleAnnotation);
final ValidateUsing validateUsing = ruleAnnotation.getAnnotation(ValidateUsing.class);
final Class<?> ruleDataType = Reflector.getRuleDataType(validateUsing);
HashMap<Class<?>, ViewDataAdapter> viewDataAdapterMap =
STOCK_ADAPTERS.get(TextView.class);
if (viewDataAdapterMap != null) {
ViewDataAdapter dataAdapter = viewDataAdapterMap.get(ruleDataType);
if (dataAdapter != null) {
register(TextView.class, ruleDataType, dataAdapter, ruleAnnotation);
} else {
String message = String.format(
"Unable to find a matching adapter for `%s`, that returns a `%s`.",
ruleAnnotation.getName(), ruleDataType.getName());
throw new SaripaarViolationException(message);
}
}
}
}
|
This is a convenience method for Annotations that operate on {@link android.widget.TextView}
and it's subclasses such as {@link android.widget.EditText}. Use this to register your custom
annotation if your {@link AnnotationRule} performs validations on
{@link java.lang.String}s, {@link java.lang.Integer}s, {@link java.lang.Float}s and
{@link java.lang.Double} values.
@param ruleAnnotations Varargs of rule {@link java.lang.annotation.Annotation}s that operate
on {@link android.widget.TextView}s.
|
register
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Registry.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Registry.java
|
Apache-2.0
|
<VIEW extends View, DATA_TYPE> void register(
final Class<VIEW> viewType,
final Class<DATA_TYPE> ruleDataType,
final ViewDataAdapter<VIEW, DATA_TYPE> viewDataAdapter,
final Class<? extends Annotation>... ruleAnnotations) {
if (ruleAnnotations != null && ruleAnnotations.length > 0) {
for (Class<? extends Annotation> ruleAnnotation : ruleAnnotations) {
register(ruleAnnotation, ruleDataType, viewType, viewDataAdapter);
}
}
}
|
Registers {@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter}s for the associated
{@link AnnotationRule}s and their {@link android.view.View}s.
@param viewType The {@link android.view.View} type on which the {@link AnnotationRule}
can be used.
@param ruleDataType Data type expected by the {@link AnnotationRule}.
@param viewDataAdapter The {@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter}
that can get the data for the {@link AnnotationRule} from the
{@link android.view.View}.
@param ruleAnnotations Varargs of rule {@link java.lang.annotation.Annotation}s that
can be used with the {@link android.view.View} and the
{@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter}.
@param <VIEW> Type parameter that is a subclass of {@link android.view.View} class.
@param <DATA_TYPE> Data type expected by the {@link AnnotationRule} and
is returned by the {@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter}.
|
register
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Registry.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Registry.java
|
Apache-2.0
|
Set<Class<? extends Annotation>> getRegisteredAnnotations() {
return mMappings.keySet();
}
|
Retrieve all registered rule annotations.
@return {@link java.util.Set} containing all registered rule
{@link java.lang.annotation.Annotation}s.
|
getRegisteredAnnotations
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Registry.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Registry.java
|
Apache-2.0
|
public final int getSequence() {
return mSequence;
}
|
Returns the sequence of the {@link com.mobsandgeeks.saripaar.Rule}.
@return The sequence.
|
getSequence
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Rule.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Rule.java
|
Apache-2.0
|
boolean areOrderedFields() {
return mOrderedFields;
}
|
Tells if the fields are ordered. Useful only after the
{@link com.mobsandgeeks.saripaar.SaripaarFieldsComparator} is used to sort collection. Will
return true, if this method is called on an unused instance.
@return true if all the fields are ordered, false otherwise.
|
areOrderedFields
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/SaripaarFieldsComparator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/SaripaarFieldsComparator.java
|
Apache-2.0
|
public List<View> getAnnotatedViews(final Class<? extends Annotation> saripaarAnnotation) {
assertNotNull(saripaarAnnotation, "saripaarAnnotation");
assertIsRegisteredAnnotation(saripaarAnnotation);
// Get the AnnotationRule class
Class<? extends AnnotationRule> annotationRuleClass = getRuleClass(saripaarAnnotation);
// Find all views with the target rule
List<View> annotatedViews = new ArrayList<View>();
Set<View> views = mViewRulesMap.keySet();
for (View view : views) {
ArrayList<Pair<Rule, ViewDataAdapter>> ruleAdapterPairs = mViewRulesMap.get(view);
for (Pair<Rule, ViewDataAdapter> ruleAdapterPair : ruleAdapterPairs) {
boolean uniqueMatchingView =
annotationRuleClass.equals(ruleAdapterPair.first.getClass())
&& !annotatedViews.contains(view);
if (uniqueMatchingView) {
annotatedViews.add(view);
}
}
}
return annotatedViews;
}
|
Retrieves all {@link android.view.View}s that are annotated with the specified annotation.
@param saripaarAnnotation The annotation we are interested in.
@return A {@link java.util.List} of {@link android.view.View}s annotated with the
given annotation.
|
getAnnotatedViews
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/ValidationContext.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/ValidationContext.java
|
Apache-2.0
|
public Object getData(final View view, Class<? extends Annotation> saripaarAnnotation) {
assertNotNull(view, "view");
assertNotNull(saripaarAnnotation, "saripaarAnnotation");
Object data = null;
ArrayList<Pair<Rule, ViewDataAdapter>> ruleAdapterPairs = mViewRulesMap.get(view);
Class<? extends AnnotationRule> annotationRuleClass = getRuleClass(saripaarAnnotation);
for (Pair<Rule, ViewDataAdapter> ruleAdapterPair : ruleAdapterPairs) {
if (annotationRuleClass.equals(ruleAdapterPair.first.getClass())) {
try {
data = ruleAdapterPair.second.getData(view);
} catch (ConversionException e) {
e.printStackTrace();
}
}
}
return data;
}
|
Retrieves the data from the given {@link android.view.View} using the appropriate
{@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter}.
@param view A {@link android.view.View}.
@param saripaarAnnotation The annotation used to annotate the {@link android.view.View}.
@return The data that's on the {@link android.view.View}.
|
getData
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/ValidationContext.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/ValidationContext.java
|
Apache-2.0
|
public List<Rule> getFailedRules() {
return failedRules;
}
|
Gets the failed {@link com.mobsandgeeks.saripaar.Rule}s.
@return A {@link java.util.List} of failed {@link com.mobsandgeeks.saripaar.Rule}s.
|
getFailedRules
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/ValidationError.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/ValidationError.java
|
Apache-2.0
|
public String getCollatedErrorMessage(final Context context) {
StringBuilder stringBuilder = new StringBuilder();
for (Rule failedRule : failedRules) {
String message = failedRule.getMessage(context).trim();
if (message.length() > 0) {
stringBuilder.append(message).append('\n');
}
}
return stringBuilder.toString().trim();
}
|
Extracts error messages from multiple failed rules and returns a {@link java.lang.String}
object.
@param context A {@link android.content.Context}.
@return A collated error message.
|
getCollatedErrorMessage
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/ValidationError.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/ValidationError.java
|
Apache-2.0
|
public static <VIEW extends View> void registerAnnotation(
final Class<? extends Annotation> annotation, final Class<VIEW> viewType,
final ViewDataAdapter<VIEW, ?> viewDataAdapter) {
ValidateUsing validateUsing = annotation.getAnnotation(ValidateUsing.class);
Class ruleDataType = Reflector.getRuleDataType(validateUsing);
SARIPAAR_REGISTRY.register(viewType, ruleDataType, viewDataAdapter, annotation);
}
|
An elaborate method for registering custom rule annotations.
@param annotation The annotation that you want to register.
@param viewType The {@link android.view.View} type.
@param viewDataAdapter An instance of the
{@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter} for your
{@link android.view.View}.
@param <VIEW> The {@link android.view.View} for which the
{@link java.lang.annotation.Annotation} and
{@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter} is being registered.
|
registerAnnotation
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public <VIEW extends View, DATA_TYPE> void registerAdapter(
final Class<VIEW> viewType, final ViewDataAdapter<VIEW, DATA_TYPE> viewDataAdapter) {
assertNotNull(viewType, "viewType");
assertNotNull(viewDataAdapter, "viewDataAdapter");
HashMap<Class<?>, ViewDataAdapter> dataTypeAdapterMap = mRegisteredAdaptersMap.get(viewType);
if (dataTypeAdapterMap == null) {
dataTypeAdapterMap = new HashMap<Class<?>, ViewDataAdapter>();
mRegisteredAdaptersMap.put(viewType, dataTypeAdapterMap);
}
// Find adapter's data type
Method getDataMethod = Reflector.findGetDataMethod(viewDataAdapter.getClass());
Class<?> adapterDataType = getDataMethod.getReturnType();
dataTypeAdapterMap.put(adapterDataType, viewDataAdapter);
}
|
Registers a {@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter} for the given
{@link android.view.View}.
@param viewType The {@link android.view.View} for which a
{@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter} is being registered.
@param viewDataAdapter A {@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter} instance.
@param <VIEW> The {@link android.view.View} type.
@param <DATA_TYPE> The {@link com.mobsandgeeks.saripaar.adapter.ViewDataAdapter} type.
|
registerAdapter
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public void setValidationListener(final ValidationListener validationListener) {
assertNotNull(validationListener, "validationListener");
this.mValidationListener = validationListener;
}
|
Set a {@link com.mobsandgeeks.saripaar.Validator.ValidationListener} to the
{@link com.mobsandgeeks.saripaar.Validator}.
@param validationListener A {@link com.mobsandgeeks.saripaar.Validator.ValidationListener}
instance. null throws an {@link java.lang.IllegalArgumentException}.
|
setValidationListener
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public void setViewValidatedAction(final ViewValidatedAction viewValidatedAction) {
this.mViewValidatedAction = viewValidatedAction;
}
|
Set a {@link com.mobsandgeeks.saripaar.Validator.ViewValidatedAction} to the
{@link com.mobsandgeeks.saripaar.Validator}.
@param viewValidatedAction A {@link com.mobsandgeeks.saripaar.Validator.ViewValidatedAction}
instance.
|
setViewValidatedAction
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public void setValidationMode(final Mode validationMode) {
assertNotNull(validationMode, "validationMode");
this.mValidationMode = validationMode;
}
|
Set the validation {@link com.mobsandgeeks.saripaar.Validator.Mode} for the current
{@link com.mobsandgeeks.saripaar.Validator} instance.
@param validationMode {@link Mode#BURST} or {@link Mode#IMMEDIATE}, null throws an
{@link java.lang.IllegalArgumentException}.
|
setValidationMode
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public Mode getValidationMode() {
return mValidationMode;
}
|
Gets the current {@link com.mobsandgeeks.saripaar.Validator.Mode}.
@return The current validation mode of the {@link com.mobsandgeeks.saripaar.Validator}.
|
getValidationMode
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public void validateInvisibleViews(final boolean validate) {
this.mValidateInvisibleViews = validate;
}
|
Configures the validator to validate invisible views.
@param validate {@code true} includes invisible views during validation.
|
validateInvisibleViews
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public void validateBefore(final View view) {
validateBefore(view, false);
}
|
Validates all {@link android.view.View}s before the specified {@link android.view.View}
parameter. {@link android.view.View} fields MUST be ordered using the
{@link com.mobsandgeeks.saripaar.annotation.Order} annotation.
@param view A {@link android.view.View}.
|
validateBefore
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public void validateTill(final View view) {
validateTill(view, false);
}
|
Validates all {@link android.view.View}s till the specified {@link android.view.View}
parameter. {@link android.view.View} fields MUST be ordered using the
{@link com.mobsandgeeks.saripaar.annotation.Order} annotation.
@param view A {@link android.view.View}.
|
validateTill
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public void validate(final boolean async) {
createRulesSafelyAndLazily(false);
View lastView = getLastView();
if (Mode.BURST.equals(mValidationMode)) {
validateUnorderedFieldsWithCallbackTill(lastView, async);
} else if (Mode.IMMEDIATE.equals(mValidationMode)) {
String reasonSuffix = String.format("in %s mode.", Mode.IMMEDIATE.toString());
validateOrderedFieldsWithCallbackTill(lastView, reasonSuffix, async);
} else {
throw new RuntimeException("This should never happen!");
}
}
|
Validates all {@link android.view.View}s with {@link com.mobsandgeeks.saripaar.Rule}s.
When validating in {@link com.mobsandgeeks.saripaar.Validator.Mode#IMMEDIATE}, all
{@link android.view.View} fields must be ordered using the
{@link com.mobsandgeeks.saripaar.annotation.Order} annotation. Asynchronous calls will cancel
any pending or ongoing asynchronous validation and start a new one.
@param async true if asynchronous, false otherwise.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public void validateBefore(final View view, final boolean async) {
createRulesSafelyAndLazily(false);
View previousView = getViewBefore(view);
validateOrderedFieldsWithCallbackTill(previousView, "when using 'validateBefore(View)'.",
async);
}
|
Validates all {@link android.view.View}s before the specified {@link android.view.View}
parameter. {@link android.view.View} fields MUST be ordered using the
{@link com.mobsandgeeks.saripaar.annotation.Order} annotation. Asynchronous calls will cancel
any pending or ongoing asynchronous validation and start a new one.
@param view A {@link android.view.View}.
@param async true if asynchronous, false otherwise.
|
validateBefore
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public void validateTill(final View view, final boolean async) {
validateOrderedFieldsWithCallbackTill(view, "when using 'validateTill(View)'.", async);
}
|
Validates all {@link android.view.View}s till the specified {@link android.view.View}
parameter. {@link android.view.View} fields MUST be ordered using the
{@link com.mobsandgeeks.saripaar.annotation.Order} annotation. Asynchronous calls will cancel
any pending or ongoing asynchronous validation and start a new one.
@param view A {@link android.view.View}.
@param async true if asynchronous, false otherwise.
|
validateTill
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public boolean isValidating() {
return mAsyncValidationTask != null
&& mAsyncValidationTask.getStatus() != AsyncTask.Status.FINISHED;
}
|
Used to find if an asynchronous validation task is running. Useful only when you run the
{@link com.mobsandgeeks.saripaar.Validator} in asynchronous mode.
@return true if the asynchronous task is running, false otherwise.
|
isValidating
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public boolean cancelAsync() {
boolean cancelled = false;
if (mAsyncValidationTask != null) {
cancelled = mAsyncValidationTask.cancel(true);
mAsyncValidationTask = null;
}
return cancelled;
}
|
Cancels a running asynchronous validation task.
@return true if a running asynchronous task was cancelled, false otherwise.
|
cancelAsync
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
public <VIEW extends View> void put(final VIEW view, final QuickRule<VIEW>... quickRules) {
assertNotNull(view, "view");
assertNotNull(quickRules, "quickRules");
if (quickRules.length == 0) {
throw new IllegalArgumentException("'quickRules' cannot be empty.");
}
if (mValidationContext == null) {
mValidationContext = new ValidationContext(view.getContext());
}
// Create rules
createRulesSafelyAndLazily(true);
// If all fields are ordered, then this field should be ordered too
if (mOrderedFields && !mViewRulesMap.containsKey(view)) {
String message = String.format("All fields are ordered, so this `%s` should be "
+ "ordered too, declare the view as a field and add the `@Order` "
+ "annotation.", view.getClass().getName());
throw new IllegalStateException(message);
}
// If there are no rules, create an empty list
ArrayList<Pair<Rule, ViewDataAdapter>> ruleAdapterPairs = mViewRulesMap.get(view);
ruleAdapterPairs = ruleAdapterPairs == null
? new ArrayList<Pair<Rule, ViewDataAdapter>>() : ruleAdapterPairs;
// Add the quick rule to existing rules
for (int i = 0, n = quickRules.length; i < n; i++) {
QuickRule quickRule = quickRules[i];
if (quickRule != null) {
ruleAdapterPairs.add(new Pair(quickRule, null));
}
}
Collections.sort(ruleAdapterPairs, mSequenceComparator);
mViewRulesMap.put(view, ruleAdapterPairs);
}
|
Add one or more {@link com.mobsandgeeks.saripaar.QuickRule}s for a {@link android.view.View}.
@param view A {@link android.view.View} for which
{@link com.mobsandgeeks.saripaar.QuickRule}(s) are to be added.
@param quickRules Varargs of {@link com.mobsandgeeks.saripaar.QuickRule}s.
@param <VIEW> The {@link android.view.View} type for which the
{@link com.mobsandgeeks.saripaar.QuickRule}s are being registered.
|
put
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/Validator.java
|
Apache-2.0
|
@Override
public <T extends Annotation> boolean containsOptionalValue(final TextView textView,
final T annotation) {
return "".equals(textView.getText().toString());
}
|
A base class that implements the {@link #containsOptionalValue(View, Annotation)} method for concrete
{@link TextView} adapters.
@author Ragunath Jawahar {@literal <rj@mobsandgeeks.com>}
@since 2.1.0
|
containsOptionalValue
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/TextViewBaseAdapter.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/TextViewBaseAdapter.java
|
Apache-2.0
|
@Override
public Double getData(final TextView textView) throws ConversionException {
String doubleString = textView.getText().toString().trim();
if (!doubleString.matches(REGEX_DECIMAL)) {
String message = String.format("Expected a floating point number, but was %s",
doubleString);
throw new ConversionException(message);
}
return Double.parseDouble(doubleString);
}
|
Adapter parses and returns a {@link java.lang.Double} from {@link android.widget.TextView}s or
its subclasses like {@link android.widget.EditText}s.
@author Ragunath Jawahar {@literal <rj@mobsandgeeks.com>}
@since 2.0
|
getData
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/TextViewDoubleAdapter.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/TextViewDoubleAdapter.java
|
Apache-2.0
|
@Override
public Float getData(final TextView textView) throws ConversionException {
String floatString = textView.getText().toString().trim();
if (!floatString.matches(REGEX_DECIMAL)) {
String message = String.format("Expected a floating point number, but was %s",
floatString);
throw new ConversionException(message);
}
return Float.parseFloat(floatString);
}
|
Adapter returns a {@link java.lang.Float} from {@link android.widget.TextView}s or
its subclasses like {@link android.widget.EditText}s.
@author Ragunath Jawahar {@literal <rj@mobsandgeeks.com>}
@since 2.0
|
getData
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/TextViewFloatAdapter.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/TextViewFloatAdapter.java
|
Apache-2.0
|
@Override
public Integer getData(final TextView textView) throws ConversionException {
String integerString = textView.getText().toString().trim();
if (!integerString.matches(REGEX_INTEGER)) {
String message = String.format("Expected an integer, but was %s", integerString);
throw new ConversionException(message);
}
return Integer.parseInt(integerString);
}
|
Adapter parses and returns an {@link java.lang.Integer} from {@link android.widget.TextView}s or
its subclasses like {@link android.widget.EditText}s.
@author Ragunath Jawahar {@literal <rj@mobsandgeeks.com>}
@since 2.0
|
getData
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/TextViewIntegerAdapter.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/TextViewIntegerAdapter.java
|
Apache-2.0
|
@Override
public String getData(final TextView textView) {
return textView.getText().toString();
}
|
Adapter returns a {@link java.lang.String} from {@link android.widget.TextView}s or
its subclasses, usually {@link android.widget.EditText}s.
@author Ragunath Jawahar {@literal <rj@mobsandgeeks.com>}
@since 2.0
|
getData
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/TextViewStringAdapter.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/adapter/TextViewStringAdapter.java
|
Apache-2.0
|
@Override
public boolean isValid(final DATA_TYPE confirmValue) {
List<View> sourceViews = mValidationContext.getAnnotatedViews(mSourceClass);
int nSourceViews = sourceViews.size();
if (nSourceViews == 0) {
String message = String.format(
"You should have a view annotated with '%s' to use '%s'.",
mSourceClass.getName(), mConfirmClass.getName());
throw new IllegalStateException(message);
} else if (nSourceViews > 1) {
String message = String.format(
"More than 1 field annotated with '%s'.", mSourceClass.getName());
throw new IllegalStateException(message);
}
// There's only one, then we're good to go :)
View view = sourceViews.get(0);
Object sourceValue = mValidationContext.getData(view, mSourceClass);
return confirmValue.equals(sourceValue);
}
|
A generic class for comparing values across two {@link android.view.View}s.
@see com.mobsandgeeks.saripaar.annotation.ConfirmEmail
@see com.mobsandgeeks.saripaar.annotation.ConfirmPassword
@author Ragunath Jawahar {@literal <rj@mobsandgeeks.com>}
@since 2.0
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/com/mobsandgeeks/saripaar/rule/SameValueContextualRule.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/com/mobsandgeeks/saripaar/rule/SameValueContextualRule.java
|
Apache-2.0
|
public boolean isValid(String value) {
return isValid(value, (String)null, (Locale)null);
}
|
<p>Validate using the default <code>Locale</code>.
@param value The value validation is being performed on.
@return <code>true</code> if the value is valid.
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
Apache-2.0
|
public boolean isValid(String value, String pattern) {
return isValid(value, pattern, (Locale)null);
}
|
<p>Validate using the specified <i>pattern</i>.
@param value The value validation is being performed on.
@param pattern The pattern used to validate the value against.
@return <code>true</code> if the value is valid.
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
Apache-2.0
|
public boolean isValid(String value, Locale locale) {
return isValid(value, (String)null, locale);
}
|
<p>Validate using the specified <code>Locale</code>.
@param value The value validation is being performed on.
@param locale The locale to use for the Format, defaults to the default
@return <code>true</code> if the value is valid.
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
Apache-2.0
|
public String format(Object value) {
return format(value, (String)null, (Locale)null);
}
|
<p>Format an object into a <code>String</code> using
the default Locale.</p>
@param value The value validation is being performed on.
@return The value formatted as a <code>String</code>.
|
format
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
Apache-2.0
|
public String format(Object value, String pattern) {
return format(value, pattern, (Locale)null);
}
|
<p>Format an object into a <code>String</code> using
the specified pattern.</p>
@param value The value validation is being performed on.
@param pattern The pattern used to format the value.
@return The value formatted as a <code>String</code>.
|
format
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
Apache-2.0
|
public String format(Object value, Locale locale) {
return format(value, (String)null, locale);
}
|
<p>Format an object into a <code>String</code> using
the specified Locale.</p>
@param value The value validation is being performed on.
@param locale The locale to use for the Format.
@return The value formatted as a <code>String</code>.
|
format
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
Apache-2.0
|
public String format(Object value, String pattern, Locale locale) {
Format formatter = getFormat(pattern, locale);
return format(value, formatter);
}
|
<p>Format an object using the specified pattern and/or
<code>Locale</code>.
@param value The value validation is being performed on.
@param pattern The pattern used to format the value.
@param locale The locale to use for the Format.
@return The value formatted as a <code>String</code>.
|
format
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
Apache-2.0
|
protected String format(Object value, Format formatter) {
return formatter.format(value);
}
|
<p>Format a value with the specified <code>Format</code>.</p>
@param value The value to be formatted.
@param formatter The Format to use.
@return The formatted value.
|
format
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
Apache-2.0
|
protected Object parse(String value, Format formatter) {
ParsePosition pos = new ParsePosition(0);
Object parsedValue = formatter.parseObject(value, pos);
if (pos.getErrorIndex() > -1) {
return null;
}
if (isStrict() && pos.getIndex() < value.length()) {
return null;
}
if (parsedValue != null) {
parsedValue = processParsedValue(parsedValue, formatter);
}
return parsedValue;
}
|
<p>Parse the value with the specified <code>Format</code>.</p>
@param value The value to be parsed.
@param formatter The Format to parse the value with.
@return The parsed value if valid or <code>null</code> if invalid.
|
parse
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractFormatValidator.java
|
Apache-2.0
|
public boolean isAllowFractions() {
return allowFractions;
}
|
<p>Indicates whether the number being validated is
a decimal or integer.</p>
@return <code>true</code> if decimals are allowed
or <code>false</code> if the number is an integer.
|
isAllowFractions
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
Apache-2.0
|
public int getFormatType() {
return formatType;
}
|
<p>Indicates the type of <code>NumberFormat</code> created
by this validator instance.</p>
@return the format type created.
|
getFormatType
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
Apache-2.0
|
public boolean isValid(String value, String pattern, Locale locale) {
Object parsedValue = parse(value, pattern, locale);
return (parsedValue == null ? false : true);
}
|
<p>Validate using the specified <code>Locale</code>.</p>
@param value The value validation is being performed on.
@param pattern The pattern used to validate the value against, or the
default for the <code>Locale</code> if <code>null</code>.
@param locale The locale to use for the date format, system default if null.
@return <code>true</code> if the value is valid.
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
Apache-2.0
|
public boolean isInRange(Number value, Number min, Number max) {
return (minValue(value, min) && maxValue(value, max));
}
|
Check if the value is within a specified range.
@param value The value validation is being performed on.
@param min The minimum value of the range.
@param max The maximum value of the range.
@return <code>true</code> if the value is within the
specified range.
|
isInRange
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
Apache-2.0
|
protected Object parse(String value, String pattern, Locale locale) {
value = (value == null ? null : value.trim());
if (value == null || value.length() == 0) {
return null;
}
Format formatter = getFormat(pattern, locale);
return parse(value, formatter);
}
|
<p>Parse the value using the specified pattern.</p>
@param value The value validation is being performed on.
@param pattern The pattern used to validate the value against, or the
default for the <code>Locale</code> if <code>null</code>.
@param locale The locale to use for the date format, system default if null.
@return The parsed value if valid or <code>null</code> if invalid.
|
parse
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
Apache-2.0
|
protected Format getFormat(String pattern, Locale locale) {
NumberFormat formatter = null;
boolean usePattern = (pattern != null && pattern.length() > 0);
if (!usePattern) {
formatter = (NumberFormat)getFormat(locale);
} else if (locale == null) {
formatter = new DecimalFormat(pattern);
} else {
DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
formatter = new DecimalFormat(pattern, symbols);
}
if (determineScale(formatter) == 0) {
formatter.setParseIntegerOnly(true);
}
return formatter;
}
|
<p>Returns a <code>NumberFormat</code> for the specified <i>pattern</i>
and/or <code>Locale</code>.</p>
@param pattern The pattern used to validate the value against or
<code>null</code> to use the default for the <code>Locale</code>.
@param locale The locale to use for the currency format, system default if null.
@return The <code>NumberFormat</code> to created.
|
getFormat
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
Apache-2.0
|
protected int determineScale(NumberFormat format) {
if (!isStrict()) {
return -1;
}
if (!isAllowFractions() || format.isParseIntegerOnly()) {
return 0;
}
int minimumFraction = format.getMinimumFractionDigits();
int maximumFraction = format.getMaximumFractionDigits();
if (minimumFraction != maximumFraction) {
return -1;
}
int scale = minimumFraction;
if (format instanceof DecimalFormat) {
int multiplier = ((DecimalFormat)format).getMultiplier();
if (multiplier == 100) {
scale += 2;
} else if (multiplier == 1000) {
scale += 3;
}
} else if (formatType == PERCENT_FORMAT) {
scale += 2;
}
return scale;
}
|
<p>Returns the <i>multiplier</i> of the <code>NumberFormat</code>.</p>
@param format The <code>NumberFormat</code> to determine the
multiplier of.
@return The multiplying factor for the format..
|
determineScale
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
Apache-2.0
|
protected Format getFormat(Locale locale) {
NumberFormat formatter = null;
switch (formatType) {
case CURRENCY_FORMAT:
if (locale == null) {
formatter = NumberFormat.getCurrencyInstance();
} else {
formatter = NumberFormat.getCurrencyInstance(locale);
}
break;
case PERCENT_FORMAT:
if (locale == null) {
formatter = NumberFormat.getPercentInstance();
} else {
formatter = NumberFormat.getPercentInstance(locale);
}
break;
default:
if (locale == null) {
formatter = NumberFormat.getInstance();
} else {
formatter = NumberFormat.getInstance(locale);
}
break;
}
return formatter;
}
|
<p>Returns a <code>NumberFormat</code> for the specified Locale.</p>
@param locale The locale a <code>NumberFormat</code> is required for,
system default if null.
@return The <code>NumberFormat</code> to created.
|
getFormat
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/AbstractNumberValidator.java
|
Apache-2.0
|
public CheckDigit getCheckDigit() {
return checkdigit;
}
|
Return the check digit validation routine.
<p>
<b>N.B.</b> Optional, if not set no Check Digit
validation will be performed on the code.
@return The check digit validation routine
|
getCheckDigit
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/CodeValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/CodeValidator.java
|
Apache-2.0
|
public RegexValidator getRegexValidator() {
return regexValidator;
}
|
Return the <i>regular expression</i> validator.
<p>
<b>N.B.</b> Optional, if not set no regular
expression validation will be performed on the code.
@return The regular expression validator
|
getRegexValidator
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/CodeValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/CodeValidator.java
|
Apache-2.0
|
public boolean isValid(String input) {
return (validate(input) != null);
}
|
Validate the code returning either <code>true</code>
or <code>false</code>.
@param input The code to validate
@return <code>true</code> if valid, otherwise
<code>false</code>
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/CodeValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/CodeValidator.java
|
Apache-2.0
|
public Object validate(String input) {
if (input == null) {
return null;
}
String code = input.trim();
if (code.length() == 0) {
return null;
}
// validate/reformat using regular expression
if (regexValidator != null) {
code = regexValidator.validate(code);
if (code == null) {
return null;
}
}
// check the length
if ((minLength >= 0 && code.length() < minLength) ||
(maxLength >= 0 && code.length() > maxLength)) {
return null;
}
// validate the check digit
if (checkdigit != null && !checkdigit.isValid(code)) {
return null;
}
return code;
}
|
Validate the code returning either the valid code or
<code>null</code> if invalid.
@param input The code to validate
@return The code if valid, otherwise <code>null</code>
if invalid
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/CodeValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/CodeValidator.java
|
Apache-2.0
|
public boolean isValid(String card) {
if (card == null || card.length() == 0) {
return false;
}
for (int i = 0; i < cardTypes.size(); i++) {
CodeValidator type = (CodeValidator)cardTypes.get(i);
if (type.isValid(card)) {
return true;
}
}
return false;
}
|
Checks if the field is a valid credit card number.
@param card The card number to validate.
@return Whether the card number is valid.
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/CreditCardValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/CreditCardValidator.java
|
Apache-2.0
|
public Object validate(String card) {
if (card == null || card.length() == 0) {
return null;
}
Object result = null;
for (int i = 0; i < cardTypes.size(); i++) {
CodeValidator type = (CodeValidator)cardTypes.get(i);
result = type.validate(card);
if (result != null) {
return result ;
}
}
return null;
}
|
Checks if the field is a valid credit card number.
@param card The card number to validate.
@return The card number if valid or <code>null</code>
if invalid.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/CreditCardValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/CreditCardValidator.java
|
Apache-2.0
|
private boolean isOn(long options, long flag) {
return (options & flag) > 0;
}
|
Tests whether the given flag is on. If the flag is not a power of 2
(ie. 3) this tests whether the combination of flags is on.
@param options The options specified.
@param flag Flag value to check.
@return whether the specified flag value is on.
|
isOn
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/CreditCardValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/CreditCardValidator.java
|
Apache-2.0
|
public static DoubleValidator getInstance() {
return VALIDATOR;
}
|
Return a singleton instance of this validator.
@return A singleton instance of the DoubleValidator.
|
getInstance
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
Apache-2.0
|
public Double validate(String value) {
return (Double)parse(value, (String)null, (Locale)null);
}
|
<p>Validate/convert a <code>Double</code> using the default
<code>Locale</code>.
@param value The value validation is being performed on.
@return The parsed <code>Double</code> if valid or <code>null</code>
if invalid.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
Apache-2.0
|
public Double validate(String value, String pattern) {
return (Double)parse(value, pattern, (Locale)null);
}
|
<p>Validate/convert a <code>Double</code> using the
specified <i>pattern</i>.
@param value The value validation is being performed on.
@param pattern The pattern used to validate the value against.
@return The parsed <code>BigDecimal</code> if valid or <code>null</code> if invalid.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
Apache-2.0
|
public Double validate(String value, Locale locale) {
return (Double)parse(value, (String)null, locale);
}
|
<p>Validate/convert a <code>Double</code> using the
specified <code>Locale</code>.
@param value The value validation is being performed on.
@param locale The locale to use for the number format, system default if null.
@return The parsed <code>Double</code> if valid or <code>null</code> if invalid.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
Apache-2.0
|
public Double validate(String value, String pattern, Locale locale) {
return (Double)parse(value, pattern, locale);
}
|
<p>Validate/convert a <code>Double</code> using the
specified pattern and/ or <code>Locale</code>.
@param value The value validation is being performed on.
@param pattern The pattern used to validate the value against, or the
default for the <code>Locale</code> if <code>null</code>.
@param locale The locale to use for the date format, system default if null.
@return The parsed <code>Double</code> if valid or <code>null</code> if invalid.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
Apache-2.0
|
protected Object processParsedValue(Object value, Format formatter) {
if (value instanceof Double) {
return value;
}
return new Double(((Number)value).doubleValue());
}
|
Convert the parsed value to a <code>Double</code>.
@param value The parsed <code>Number</code> object created.
@param formatter The Format used to parse the value with.
@return The validated/converted <code>Double</code> value if valid
or <code>null</code> if invalid.
|
processParsedValue
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/DoubleValidator.java
|
Apache-2.0
|
public static IntegerValidator getInstance() {
return VALIDATOR;
}
|
Return a singleton instance of this validator.
@return A singleton instance of the IntegerValidator.
|
getInstance
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
Apache-2.0
|
public Integer validate(String value) {
return (Integer)parse(value, (String)null, (Locale)null);
}
|
<p>Validate/convert an <code>Integer</code> using the default
<code>Locale</code>.
@param value The value validation is being performed on.
@return The parsed <code>Integer</code> if valid or <code>null</code>
if invalid.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
Apache-2.0
|
public Integer validate(String value, String pattern) {
return (Integer)parse(value, pattern, (Locale)null);
}
|
<p>Validate/convert an <code>Integer</code> using the
specified <i>pattern</i>.
@param value The value validation is being performed on.
@param pattern The pattern used to validate the value against.
@return The parsed <code>Integer</code> if valid or <code>null</code> if invalid.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
Apache-2.0
|
public Integer validate(String value, Locale locale) {
return (Integer)parse(value, (String)null, locale);
}
|
<p>Validate/convert an <code>Integer</code> using the
specified <code>Locale</code>.
@param value The value validation is being performed on.
@param locale The locale to use for the number format, system default if null.
@return The parsed <code>Integer</code> if valid or <code>null</code> if invalid.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
Apache-2.0
|
public Integer validate(String value, String pattern, Locale locale) {
return (Integer)parse(value, pattern, locale);
}
|
<p>Validate/convert a <code>Integer</code> using the
specified pattern and/ or <code>Locale</code>.
@param value The value validation is being performed on.
@param pattern The pattern used to validate the value against, or the
default for the <code>Locale</code> if <code>null</code>.
@param locale The locale to use for the date format, system default if null.
@return The parsed <code>Integer</code> if valid or <code>null</code> if invalid.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
Apache-2.0
|
protected Object processParsedValue(Object value, Format formatter) {
long longValue = ((Number)value).longValue();
if (longValue < Integer.MIN_VALUE ||
longValue > Integer.MAX_VALUE) {
return null;
}
return new Integer((int)longValue);
}
|
<p>Perform further validation and convert the <code>Number</code> to
an <code>Integer</code>.</p>
@param value The parsed <code>Number</code> object created.
@param formatter The Format used to parse the value with.
@return The parsed <code>Number</code> converted to an
<code>Integer</code> if valid or <code>null</code> if invalid.
|
processParsedValue
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/IntegerValidator.java
|
Apache-2.0
|
public static ISBNValidator getInstance() {
return ISBN_VALIDATOR;
}
|
Return a singleton instance of the ISBN validator which
converts ISBN-10 codes to ISBN-13.
@return A singleton instance of the ISBN validator.
|
getInstance
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
Apache-2.0
|
public static ISBNValidator getInstance(boolean convert) {
return (convert ? ISBN_VALIDATOR : ISBN_VALIDATOR_NO_CONVERT);
}
|
Return a singleton instance of the ISBN validator specifying
whether ISBN-10 codes should be converted to ISBN-13.
@param convert <code>true</code> if valid ISBN-10 codes
should be converted to ISBN-13 codes or <code>false</code>
if valid ISBN-10 codes should be returned unchanged.
@return A singleton instance of the ISBN validator.
|
getInstance
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
Apache-2.0
|
public boolean isValid(String code) {
return (isValidISBN13(code) || isValidISBN10(code));
}
|
Check the code is either a valid ISBN-10 or ISBN-13 code.
@param code The code to validate.
@return <code>true</code> if a valid ISBN-10 or
ISBN-13 code, otherwise <code>false</code>.
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
Apache-2.0
|
public boolean isValidISBN10(String code) {
return isbn10Validator.isValid(code);
}
|
Check the code is a valid ISBN-10 code.
@param code The code to validate.
@return <code>true</code> if a valid ISBN-10
code, otherwise <code>false</code>.
|
isValidISBN10
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
Apache-2.0
|
public boolean isValidISBN13(String code) {
return isbn13Validator.isValid(code);
}
|
Check the code is a valid ISBN-13 code.
@param code The code to validate.
@return <code>true</code> if a valid ISBN-13
code, otherwise <code>false</code>.
|
isValidISBN13
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
Apache-2.0
|
public String validate(String code) {
String result = validateISBN13(code);
if (result == null) {
result = validateISBN10(code);
if (result != null && convert) {
result = convertToISBN13(result);
}
}
return result;
}
|
Check the code is either a valid ISBN-10 or ISBN-13 code.
<p>
If valid, this method returns the ISBN code with
formatting characters removed (i.e. space or hyphen).
<p>
Converts an ISBN-10 codes to ISBN-13 if
<code>convertToISBN13</code> is <code>true</code>.
@param code The code to validate.
@return A valid ISBN code if valid, otherwise <code>null</code>.
|
validate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
Apache-2.0
|
public String validateISBN10(String code) {
Object result = isbn10Validator.validate(code);
return (result == null ? null : result.toString());
}
|
Check the code is a valid ISBN-10 code.
<p>
If valid, this method returns the ISBN-10 code with
formatting characters removed (i.e. space or hyphen).
@param code The code to validate.
@return A valid ISBN-10 code if valid,
otherwise <code>null</code>.
|
validateISBN10
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
Apache-2.0
|
public String validateISBN13(String code) {
Object result = isbn13Validator.validate(code);
return (result == null ? null : result.toString());
}
|
Check the code is a valid ISBN-13 code.
<p>
If valid, this method returns the ISBN-13 code with
formatting characters removed (i.e. space or hyphen).
@param code The code to validate.
@return A valid ISBN-13 code if valid,
otherwise <code>null</code>.
|
validateISBN13
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
Apache-2.0
|
public String convertToISBN13(String isbn10) {
if (isbn10 == null) {
return null;
}
String input = isbn10.trim();
if (input.length() != 10) {
throw new IllegalArgumentException("Invalid length " + input.length() + " for '" + input + "'");
}
// Calculate the new ISBN-13 code
String isbn13 = "978" + input.substring(0, 9);
try {
String checkDigit = isbn13Validator.getCheckDigit().calculate(isbn13);
isbn13 += checkDigit;
return isbn13;
} catch (CheckDigitException e) {
throw new IllegalArgumentException("Check digit error for '" + input + "' - " + e.getMessage());
}
}
|
Convert an ISBN-10 code to an ISBN-13 code.
<p>
This method requires a valid ISBN-10 with NO formatting
characters.
@param isbn10 The ISBN-10 code to convert
@return A converted ISBN-13 code or <code>null</code>
if the ISBN-10 code is not valid
|
convertToISBN13
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/ISBNValidator.java
|
Apache-2.0
|
public boolean isValid(String value) {
if (value == null) {
return false;
}
for (int i = 0; i < patterns.length; i++) {
if (patterns[i].matcher(value).matches()) {
return true;
}
}
return false;
}
|
Validate a value against the set of regular expressions.
@param value The value to validate.
@return <code>true</code> if the value is valid
otherwise <code>false</code>.
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/RegexValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/RegexValidator.java
|
Apache-2.0
|
public String[] match(String value) {
if (value == null) {
return null;
}
for (int i = 0; i < patterns.length; i++) {
Matcher matcher = patterns[i].matcher(value);
if (matcher.matches()) {
int count = matcher.groupCount();
String[] groups = new String[count];
for (int j = 0; j < count; j++) {
groups[j] = matcher.group(j+1);
}
return groups;
}
}
return null;
}
|
Validate a value against the set of regular expressions
returning the array of matched groups.
@param value The value to validate.
@return String array of the <i>groups</i> matched if
valid or <code>null</code> if invalid
|
match
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/RegexValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/RegexValidator.java
|
Apache-2.0
|
public boolean isValid(String value) {
if (value == null) {
return false;
}
// Check the whole url address structure
Matcher urlMatcher = URL_PATTERN.matcher(value);
if (!urlMatcher.matches()) {
return false;
}
String scheme = urlMatcher.group(PARSE_URL_SCHEME);
if (!isValidScheme(scheme)) {
return false;
}
String authority = urlMatcher.group(PARSE_URL_AUTHORITY);
if ("file".equals(scheme) && "".equals(authority)) {
// Special case - file: allows an empty authority
} else {
// Validate the authority
if (!isValidAuthority(authority)) {
return false;
}
}
if (!isValidPath(urlMatcher.group(PARSE_URL_PATH))) {
return false;
}
if (!isValidQuery(urlMatcher.group(PARSE_URL_QUERY))) {
return false;
}
if (!isValidFragment(urlMatcher.group(PARSE_URL_FRAGMENT))) {
return false;
}
return true;
}
|
<p>Checks if a field has a valid url address.</p>
Note that the method calls #isValidAuthority()
which checks that the domain is valid.
@param value The value validation is being performed on. A <code>null</code>
value is considered invalid.
@return true if the url is valid.
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/UrlValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/UrlValidator.java
|
Apache-2.0
|
protected boolean isValidScheme(String scheme) {
if (scheme == null) {
return false;
}
// TODO could be removed if external schemes were checked in the ctor before being stored
if (!SCHEME_PATTERN.matcher(scheme).matches()) {
return false;
}
if (isOff(ALLOW_ALL_SCHEMES) && !allowedSchemes.contains(scheme.toLowerCase(Locale.ENGLISH))) {
return false;
}
return true;
}
|
Validate scheme. If schemes[] was initialized to a non null,
then only those schemes are allowed.
Otherwise the default schemes are "http", "https", "ftp".
Matching is case-blind.
@param scheme The scheme to validate. A <code>null</code> value is considered
invalid.
@return true if valid.
|
isValidScheme
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/UrlValidator.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/UrlValidator.java
|
Apache-2.0
|
protected int weightedValue(int charValue, int leftPos, int rightPos) {
int weight = POSITION_WEIGHT[rightPos % 2];
return charValue * weight;
}
|
<p>Calculates the <i>weighted</i> value of a character in the
code at a specified position.</p>
<p>For EAN-13 (from right to left) <b>odd</b> digits are weighted
with a factor of <b>one</b> and <b>even</b> digits with a factor
of <b>three</b>.</p>
@param charValue The numeric value of the character.
@param leftPos The position of the character in the code, counting from left to right
@param rightPos The positionof the character in the code, counting from right to left
@return The weighted value of the character.
|
weightedValue
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/checkdigit/EAN13CheckDigit.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/checkdigit/EAN13CheckDigit.java
|
Apache-2.0
|
protected int weightedValue(int charValue, int leftPos, int rightPos) {
return charValue * rightPos;
}
|
Calculates the <i>weighted</i> value of a charcter in the
code at a specified position.
<p>For ISBN-10 (from right to left) digits are weighted
by their position.</p>
@param charValue The numeric value of the character.
@param leftPos The position of the character in the code, counting from left to right
@param rightPos The positionof the character in the code, counting from right to left
@return The weighted value of the character.
|
weightedValue
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/checkdigit/ISBN10CheckDigit.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/checkdigit/ISBN10CheckDigit.java
|
Apache-2.0
|
protected int toInt(char character, int leftPos, int rightPos)
throws CheckDigitException {
if (rightPos == 1 && character == 'X') {
return 10;
}
return super.toInt(character, leftPos, rightPos);
}
|
<p>Convert a character at a specified position to an
integer value.</p>
<p>Character 'X' check digit converted to 10.</p>
@param character The character to convert.
@param leftPos The position of the character in the code, counting from left to right
@param rightPos The position of the character in the code, counting from right to left
@return The integer value of the character.
@throws CheckDigitException if an error occurs.
|
toInt
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/checkdigit/ISBN10CheckDigit.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/checkdigit/ISBN10CheckDigit.java
|
Apache-2.0
|
protected String toCheckDigit(int charValue)
throws CheckDigitException {
if (charValue == 10) {
return "X";
}
return super.toCheckDigit(charValue);
}
|
<p>Convert an integer value to a character at a specified position.</p>
<p>Value '10' for position 1 (check digit) converted to 'X'.</p>
@param charValue The integer value of the character.
@return The converted character.
@throws CheckDigitException if an error occurs.
|
toCheckDigit
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/checkdigit/ISBN10CheckDigit.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/checkdigit/ISBN10CheckDigit.java
|
Apache-2.0
|
protected int weightedValue(int charValue, int leftPos, int rightPos) {
int weight = POSITION_WEIGHT[rightPos % 2];
int weightedValue = charValue * weight;
return weightedValue > 9 ? (weightedValue - 9) : weightedValue;
}
|
<p>Calculates the <i>weighted</i> value of a charcter in the
code at a specified position.</p>
<p>For Luhn (from right to left) <b>odd</b> digits are weighted
with a factor of <b>one</b> and <b>even</b> digits with a factor
of <b>two</b>. Weighted values > 9, have 9 subtracted</p>
@param charValue The numeric value of the character.
@param leftPos The position of the character in the code, counting from left to right
@param rightPos The positionof the character in the code, counting from right to left
@return The weighted value of the character.
|
weightedValue
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/checkdigit/LuhnCheckDigit.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/checkdigit/LuhnCheckDigit.java
|
Apache-2.0
|
public int getModulus() {
return modulus;
}
|
Return the modulus value this check digit routine is based on.
@return The modulus value this check digit routine is based on
|
getModulus
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/checkdigit/ModulusCheckDigit.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/checkdigit/ModulusCheckDigit.java
|
Apache-2.0
|
public boolean isValid(String code) {
if (code == null || code.length() == 0) {
return false;
}
try {
int modulusResult = calculateModulus(code, true);
return (modulusResult == 0);
} catch (CheckDigitException ex) {
return false;
}
}
|
Validate a modulus check digit for a code.
@param code The code to validate
@return <code>true</code> if the check digit is valid, otherwise
<code>false</code>
|
isValid
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/checkdigit/ModulusCheckDigit.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/checkdigit/ModulusCheckDigit.java
|
Apache-2.0
|
public String calculate(String code) throws CheckDigitException {
if (code == null || code.length() == 0) {
throw new CheckDigitException("Code is missing");
}
int modulusResult = calculateModulus(code, false);
int charValue = (modulus - modulusResult) % modulus;
return toCheckDigit(charValue);
}
|
Calculate a modulus <i>Check Digit</i> for a code.
@param code The code to calculate the Check Digit for
@return The calculated Check Digit
@throws CheckDigitException if an error occurs calculating
the check digit for the specified code
|
calculate
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/checkdigit/ModulusCheckDigit.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/checkdigit/ModulusCheckDigit.java
|
Apache-2.0
|
protected int calculateModulus(String code, boolean includesCheckDigit) throws CheckDigitException {
int total = 0;
for (int i = 0; i < code.length(); i++) {
int lth = code.length() + (includesCheckDigit ? 0 : 1);
int leftPos = i + 1;
int rightPos = lth - i;
int charValue = toInt(code.charAt(i), leftPos, rightPos);
total += weightedValue(charValue, leftPos, rightPos);
}
if (total == 0) {
throw new CheckDigitException("Invalid code, sum is zero");
}
return total % modulus;
}
|
Calculate the modulus for a code.
@param code The code to calculate the modulus for.
@param includesCheckDigit Whether the code includes the Check Digit or not.
@return The modulus value
@throws CheckDigitException if an error occurs calculating the modulus
for the specified code
|
calculateModulus
|
java
|
ragunathjawahar/android-saripaar
|
saripaar/src/main/java/commons/validator/routines/checkdigit/ModulusCheckDigit.java
|
https://github.com/ragunathjawahar/android-saripaar/blob/master/saripaar/src/main/java/commons/validator/routines/checkdigit/ModulusCheckDigit.java
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.