Example usage for org.apache.commons.lang3 StringUtils isNumeric

List of usage examples for org.apache.commons.lang3 StringUtils isNumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isNumeric.

Prototype

public static boolean isNumeric(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode digits.

Usage

From source file:org.efaps.esjp.admin.common.systemconfiguration.SystemConf_Base.java

/**
 * Value field value.//  w  ww. java  2 s  . c  o m
 *
 * @param _parameter the _parameter
 * @return the return
 * @throws EFapsException the e faps exception
 */
public Return valueFieldValue(final Parameter _parameter) throws EFapsException {
    final Return ret = new Return();
    if (TargetMode.CREATE.equals(_parameter.get(ParameterValues.ACCESSMODE))
            || TargetMode.EDIT.equals(_parameter.get(ParameterValues.ACCESSMODE))) {

        if (_parameter.getInstance() != null && _parameter.getInstance().isValid()
                && _parameter.getInstance().getType().isKindOf(CIAdminCommon.SystemConfigurationAbstract)) {
            final boolean isLink = "true".equalsIgnoreCase(getProperty(_parameter, "SysConfLink"));

            final PrintQuery print = new PrintQuery(_parameter.getInstance());
            final SelectBuilder sel = SelectBuilder.get()
                    .linkto(CIAdminCommon.SystemConfigurationAbstract.AbstractLink)
                    .attribute(CIAdminCommon.SystemConfiguration.UUID);
            print.addSelect(sel);
            print.addAttribute(CIAdminCommon.SystemConfigurationAbstract.Key);
            print.execute();
            final String uuid = print.getSelect(sel);
            final String key = print.getAttribute(CIAdminCommon.SystemConfigurationAbstract.Key);

            ISysConfAttribute attr = isLink ? SysConfResourceConfig.getResourceConfig().getLink(uuid, key)
                    : SysConfResourceConfig.getResourceConfig().getAttribute(uuid, key);
            if (attr == null && StringUtils.isNumeric(key.substring(key.length() - 2, key.length()))) {
                attr = isLink
                        ? SysConfResourceConfig.getResourceConfig().getLink(uuid,
                                key.substring(0, key.length() - 2))
                        : SysConfResourceConfig.getResourceConfig().getAttribute(uuid,
                                key.substring(0, key.length() - 2));
            }
            final IUIValue uiValue = (IUIValue) _parameter.get(ParameterValues.UIOBJECT);
            if (attr != null) {
                ret.put(ReturnValues.SNIPLETT,
                        attr.getHtml(_parameter, uiValue.getObject(), uiValue.getField().getName()).toString());
            } else {
                ret.put(ReturnValues.SNIPLETT, new PropertiesSysConfAttribute()
                        .getHtml(_parameter, uiValue.getObject(), uiValue.getField().getName()).toString());
            }
        }
    }
    return ret;
}

From source file:org.efaps.esjp.common.uiform.Field_Base.java

/**
 * @param _parameter    Parameter as passed from the eFaps API
 * @return Return containing Html Snipplet
 * @throws EFapsException on error/* w ww. j av  a2  s  . com*/
 */
public Return getOptionList4DateTime(final Parameter _parameter) throws EFapsException {
    final List<DropDownPosition> positions = new ArrayList<>();
    final String dateFieldType = getProperty(_parameter, "DateFieldType", "YEAR");
    switch (dateFieldType) {
    case "MONTH":
        for (final Month month : Month.values()) {
            final DropDownPosition pos = getDropDownPosition(_parameter, month.getValue(),
                    month.getDisplayName(TextStyle.FULL, Context.getThreadContext().getLocale()));
            pos.setSelected(month.getValue() == new DateTime().getMonthOfYear());
            positions.add(pos);
        }
        break;
    case "YEAR":
    default:
        final String fromStr = getProperty(_parameter, "From", "-10");
        final String toStr = getProperty(_parameter, "To", "+10");
        LocalDate start;
        if (StringUtils.isNumeric(fromStr)) {
            start = LocalDate.of(Integer.parseInt(fromStr), 1, 1);
        } else {
            start = LocalDate.now().plusYears(Integer.parseInt(fromStr));
        }
        final LocalDate end;
        if (StringUtils.isNumeric(toStr)) {
            end = LocalDate.of(Integer.parseInt(toStr), 1, 1);
        } else {
            end = LocalDate.now().plusYears(Integer.parseInt(toStr));
        }
        while (start.isBefore(end)) {
            final DropDownPosition pos = getDropDownPosition(_parameter, start.getYear(), start.getYear());
            pos.setSelected(start.getYear() == new DateTime().getYear());
            positions.add(pos);
            start = start.plusYears(1);
        }
        break;
    }
    final Return ret = new Return();
    ret.put(ReturnValues.VALUES, positions);
    return ret;
}

From source file:org.efaps.ui.wicket.models.field.FieldConfiguration.java

/**
 * @return the size of the field//from  w w w.  jav a 2s.c om
 */
public String getWidth() {
    String ret = "";
    if (hasProperty(UIFormFieldProperty.WIDTH)) {
        final String widthTmp = getProperty(UIFormFieldProperty.WIDTH);
        if (StringUtils.isNumeric(widthTmp)) {
            ret = widthTmp + "ch";
        } else {
            ret = widthTmp;
        }
    }
    return ret;
}

From source file:org.efaps.ui.wicket.models.field.FieldConfiguration.java

/**
 * @return the size of the field//from  w w  w  .j av  a2  s  . co  m
 */
public boolean isFixedWidth() {
    return hasProperty(UIFormFieldProperty.WIDTH)
            && !StringUtils.isNumeric(getField().getProperty(UIFormFieldProperty.WIDTH));
}

From source file:org.elasticsearch.common.joda.DateMathParser.java

private long parseDateTime(String value, DateTimeZone timeZone) {

    // first check for timestamp
    if (value.length() > 4 && StringUtils.isNumeric(value)) {
        try {//from   w  w  w  . j av a 2  s  . c  o  m
            long time = Long.parseLong(value);
            return timeUnit.toMillis(time);
        } catch (NumberFormatException e) {
            throw new ElasticsearchParseException("failed to parse date field [" + value + "] as timestamp", e);
        }
    }

    DateTimeFormatter parser = dateTimeFormatter.parser();
    if (timeZone != null) {
        parser = parser.withZone(timeZone);
    }
    try {
        return parser.parseMillis(value);
    } catch (IllegalArgumentException e) {

        throw new ElasticsearchParseException(
                "failed to parse date field [" + value + "] with format [" + dateTimeFormatter.format() + "]",
                e);
    }
}

From source file:org.ext.uberfire.social.activities.persistence.SocialFile.java

private String readNextSocialEventJSON() throws IOException {
    if (startReading()) {
        prepareForReading();/*  w  ww . j a v a  2  s .com*/
    }
    if (reader.size() <= 0) {
        throw new EmptySocialFile();
    }

    reverseSearchForSeparatorPosition();

    StringBuilder numberOfBytesNextJSON = getNumberOfBytesOfJSON();

    if (StringUtils.isNumeric(numberOfBytesNextJSON.toString())) {
        return extractJSON(numberOfBytesNextJSON);
    } else {
        return readNextSocialEventJSON();
    }
}

From source file:org.finra.herd.service.helper.StorageDaoHelper.java

/**
 * Gets a storage attribute value by name. The value must be a valid integer, otherwise a validation error is thrown.
 *
 * @param attributeName the attribute name (case insensitive)
 * @param storageEntity the storage entity
 * @param attributeRequired specifies whether the attribute is mandatory (i.e. whether it has a value or not).
 * @param attributeValueRequiredIfExists specifies whether the attribute value is mandatory (i.e. the attribute must exist and its value must also contain a
 * value)./*from  ww  w .ja va  2  s  .c o m*/
 *
 * @return the attribute value from the attribute with the attribute name.
 * @throws IllegalStateException if the attribute is mandatory and this storage contains no attribute with this attribute name or the value is blank. This
 * will produce a 500 HTTP status code error. If storage attributes are able to be updated by a REST invocation in the future, we might want to consider
 * making this a 400 instead since the user has the ability to fix the issue on their own. Also throws when the value exists, but is not a valid integer.
 */
public Integer getStorageAttributeIntegerValueByName(String attributeName, StorageEntity storageEntity,
        boolean attributeRequired, boolean attributeValueRequiredIfExists) throws IllegalStateException {
    Integer intValue = null;
    String value = getStorageAttributeValueByName(attributeName, storageEntity, attributeRequired,
            attributeValueRequiredIfExists);
    if (value != null) {
        if (!StringUtils.isNumeric(value)) {
            throw new IllegalStateException("Storage attribute \"" + attributeName
                    + "\" must be a valid integer. Actual value is \"" + value + "\"");
        }
        intValue = Integer.parseInt(value.trim());
    }
    return intValue;
}

From source file:org.fire.platform.util.DateUtil.java

/**
 * ??true?false//from w  w  w  .  j  a  va2 s  .c om
 * 
 * @param endTime
 * @return
 */
public static boolean isOverdue(String endTime) {
    if (StringUtils.isEmpty(endTime) || !StringUtils.isNumeric(endTime)) {
        return false;
    }
    // ?
    int now = Integer.parseInt(getTime("yyyyMMdd", new Date()));
    // ?0??
    return Integer.parseInt(endTime) - now < 0;
}

From source file:org.goko.controller.grbl.v08.configuration.GrblIntegerSetting.java

/** (inheritDoc)
 * @see org.goko.controller.grbl.v08.configuration.GrblSetting#setValueFromString(java.lang.String)
 *//* ww  w  .ja  va  2 s.c om*/
@Override
public void setValueFromString(String value) {
    if (StringUtils.isNumeric(value)) {
        setValue(Integer.valueOf(value));
    }
}

From source file:org.goko.controller.grbl.v08.configuration.serializer.StringBooleanSerializer.java

/** (inheritDoc)
 * @see org.goko.controller.grbl.v08.configuration.serializer.AbstractGrblSerializer#fromSource(java.lang.Object)
 *//*from w ww .j  a  v a  2 s .  c  o  m*/
@Override
public Boolean fromSource(String str) throws GkException {
    if (StringUtils.isNumeric(str)) {
        return StringUtils.equals(str, "1");
    }
    return null;
}