All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.op4j.functions.FnString Maven / Gradle / Ivy

The newest version!
/*
 * =============================================================================
 * 
 *   Copyright (c) 2010, The OP4J team (http://www.op4j.org)
 * 
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 * =============================================================================
 */
package org.op4j.functions;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.nio.charset.Charset;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.LocaleUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.time.DateUtils;
import org.op4j.Op;
import org.op4j.exceptions.ExecutionException;
import org.op4j.functions.FnString.Replace.ReplaceType;
import org.op4j.functions.FnStringAuxNumberConverters.ToBigDecimal;
import org.op4j.functions.FnStringAuxNumberConverters.ToBigInteger;
import org.op4j.functions.FnStringAuxNumberConverters.ToByte;
import org.op4j.functions.FnStringAuxNumberConverters.ToDouble;
import org.op4j.functions.FnStringAuxNumberConverters.ToFloat;
import org.op4j.functions.FnStringAuxNumberConverters.ToInteger;
import org.op4j.functions.FnStringAuxNumberConverters.ToLong;
import org.op4j.functions.FnStringAuxNumberConverters.ToShort;
import org.op4j.util.VarArgsUtil;

/**
 * 
 * @since 1.0
 * 
 * @author Soraya Sánchez
 * @author Daniel Fernández
 *
 */
public final class FnString {

	private static final Function ESCAPE_CSV_STRING_FUNC = new EscapeCSV();
	private static final Function UNESCAPE_CSV_STRING_FUNC = new UnescapeCSV();
	private static final Function ESCAPE_XML_STRING_FUNC = new EscapeXML();
	private static final Function UNESCAPE_XML_STRING_FUNC = new UnescapeXML();
	private static final Function ESCAPE_HTML_STRING_FUNC = new EscapeHTML();
	private static final Function UNESCAPE_HTML_STRING_FUNC = new UnescapeHTML();
	private static final Function ESCAPE_JAVASCRIPT_STRING_FUNC = new EscapeJavaScript();
	private static final Function UNESCAPE_JAVASCRIPT_STRING_FUNC = new UnescapeJavaScript();
	private static final Function TO_UPPER_CASE_STRING_FUNC = new ToUpperCase();
	private static final Function TO_LOWER_CASE_STRING_FUNC = new ToLowerCase();
	private static final Function UN_CAPITALIZE_STRING_FUNC = new UnCapitalize();
	private static final Function CAPITALIZE_STRING_FUNC = new Capitalize();
	private static final Function TRIM_STRING_FUNC = new Trim();
	private static final Function STRIP_STRING_FUNC = new Strip();
	
	private static final Function TO_BIG_DECIMAL = new ToBigDecimal();
    private static final Function TO_BIG_INTEGER = new ToBigInteger();
    private static final Function TO_DOUBLE = new ToDouble();
    private static final Function TO_FLOAT = new ToFloat();
    private static final Function TO_LONG = new ToLong();
    private static final Function TO_INTEGER = new ToInteger();
    private static final Function TO_SHORT = new ToShort();
    private static final Function TO_BYTE = new ToByte();
	
    private static final Function TO_BOOLEAN = new ToBoolean();
	
    private static final Function> SPLIT = new Split();
    private static final Function SPLIT_AS_ARRAY = new SplitAsArray();
    
    private static final Function,String> JOIN = new Join();
    private static final Function JOIN_ARRAY = new JoinArray();
    
    private static final Function ASCIIFY = new Asciify();
    
    private static final Function IS_ALPHA = new IsAlpha();
    private static final Function IS_ALPHA_SPACE = new IsAlpha(true);
    private static final Function IS_NUMERIC = new IsNumeric();
    private static final Function IS_NUMERIC_SPACE = new IsNumeric(true);
    
    private static final Function CAN_BE_BIG_DECIMAL = new CanBeBigDecimal();
    private static final Function CAN_BE_BIG_INTEGER = new CanBeBigInteger();
    private static final Function CAN_BE_DOUBLE = new CanBeDouble();
    private static final Function CAN_BE_FLOAT = new CanBeFloat();
    private static final Function CAN_BE_LONG = new CanBeLong();
    private static final Function CAN_BE_INTEGER = new CanBeInteger();
    private static final Function CAN_BE_SHORT = new CanBeShort();
    private static final Function CAN_BE_BYTE = new CanBeByte();
    
    private static final Function IS_VALID_BIG_INTEGER = new IsValidBigInteger();
    private static final Function IS_VALID_LONG = new IsValidLong();
    private static final Function IS_VALID_INTEGER = new IsValidInteger();
    private static final Function IS_VALID_SHORT = new IsValidShort();
    private static final Function IS_VALID_BYTE = new IsValidByte();
    
    private static final Function IS_EMPTY = new IsEmpty();
    private static final Function IS_BLANK = new IsBlank();
    
    private static final Function REVERSE = new Reverse();
    
	private FnString() {
		super();           
	}

	
    
	/**
	 * 

* Converts a String into a BigDecimal, using the default configuration * for for decimal point and precision. *

* * @return the resulting BigDecimal object */ public static final Function toBigDecimal() { return TO_BIG_DECIMAL; } /** *

* Converts a String into a BigDecimal, using the specified locale for decimal * point and thousands separator configuration. *

* * @param locale the locale defining the way in which the number was written * @return the resulting BigDecimal object */ public static final Function toBigDecimal(final Locale locale) { return new ToBigDecimal(locale); } /** *

* Converts a String into a BigDecimal, using the specified locale for decimal * point and thousands separator configuration. Locale is specified as a String * (for example: "en_US", "es_ES", etc.) *

* * @param locale the locale defining the way in which the number was written * @return the resulting BigDecimal object */ public static final Function toBigDecimal(final String locale) { return new ToBigDecimal(locale); } /** *

* Converts a String into a BigDecimal, using the specified decimal point * configuration ({@link DecimalPoint}). The target String should contain no * thousand separators. *

* * @param decimalPoint the decimal point being used by the String * @return the resulting BigDecimal object */ public static final Function toBigDecimal(final DecimalPoint decimalPoint) { return new ToBigDecimal(decimalPoint); } /** *

* Converts a String into a BigDecimal, using the default configuration * for for decimal point and thousands separator and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value. *

* * @param scale the desired scale for the resulting BigDecimal object * @param roundingMode the rounding mode to be used when setting the scale * @return the resulting BigDecimal object */ public static final Function toBigDecimal(final int scale, final RoundingMode roundingMode) { return new ToBigDecimal(scale, roundingMode); } /** *

* Converts a String into a BigDecimal, using the specified locale for decimal * point and thousands separator configuration and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value. *

* * @param scale the desired scale for the resulting BigDecimal object * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting BigDecimal object */ public static final Function toBigDecimal(final int scale, final RoundingMode roundingMode, final Locale locale) { return new ToBigDecimal(scale, roundingMode, locale); } /** *

* Converts a String into a BigDecimal, using the specified locale for decimal * point and thousands separator configuration and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value. Locale is specified as a String * (for example: "en_US", "es_ES", etc.) *

* * @param scale the desired scale for the resulting BigDecimal object * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting BigDecimal object */ public static final Function toBigDecimal(final int scale, final RoundingMode roundingMode, final String locale) { return new ToBigDecimal(scale, roundingMode, locale); } /** *

* Converts a String into a BigDecimal, using the specified decimal point * configuration ({@link DecimalPoint}) and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value.. The target String should contain no * thousand separators. *

* * @param scale the desired scale for the resulting BigDecimal object * @param roundingMode the rounding mode to be used when setting the scale * @param decimalPoint the decimal point being used by the String * @return the resulting BigDecimal object */ public static final Function toBigDecimal(final int scale, final RoundingMode roundingMode, final DecimalPoint decimalPoint) { return new ToBigDecimal(scale, roundingMode, decimalPoint); } /** *

* Converts a String into a BigInteger, using the default configuration. * Any fractional part of the input String will be removed. *

* * @return the resulting BigInteger object */ public static final Function toBigInteger() { return TO_BIG_INTEGER; } /** *

* Converts a String into a BigInteger, using the specified locale for decimal * point and thousands separator configuration. * Any fractional part of the input String will be removed. *

* * @param locale the locale defining the way in which the number was written * @return the resulting BigInteger object */ public static final Function toBigInteger(final Locale locale) { return new ToBigInteger(locale); } /** *

* Converts a String into a BigInteger, using the specified locale for decimal * point and thousands separator configuration. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). * Any fractional part of the input String will be removed. *

* * @param locale the locale defining the way in which the number was written * @return the resulting BigInteger object */ public static final Function toBigInteger(final String locale) { return new ToBigInteger(locale); } /** *

* Converts a String into a BigInteger, using the specified decimal point * configuration ({@link DecimalPoint}). The target String should contain no * thousand separators. * Any fractional part of the input String will be removed. *

* * @param decimalPoint the decimal point being used by the String * @return the resulting BigInteger object */ public static final Function toBigInteger(final DecimalPoint decimalPoint) { return new ToBigInteger(decimalPoint); } /** *

* Converts a String into a BigInteger, using the specified radix for computing the * equivalent number. The input String must be a valid BigInteger in the given radix * (i.e. if radix is 5, 34 would be a valid input whereas 34.3 wouldn't as '.' is not allowed). *

* * @param radix the radix in which the number is supposedly represented in the String * @return the resulting BigInteger object */ public static final Function toBigInteger(final int radix) { return new ToBigInteger(Integer.valueOf(radix)); } /** *

* Converts a String into a BigInteger, using the default configuration * for for decimal point and thousands separator. Rounding * mode is used for removing the decimal part of the number. * Any fractional part of the input String will be removed. *

* * @param roundingMode the rounding mode to be used when setting the scale * @return the resulting BigInteger object */ public static final Function toBigInteger(final RoundingMode roundingMode) { return new ToBigInteger(roundingMode); } /** *

* Converts a String into a BigInteger, using the specified decimal point * configuration ({@link DecimalPoint}). Rounding mode is used for removing the * decimal part of the number. The target String should contain no * thousand separators. * Any fractional part of the input String will be removed. *

* * @param roundingMode the rounding mode to be used when setting the scale * @param decimalPoint the decimal point being used by the String * @return the resulting BigInteger object */ public static final Function toBigInteger(final RoundingMode roundingMode, final DecimalPoint decimalPoint) { return new ToBigInteger(roundingMode, decimalPoint); } /** *

* Converts a String into a BigInteger, using the specified locale for determining * decimal point. Rounding mode is used for removing the * decimal part of the number. * Any fractional part of the input String will be removed. *

* * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting BigInteger object */ public static final Function toBigInteger(final RoundingMode roundingMode, final Locale locale) { return new ToBigInteger(roundingMode, locale); } /** *

* Converts a String into a BigInteger, using the specified locale for determining * decimal point. Rounding mode is used for removing the * decimal part of the number. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). * Any fractional part of the input String will be removed. *

* * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting BigInteger object */ public static final Function toBigInteger(final RoundingMode roundingMode, final String locale) { return new ToBigInteger(roundingMode, locale); } /** *

* Converts a String into a Double, using the default configuration * for for decimal point and precision. * The input string must be between * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE} *

* * @return the resulting Double object */ public static final Function toDouble() { return TO_DOUBLE; } /** *

* Converts a String into a Double, using the specified locale for decimal * point and thousands separator configuration. * The input string must be between * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Double object */ public static final Function toDouble(final Locale locale) { return new ToDouble(locale); } /** *

* Converts a String into a Double, using the specified locale for decimal * point and thousands separator configuration. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The input string must be between * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Double object */ public static final Function toDouble(final String locale) { return new ToDouble(locale); } /** *

* Converts a String into a Double, using the specified decimal point * configuration ({@link DecimalPoint}). The target String should contain no * thousand separators. The input string must be between * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE} *

* * @param decimalPoint the decimal point being used by the String * @return the resulting Double object */ public static final Function toDouble(final DecimalPoint decimalPoint) { return new ToDouble(decimalPoint); } /** *

* Converts a String into a Double, using the default configuration * for for decimal point and thousands separator and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value. * The input string must be between * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE} *

* * @param scale the desired scale for the resulting Double object * @param roundingMode the rounding mode to be used when setting the scale * @return the resulting Double object */ public static final Function toDouble(final int scale, final RoundingMode roundingMode) { return new ToDouble(scale, roundingMode); } /** *

* Converts a String into a Double, using the specified locale for decimal * point and thousands separator configuration and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value. * The input string must be between * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE} *

* * @param scale the desired scale for the resulting Double object * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Double object */ public static final Function toDouble(final int scale, final RoundingMode roundingMode, final Locale locale) { return new ToDouble(scale, roundingMode, locale); } /** *

* Converts a String into a Double, using the specified locale for decimal * point and thousands separator configuration and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). * The input string must be between * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE} *

* * @param scale the desired scale for the resulting Double object * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Double object */ public static final Function toDouble(final int scale, final RoundingMode roundingMode, final String locale) { return new ToDouble(scale, roundingMode, locale); } /** *

* Converts a String into a Double, using the specified decimal point * configuration ({@link DecimalPoint}) and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value. * The input string must be between * {@link Double#MIN_VALUE} and {@link Double#MAX_VALUE} *

* * @param scale the desired scale for the resulting Double object * @param roundingMode the rounding mode to be used when setting the scale * @param decimalPoint the decimal point being used by the String * @return the resulting Double object */ public static final Function toDouble(final int scale, final RoundingMode roundingMode, final DecimalPoint decimalPoint) { return new ToDouble(scale, roundingMode, decimalPoint); } /** *

* Converts a String into a Float, using the default configuration * for for decimal point and precision. * The input string must be between * {@link Float#MIN_VALUE} and {@link Float#MAX_VALUE} *

* * @return the resulting Float object */ public static final Function toFloat() { return TO_FLOAT; } /** *

* Converts a String into a Float, using the specified locale for decimal * point and thousands separator configuration. The input string must be between * {@link Float#MIN_VALUE} and {@link Float#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Float object */ public static final Function toFloat(final Locale locale) { return new ToFloat(locale); } /** *

* Converts a String into a Float, using the specified locale for decimal * point and thousands separator configuration. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The input string must be between * {@link Float#MIN_VALUE} and {@link Float#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Float object */ public static final Function toFloat(final String locale) { return new ToFloat(locale); } /** *

* Converts a String into a Float, using the specified decimal point * configuration ({@link DecimalPoint}). The target String should contain no * thousand separators. The input string must be between * {@link Float#MIN_VALUE} and {@link Float#MAX_VALUE} *

* * @param decimalPoint the decimal point being used by the String * @return the resulting Float object */ public static final Function toFloat(final DecimalPoint decimalPoint) { return new ToFloat(decimalPoint); } /** *

* Converts a String into a Float, using the default configuration * for for decimal point and thousands separator and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value. * The input string must be between * {@link Float#MIN_VALUE} and {@link Float#MAX_VALUE} *

* * @param scale the desired scale for the resulting Float object * @param roundingMode the rounding mode to be used when setting the scale * @return the resulting Float object */ public static final Function toFloat(final int scale, final RoundingMode roundingMode) { return new ToFloat(scale, roundingMode); } /** *

* Converts a String into a Float, using the specified locale for decimal * point and thousands separator configuration and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value. * The input string must be between * {@link Float#MIN_VALUE} and {@link Float#MAX_VALUE} *

* * @param scale the desired scale for the resulting Float object * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Float object */ public static final Function toFloat(final int scale, final RoundingMode roundingMode, final Locale locale) { return new ToFloat(scale, roundingMode, locale); } /** *

* Converts a String into a Float, using the specified locale for decimal * point and thousands separator configuration and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The input string must be between * {@link Float#MIN_VALUE} and {@link Float#MAX_VALUE} *

* * @param scale the desired scale for the resulting Float object * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Float object */ public static final Function toFloat(final int scale, final RoundingMode roundingMode, final String locale) { return new ToFloat(scale, roundingMode, locale); } /** *

* Converts a String into a Float, using the specified decimal point * configuration ({@link DecimalPoint}) and establishing the specified scale. Rounding * mode is used for setting the scale to the specified value.. The target String should contain no * thousand separators. The input string must be between * {@link Float#MIN_VALUE} and {@link Float#MAX_VALUE} *

* * @param scale the desired scale for the resulting Float object * @param roundingMode the rounding mode to be used when setting the scale * @param decimalPoint the decimal point being used by the String * @return the resulting Float object */ public static final Function toFloat(final int scale, final RoundingMode roundingMode, final DecimalPoint decimalPoint) { return new ToFloat(scale, roundingMode, decimalPoint); } /** *

* Converts a String into a Long, using the default configuration. * The integer part of the input string must be between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE} *

* * @return the resulting Long object */ public static final Function toLong() { return TO_LONG; } /** *

* Converts a String into a Long, using the specified locale for decimal * point and thousands separator configuration. The * integer part of the input string must be between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Long object */ public static final Function toLong(final Locale locale) { return new ToLong(locale); } /** *

* Converts a String into a Long, using the specified locale for decimal * point and thousands separator configuration. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The * integer part of the input string must be between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Long object */ public static final Function toLong(final String locale) { return new ToLong(locale); } /** *

* Converts a String into a Long, using the specified decimal point * configuration ({@link DecimalPoint}). The target String should contain no * thousand separators. The integer part of the input string must be between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE} *

* * @param decimalPoint the decimal point being used by the String * @return the resulting Long object */ public static final Function toLong(final DecimalPoint decimalPoint) { return new ToLong(decimalPoint); } /** *

* Converts a String into a Long, using the specified radix for computing the * equivalent number. The input String must be a valid Long in the given radix * (i.e. if radix is 5, 34 would be a valid input whereas 34.3 wouldn't as '.' is not allowed) *

* * @param radix the radix in which the number is supposedly represented in the String * @return the resulting Long object */ public static final Function toLong(final int radix) { return new ToLong(Integer.valueOf(radix)); } /** *

* Converts a String into a Long, using the default configuration * for for decimal point and thousands separator. Rounding * mode is used for removing the decimal part of the number. The * integer part of the input string must be between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @return the resulting Long object */ public static final Function toLong(final RoundingMode roundingMode) { return new ToLong(roundingMode); } /** *

* Converts a String into a Long, using the specified decimal point * configuration ({@link DecimalPoint}). Rounding mode is used for removing the * decimal part of the number. The target String should contain no * thousand separators. The integer part of the input string must be between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param decimalPoint the decimal point being used by the String * @return the resulting Long object */ public static final Function toLong(final RoundingMode roundingMode, final DecimalPoint decimalPoint) { return new ToLong(roundingMode, decimalPoint); } /** *

* Converts a String into a Long, using the specified locale for determining * decimal point. Rounding mode is used for removing the * decimal part of the number. The integer part of the input string must be between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Long object */ public static final Function toLong(final RoundingMode roundingMode, final Locale locale) { return new ToLong(roundingMode, locale); } /** *

* Converts a String into a Long, using the specified locale for determining * decimal point. Rounding mode is used for removing the * decimal part of the number. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The * integer part of the input string must be between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Long object */ public static final Function toLong(final RoundingMode roundingMode, final String locale) { return new ToLong(roundingMode, locale); } /** *

* Converts a String into an Integer, using the default * configuration. The integer part of the input string must be between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE} *

* * @return the resulting Integer object */ public static final Function toInteger() { return TO_INTEGER; } /** *

* Converts a String into an Integer, using the specified locale for decimal * point and thousands separator configuration. The * integer part of the input string must be between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Integer object */ public static final Function toInteger(final Locale locale) { return new ToInteger(locale); } /** *

* Converts a String into an Integer, using the specified locale for decimal * point and thousands separator configuration. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The * integer part of the input string must be between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Integer object */ public static final Function toInteger(final String locale) { return new ToInteger(locale); } /** *

* Converts a String into an Integer, using the specified decimal point * configuration ({@link DecimalPoint}). The target String should contain no * thousand separators. The integer part of the input string must be between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE} *

* * @param decimalPoint the decimal point being used by the String * @return the resulting Integer object */ public static final Function toInteger(final DecimalPoint decimalPoint) { return new ToInteger(decimalPoint); } /** *

* Converts a String into an Integer, using the specified radix for computing the * equivalent number. The input String must be a valid Integer in the given radix * (i.e. if radix is 5, 34 would be a valid input whereas 34.3 wouldn't as '.' is not allowed) *

* * @param radix the radix in which the number is supposedly represented in the String * @return the resulting Integer object */ public static final Function toInteger(final int radix) { return new ToInteger(Integer.valueOf(radix)); } /** *

* Converts a String into an Integer, using the default configuration * for for decimal point and thousands separator. Rounding * mode is used for removing the decimal part of the number. The * integer part of the input string must be between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @return the resulting Integer object */ public static final Function toInteger(final RoundingMode roundingMode) { return new ToInteger(roundingMode); } /** *

* Converts a String into an Integer, using the specified decimal point * configuration ({@link DecimalPoint}). Rounding mode is used for removing the * decimal part of the number. The target String should contain no * thousand separators. The integer part of the input string must be between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param decimalPoint the decimal point being used by the String * @return the resulting Integer object */ public static final Function toInteger(final RoundingMode roundingMode, final DecimalPoint decimalPoint) { return new ToInteger(roundingMode, decimalPoint); } /** *

* Converts a String into an Integer, using the specified locale for determining * decimal point. Rounding mode is used for removing the * decimal part of the number. The integer part of the input string must be between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Integer object */ public static final Function toInteger(final RoundingMode roundingMode, final Locale locale) { return new ToInteger(roundingMode, locale); } /** *

* Converts a String into an Integer, using the specified locale for determining * decimal point. Rounding mode is used for removing the * decimal part of the number. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The * integer part of the input string must be between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Integer object */ public static final Function toInteger(final RoundingMode roundingMode, final String locale) { return new ToInteger(roundingMode, locale); } /** *

* Converts a String into a Short, using the default configuration. * The integer part of the input string must be between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE} *

* * @return the resulting Short object */ public static final Function toShort() { return TO_SHORT; } /** *

* Converts a String into a Short, using the specified locale for decimal * point and thousands separator configuration. The * integer part of the input string must be between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Short object */ public static final Function toShort(final Locale locale) { return new ToShort(locale); } /** *

* Converts a String into a Short, using the specified locale for decimal * point and thousands separator configuration. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The * integer part of the input string must be between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Short object */ public static final Function toShort(final String locale) { return new ToShort(locale); } /** *

* Converts a String into a Short, using the specified decimal point * configuration ({@link DecimalPoint}). The target String should contain no * thousand separators. The integer part of the input string must be between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE} *

* * @param decimalPoint the decimal point being used by the String * @return the resulting Short object */ public static final Function toShort(final DecimalPoint decimalPoint) { return new ToShort(decimalPoint); } /** *

* Converts a String into a Short, using the specified radix for computing the * equivalent number. The input String must be a valid Short in the given radix * (i.e. if radix is 5, 34 would be a valid input whereas 34.3 wouldn't as '.' is not allowed) *

* * @param radix the radix in which the number is supposedly represented in the String * @return the resulting Short object */ public static final Function toShort(final int radix) { return new ToShort(Integer.valueOf(radix)); } /** *

* Converts a String into a Short, using the default configuration * for for decimal point and thousands separator. Rounding * mode is used for removing the decimal part of the number. The * integer part of the input string must be between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @return the resulting Short object */ public static final Function toShort(final RoundingMode roundingMode) { return new ToShort(roundingMode); } /** *

* Converts a String into a Short, using the specified decimal point * configuration ({@link DecimalPoint}). Rounding mode is used for removing the * decimal part of the number. The target String should contain no * thousand separators. The integer part of the input string must be between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param decimalPoint the decimal point being used by the String * @return the resulting Short object */ public static final Function toShort(final RoundingMode roundingMode, final DecimalPoint decimalPoint) { return new ToShort(roundingMode, decimalPoint); } /** *

* Converts a String into a Short, using the specified locale for determining * decimal point. Rounding mode is used for removing the * decimal part of the number. The integer part of the input string must be between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Short object */ public static final Function toShort(final RoundingMode roundingMode, final Locale locale) { return new ToShort(roundingMode, locale); } /** *

* Converts a String into a Short, using the specified locale for determining * decimal point. Rounding mode is used for removing the * decimal part of the number. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The * integer part of the input string must be between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Short object */ public static final Function toShort(final RoundingMode roundingMode, final String locale) { return new ToShort(roundingMode, locale); } /** *

* Converts a String into a Byte, using the default configuration. * Any fractional part of the input String will be removed. The * integer part of the input string must be between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE} *

* * @return the resulting Byte object */ public static final Function toByte() { return TO_BYTE; } /** *

* Converts a String into a Byte, using the specified locale for decimal * point and thousands separator configuration. The * integer part of the input string must be between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Byte object */ public static final Function toByte(final Locale locale) { return new ToByte(locale); } /** *

* Converts a String into a Byte, using the specified locale for decimal * point and thousands separator configuration. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The * integer part of the input string must be between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE} *

* * @param locale the locale defining the way in which the number was written * @return the resulting Byte object */ public static final Function toByte(final String locale) { return new ToByte(locale); } /** *

* Converts a String into a Byte, using the specified decimal point * configuration ({@link DecimalPoint}). The target String should contain no * thousand separators. The integer part of the input string must be between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE} *

* * @param decimalPoint the decimal point being used by the String * @return the resulting Byte object */ public static final Function toByte(final DecimalPoint decimalPoint) { return new ToByte(decimalPoint); } /** *

* Converts a String into a Byte, using the specified radix for computing the * equivalent number. The input String must be a valid Byte in the given radix *

* * @param radix the radix in which the number is supposedly represented in the String * @return the resulting Byte object */ public static final Function toByte(final int radix) { return new ToByte(Integer.valueOf(radix)); } /** *

* Converts a String into a Byte, using the default configuration * for for decimal point and thousands separator. Rounding * mode is used for removing the decimal part of the number. * The integer part of the input string must be between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @return the resulting Byte object */ public static final Function toByte(final RoundingMode roundingMode) { return new ToByte(roundingMode); } /** *

* Converts a String into a Byte, using the specified decimal point * configuration ({@link DecimalPoint}). Rounding mode is used for removing the * decimal part of the number. The target String should contain no * thousand separators. The integer part of the input string must be between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param decimalPoint the decimal point being used by the String * @return the resulting Byte object */ public static final Function toByte(final RoundingMode roundingMode, final DecimalPoint decimalPoint) { return new ToByte(roundingMode, decimalPoint); } /** *

* Converts a String into a Byte, using the specified locale for determining * decimal point. Rounding mode is used for removing the * decimal part of the number. The integer part of the input string must be between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Byte object */ public static final Function toByte(final RoundingMode roundingMode, final Locale locale) { return new ToByte(roundingMode, locale); } /** *

* Converts a String into a Byte, using the specified locale for determining * decimal point. Rounding mode is used for removing the * decimal part of the number. Locale is specified as a String * (for example: "en_US", "es_ES", etc.). The * integer part of the input string must be between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE} *

* * @param roundingMode the rounding mode to be used when setting the scale * @param locale the locale defining the way in which the number was written * @return the resulting Byte object */ public static final Function toByte(final RoundingMode roundingMode, final String locale) { return new ToByte(roundingMode, locale); } /** *

* Converts a String into a Boolean. Case is ignored, and all three * "true"/"false", "yes"/"no" and "on"/"off" versions are * supported. *

*

* This method calls org.apache.commons.lang.StringUtils.toBooleanObject(). *

* * @return the resulting Boolean object */ public static final Function toBoolean() { return TO_BOOLEAN; } /** *

* Turns a String into a value valid for being a CSV column value, * enclosed in double quotes if needed. *

*

* This method calls org.apache.commons.lang.StringUtils.escapeCsv(). * From its definition: *

*
    *
  • If the value contains a comma, newline or double quote, then the * String value is written enclosed in double quotes.
  • *
  • Any double quote characters in the value are escaped with another double quote.
  • *
  • If the value does not contain a comma, newline or double quote, then the * String value is written unchanged (null values are ignored).
  • *
* * @return the resulting String. */ public static final Function escapeCSV() { return ESCAPE_CSV_STRING_FUNC; } /** *

* Removes escaping from a String escaped for a CSV column. *

*

* This method calls org.apache.commons.lang.StringUtils.unescapeCsv(). * From its definition: *

*
    *
  • Returns a String value for an unescaped CSV column.
  • *
  • If the value is enclosed in double quotes, and contains a comma, newline * or double quote, then quotes are removed.
  • *
  • Any double quote escaped characters (a pair of double quotes) are unescaped * to just one double quote.
  • *
  • If the value is not enclosed in double quotes, or is and does not contain a * comma, newline or double quote, then the String value is returned unchanged.
  • *
* * @return the resulting String. */ public static final Function unescapeCSV() { return UNESCAPE_CSV_STRING_FUNC; } /** *

* Escapes the characters in a String using XML entities. *

*

* This method calls org.apache.commons.lang.StringUtils.escapeXml(). * From its definition: *

*
    *
  • For example: "bread" & "butter" => * "bread" & "butter".
  • *
  • Supports only the five basic XML entities (gt, lt, quot, amp, apos). * Does not support DTDs or external entities.
  • *
  • Note that unicode characters greater than 0x7f are currently escaped to * their numerical \\u equivalent. This may change in future releases.
  • *
* * @return the resulting String. */ public static final Function escapeXML() { return ESCAPE_XML_STRING_FUNC; } /** *

* Unescapes a string containing XML entity escapes to a string * containing the actual Unicode characters corresponding to the * escapes. *

*

* This method calls org.apache.commons.lang.StringUtils.unescapeXml(). * From its definition: *

*
    *
  • Supports only the five basic XML entities (gt, lt, quot, amp, apos). * Does not support DTDs or external entities.
  • *
  • Note that numerical \\u unicode codes are unescaped to their respective * unicode characters. This may change in future releases.
  • *
* * @return the resulting String. */ public static final Function unescapeXML() { return UNESCAPE_XML_STRING_FUNC; } /** *

* Escapes the characters in a String using HTML entities. *

*

* This method calls org.apache.commons.lang.StringUtils.escapeHtml(). * From its definition: *

*
    *
  • The string "bread" & "butter" becomes * "bread" & "butter".
  • *
  • Supports all known HTML 4.0 entities, including funky accents. * Note that the commonly used apostrophe escape character (') * is not a legal entity and so is not supported).
  • *
* * @return the resulting String. */ public static final Function escapeHTML() { return ESCAPE_HTML_STRING_FUNC; } /** *

* Unescapes a string containing entity escapes to a string * containing the actual Unicode characters corresponding to the * escapes. Supports HTML 4.0 entities. *

*

* This method calls org.apache.commons.lang.StringUtils.unescapeHtml(). * From its definition: *

*
    *
  • The string &lt;Fran&ccedil;ais&gt; * will become <Français>
  • *
  • If an entity is unrecognized, it is left alone, and inserted * verbatim into the result string. e.g. &gt;&zzzz;x will * become >&zzzz;x.
  • *
* * @return the resulting String. */ public static final Function unescapeHTML() { return UNESCAPE_HTML_STRING_FUNC; } /** *

* Escapes the characters in a String using JavaScript String rules. *

*

* This method calls org.apache.commons.lang.StringUtils.escapeJavascript(). * From its definition: *

*
    *
  • Escapes any values it finds into their JavaScript String form. * Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
  • *
  • So a tab becomes the characters '\\' and 't'.
  • *
  • The only difference between Java strings and JavaScript strings * is that in JavaScript, a single quote must be escaped.
  • *
* *

Example:

*
    *
  • input string: He didn't say, "Stop!"
  • *
  • output string: He didn\'t say, \"Stop!\"
  • *
* * @return the resulting String. */ public static final Function escapeJavaScript() { return ESCAPE_JAVASCRIPT_STRING_FUNC; } /** *

* Unescapes any JavaScript literals found in the String. *

* *

* For example, it will turn a sequence of '\' and 'n' * into a newline character, unless the '\' is preceded by another * '\'. *

*

* This method calls org.apache.commons.lang.StringUtils.unescapeJavascript(). *

* * @return the resulting String. */ public static final Function unescapeJavaScript() { return UNESCAPE_JAVASCRIPT_STRING_FUNC; } /** *

* Converts the target String into the Hexadecimal representation of its bytes using the * specified Charset to obtain them (the bytes). *

* * @param charset the charset to be used * @return the resulting String. */ public static final Function toHexadecimal(final Charset charset) { return new ToHexadecimal(charset); } /** *

* Converts the target String from the Hexadecimal representation of its bytes back into * a String using the specified Charset. *

* * @param charset the charset to be used * @return the resulting String. */ public static final Function fromHexadecimal(final Charset charset) { return new FromHexadecimal(charset); } /** *

* Converts the target String to upper case. *

* * @return the resulting String. */ public static final Function toUpperCase() { return TO_UPPER_CASE_STRING_FUNC; } /** *

* Converts the target String to lower case. *

* * @return the resulting String */ public static final Function toLowerCase() { return TO_LOWER_CASE_STRING_FUNC; } /** *

* Converts the first letter of each word in the target String to lowercase *

* * @return the resulting String */ public static final Function unCapitalize() { return UN_CAPITALIZE_STRING_FUNC; } /** *

* Converts the first letter of each word in the target String to upper case. *

* * @return the resulting String */ public static final Function capitalize() { return CAPITALIZE_STRING_FUNC; } /** *

* Removes control characters (char <= 32) from both ends of the target String. *

* * @return the resulting String */ public static final Function trim() { return TRIM_STRING_FUNC; } /** *

* Strips whitespace from both sides of the target String. *

* * @return the resulting String */ public static final Function strip() { return STRIP_STRING_FUNC; } /** *

* Checks whether the target String can be converted into a Calendar based on the * input parameters or not. If it returns true, {@link FnString#toCalendar(String)} * can be called safely. *

*

* Pattern format is that of java.text.SimpleDateFormat. *

* * @param pattern the pattern to be used * @return true if the target {@link String} represents a {@link Calendar}, * false otherwise */ public static final Function isCalendar(final String pattern) { return new IsCalendar(pattern); } /** *

* Checks whether the target {@link String} represents a {@link Calendar} or not. * If it returns true, {@link FnString#toCalendar(String, Locale)} can be called * safely. *

*

* Pattern format is that of java.text.SimpleDateFormat. *

* * @param pattern the pattern to be used. * @param locale the locale which will be used for parsing month names * @return true if the target {@link String} represents a {@link Calendar}, * false otherwise */ public static final Function isCalendar(final String pattern, final Locale locale) { return new IsCalendar(pattern, locale); } /** *

* Returns true if the target {@link String} can be converted into a {@link Calendar} * based on the input parameters. If it returns true, the function * {@link ToCalendar#ToCalendar(String, String)} can be called safely. *

*

* Pattern format is that of java.text.SimpleDateFormat. *

* * @param pattern the pattern to be used (ex: "en_US", "es_ES", etc.) * @param locale the locale which will be used for parsing month names * @return true if it can be converted, false otherwise */ public static final Function isCalendar(final String pattern, final String locale) { return new IsCalendar(pattern, locale); } /** *

* Converts the target String to a java.util.Calendar by applying the specified * pattern. *

*

* Pattern format is that of java.text.SimpleDateFormat. *

* * @param pattern the pattern to be used * @return the resulting Calendar */ public static final Function toCalendar(final String pattern) { return new ToCalendar(pattern); } /** *

* Converts the target String to a java.util.Calendar by applying the specified * pattern and locale. The locale is needed for correctly parsing month names. *

*

* Pattern format is that of java.text.SimpleDateFormat. *

* * @param pattern the pattern to be used. * @param locale the locale which will be used for parsing month names * @return the resulting Calendar */ public static final Function toCalendar(final String pattern, final Locale locale) { return new ToCalendar(pattern, locale); } /** *

* Converts the target String to a java.util.Calendar by applying the specified * pattern and locale. The locale is needed for correctly parsing month names. *

*

* Pattern format is that of java.text.SimpleDateFormat. *

* * @param pattern the pattern to be used (ex: "en_US", "es_ES", etc.) * @param locale the locale which will be used for parsing month names * @return the resulting Calendar */ public static final Function toCalendar(final String pattern, final String locale) { return new ToCalendar(pattern, locale); } /** *

* Converts the target String to a java.util.Date by applying the specified * pattern. *

*

* Pattern format is that of java.text.SimpleDateFormat. *

* * @param pattern the pattern to be used * @return the resulting Date */ public static final Function toDate(final String pattern) { return new ToDate(pattern); } /** *

* Converts the target String to a java.util.Date by applying the specified * pattern and locale. The locale is needed for correctly parsing month names. *

*

* Pattern format is that of java.text.SimpleDateFormat. *

* * @param pattern the pattern to be used. * @param locale the locale which will be used for parsing month names * @return the resulting Date */ public static final Function toDate(final String pattern, final Locale locale) { return new ToDate(pattern, locale); } /** *

* Converts the target String to a java.util.Date by applying the specified * pattern and locale. The locale is needed for correctly parsing month names. *

*

* Pattern format is that of java.text.SimpleDateFormat. *

* * @param pattern the pattern to be used (ex: "en_US", "es_ES", etc.) * @param locale the locale which will be used for parsing month names * @return the resulting Date */ public static final Function toDate(final String pattern, final String locale) { return new ToDate(pattern, locale); } /** *

* Performs an equals operation between the target object and the * specified one. *

* * @param object the object that will be passed as a parameter to the "equals" operation. * @return the boolean result of the "equals" operation. */ public static final Function eq(final String object) { return FnObject.eq(object); } /** *

* Performs an inverse equals operation between the target object and the * specified one. *

* * @param object the object that will be passed as a parameter to the "equals" operation. * @return the boolean result of the inverse of an "equals" operation. */ public static final Function notEq(final String object) { return FnObject.notEq(object); } /** *

* Determines whether the target object is null or not. *

* * @return true if the target object is null, false if not. */ public static final Function isNull() { return FnObject.isNull(); } /** *

* Determines whether the target object is null or not. *

* * @return false if the target object is null, true if not. */ public static final Function isNotNull() { return FnObject.isNotNull(); } /** *

* Determines whether the target object is less than the specified object * in value, this is, whether target.compareTo(object) < 0. Both * the target and the specified object have to implement {@link Comparable}. *

* * @param object the object to compare to the target * @return true if target is less than the specified object, false if not */ public static final Function lessThan(final String object) { return FnObject.lessThan(object); } /** *

* Determines whether the target object is less or equal to the specified object * in value, this is, whether target.compareTo(object) <= 0. Both * the target and the specified object have to implement {@link Comparable}. *

* * @param object the object to compare to the target * @return true if target is less or equal to the specified object, false if not */ public static final Function lessOrEqTo(final String object) { return FnObject.lessOrEqTo(object); } /** *

* Determines whether the target object is greater than the specified object * in value, this is, whether target.compareTo(object) > 0. Both * the target and the specified object have to implement {@link Comparable}. *

* * @param object the object to compare to the target * @return true if target is greater than the specified object, false if not */ public static final Function greaterThan(final String object) { return FnObject.greaterThan(object); } /** *

* Determines whether the target object is greater or equal to the specified object * in value, this is, whether target.compareTo(object) >= 0. Both * the target and the specified object have to implement {@link Comparable}. *

* * @param object the object to compare to the target * @return true if target is greater or equal to the specified object, false if not */ public static final Function greaterOrEqTo(final String object) { return FnObject.greaterOrEqTo(object); } /** *

* Determines whether the target String matches the specified regular * expression. *

*

* Regular expressions must conform to the java.util.regex.Pattern format. *

* * @param regex the regular expression to match against * @return true if the target String matches the regex, false if not. */ public static final Function matches(final String regex) { return new Matches(regex); } /** *

* Determines whether the target String contains a fragment matching the specified regular * expression. *

*

* Regular expressions must conform to the java.util.regex.Pattern format. *

* * @param regex the regular expression to match against * @return true if the target String contains a fragment matching the regex, false if not. */ public static final Function contains(final String regex) { return new Contains(regex); } /** *

* Extracts the first substring from the target String that matches the specified * regular expression. *

*

* Regular expressions must conform to the java.util.regex.Pattern format. *

* * @param regex the regular expression to match against * @return the matching substring. */ public static final Function extractFirst(final String regex) { return new Extract(regex, false); } /** *

* Extracts the last substring from the target String that matches the specified * regular expression. *

*

* Regular expressions must conform to the java.util.regex.Pattern format. *

* * @param regex the regular expression to match against * @return the matching substring. */ public static final Function extractLast(final String regex) { return new Extract(regex, true); } /** *

* Extracts every substring from the target String that match the specified * regular expression. *

*

* Regular expressions must conform to the java.util.regex.Pattern format. *

* * @param regex the regular expression to match against * @return a List with the matching substrings */ public static final Function> extractAll(final String regex) { return new ExtractAll(regex); } /** *

* Matches the entire target String against the specified regular expression and extracts * the specified group from it (as specified by java.util.regex.Matcher. *

*

* Regular expressions must conform to the java.util.regex.Pattern format. *

* * @param regex the regular expression to match against * @param group the group number to be extracted * @return the substring matching the group number */ public static final Function matchAndExtract(final String regex, final int group) { return new MatchAndExtract(regex, group); } /** *

* Matches the entire target String against the specified regular expression and extracts * the specified groups from it (as specified by java.util.regex.Matcher. *

*

* Regular expressions must conform to the java.util.regex.Pattern format. *

* * @param regex the regular expression to match against * @param groups the group numbers to be extracted * @return a List with the substrings matching the group number */ public static final Function> matchAndExtractAll(final String regex, final int... groups) { return new MatchAndExtractAll(regex, VarArgsUtil.asRequiredIntegerList(groups)); } /** *

* Replaces in the target String the first substring matching the specified regular expression * with the specified replacement String. *

*

* Regular expressions must conform to the java.util.regex.Pattern format. *

* * @param regex the regular expression to match against * @param replacement the replacement string * @return the resulting String */ public static final Function replaceFirst(final String regex, final String replacement) { return new Replace(regex, replacement, ReplaceType.FIRST); } /** *

* Replaces in the target String the last substring matching the specified regular expression * with the specified replacement String. *

*

* Regular expressions must conform to the java.util.regex.Pattern format. *

* * @param regex the regular expression to match against * @param replacement the replacement string * @return the resulting String */ public static final Function replaceLast(final String regex, final String replacement) { return new Replace(regex, replacement, ReplaceType.LAST); } /** *

* Replaces in the target String all substrings matching the specified regular expression * with the specified replacement String. *

*

* Regular expressions must conform to the java.util.regex.Pattern format. *

* * @param regex the regular expression to match against * @param replacement the replacement string * @return the resulting String */ public static final Function replaceAll(final String regex, final String replacement) { return new Replace(regex, replacement, ReplaceType.ALL); } /** *

* Splits a String into a list of substrings using a whitespace as a separator. *

* * @return a List with the resulting substrings. */ public static final Function> split() { return SPLIT; } /** *

* Splits a String into a list of substrings using the given separator * as a substrings separator (the separator is not included in the * elements of the returned list). *

* * @param separator the separator to be used * @return a List with the resulting substrings. */ public static final Function> split(final String separator) { return new Split(separator); } /** *

* Splits a String into an array of substrings using a whitespace as a separator. *

* * @return an array with the resulting substrings. */ public static final Function splitAsArray() { return SPLIT_AS_ARRAY; } /** *

* Splits a String into an array of substrings using the given separator * as a substrings separator (the separator is not included in the * elements of the returned array). *

* * @param separator the separator to be used * @return an array with the resulting substrings. */ public static final Function splitAsArray(final String separator) { return new SplitAsArray(separator); } /** *

* Joins the string representation of the objects in the list (which might be * Strings themselves) into a single String (no separator used). *

* * @return the resulting String */ public static final Function, String> join() { return JOIN; } /** *

* Joins the string representation of the objects in the list (which might be * Strings themselves) into a single String using the given separator. *

* * @return the resulting String */ public static final Function, String> join(String separator) { return new Join(separator); } /** *

* Joins the string representation of the objects in the array (which might be * Strings themselves) into a single String (no separator used). *

* * @return the resulting String */ public static final Function joinArray() { return JOIN_ARRAY; } /** *

* Joins the string representation of the objects in the array (which might be * Strings themselves) into a single String using the given separator. *

* * @return the resulting String */ public static final Function joinArray(String separator) { return new JoinArray(separator); } /** *

* ASCIIfies a String containing text in (mainly) European languages by removing a set of * recognized diacritic symbols and performing a number of transformations. Calling this method * is equivalent to calling {@link #asciify(AsciifyMode)} using the DEFAULT mode. *

* * * @return the transformed String */ public static final Function asciify() { return ASCIIFY; } /** *

* ASCIIfies a String containing text in (mainly) European languages by removing a set of * recognized diacritic symbols and performing a number of transformations, determined * by the {@link AsciifyMode} parameter. *

*

* Transformations for AsciifyMode.DEFAULT are: *

*
    *
  • À, Á, Â, Ã, Ä, Å, \u0100, \u0102, \u0104, \u01CD, \u01FA / à, á, â, ã, ä, å, \u0101, \u0103, \u0105, \u01CE, \u01FB = A / a
  • *
  • Æ, \u01FC / æ, \u01FD = AE / ae
  • *
  • Ç, \u0106, \u0108, \u010A, \u010C / ç, \u0107, \u0109, \u010B, \u010D = C / c
  • *
  • Ð, \u010E, \u0110 / ð, \u010F, \u0111 = D / d
  • *
  • È, É, Ê, Ë, \u0112, \u0114, \u0116, \u0118, \u011A / è, é, ê, ë, \u0113, \u0115, \u0117, \u0119, \u011B = E / e
  • *
  • \u011C, \u011E, \u0120, \u0122 / \u011D, \u011F, \u0121, \u0123 = G / g
  • *
  • \u0124, \u0126 / \u0125, \u0127 = H / h
  • *
  • Ì, Í, Î, Ï, \u0128, \u012A, \u012C, \u012E, \u0130, \u01CF / ì, í, î, ï, \u0129, \u012B, \u012D, \u012F, \u0131, \u01D0 = I / i
  • *
  • \u0132 / \u0133 = IJ / ij
  • *
  • \u0134 / \u0135 = J / j
  • *
  • \u0136 / \u0137, \u0138 = K / k
  • *
  • \u0139, \u013B, \u013D, \u013F, \u0141 / \u013A, \u013C, \u013E, \u0140, \u0142 = L / l
  • *
  • Ñ, \u0143, \u0145, \u0147, \u014A / ñ, \u0144, \u0146, \u0148, \u0149, \u014B = N / n
  • *
  • Ò, Ó, Ô, Õ, Ö, Ø, \u014C, \u014E, \u0150, \u01A0, \u01D1, \u01FE / ò, ó, ô, õ, ö, ø, \u014D, \u014F, \u0151, \u01A1, \u01D2, \u01FF = O / o
  • *
  • \u0152 / \u0153 = OE / oe
  • *
  • \u0154, \u0156, \u0158 / \u0155, \u0157, \u0159 = R / r
  • *
  • \u015A, \u015C, \u015E, \u0160 / \u015B, \u015D, \u015F, \u0161 = S / s
  • *
  • ß = "ss" if the preceding character is lower case, "SS" otherwise.
  • *
  • \u0162, \u0164, \u0166 / \u0163, \u0165, \u0167 = T / t
  • *
  • Þ / þ = TH / th
  • *
  • Ù, Ú, Û, Ü, \u0168, \u016A, \u016C, \u016E, \u0170, \u0172, \u01AF, \u01D3, \u01D5, \u01D7, \u01D9, \u01DB / ù, ú, û, ü, \u0169, \u016B, \u016D, \u016F, \u0171, \u0173, \u01B0, \u01D4, \u01D6, \u01D8, \u01DA, \u01DC = U / u
  • *
  • \u0174 / \u0175 = W / w
  • *
  • Ý, \u0178, \u0176 / ý, ÿ, \u0177 = Y / y
  • *
  • \u0179, \u017B, \u017D / \u017A, \u017C, \u017E = Z / z
  • *
*

* Transformations for AsciifyMode.UMLAUT_E are the same as DEFAULT * with the following differences: *

*
    *
  • Ä / ä = AE / ae
  • *
  • Ö / ö = OE / oe
  • *
  • Ü / ü = UE / ue
  • *
* * * @return the transformed String */ public static final Function asciify(final AsciifyMode mode) { return new Asciify(mode); } /** *

* Checks if a String contains only unicode letters or not *

* * @return whether the input String contains only unicode letters or not */ public static final Function isAlpha() { return IS_ALPHA; } /** *

* Checks if a String contains only unicode letters and spaces or not *

* * @return true if the input String contains only unicode letters and spaces. * Otherwise, false */ public static final Function isAlphaSpace() { return IS_ALPHA_SPACE; } /** *

* Checks if a String contains only unicode digits or not *

* * @return whether the input String contains only unicode digits or not */ public static final Function isNumeric() { return IS_NUMERIC; } /** *

* Checks if a String contains only unicode digits and spaces or not *

* * @return true if the input String contains only unicode digits and spaces. * Otherwise, false */ public static final Function isNumericSpace() { return IS_NUMERIC_SPACE; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. *

* * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @since 1.2 */ public static final Function canBeBigDecimal() { return CAN_BE_BIG_DECIMAL; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal} in the given {@link Locale} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @since 1.2 */ public static final Function canBeBigDecimal(final Locale locale) { return new CanBeBigDecimal(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal} in the given {@link Locale} specified as a {@link String} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @since 1.2 */ public static final Function canBeBigDecimal(final String locale) { return new CanBeBigDecimal(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal} using the specified decimal point * configuration ({@link DecimalPoint}). *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @since 1.2 */ public static final Function canBeBigDecimal(final DecimalPoint decimalPoint) { return new CanBeBigDecimal(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. *

* * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @deprecated use {@link FnString#canBeBigDecimal()} instead. This method will * be removed in version 1.3 */ @Deprecated public static final Function isBigDecimal() { return CAN_BE_BIG_DECIMAL; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal} in the given {@link Locale} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @deprecated use {@link FnString#canBeBigDecimal(Locale)} instead. This method will * be removed in version 1.3 */ @Deprecated public static final Function isBigDecimal(final Locale locale) { return new CanBeBigDecimal(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal} in the given {@link Locale} specified as a {@link String} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @deprecated use {@link FnString#canBeBigDecimal(String)} instead. This method will * be removed in version 1.3 */ @Deprecated public static final Function isBigDecimal(final String locale) { return new CanBeBigDecimal(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal} using the specified decimal point * configuration ({@link DecimalPoint}). *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @deprecated use {@link FnString#canBeBigDecimal(DecimalPoint)} instead. This method will * be removed in version 1.3 */ @Deprecated public static final Function isBigDecimal(final DecimalPoint decimalPoint) { return new CanBeBigDecimal(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. That is, if it represents either * a decimal or non decimal number. This function is the same * as {@link FnString#canBeBigDecimal()}. *

* * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @since 1.2 */ public static final Function isValidBigDecimal() { return CAN_BE_BIG_DECIMAL; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal} in the given {@link Locale}. That is, if it * represents either a decimal or non decimal number. This function is the same * as {@link FnString#canBeBigDecimal(Locale)} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @since 1.2 */ public static final Function isValidBigDecimal(final Locale locale) { return new CanBeBigDecimal(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal} in the given {@link Locale} specified as a {@link String}. * That is, if it represents either a decimal or non decimal number. This * function is the same as {@link FnString#canBeBigDecimal(String)} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @since 1.2 */ public static final Function isValidBigDecimal(final String locale) { return new CanBeBigDecimal(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigDecimal} using the specified decimal point * configuration ({@link DecimalPoint}). That is, if it represents either * a decimal or non decimal number. This function is the same * as {@link FnString#canBeBigDecimal(DecimalPoint)}. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link BigDecimal}. * Otherwise, false * * @since 1.2 */ public static final Function isValidBigDecimal(final DecimalPoint decimalPoint) { return new CanBeBigDecimal(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. *

* * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @since 1.2 */ public static final Function canBeBigInteger() { return CAN_BE_BIG_INTEGER; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} in the given {@link Locale} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @since 1.2 */ public static final Function canBeBigInteger(final Locale locale) { return new CanBeBigInteger(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} in the given {@link Locale} specified as a {@link String} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @since 1.2 */ public static final Function canBeBigInteger(final String locale) { return new CanBeBigInteger(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} using the specified decimal point * configuration ({@link DecimalPoint}). *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @since 1.2 */ public static final Function canBeBigInteger(final DecimalPoint decimalPoint) { return new CanBeBigInteger(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} in the specified radix. It uses the default * configuration to check the {@link String} *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @since 1.2 */ public static final Function canBeBigInteger(final int radix) { return new CanBeBigInteger(radix); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. *

* * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @deprecated use {@link FnString#canBeBigInteger()} instead. This method will be * removed in version 1.3 */ @Deprecated public static final Function isBigInteger() { return CAN_BE_BIG_INTEGER; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} in the given {@link Locale} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @deprecated use {@link FnString#canBeBigInteger(Locale)} instead. This method will be * removed in version 1.3 */ @Deprecated public static final Function isBigInteger(final Locale locale) { return new CanBeBigInteger(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} in the given {@link Locale} specified as a {@link String} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @deprecated use {@link FnString#canBeBigInteger(String)} instead. This method will be * removed in version 1.3 */ @Deprecated public static final Function isBigInteger(final String locale) { return new CanBeBigInteger(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} using the specified decimal point * configuration ({@link DecimalPoint}). *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @deprecated use {@link FnString#canBeBigInteger(DecimalPoint)} instead. This method will be * removed in version 1.3 */ @Deprecated public static final Function isBigInteger(final DecimalPoint decimalPoint) { return new CanBeBigInteger(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} in the specified radix. It uses the default * configuration to check the {@link String} *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @deprecated use {@link FnString#canBeBigInteger(int)} instead. This method will be * removed in version 1.3 */ @Deprecated public static final Function isBigInteger(final int radix) { return new CanBeBigInteger(radix); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger}. That is, if it represents a non decimal number. It uses * the default configuration from the JVM (en_US) * to check whether the string is valid or not. *

* * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @since 1.2 */ public static final Function isValidBigInteger() { return IS_VALID_BIG_INTEGER; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} in the given {@link Locale}.That is, if * it represents a non decimal number. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @since 1.2 */ public static final Function isValidBigInteger(final Locale locale) { return new IsValidBigInteger(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} in the given {@link Locale} specified as a {@link String}. * That is, if it represents a non decimal number. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @since 1.2 */ public static final Function isValidBigInteger(final String locale) { return new IsValidBigInteger(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link BigInteger} in the specified radix. It uses the default * configuration to check the {@link String}. That is, if it * represents a non decimal number. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link BigInteger}. * Otherwise, false * * @since 1.2 */ public static final Function isValidBigInteger(final int radix) { return new IsValidBigInteger(radix); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toDouble()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @since 1.2 */ public static final Function canBeDouble() { return CAN_BE_DOUBLE; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double} in the given {@link Locale}. * If this method returns false, {@link FnString#toDouble(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @since 1.2 */ public static final Function canBeDouble(final Locale locale) { return new CanBeDouble(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toDouble(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @since 1.2 */ public static final Function canBeDouble(final String locale) { return new CanBeDouble(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toDouble(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @since 1.2 */ public static final Function canBeDouble(final DecimalPoint decimalPoint) { return new CanBeDouble(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toDouble()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @deprecated use {@link FnString#canBeDouble()} instead. This method will be removed * in version 1.3 */ @Deprecated public static final Function isDouble() { return CAN_BE_DOUBLE; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double} in the given {@link Locale}. * If this method returns false, {@link FnString#toDouble(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @deprecated use {@link FnString#canBeDouble(Locale)} instead. This method will be removed * in version 1.3 */ @Deprecated public static final Function isDouble(final Locale locale) { return new CanBeDouble(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toDouble(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @deprecated use {@link FnString#canBeDouble(String)} instead. This method will be removed * in version 1.3 */ @Deprecated public static final Function isDouble(final String locale) { return new CanBeDouble(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toDouble(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @deprecated use {@link FnString#canBeDouble(DecimalPoint)} instead. This method will be removed * in version 1.3 */ @Deprecated public static final Function isDouble(final DecimalPoint decimalPoint) { return new CanBeDouble(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * That is, if it represents either a decimal or non decimal number that fits * in a {@link Double} number. This function is the same * as {@link FnString#canBeDouble()} *

* * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @since 1.2 */ public static final Function isValidDouble() { return CAN_BE_DOUBLE; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double} in the given {@link Locale}. * That is, if it represents either a decimal or non decimal number that fits * in a {@link Double} number. This function is the same * as {@link FnString#canBeDouble(Locale)} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @since 1.2 */ public static final Function isValidDouble(final Locale locale) { return new CanBeDouble(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double} in the given {@link Locale} specified as a {@link String}. * That is, if it represents either a decimal or non decimal number that fits * in a {@link Double} number. This function is the same * as {@link FnString#canBeDouble(String)} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @since 1.2 */ public static final Function isValidDouble(final String locale) { return new CanBeDouble(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Double} using the specified decimal point * configuration ({@link DecimalPoint}). * That is, if it represents either a decimal or non decimal number that fits * in a {@link Double} number. This function is the same * as {@link FnString#canBeDouble(DecimalPoint)} *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Double}. * Otherwise, false * * @since 1.2 */ public static final Function isValidDouble(final DecimalPoint decimalPoint) { return new CanBeDouble(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toFloat()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @since 1.2 */ public static final Function canBeFloat() { return CAN_BE_FLOAT; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float} in the given {@link Locale}. * If this method returns false, {@link FnString#toFloat(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @since 1.2 */ public static final Function canBeFloat(final Locale locale) { return new CanBeFloat(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toFloat(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @since 1.2 */ public static final Function canBeFloat(final String locale) { return new CanBeFloat(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toFloat(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @since 1.2 */ public static final Function canBeFloat(final DecimalPoint decimalPoint) { return new CanBeFloat(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toFloat()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @deprecated use {@link FnString#canBeFloat()} instead. This method will be removed in * version 1.3 */ @Deprecated public static final Function isFloat() { return CAN_BE_FLOAT; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float} in the given {@link Locale}. * If this method returns false, {@link FnString#toFloat(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @deprecated use {@link FnString#canBeFloat(Locale)} instead. This method will be removed in * version 1.3 */ @Deprecated public static final Function isFloat(final Locale locale) { return new CanBeFloat(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toFloat(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @deprecated use {@link FnString#canBeFloat(String)} instead. This method will be removed in * version 1.3 */ @Deprecated public static final Function isFloat(final String locale) { return new CanBeFloat(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toFloat(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @deprecated use {@link FnString#canBeFloat(DecimalPoint)} instead. This method will be removed in * version 1.3 */ @Deprecated public static final Function isFloat(final DecimalPoint decimalPoint) { return new CanBeFloat(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * That is, if it represents either a decimal or non decimal number that fits * in a {@link Float} number. This function is the same * as {@link FnString#canBeFloat()} *

* * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @since 1.2 */ public static final Function isValidFloat() { return CAN_BE_FLOAT; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float} in the given {@link Locale}. * That is, if it represents either a decimal or non decimal number that * fits in a {@link Float} number. This function is the * same as {@link FnString#canBeFloat(Locale)} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @since 1.2 */ public static final Function isValidFloat(final Locale locale) { return new CanBeFloat(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float} in the given {@link Locale} specified as a {@link String}. * That is, if it represents either a decimal or non decimal number * that fits in a {@link Float} number. * This function is the same as {@link FnString#canBeFloat(String)} *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @since 1.2 */ public static final Function isValidFloat(final String locale) { return new CanBeFloat(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Float} using the specified decimal point * configuration ({@link DecimalPoint}). That is, if it represents either a * decimal or non decimal number that fits in a {@link Float} number. * This function is the same as {@link FnString#canBeFloat(DecimalPoint)}. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Float}. * Otherwise, false * * @since 1.2 */ public static final Function isValidFloat(final DecimalPoint decimalPoint) { return new CanBeFloat(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Long}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toLong()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @since 1.2 */ public static final Function canBeLong() { return CAN_BE_LONG; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Long} in the given {@link Locale}. * If this method returns false, {@link FnString#toLong(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @since 1.2 */ public static final Function canBeLong(final Locale locale) { return new CanBeLong(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Long} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toLong(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @since 1.2 */ public static final Function canBeLong(final String locale) { return new CanBeLong(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Long} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toLong(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @since 1.2 */ public static final Function canBeLong(final DecimalPoint decimalPoint) { return new CanBeLong(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Long} in the specified radix. It uses the default * configuration to check the {@link String}. * If this method returns false, {@link FnString#toLong(int)} will throw an exception if called. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @since 1.2 */ public static final Function canBeLong(final int radix) { return new CanBeLong(radix); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Long}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toLong()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @deprecated use {@link FnString#canBeLong()} instead. This method will be removed in * version 1.3 */ @Deprecated public static final Function isLong() { return CAN_BE_LONG; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Long} in the given {@link Locale}. * If this method returns false, {@link FnString#toLong(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @deprecated use {@link FnString#canBeLong(Locale)} instead. This method will be removed in * version 1.3 */ @Deprecated public static final Function isLong(final Locale locale) { return new CanBeLong(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Long} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toLong(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @deprecated use {@link FnString#canBeLong(String)} instead. This method will be removed in * version 1.3 */ @Deprecated public static final Function isLong(final String locale) { return new CanBeLong(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Long} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toLong(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @deprecated use {@link FnString#canBeLong(DecimalPoint)} instead. This method will be removed in * version 1.3 */ @Deprecated public static final Function isLong(final DecimalPoint decimalPoint) { return new CanBeLong(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Long} in the specified radix. It uses the default * configuration to check the {@link String}. * If this method returns false, {@link FnString#toLong(int)} will throw an exception if called. *

* * @param radixthe radix being used by the String * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @deprecated use {@link FnString#canBeLong(int)} instead. This method will be removed in * version 1.3 */ @Deprecated public static final Function isLong(final int radix) { return new CanBeLong(radix); } /** *

* Returns true if the input {@link String} represents an {@link Long}, * that is, it it represents a non decimal number between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE}. *

* * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @since 1.2 */ public static final Function isValidLong() { return IS_VALID_LONG; } /** *

* Returns true if the input {@link String} represents an {@link Long}, * that is, it it represents a non decimal number between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE}. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @since 1.2 */ public static final Function isValidLong(final Locale locale) { return new IsValidLong(locale); } /** *

* Returns true if the input {@link String} represents an {@link Long}, * that is, it it represents a non decimal number between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE}. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @since 1.2 */ public static final Function isValidLong(final String locale) { return new IsValidLong(locale); } /** *

* Returns true if the input {@link String} represents an {@link Long}, * that is, it it represents a non decimal number between * {@link Long#MIN_VALUE} and {@link Long#MAX_VALUE}. It uses the default * configuration to check the {@link String}. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Long}. * Otherwise, false * * @since 1.2 */ public static final Function isValidLong(final int radix) { return new IsValidLong(radix); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Integer}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toInteger()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @since 1.2 */ public static final Function canBeInteger() { return CAN_BE_INTEGER; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Integer} in the given {@link Locale}. * If this method returns false, {@link FnString#toInteger(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @since 1.2 */ public static final Function canBeInteger(final Locale locale) { return new CanBeInteger(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Integer} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toInteger(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @since 1.2 */ public static final Function canBeInteger(final String locale) { return new CanBeInteger(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Integer} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toInteger(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @since 1.2 */ public static final Function canBeInteger(final DecimalPoint decimalPoint) { return new CanBeInteger(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Integer} in the specified radix. It uses the default * configuration to check the {@link String}. * If this method returns false, {@link FnString#toInteger(int)} will throw an exception if called. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @since 1.2 */ public static final Function canBeInteger(final int radix) { return new CanBeInteger(radix); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Integer}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toInteger()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @deprecated use {@link FnString#canBeInteger()} instead. This method will be * removed in version 1.3 */ @Deprecated public static final Function isInteger() { return CAN_BE_INTEGER; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Integer} in the given {@link Locale}. * If this method returns false, {@link FnString#toInteger(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @deprecated use {@link FnString#canBeInteger(Locale)} instead. This method will be * removed in version 1.3 */ @Deprecated public static final Function isInteger(final Locale locale) { return new CanBeInteger(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Integer} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toInteger(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @deprecated use {@link FnString#canBeInteger(String)} instead. This method will be * removed in version 1.3 */ @Deprecated public static final Function isInteger(final String locale) { return new CanBeInteger(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Integer} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toInteger(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @deprecated use {@link FnString#canBeInteger(DecimalPoint)} instead. This method will be * removed in version 1.3 */ @Deprecated public static final Function isInteger(final DecimalPoint decimalPoint) { return new CanBeInteger(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Integer} in the specified radix. It uses the default * configuration to check the {@link String}. * If this method returns false, {@link FnString#toInteger(int)} will throw an exception if called. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @deprecated use {@link FnString#canBeInteger(int)} instead. This method will be * removed in version 1.3 */ @Deprecated public static final Function isInteger(final int radix) { return new CanBeInteger(radix); } /** *

* Returns true if the input {@link String} represents an {@link Integer}, * that is, it it represents a non decimal number between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE}. *

* * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @since 1.2 */ public static final Function isValidInteger() { return IS_VALID_INTEGER; } /** *

* Returns true if the input {@link String} represents an {@link Integer}, * that is, it it represents a non decimal number between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE}. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @since 1.2 */ public static final Function isValidInteger(final Locale locale) { return new IsValidInteger(locale); } /** *

* Returns true if the input {@link String} represents an {@link Integer}, * that is, it it represents a non decimal number between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE}. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @since 1.2 */ public static final Function isValidInteger(final String locale) { return new IsValidInteger(locale); } /** *

* Returns true if the input {@link String} represents an {@link Integer}, * that is, it it represents a non decimal number between * {@link Integer#MIN_VALUE} and {@link Integer#MAX_VALUE}. It uses the default * configuration to check the {@link String}. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Integer}. * Otherwise, false * * @since 1.2 */ public static final Function isValidInteger(final int radix) { return new IsValidInteger(radix); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Short}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toShort()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @since 1.2 */ public static final Function canBeShort() { return CAN_BE_SHORT; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Short} in the given {@link Locale}. * If this method returns false, {@link FnString#toShort(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @since 1.2 */ public static final Function canBeShort(final Locale locale) { return new CanBeShort(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Short} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toShort(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @since 1.2 */ public static final Function canBeShort(final String locale) { return new CanBeShort(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Short} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toShort(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @since 1.2 */ public static final Function canBeShort(final DecimalPoint decimalPoint) { return new CanBeShort(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Short} in the specified radix. It uses the default * configuration to check the {@link String}. * If this method returns false, {@link FnString#toShort(int)} will throw an exception if called. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @since 1.2 */ public static final Function canBeShort(final int radix) { return new CanBeShort(radix); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Short}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toShort()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @deprecated use {@link FnString#canBeShort()} instead. This method will be removed * in version 1.3 */ @Deprecated public static final Function isShort() { return CAN_BE_SHORT; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Short} in the given {@link Locale}. * If this method returns false, {@link FnString#toShort(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @deprecated use {@link FnString#canBeShort(Locale)} instead. This method will be removed * in version 1.3 */ @Deprecated public static final Function isShort(final Locale locale) { return new CanBeShort(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Short} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toShort(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @deprecated use {@link FnString#canBeShort(String)} instead. This method will be removed * in version 1.3 */ @Deprecated public static final Function isShort(final String locale) { return new CanBeShort(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Short} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toShort(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @deprecated use {@link FnString#canBeShort(DecimalPoint)} instead. This method will be removed * in version 1.3 */ @Deprecated public static final Function isShort(final DecimalPoint decimalPoint) { return new CanBeShort(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Short} in the specified radix. It uses the default * configuration to check the {@link String}. * If this method returns false, {@link FnString#toShort(int)} will throw an exception if called. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @deprecated use {@link FnString#canBeShort(int)} instead. This method will be removed * in version 1.3 */ @Deprecated public static final Function isShort(final int radix) { return new CanBeShort(radix); } /** *

* Returns true if the input {@link String} represents a {@link Short}, * that is, it it represents a non decimal number between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE}. *

* * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @since 1.2 */ public static final Function isValidShort() { return IS_VALID_SHORT; } /** *

* Returns true if the input {@link String} represents a {@link Short}, * that is, it it represents a non decimal number between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE}. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @since 1.2 */ public static final Function isValidShort(final Locale locale) { return new IsValidShort(locale); } /** *

* Returns true if the input {@link String} represents a {@link Short}, * that is, it it represents a non decimal number between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE}. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @since 1.2 */ public static final Function isValidShort(final String locale) { return new IsValidShort(locale); } /** *

* Returns true if the input {@link String} represents a {@link Short}, * that is, it it represents a non decimal number between * {@link Short#MIN_VALUE} and {@link Short#MAX_VALUE}. It uses the default * configuration to check the {@link String}. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Short}. * Otherwise, false * * @since 1.2 */ public static final Function isValidShort(final int radix) { return new IsValidShort(radix); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Byte}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toByte()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @since 1.2 */ public static final Function canBeByte() { return CAN_BE_BYTE; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Byte} in the given {@link Locale}. * If this method returns false, {@link FnString#toByte(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @since 1.2 */ public static final Function canBeByte(final Locale locale) { return new CanBeByte(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Byte} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toByte(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @since 1.2 */ public static final Function canBeByte(final String locale) { return new CanBeByte(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Byte} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toByte(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @since 1.2 */ public static final Function canBeByte(final DecimalPoint decimalPoint) { return new CanBeByte(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Byte} in the specified radix. It uses the default * configuration to check the {@link String}. * If this method returns false, {@link FnString#toByte(int)} will throw an exception if called. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @since 1.2 */ public static final Function canBeByte(final int radix) { return new CanBeByte(radix); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Byte}. It uses the default configuration from the JVM (en_US) * to check whether the string is valid or not. * If this method returns false, {@link FnString#toByte()} will throw an exception if called. *

* * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @deprecated use {@link FnString#canBeByte()} instead. This method will be removed * in version 1.3 * */ @Deprecated public static final Function isByte() { return CAN_BE_BYTE; } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Byte} in the given {@link Locale}. * If this method returns false, {@link FnString#toByte(Locale)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @deprecated use {@link FnString#canBeByte(Locale)} instead. This method will be removed * in version 1.3 * */ @Deprecated public static final Function isByte(final Locale locale) { return new CanBeByte(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Byte} in the given {@link Locale} specified as a {@link String}. * If this method returns false, {@link FnString#toByte(String)} will throw an exception if called. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @deprecated use {@link FnString#canBeByte(String)} instead. This method will be removed * in version 1.3 * */ @Deprecated public static final Function isByte(final String locale) { return new CanBeByte(locale); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Byte} using the specified decimal point * configuration ({@link DecimalPoint}). * If this method returns false, {@link FnString#toByte(DecimalPoint)} will throw an exception if called. *

* * @param decimalPoint the decimal point being used by the String * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @deprecated use {@link FnString#canBeByte(DecimalPoint)} instead. This method will be removed * in version 1.3 * */ @Deprecated public static final Function isByte(final DecimalPoint decimalPoint) { return new CanBeByte(decimalPoint); } /** *

* Returns true if the input {@link String} can be converted into a * valid {@link Byte} in the specified radix. It uses the default * configuration to check the {@link String}. * If this method returns false, {@link FnString#toByte(int)} will throw an exception if called. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @deprecated use {@link FnString#canBeByte(int)} instead. This method will be removed * in version 1.3 * */ @Deprecated public static final Function isByte(final int radix) { return new CanBeByte(radix); } /** *

* Returns true if the input {@link String} represents a {@link Byte}, * that is, it it represents a non decimal number between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE}. *

* * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @since 1.2 */ public static final Function isValidByte() { return IS_VALID_BYTE; } /** *

* Returns true if the input {@link String} represents a {@link Byte}, * that is, it it represents a non decimal number between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE}. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @since 1.2 */ public static final Function isValidByte(final Locale locale) { return new IsValidByte(locale); } /** *

* Returns true if the input {@link String} represents a {@link Byte}, * that is, it it represents a non decimal number between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE}. *

* * @param locale the locale defining the way in which the number is written * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @since 1.2 */ public static final Function isValidByte(final String locale) { return new IsValidByte(locale); } /** *

* Returns true if the input {@link String} represents a {@link Byte}, * that is, it it represents a non decimal number between * {@link Byte#MIN_VALUE} and {@link Byte#MAX_VALUE}. It uses the default * configuration to check the {@link String}. *

* * @param radix the radix being used by the String * @return true if the input {@link String} represents a valid {@link Byte}. * Otherwise, false * * @since 1.2 */ public static final Function isValidByte(final int radix) { return new IsValidByte(radix); } /** *

* It checks whether the input {@link String} starts with the specified * prefix or not. If the suffix is empty, starts with or is equal to * the input, it will return true. *

* * @param prefix the prefix to be search at the beginning of the input * @return true if the input {@link String} starts with the specified prefix */ public static final Function startsWith(final String prefix) { return new StartsWith(prefix); } /** *

* It checks whether the input substring after the given offset starts * with the given prefix or not. *

* * @param prefix the prefix to be search after the specified offset * @param offset where to begin looking for the prefix * @return */ public static final Function startsWith(final String prefix, final int offset) { return new StartsWith(prefix, offset); } /** *

* Checkx whether the input {@link String} ends with the specified suffix or not. * If the suffix is empty, ends with or is equal to the input, it will return true. *

* * @param suffix suffix to be search at the end of the input * @return true if the input {@link String} ends with the specified suffix */ public static final Function endsWith(final String suffix) { return new EndsWith(suffix); } /** *

* Returns the substring of input from start position (null if null * String input). It calls {@link StringUtils#substring(String, int)} *

* * @param start the position to start from, negative means count back from the * end of the String by this many characters * @return the substring */ public static final Function substring(final int start) { return new SubString(start); } /** *

* Returns the substring of input from start position to end position (null if null * String input). It calls {@link StringUtils#substring(String, int, int)} *

* * @param start the position to start from, negative means count back from the * end of the String by this many characters * @param end the position to end at (exclusive), negative means count back * from the end of the String by this many characters * @return the substring */ public static final Function substring(final int start, final int end) { return new SubString(start, end); } /** *

* Returns the substring before the first occurrence of the given separator. It calls * {@link StringUtils#substringBefore(String, String)} *

* * @param separator the {@link String} to search for (may be null) * @return the substring before the first occurrence of the separator, null * if null String input */ public static final Function substringBefore(final String separator) { return new SubStringBefore(separator); } /** *

* Returns the substring before the last occurrence of the given separator. It calls * {@link StringUtils#substringBeforeLast(String, String)} *

* * @param separator the {@link String} to search for (may be null) * @return the substring before the last occurrence of the separator, null * if null String input */ public static final Function substringBeforeLast(final String separator) { return new SubStringBeforeLast(separator); } /** *

* Returns the substring after the first occurrence of the given separator. It calls * {@link StringUtils#substringAfter(String, String)} *

* * @param separator the {@link String} to search for (may be null) * @return the substring after the first occurrence of the separator, null * if null String input */ public static final Function substringAfter(final String separator) { return new SubStringAfter(separator); } /** *

* Returns the substring after the last occurrence of the given separator. It calls * {@link StringUtils#substringAfterLast(String, String)} *

* * @param separator the {@link String} to search for (may be null) * @return the substring after the last occurrence of the separator, null * if null String input */ public static final Function substringAfterLast(final String separator) { return new SubStringAfterLast(separator); } /** *

* Returns the substring between tag and tag or null if there is no match. It calls * {@link StringUtils#substringBetween(String, String)} *

* * @param tag the String before and after the substring, may be null * @return the substring, null if no match */ public static final Function substringBetween(final String tag) { return new SubStringBetween(tag); } /** *

* Returns the substring between open and close or null if there is no match. It calls * {@link StringUtils#substringBetween(String, String, String)} *

* * @param open the String before the substring, may be null * @param close the String after the substring, may be null * @return the substring, null if no match */ public static final Function substringBetween(final String open, final String close) { return new SubStringBetween(open, close); } /** *

* Returns whether the target {@link String} is empty or not. It calls * {@link StringUtils#isEmpty(String)}. The string is empty if it is "" * or null *

* * @return whether the String is empty or not */ public static final Function isEmpty() { return IS_EMPTY; } /** *

* Returns whether the target {@link String} is blank or not. It calls * {@link StringUtils#isBlank(String)}. The string is blank if it is * whitespace, empty ("") or null. *

* * @return whether the String is blank or not */ public static final Function isBlank() { return IS_BLANK; } /** *

* It reverses the input {@link String} *

* * @return a {@link String} equals to the input string reversed */ public static final Function reverse() { return REVERSE; } /** * The String is returned in a way it can be used to fill in a CSV column as StringEscapeUtils does * */ static final class EscapeCSV extends Function { EscapeCSV() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringEscapeUtils.escapeCsv(input); } } /** * The String is returned without the escape characters used to * include it in a CSV column (i.e. no quotes enclosing it, no escaped quotes) * as StringEscapeUtils does * */ static final class UnescapeCSV extends Function { UnescapeCSV() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringEscapeUtils.unescapeCsv(input); } } /** * The String is returned with the XML characters escaped as StringEscapeUtils does * */ static final class EscapeXML extends Function { EscapeXML() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringEscapeUtils.escapeXml(input); } } /** * The String is returned without the XML escape characters as StringEscapeUtils does * */ static final class UnescapeXML extends Function { UnescapeXML() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringEscapeUtils.unescapeXml(input); } } /** * It escapes the given String using HTML entities (as StringEscapeUtils does) * */ static final class EscapeHTML extends Function { EscapeHTML() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringEscapeUtils.escapeHtml(input); } } /** * It unescapes the given String and converts its HTML entity escapes into * their unicode characters (as StringEscapeUtils does) * */ static final class UnescapeHTML extends Function { UnescapeHTML() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringEscapeUtils.unescapeHtml(input); } } /** * It converts the given String into a JavaScript valid one (as StringEscapeUtils does) * */ static final class EscapeJavaScript extends Function { EscapeJavaScript() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringEscapeUtils.escapeJavaScript(input); } } /** * It unescapes the given JavaScript valid String (as StringEscapeUtils does) * */ static final class UnescapeJavaScript extends Function { UnescapeJavaScript() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringEscapeUtils.unescapeJavaScript(input); } } /** * It converts the given String into its Hexadecimal representation using the specified Charset * */ static final class ToHexadecimal extends AbstractNullAsNullFunction { private Charset charset = null; ToHexadecimal(Charset charset) { super(); this.charset = charset; } @Override protected String nullAsNullExecute(final String input, final ExecCtx ctx) throws Exception { Validate.notNull(this.charset, "Charset can't be null"); final byte[] inputAsByteArray = input.getBytes(this.charset.name()); final StringBuffer output = new StringBuffer(); for (byte i = 0; i < inputAsByteArray.length; i++) { output.append(Integer.toHexString(inputAsByteArray[i])); } return output.toString(); } } /** * The given String is converted from its Hexadecimal representation into a String using the specified Charset * */ static final class FromHexadecimal extends AbstractNullAsNullFunction { private Charset charset = null; FromHexadecimal(Charset charset) { super(); this.charset = charset; } @Override protected String nullAsNullExecute(final String input, final ExecCtx ctx) throws Exception { Validate.notNull(this.charset, "Charset can't be null"); final StringBuffer output = new StringBuffer(); for (int i = 0; i < input.length(); i = i + 2) { final byte current = (byte) Integer.parseInt(String.valueOf(input.charAt(i)) + String.valueOf(input.charAt(i + 1)), 16); output.append(new String(new byte[] {current}, this.charset.name())); } return output.toString(); } } /** * It converts the given String to uppercase * */ static final class ToUpperCase extends Function { ToUpperCase() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringUtils.upperCase(input); } } /** * It converts the given String to lowercase * */ static final class ToLowerCase extends Function { ToLowerCase() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringUtils.lowerCase(input); } } /** * It converts the first letter of the given String to lowercase * */ static final class UnCapitalize extends Function { UnCapitalize() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringUtils.uncapitalize(input); } } /** * It converts the first letter of the given String to uppercase * */ static final class Capitalize extends Function { Capitalize() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringUtils.capitalize(input); } } /** * Removes control characters (char <= 32) from both ends of the given String * */ static final class Trim extends Function { Trim() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringUtils.trim(input); } } /** * Strips whitespace from both sides of the given String * */ static final class Strip extends Function { Strip() { super(); } public String execute(final String input, final ExecCtx ctx) throws Exception { return StringUtils.strip(input); } } static final class ToBoolean extends AbstractNullAsNullFunction { ToBoolean() { super(); } @Override protected Boolean nullAsNullExecute(final String string, final ExecCtx ctx) throws Exception { return BooleanUtils.toBooleanObject(string); } } static final class ToCalendar extends AbstractNullAsNullFunction { private final SimpleDateFormat simpleDateFormat; ToCalendar(final String pattern) { super(); Validate.notNull(pattern, "A pattern must be specified"); if (StringUtils.contains(pattern, "MMM")) { throw new IllegalArgumentException("The use of MMM or MMMM as part of the date pattern requires a Locale"); } if (StringUtils.contains(pattern, "EEE")) { throw new IllegalArgumentException("The use of EEE or EEEE as part of the date pattern requires a Locale"); } this.simpleDateFormat = new SimpleDateFormat(pattern); } ToCalendar(final String pattern, final Locale locale) { super(); Validate.notNull(pattern, "A pattern must be specified"); Validate.notNull(locale, "A locale must be specified"); this.simpleDateFormat = new SimpleDateFormat(pattern, locale); } ToCalendar(final String pattern, final String locale) { super(); Validate.notNull(pattern, "A pattern must be specified"); Validate.notNull(locale, "A locale must be specified"); this.simpleDateFormat = new SimpleDateFormat(pattern, LocaleUtils.toLocale(locale)); } @Override protected Calendar nullAsNullExecute(final String object, final ExecCtx ctx) throws Exception { // Calendar is truncated to YEAR to ensure all fields are set to zero before // parsing the string into the new calendar object final Calendar calendar = DateUtils.truncate(Calendar.getInstance(), Calendar.YEAR); //It uses ParsePosition to make sure the whole //string has been converted into a number ParsePosition pp = new ParsePosition(0); Date date = this.simpleDateFormat.parse(object, pp); if (pp.getIndex() != object.length()) { throw new ParseException("The whole input String does not represent a valid Date", pp.getIndex()); } calendar.setTime(date); return calendar; } } static final class IsCalendar extends Function { private String pattern = null; private Locale locale = null; IsCalendar(final String pattern) { super(); Validate.notNull(pattern, "A pattern must be specified"); if (StringUtils.contains(pattern, "MMM")) { throw new IllegalArgumentException("The use of MMM or MMMM as part of the date pattern requires a Locale"); } if (StringUtils.contains(pattern, "EEE")) { throw new IllegalArgumentException("The use of EEE or EEEE as part of the date pattern requires a Locale"); } this.pattern = pattern; } IsCalendar(final String pattern, final Locale locale) { super(); Validate.notNull(pattern, "A pattern must be specified"); Validate.notNull(locale, "A locale must be specified"); this.pattern = pattern; this.locale = locale; } IsCalendar(final String pattern, final String locale) { super(); Validate.notNull(pattern, "A pattern must be specified"); Validate.notNull(locale, "A locale must be specified"); this.pattern = pattern; this.locale = LocaleUtils.toLocale(locale); } public Boolean execute(final String object, final ExecCtx ctx) throws Exception { try { if (this.locale != null) { Op.on(object).exec(FnString.toCalendar(this.pattern, this.locale)).get(); } else { Op.on(object).exec(FnString.toCalendar(this.pattern)).get(); } return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } } static final class ToDate extends AbstractNullAsNullFunction { private final SimpleDateFormat simpleDateFormat; ToDate(final String pattern) { super(); Validate.notNull(pattern, "A pattern must be specified"); if (StringUtils.contains(pattern, "MMM")) { throw new IllegalArgumentException("The use of MMM or MMMM as part of the date pattern requires a Locale"); } if (StringUtils.contains(pattern, "EEE")) { throw new IllegalArgumentException("The use of EEE or EEEE as part of the date pattern requires a Locale"); } this.simpleDateFormat = new SimpleDateFormat(pattern); } ToDate(final String pattern, final Locale locale) { super(); Validate.notNull(pattern, "A pattern must be specified"); Validate.notNull(locale, "A locale must be specified"); this.simpleDateFormat = new SimpleDateFormat(pattern, locale); } ToDate(final String pattern, final String locale) { super(); Validate.notNull(pattern, "A pattern must be specified"); Validate.notNull(locale, "A locale must be specified"); this.simpleDateFormat = new SimpleDateFormat(pattern, LocaleUtils.toLocale(locale)); } @Override protected Date nullAsNullExecute(final String object, final ExecCtx ctx) throws Exception { // Calendar is truncated to YEAR to ensure all fields are set to zero before // parsing the string into the new calendar object final Calendar calendar = DateUtils.truncate(Calendar.getInstance(), Calendar.YEAR); //It uses ParsePosition to make sure the whole //string has been converted into a number ParsePosition pp = new ParsePosition(0); Date date = this.simpleDateFormat.parse(object, pp); if (pp.getIndex() != object.length()) { throw new ParseException("The whole input String does not represent a valid Date", pp.getIndex()); } calendar.setTime(date); return calendar.getTime(); } } static final class Matches extends AbstractNotNullFunction { private final Pattern pattern; Matches(final String regex) { super(); Validate.notEmpty(regex, "Regular expression cannot be null or empty"); this.pattern = Pattern.compile(regex); } @Override protected Boolean notNullExecute(final String input, final ExecCtx ctx) throws Exception { final Matcher matcher = this.pattern.matcher(input); return Boolean.valueOf(matcher.matches()); } } static final class Contains extends AbstractNotNullFunction { private final Pattern pattern; Contains(final String regex) { super(); Validate.notEmpty(regex, "Regular expression cannot be null or empty"); this.pattern = Pattern.compile(regex); } @Override protected Boolean notNullExecute(final String input, final ExecCtx ctx) throws Exception { final Matcher matcher = this.pattern.matcher(input); return Boolean.valueOf(matcher.find()); } } static final class Extract extends AbstractNotNullFunction { private final Pattern pattern; private final boolean last; Extract(final String regex, final boolean last) { super(); Validate.notEmpty(regex, "Regular expression cannot be null or empty"); this.pattern = Pattern.compile(regex); this.last = last; } @Override protected String notNullExecute(final String input, final ExecCtx ctx) throws Exception { final Matcher matcher = this.pattern.matcher(input); if (!this.last) { if (!matcher.find()) { throw new ExecutionException("Cannot extract: target does not match regular expression"); } return matcher.group(); } String result = null; while (matcher.find()) { result = matcher.group(); } if (result == null) { throw new ExecutionException("Cannot extract: target does not match regular expression"); } return result; } } static final class ExtractAll extends AbstractNotNullFunction> { private final Pattern pattern; ExtractAll(final String regex) { super(); Validate.notEmpty(regex, "Regular expression cannot be null or empty"); this.pattern = Pattern.compile(regex); } @Override protected List notNullExecute(final String input, final ExecCtx ctx) throws Exception { final Matcher matcher = this.pattern.matcher(input); final List result = new ArrayList(); while (matcher.find()) { result.add(matcher.group()); } return Collections.unmodifiableList(result); } } static final class MatchAndExtract extends AbstractNotNullFunction { private final Pattern pattern; private final int group; MatchAndExtract(final String regex, final int group) { super(); Validate.notEmpty(regex, "Regular expression cannot be null or empty"); this.pattern = Pattern.compile(regex); this.group = group; } @Override protected String notNullExecute(final String input, final ExecCtx ctx) throws Exception { final Matcher matcher = this.pattern.matcher(input); if (!matcher.matches()) { throw new ExecutionException("Cannot extract: target does not match regular expression"); } return matcher.group(this.group); } } static final class MatchAndExtractAll extends AbstractNotNullFunction> { private final Pattern pattern; private final List groups; MatchAndExtractAll(final String regex, final List groups) { super(); Validate.notEmpty(regex, "Regular expression cannot be null or empty"); Validate.notEmpty(groups, "Groups cannot be null or empty"); this.pattern = Pattern.compile(regex); this.groups = new ArrayList(groups); } @Override protected List notNullExecute(final String input, final ExecCtx ctx) throws Exception { final Matcher matcher = this.pattern.matcher(input); if (!matcher.matches()) { throw new ExecutionException("Cannot extract: target does not match regular expression"); } final List result = new ArrayList(); for (final Integer group : this.groups) { result.add(matcher.group(group.intValue())); } return result; } } static final class Replace extends AbstractNotNullFunction { public enum ReplaceType { ALL, FIRST, LAST } private final Pattern pattern; private final String replacement; private final ReplaceType replaceType; Replace(final String regex, String replacement, final ReplaceType replaceType) { super(); Validate.notEmpty(regex, "Regular expression cannot be null or empty"); this.pattern = Pattern.compile(regex); this.replacement = replacement; this.replaceType = replaceType; } @Override protected String notNullExecute(final String input, final ExecCtx ctx) throws Exception { final Matcher matcher = this.pattern.matcher(input); if (this.replaceType.equals(ReplaceType.ALL)) { return matcher.replaceAll(this.replacement); } if (this.replaceType.equals(ReplaceType.FIRST)) { return matcher.replaceFirst(this.replacement); } int regionStart = -1; while (matcher.find()) { regionStart = matcher.start(); } if (regionStart == -1) { return input; } return input.substring(0, regionStart) + this.pattern.matcher(input.substring(regionStart)).replaceFirst(this.replacement); } } static final class Split extends AbstractNullAsNullFunction> { private final String separator; Split() { super(); this.separator = null; } Split(String separator) { super(); this.separator = separator; } @Override public List nullAsNullExecute(final String input, final ExecCtx ctx) throws Exception { if (StringUtils.isEmpty(this.separator)) { return Op.on(StringUtils.split(input)).toList().get(); } return Op.on(StringUtils.split(input, this.separator)).toList().get(); } } static final class SplitAsArray extends AbstractNullAsNullFunction { private final String separator; SplitAsArray() { super(); this.separator = null; } SplitAsArray(String separator) { super(); this.separator = separator; } @Override public String[] nullAsNullExecute(final String input, final ExecCtx ctx) throws Exception { if (StringUtils.isEmpty(this.separator)) { return StringUtils.split(input); } return StringUtils.split(input, this.separator); } } static final class Join extends AbstractNullAsNullFunction,String> { private final String separator; Join() { super(); this.separator = null; } Join(String separator) { super(); this.separator = separator; } @Override public String nullAsNullExecute(final List input, final ExecCtx ctx) throws Exception { if (this.separator != null) { return StringUtils.join(input.toArray(), this.separator); } return StringUtils.join(input.toArray()); } } static final class JoinArray extends AbstractNullAsNullFunction { private final String separator; JoinArray() { super(); this.separator = null; } JoinArray(String separator) { super(); this.separator = separator; } @Override public String nullAsNullExecute(final Object[] input, final ExecCtx ctx) throws Exception { if (this.separator != null) { return StringUtils.join(input, this.separator); } return StringUtils.join(input); } } public enum AsciifyMode { DEFAULT, UMLAUT_E } static final class Asciify extends AbstractNullAsNullFunction { private final static char ESSZETT = '\u00DF'; private static String[] defaultSearchList; private static String[] defaultReplacementList; private static String[] umlautESearchList; private static String[] umlautEReplacementList; private final AsciifyMode mode; static { final Map replacements = new LinkedHashMap(); replacements.put("\u00C0", "A"); replacements.put("\u00C1", "A"); replacements.put("\u00C2", "A"); replacements.put("\u00C3", "A"); replacements.put("\u00C4", "A"); replacements.put("\u00C5", "A"); replacements.put("\u0100", "A"); replacements.put("\u0102", "A"); replacements.put("\u0104", "A"); replacements.put("\u01CD", "A"); replacements.put("\u01FA", "A"); replacements.put("\u00C6", "AE"); replacements.put("\u01FC", "AE"); replacements.put("\u00C7", "C"); replacements.put("\u0106", "C"); replacements.put("\u0108", "C"); replacements.put("\u010A", "C"); replacements.put("\u010C", "C"); replacements.put("\u00D0", "D"); replacements.put("\u010E", "D"); replacements.put("\u0110", "D"); replacements.put("\u00C8", "E"); replacements.put("\u00C9", "E"); replacements.put("\u00CA", "E"); replacements.put("\u00CB", "E"); replacements.put("\u0112", "E"); replacements.put("\u0114", "E"); replacements.put("\u0116", "E"); replacements.put("\u0118", "E"); replacements.put("\u011A", "E"); replacements.put("\u011C", "G"); replacements.put("\u011E", "G"); replacements.put("\u0120", "G"); replacements.put("\u0122", "G"); replacements.put("\u0124", "H"); replacements.put("\u0126", "H"); replacements.put("\u00CC", "I"); replacements.put("\u00CD", "I"); replacements.put("\u00CE", "I"); replacements.put("\u00CF", "I"); replacements.put("\u0128", "I"); replacements.put("\u012A", "I"); replacements.put("\u012C", "I"); replacements.put("\u012E", "I"); replacements.put("\u0130", "I"); replacements.put("\u01CF", "I"); replacements.put("\u0132", "IJ"); replacements.put("\u0134", "J"); replacements.put("\u0136", "K"); replacements.put("\u0139", "L"); replacements.put("\u013B", "L"); replacements.put("\u013D", "L"); replacements.put("\u013F", "L"); replacements.put("\u0141", "L"); replacements.put("\u00D1", "N"); replacements.put("\u0143", "N"); replacements.put("\u0145", "N"); replacements.put("\u0147", "N"); replacements.put("\u014A", "N"); replacements.put("\u00D2", "O"); replacements.put("\u00D3", "O"); replacements.put("\u00D4", "O"); replacements.put("\u00D5", "O"); replacements.put("\u00D6", "O"); replacements.put("\u00D8", "O"); replacements.put("\u014C", "O"); replacements.put("\u014E", "O"); replacements.put("\u0150", "O"); replacements.put("\u01A0", "O"); replacements.put("\u01D1", "O"); replacements.put("\u01FE", "O"); replacements.put("\u0152", "OE"); replacements.put("\u0154", "R"); replacements.put("\u0156", "R"); replacements.put("\u0158", "R"); replacements.put("\u015A", "S"); replacements.put("\u015C", "S"); replacements.put("\u015E", "S"); replacements.put("\u0160", "S"); replacements.put("\u0162", "T"); replacements.put("\u0164", "T"); replacements.put("\u0166", "T"); replacements.put("\u00D9", "U"); replacements.put("\u00DA", "U"); replacements.put("\u00DB", "U"); replacements.put("\u00DC", "U"); replacements.put("\u0168", "U"); replacements.put("\u016A", "U"); replacements.put("\u016C", "U"); replacements.put("\u016E", "U"); replacements.put("\u0170", "U"); replacements.put("\u0172", "U"); replacements.put("\u01AF", "U"); replacements.put("\u01D3", "U"); replacements.put("\u01D5", "U"); replacements.put("\u01D7", "U"); replacements.put("\u01D9", "U"); replacements.put("\u01DB", "U"); replacements.put("\u0174", "W"); replacements.put("\u00DD", "Y"); replacements.put("\u0176", "Y"); replacements.put("\u0178", "Y"); replacements.put("\u0179", "Z"); replacements.put("\u017B", "Z"); replacements.put("\u017D", "Z"); replacements.put("\u00DE", "TH"); replacements.put("\u00E0", "a"); replacements.put("\u00E1", "a"); replacements.put("\u00E2", "a"); replacements.put("\u00E3", "a"); replacements.put("\u00E4", "a"); replacements.put("\u00E5", "a"); replacements.put("\u0101", "a"); replacements.put("\u0103", "a"); replacements.put("\u0105", "a"); replacements.put("\u01CE", "a"); replacements.put("\u01FB", "a"); replacements.put("\u00E6", "ae"); replacements.put("\u01FD", "ae"); replacements.put("\u00E7", "c"); replacements.put("\u0107", "c"); replacements.put("\u0109", "c"); replacements.put("\u010B", "c"); replacements.put("\u010D", "c"); replacements.put("\u00F0", "d"); replacements.put("\u010F", "d"); replacements.put("\u0111", "d"); replacements.put("\u00E8", "e"); replacements.put("\u00E9", "e"); replacements.put("\u00EA", "e"); replacements.put("\u00EB", "e"); replacements.put("\u0113", "e"); replacements.put("\u0115", "e"); replacements.put("\u0117", "e"); replacements.put("\u0119", "e"); replacements.put("\u011B", "e"); replacements.put("\u011D", "g"); replacements.put("\u011F", "g"); replacements.put("\u0121", "g"); replacements.put("\u0123", "g"); replacements.put("\u0125", "h"); replacements.put("\u0127", "h"); replacements.put("\u00EC", "i"); replacements.put("\u00ED", "i"); replacements.put("\u00EE", "i"); replacements.put("\u00EF", "i"); replacements.put("\u0129", "i"); replacements.put("\u012B", "i"); replacements.put("\u012D", "i"); replacements.put("\u012F", "i"); replacements.put("\u0131", "i"); replacements.put("\u01D0", "i"); replacements.put("\u0133", "ij"); replacements.put("\u0135", "j"); replacements.put("\u0137", "k"); replacements.put("\u0138", "k"); replacements.put("\u013A", "l"); replacements.put("\u013C", "l"); replacements.put("\u013E", "l"); replacements.put("\u0140", "l"); replacements.put("\u0142", "l"); replacements.put("\u00F1", "n"); replacements.put("\u0144", "n"); replacements.put("\u0146", "n"); replacements.put("\u0148", "n"); replacements.put("\u0149", "n"); replacements.put("\u014B", "n"); replacements.put("\u00F2", "o"); replacements.put("\u00F3", "o"); replacements.put("\u00F4", "o"); replacements.put("\u00F5", "o"); replacements.put("\u00F6", "o"); replacements.put("\u00F8", "o"); replacements.put("\u014D", "o"); replacements.put("\u014F", "o"); replacements.put("\u0151", "o"); replacements.put("\u01A1", "o"); replacements.put("\u01D2", "o"); replacements.put("\u01FF", "o"); replacements.put("\u0153", "oe"); replacements.put("\u0155", "r"); replacements.put("\u0157", "r"); replacements.put("\u0159", "r"); replacements.put("\u015B", "s"); replacements.put("\u015D", "s"); replacements.put("\u015F", "s"); replacements.put("\u0161", "s"); replacements.put("\u0163", "t"); replacements.put("\u0165", "t"); replacements.put("\u0167", "t"); replacements.put("\u00F9", "u"); replacements.put("\u00FA", "u"); replacements.put("\u00FB", "u"); replacements.put("\u00FC", "u"); replacements.put("\u0169", "u"); replacements.put("\u016B", "u"); replacements.put("\u016D", "u"); replacements.put("\u016F", "u"); replacements.put("\u0171", "u"); replacements.put("\u0173", "u"); replacements.put("\u01B0", "u"); replacements.put("\u01D4", "u"); replacements.put("\u01D6", "u"); replacements.put("\u01D8", "u"); replacements.put("\u01DA", "u"); replacements.put("\u01DC", "u"); replacements.put("\u0175", "w"); replacements.put("\u00FD", "y"); replacements.put("\u00FE", "th"); replacements.put("\u00FF", "y"); replacements.put("\u0177", "y"); replacements.put("\u017A", "z"); replacements.put("\u017C", "z"); replacements.put("\u017E", "z"); defaultSearchList = replacements.keySet().toArray(new String[replacements.size()]); defaultReplacementList = replacements.values().toArray(new String[replacements.size()]); replacements.put("\u00C4", "AE"); replacements.put("\u00D6", "OE"); replacements.put("\u00DC", "UE"); replacements.put("\u00E4", "ae"); replacements.put("\u00F6", "oe"); replacements.put("\u00FC", "ue"); umlautESearchList = replacements.keySet().toArray(new String[replacements.size()]); umlautEReplacementList = replacements.values().toArray(new String[replacements.size()]); } public Asciify(final AsciifyMode mode) { super(); this.mode = mode; } public Asciify() { this(AsciifyMode.DEFAULT); } @Override protected String nullAsNullExecute(final String object, final ExecCtx ctx) throws Exception { final String result = (this.mode.equals(AsciifyMode.UMLAUT_E)? StringUtils.replaceEach(object, umlautESearchList, umlautEReplacementList) : StringUtils.replaceEach(object, defaultSearchList, defaultReplacementList)); int esTsetIndex; if ((esTsetIndex = result.indexOf(ESSZETT)) == -1) { return result; } int prevIndex = 0; final StringBuilder strBuilder = new StringBuilder(); while (esTsetIndex != -1) { strBuilder.append(result.substring(prevIndex,esTsetIndex)); if (esTsetIndex > 0) { int minus = 1; char lastChar = result.charAt(esTsetIndex - minus); while (minus <= esTsetIndex && (Character.isWhitespace(lastChar) || lastChar == ESSZETT)) { lastChar = result.charAt(esTsetIndex - minus); minus++; } if (lastChar >= 'a' && lastChar <= 'z') { strBuilder.append("ss"); } else { strBuilder.append("SS"); } } else { strBuilder.append("SS"); } prevIndex = esTsetIndex + 1; esTsetIndex = result.indexOf(ESSZETT, prevIndex); } strBuilder.append(result.substring(prevIndex)); return strBuilder.toString(); } } static final class IsAlpha extends Function { final boolean spacesAllowed; public IsAlpha() { super(); this.spacesAllowed = false; } public IsAlpha(boolean spacesAllowed) { super(); this.spacesAllowed = spacesAllowed; } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.spacesAllowed) { return Boolean.valueOf(StringUtils.isAlphaSpace(input)); } return Boolean.valueOf(StringUtils.isAlpha(input)); } } static final class IsNumeric extends Function { final boolean spacesAllowed; public IsNumeric() { super(); this.spacesAllowed = false; } public IsNumeric(boolean spacesAllowed) { super(); this.spacesAllowed = spacesAllowed; } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.spacesAllowed) { return Boolean.valueOf(StringUtils.isNumericSpace(input)); } return Boolean.valueOf(StringUtils.isNumeric(input)); } } static final class CanBeBigDecimal extends Function { final Locale locale; final DecimalPoint decimalPoint; public CanBeBigDecimal() { super(); this.locale = null; this.decimalPoint = null; } public CanBeBigDecimal(Locale locale) { super(); this.locale = locale; this.decimalPoint = null; } public CanBeBigDecimal(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.decimalPoint = null; } public CanBeBigDecimal(DecimalPoint decimalPoint) { super(); this.locale = null; this.decimalPoint = decimalPoint; } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.decimalPoint == null) { try { Op.on(input).exec(FnString.toBigDecimal()).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.locale != null) { try { Op.on(input).exec(FnString.toBigDecimal(this.locale)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.decimalPoint != null) { try { Op.on(input).exec(FnString.toBigDecimal(this.decimalPoint)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } return Boolean.FALSE; } } static final class CanBeBigInteger extends Function { final Locale locale; final DecimalPoint decimalPoint; final Integer radix; public CanBeBigInteger() { super(); this.locale = null; this.decimalPoint = null; this.radix = null; } public CanBeBigInteger(Locale locale) { super(); this.locale = locale; this.decimalPoint = null; this.radix = null; } public CanBeBigInteger(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.decimalPoint = null; this.radix = null; } public CanBeBigInteger(DecimalPoint decimalPoint) { super(); this.locale = null; this.decimalPoint = decimalPoint; this.radix = null; } public CanBeBigInteger(int radix) { super(); this.locale = null; this.decimalPoint = null; this.radix = Integer.valueOf(radix); } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.decimalPoint == null) { if (this.radix != null) { try { Op.on(input).exec(FnString.toBigInteger(this.radix.intValue())).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } try { Op.on(input).exec(FnString.toBigInteger()).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.locale != null) { try { Op.on(input).exec(FnString.toBigInteger(this.locale)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.decimalPoint != null) { try { Op.on(input).exec(FnString.toBigInteger(this.decimalPoint)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } return Boolean.FALSE; } } static final class IsValidBigInteger extends Function { final Locale locale; final Integer radix; public IsValidBigInteger() { super(); this.locale = null; this.radix = null; } public IsValidBigInteger(Locale locale) { super(); this.locale = locale; this.radix = null; } public IsValidBigInteger(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.radix = null; } public IsValidBigInteger(int radix) { super(); this.locale = null; this.radix = Integer.valueOf(radix); } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.radix != null) { try { Op.on(input).exec(FnString.toBigInteger(this.radix.intValue())).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.radix == null) { DecimalFormat notDecimalFormat = (DecimalFormat) NumberFormat .getInstance(this.locale == null ? Locale.US : this.locale); notDecimalFormat.setParseIntegerOnly(true); notDecimalFormat.setParseBigDecimal(true); //It uses ParsePosition to make sure the whole //string has been converted into a number ParsePosition pp = new ParsePosition(0); @SuppressWarnings("unused") Number number = notDecimalFormat.parse(input, pp); if (pp.getIndex() != input.length()) { return Boolean.FALSE; } return Boolean.TRUE; } return Boolean.FALSE; } } static final class CanBeDouble extends Function { final Locale locale; final DecimalPoint decimalPoint; public CanBeDouble() { super(); this.locale = null; this.decimalPoint = null; } public CanBeDouble(Locale locale) { super(); this.locale = locale; this.decimalPoint = null; } public CanBeDouble(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.decimalPoint = null; } public CanBeDouble(DecimalPoint decimalPoint) { super(); this.locale = null; this.decimalPoint = decimalPoint; } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.decimalPoint == null) { try { Op.on(input).exec(FnString.toDouble()).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.locale != null) { try { Op.on(input).exec(FnString.toDouble(this.locale)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.decimalPoint != null) { try { Op.on(input).exec(FnString.toDouble(this.decimalPoint)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } return Boolean.FALSE; } } static final class CanBeFloat extends Function { final Locale locale; final DecimalPoint decimalPoint; public CanBeFloat() { super(); this.locale = null; this.decimalPoint = null; } public CanBeFloat(Locale locale) { super(); this.locale = locale; this.decimalPoint = null; } public CanBeFloat(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.decimalPoint = null; } public CanBeFloat(DecimalPoint decimalPoint) { super(); this.locale = null; this.decimalPoint = decimalPoint; } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.decimalPoint == null) { try { Op.on(input).exec(FnString.toFloat()).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.locale != null) { try { Op.on(input).exec(FnString.toFloat(this.locale)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.decimalPoint != null) { try { Op.on(input).exec(FnString.toFloat(this.decimalPoint)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } return Boolean.FALSE; } } static final class CanBeLong extends Function { final Locale locale; final DecimalPoint decimalPoint; final Integer radix; public CanBeLong() { super(); this.locale = null; this.decimalPoint = null; this.radix = null; } public CanBeLong(Locale locale) { super(); this.locale = locale; this.decimalPoint = null; this.radix = null; } public CanBeLong(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.decimalPoint = null; this.radix = null; } public CanBeLong(DecimalPoint decimalPoint) { super(); this.locale = null; this.decimalPoint = decimalPoint; this.radix = null; } public CanBeLong(int radix) { super(); this.locale = null; this.decimalPoint = null; this.radix = Integer.valueOf(radix); } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.decimalPoint == null) { if (this.radix != null) { try { Op.on(input).exec(FnString.toLong(this.radix.intValue())).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } try { Op.on(input).exec(FnString.toLong()).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.locale != null) { try { Op.on(input).exec(FnString.toLong(this.locale)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.decimalPoint != null) { try { Op.on(input).exec(FnString.toLong(this.decimalPoint)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } return Boolean.FALSE; } } static final class IsValidLong extends Function { final Locale locale; final Integer radix; final static BigDecimal min = BigDecimal.valueOf(Long.MIN_VALUE); final static BigDecimal max = BigDecimal.valueOf(Long.MAX_VALUE); public IsValidLong() { super(); this.locale = null; this.radix = null; } public IsValidLong(Locale locale) { super(); this.locale = locale; this.radix = null; } public IsValidLong(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.radix = null; } public IsValidLong(int radix) { super(); this.locale = null; this.radix = Integer.valueOf(radix); } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.radix != null) { try { Op.on(input).exec(FnString.toLong(this.radix.intValue())).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.radix == null) { DecimalFormat notDecimalFormat = (DecimalFormat) NumberFormat .getInstance(this.locale == null ? Locale.US : this.locale); notDecimalFormat.setParseIntegerOnly(true); notDecimalFormat.setParseBigDecimal(true); //It uses ParsePosition to make sure the whole //string has been converted into a number ParsePosition pp = new ParsePosition(0); Number number = notDecimalFormat.parse(input, pp); BigDecimal bigDecimal = null; if (number instanceof BigDecimal) { bigDecimal = (BigDecimal) number; } else if (number instanceof BigInteger) { bigDecimal = new BigDecimal((BigInteger) number); } else { bigDecimal = new BigDecimal(number.doubleValue()); } if (bigDecimal.compareTo(min) < 0 || bigDecimal.compareTo(max) > 0) { return Boolean.FALSE; } if (pp.getIndex() != input.length()) { return Boolean.FALSE; } return Boolean.TRUE; } return Boolean.FALSE; } } static final class CanBeInteger extends Function { final Locale locale; final DecimalPoint decimalPoint; final Integer radix; public CanBeInteger() { super(); this.locale = null; this.decimalPoint = null; this.radix = null; } public CanBeInteger(Locale locale) { super(); this.locale = locale; this.decimalPoint = null; this.radix = null; } public CanBeInteger(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.decimalPoint = null; this.radix = null; } public CanBeInteger(DecimalPoint decimalPoint) { super(); this.locale = null; this.decimalPoint = decimalPoint; this.radix = null; } public CanBeInteger(int radix) { super(); this.locale = null; this.decimalPoint = null; this.radix = Integer.valueOf(radix); } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.decimalPoint == null) { if (this.radix != null) { try { Op.on(input).exec(FnString.toInteger(this.radix.intValue())).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } try { Op.on(input).exec(FnString.toInteger()).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.locale != null) { try { Op.on(input).exec(FnString.toInteger(this.locale)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.decimalPoint != null) { try { Op.on(input).exec(FnString.toInteger(this.decimalPoint)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } return Boolean.FALSE; } } static final class IsValidInteger extends Function { final Locale locale; final Integer radix; final static BigDecimal min = BigDecimal.valueOf((double)Integer.MIN_VALUE); final static BigDecimal max = BigDecimal.valueOf((double)Integer.MAX_VALUE); public IsValidInteger() { super(); this.locale = null; this.radix = null; } public IsValidInteger(Locale locale) { super(); this.locale = locale; this.radix = null; } public IsValidInteger(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.radix = null; } public IsValidInteger(int radix) { super(); this.locale = null; this.radix = Integer.valueOf(radix); } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.radix != null) { try { Op.on(input).exec(FnString.toInteger(this.radix.intValue())).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.radix == null) { DecimalFormat notDecimalFormat = (DecimalFormat) NumberFormat .getInstance(this.locale == null ? Locale.US : this.locale); notDecimalFormat.setParseIntegerOnly(true); notDecimalFormat.setParseBigDecimal(true); //It uses ParsePosition to make sure the whole //string has been converted into a number ParsePosition pp = new ParsePosition(0); Number number = notDecimalFormat.parse(input, pp); BigDecimal bigDecimal = null; if (number instanceof BigDecimal) { bigDecimal = (BigDecimal) number; } else if (number instanceof BigInteger) { bigDecimal = new BigDecimal((BigInteger) number); } else { bigDecimal = new BigDecimal(number.doubleValue()); } if (bigDecimal.compareTo(min) < 0 || bigDecimal.compareTo(max) > 0) { return Boolean.FALSE; } if (pp.getIndex() != input.length()) { return Boolean.FALSE; } return Boolean.TRUE; } return Boolean.FALSE; } } static final class CanBeShort extends Function { final Locale locale; final DecimalPoint decimalPoint; final Integer radix; public CanBeShort() { super(); this.locale = null; this.decimalPoint = null; this.radix = null; } public CanBeShort(Locale locale) { super(); this.locale = locale; this.decimalPoint = null; this.radix = null; } public CanBeShort(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.decimalPoint = null; this.radix = null; } public CanBeShort(DecimalPoint decimalPoint) { super(); this.locale = null; this.decimalPoint = decimalPoint; this.radix = null; } public CanBeShort(int radix) { super(); this.locale = null; this.decimalPoint = null; this.radix = Integer.valueOf(radix); } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.decimalPoint == null) { if (this.radix != null) { try { Op.on(input).exec(FnString.toShort(this.radix.intValue())).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } try { Op.on(input).exec(FnString.toShort()).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.locale != null) { try { Op.on(input).exec(FnString.toShort(this.locale)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.decimalPoint != null) { try { Op.on(input).exec(FnString.toShort(this.decimalPoint)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } return Boolean.FALSE; } } static final class IsValidShort extends Function { final Locale locale; final Integer radix; final static BigDecimal min = BigDecimal.valueOf((double)Short.MIN_VALUE); final static BigDecimal max = BigDecimal.valueOf((double)Short.MAX_VALUE); public IsValidShort() { super(); this.locale = null; this.radix = null; } public IsValidShort(Locale locale) { super(); this.locale = locale; this.radix = null; } public IsValidShort(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.radix = null; } public IsValidShort(int radix) { super(); this.locale = null; this.radix = Integer.valueOf(radix); } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.radix != null) { try { Op.on(input).exec(FnString.toShort(this.radix.intValue())).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.radix == null) { DecimalFormat notDecimalFormat = (DecimalFormat) NumberFormat .getInstance(this.locale == null ? Locale.US : this.locale); notDecimalFormat.setParseIntegerOnly(true); notDecimalFormat.setParseBigDecimal(true); //It uses ParsePosition to make sure the whole //string has been converted into a number ParsePosition pp = new ParsePosition(0); Number number = notDecimalFormat.parse(input, pp); BigDecimal bigDecimal = null; if (number instanceof BigDecimal) { bigDecimal = (BigDecimal) number; } else if (number instanceof BigInteger) { bigDecimal = new BigDecimal((BigInteger) number); } else { bigDecimal = new BigDecimal(number.doubleValue()); } if (bigDecimal.compareTo(min) < 0 || bigDecimal.compareTo(max) > 0) { return Boolean.FALSE; } if (pp.getIndex() != input.length()) { return Boolean.FALSE; } return Boolean.TRUE; } return Boolean.FALSE; } } static final class CanBeByte extends Function { final Locale locale; final DecimalPoint decimalPoint; final Integer radix; public CanBeByte() { super(); this.locale = null; this.decimalPoint = null; this.radix = null; } public CanBeByte(Locale locale) { super(); this.locale = locale; this.decimalPoint = null; this.radix = null; } public CanBeByte(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.decimalPoint = null; this.radix = null; } public CanBeByte(DecimalPoint decimalPoint) { super(); this.locale = null; this.decimalPoint = decimalPoint; this.radix = null; } public CanBeByte(int radix) { super(); this.locale = null; this.decimalPoint = null; this.radix = Integer.valueOf(radix); } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.decimalPoint == null) { if (this.radix != null) { try { Op.on(input).exec(FnString.toByte(this.radix.intValue())).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } try { Op.on(input).exec(FnString.toByte()).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.locale != null) { try { Op.on(input).exec(FnString.toByte(this.locale)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.decimalPoint != null) { try { Op.on(input).exec(FnString.toByte(this.decimalPoint)).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } return Boolean.FALSE; } } static final class IsValidByte extends Function { final Locale locale; final Integer radix; final static BigDecimal min = BigDecimal.valueOf((double)Byte.MIN_VALUE); final static BigDecimal max = BigDecimal.valueOf((double)Byte.MAX_VALUE); public IsValidByte() { super(); this.locale = null; this.radix = null; } public IsValidByte(Locale locale) { super(); this.locale = locale; this.radix = null; } public IsValidByte(String locale) { super(); this.locale = LocaleUtils.toLocale(locale); this.radix = null; } public IsValidByte(int radix) { super(); this.locale = null; this.radix = Integer.valueOf(radix); } public Boolean execute(String input, ExecCtx ctx) throws Exception { if (this.locale == null && this.radix != null) { try { Op.on(input).exec(FnString.toByte(this.radix.intValue())).get(); return Boolean.TRUE; } catch (ExecutionException e) { return Boolean.FALSE; } } if (this.radix == null) { DecimalFormat notDecimalFormat = (DecimalFormat) NumberFormat .getInstance(this.locale == null ? Locale.US : this.locale); notDecimalFormat.setParseIntegerOnly(true); notDecimalFormat.setParseBigDecimal(true); //It uses ParsePosition to make sure the whole //string has been converted into a number ParsePosition pp = new ParsePosition(0); Number number = notDecimalFormat.parse(input, pp); BigDecimal bigDecimal = null; if (number instanceof BigDecimal) { bigDecimal = (BigDecimal) number; } else if (number instanceof BigInteger) { bigDecimal = new BigDecimal((BigInteger) number); } else { bigDecimal = new BigDecimal(number.doubleValue()); } if (bigDecimal.compareTo(min) < 0 || bigDecimal.compareTo(max) > 0) { return Boolean.FALSE; } if (pp.getIndex() != input.length()) { return Boolean.FALSE; } return Boolean.TRUE; } return Boolean.FALSE; } } static final class StartsWith extends AbstractNotNullFunction { final String prefix; final int offset; public StartsWith(String prefix) { super(); this.prefix = prefix; this.offset = 0; } public StartsWith(String prefix, int offset) { super(); this.prefix = prefix; this.offset = offset; } @Override public Boolean notNullExecute(String input, ExecCtx ctx) throws Exception { Validate.notNull(input, "input can't be null"); return Boolean.valueOf(input .startsWith(this.prefix, this.offset)); } } static final class EndsWith extends AbstractNotNullFunction { final String suffix; public EndsWith(String suffix) { super(); this.suffix = suffix; } @Override public Boolean notNullExecute(String input, ExecCtx ctx) throws Exception { Validate.notNull(input, "input can't be null"); return Boolean.valueOf(input .endsWith(this.suffix)); } } static final class SubString extends Function { final int start; final Integer end; public SubString(int start) { super(); this.start = start; this.end = null; } public SubString(int start, int end) { super(); this.start = start; this.end = Integer.valueOf(end); } public String execute(String input, ExecCtx ctx) throws Exception { if (this.end == null) { return StringUtils.substring(input, this.start); } return StringUtils.substring(input, this.start, this.end.intValue()); } } static final class SubStringBefore extends Function { final String separator; public SubStringBefore(String separator) { super(); this.separator = separator; } public String execute(String input, ExecCtx ctx) throws Exception { return StringUtils.substringBefore(input, this.separator); } } static final class SubStringBeforeLast extends Function { final String separator; public SubStringBeforeLast(String separator) { super(); this.separator = separator; } public String execute(String input, ExecCtx ctx) throws Exception { return StringUtils.substringBeforeLast(input, this.separator); } } static final class SubStringAfter extends Function { final String separator; public SubStringAfter(String separator) { super(); this.separator = separator; } public String execute(String input, ExecCtx ctx) throws Exception { return StringUtils.substringAfter(input, this.separator); } } static final class SubStringAfterLast extends Function { final String separator; public SubStringAfterLast(String separator) { super(); this.separator = separator; } public String execute(String input, ExecCtx ctx) throws Exception { return StringUtils.substringAfterLast(input, this.separator); } } static final class SubStringBetween extends Function { final String open; final String close; public SubStringBetween(String tag) { super(); this.open = tag; this.close = null; } public SubStringBetween(String open, String close) { super(); this.open = open; this.close = close; } public String execute(String input, ExecCtx ctx) throws Exception { if (this.close == null) { return StringUtils.substringBetween(input, this.open); } return StringUtils.substringBetween(input, this.open, this.close); } } static final class IsEmpty extends Function { public IsEmpty() { super(); } public Boolean execute(String input, ExecCtx ctx) throws Exception { return Boolean.valueOf(StringUtils.isEmpty(input)); } } static final class IsBlank extends Function { public IsBlank() { super(); } public Boolean execute(String input, ExecCtx ctx) throws Exception { return Boolean.valueOf(StringUtils.isBlank(input)); } } static final class Reverse extends Function { public Reverse() { super(); } public String execute(String input, ExecCtx ctx) throws Exception { return StringUtils.reverse(input); } } }