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

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

Introduction

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

Prototype

public static boolean endsWith(final CharSequence str, final CharSequence suffix) 

Source Link

Document

Check if a CharSequence ends with a specified suffix.

null s are handled without exceptions.

Usage

From source file:org.cleverbus.core.alerts.AlertsJmxConfiguration.java

@Override
public Object getAttribute(String attrName)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    Assert.notNull(attrName, "attrName must not be null");

    AlertInfo alert = getAlert(attrName);

    if (StringUtils.endsWith(attrName, ENABLE_SUFFIX)) {
        return alert.isEnabled();
    } else if (StringUtils.endsWith(attrName, LIMIT_SUFFIX)) {
        return String.valueOf(alert.getLimit());
    } else {// w w  w.  ja va2 s  .com
        throw new IllegalStateException("unsupported attribute name '" + attrName + "'");
    }
}

From source file:org.cleverbus.core.alerts.AlertsJmxConfiguration.java

private AlertInfo getAlert(String attrName) throws AttributeNotFoundException {
    String alertId;//from  w w w . j a  v a2  s.c om
    if (StringUtils.endsWith(attrName, ENABLE_SUFFIX)) {
        alertId = StringUtils.substringBefore(attrName, ENABLE_SUFFIX);
    } else if (StringUtils.endsWith(attrName, LIMIT_SUFFIX)) {
        alertId = StringUtils.substringBefore(attrName, LIMIT_SUFFIX);
    } else {
        throw new AttributeNotFoundException("attribute name is not in expected format");
    }

    AlertInfo alert = configuration.findAlert(alertId);

    if (alert == null) {
        throw new AttributeNotFoundException("There is no alert for id '" + alertId + "'");
    }

    return alert;
}

From source file:org.cleverbus.core.alerts.AlertsJmxConfiguration.java

@Override
public void setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Assert.notNull(attribute, "attribute must not be null");

    String attrName = attribute.getName();
    String value = (String) attribute.getValue();

    AlertInfo alert = getAlert(attrName);

    if (StringUtils.endsWith(attrName, ENABLE_SUFFIX)) {
        alert.setEnabled(BooleanUtils.toBoolean(value));
    } else if (StringUtils.endsWith(attrName, LIMIT_SUFFIX)) {
        alert.setLimit(Long.valueOf(value));
    } else {/*from w  w  w  . j  a v  a2 s  .c o  m*/
        throw new IllegalStateException("unsupported attribute name '" + attrName + "'");
    }
}

From source file:org.goko.controller.grbl.v08.GrblCommunicator.java

/**
 * Handling of incoming data//w  w  w .  jav  a  2s .  c  o m
 * @param data the received data
 * @throws GkException GkException
 */
protected void handleIncomingData(String data) throws GkException {
    String trimmedData = StringUtils.trim(data);
    if (StringUtils.isNotEmpty(trimmedData)) {
        /* Received OK response */
        if (StringUtils.equals(trimmedData, Grbl.OK_RESPONSE)) {
            grbl.handleOkResponse();

            /* Received error  */
        } else if (StringUtils.startsWith(trimmedData, "error:")) {
            grbl.handleError(trimmedData);

            /* Received status report  */
        } else if (StringUtils.startsWith(trimmedData, "<") && StringUtils.endsWith(trimmedData, ">")) {
            grbl.handleStatusReport(parseStatusReport(trimmedData));

            /* Received Grbl header */
        } else if (StringUtils.startsWith(trimmedData, "Grbl")) {
            handleHeader(trimmedData);
            grbl.initialiseConnectedState();
            //   refreshStatus();

            /* Received a configuration confirmation */
        } else if (StringUtils.defaultString(trimmedData).matches("\\$[0-9]*=.*")) {
            grbl.handleConfigurationReading(trimmedData);

            /* Received a work position report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[G5.*\\]")) {
            Tuple6b targetPoint = new Tuple6b().setNull();
            String offsetName = parseCoordinateSystem(trimmedData, targetPoint);
            grbl.setOffsetCoordinate(offsetName, targetPoint);

            /* Received an offset position report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[(G92|G28|G30).*\\]")) {
            //            Tuple6b targetPoint = new Tuple6b().setNull();
            //            String coordinateSystemName = parseCoordinateSystem(trimmedData, targetPoint);
            //            grbl.setOffsetCoordinate(coordinateSystemName, targetPoint);
            // TODO Handle G92
            /* Parser state report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[(G0|G1|G2|G3).*\\]")) {
            grbl.receiveParserState(StringUtils.substringBetween(trimmedData, "[", "]"));
            /* Unkown format received */
        } else {
            LOG.error("Ignoring received data " + trimmedData);
            grbl.getApplicativeLogService().warning("Ignoring received data " + trimmedData,
                    GrblControllerService.SERVICE_ID);
        }
    }
}

From source file:org.goko.controller.grbl.v09.GrblCommunicator.java

/**
 * Handling of incoming data/*w  ww  .  j av  a  2s.  c o  m*/
 * @param data the received data
 * @throws GkException GkException
 */
protected void handleIncomingData(String data) throws GkException {
    String trimmedData = StringUtils.trim(data);
    if (StringUtils.isNotEmpty(trimmedData)) {
        /* Received OK response */
        if (StringUtils.equals(trimmedData, Grbl.OK_RESPONSE)) {
            grbl.handleOkResponse();

            /* Received error  */
        } else if (StringUtils.startsWith(trimmedData, "error:")) {
            grbl.handleError(trimmedData);

            /* Received status report  */
        } else if (StringUtils.startsWith(trimmedData, "<") && StringUtils.endsWith(trimmedData, ">")) {
            grbl.handleStatusReport(parseStatusReport(trimmedData));

            /* Received Grbl header */
        } else if (StringUtils.startsWith(trimmedData, "Grbl")) {
            handleHeader(trimmedData);
            grbl.initialiseConnectedState();
            //   refreshStatus();

            /* Received a configuration confirmation */
        } else if (StringUtils.defaultString(trimmedData).matches("\\$[0-9]*=.*")) {
            grbl.handleConfigurationReading(trimmedData);

            /* Received a probe result */
        } else if (StringUtils.defaultString(trimmedData).matches("\\$[PRB*]")) {
            //[PRB:0.000,0.000,0.000:0]
            ProbeResult probeResult = parseProbeResult(StringUtils.defaultString(trimmedData));
            grbl.handleProbeResult(probeResult);
            /* Received a work position report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[G5.*\\]")) {
            Tuple6b targetPoint = new Tuple6b().setNull();
            String offsetName = parseCoordinateSystem(trimmedData, targetPoint);
            grbl.setOffsetCoordinate(offsetName, targetPoint);

            /* Received an offset position report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[(G92|G28|G30).*\\]")) {
            //            Tuple6b targetPoint = new Tuple6b().setNull();
            //            String coordinateSystemName = parseCoordinateSystem(trimmedData, targetPoint);
            //            grbl.setOffsetCoordinate(coordinateSystemName, targetPoint);
            // TODO Handle G92
            /* Parser state report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[(G0|G1|G2|G3).*\\]")) {
            grbl.receiveParserState(StringUtils.substringBetween(trimmedData, "[", "]"));
            /* Unkown format received */
        } else {
            LOG.error("Ignoring received data " + trimmedData);
            grbl.getApplicativeLogService().warning("Ignoring received data " + trimmedData,
                    GrblControllerService.SERVICE_ID);
        }
    }
}

From source file:org.goko.controller.tinyg.json.TinyGJsonUtils.java

/**
 * Determines if a string can be parsed as json object
 *
 * @param str the string//from   ww w . j  av a 2s . c  o  m
 * @return <code>true</code> or <code>false</code>
 */
public static boolean isJsonFormat(String str) {
    return StringUtils.startsWith(str.trim(), "{") && StringUtils.endsWith(str.trim(), "}");
}

From source file:org.goko.grbl.controller.GrblCommunicator.java

/**
 * Handling of incoming data//from   ww  w.  j  av a  2s. c  o m
 * @param data the received data
 * @throws GkException GkException
 */
protected void handleIncomingData(String data) throws GkException {
    String trimmedData = StringUtils.trim(data);
    if (StringUtils.isNotEmpty(trimmedData)) {
        /* Received OK response */
        if (StringUtils.equals(trimmedData, Grbl.OK_RESPONSE)) {
            grbl.handleOkResponse();

            /* Received error  */
        } else if (StringUtils.startsWith(trimmedData, "error:")) {
            grbl.handleError(trimmedData);

            /* Received status report  */
        } else if (StringUtils.startsWith(trimmedData, "<") && StringUtils.endsWith(trimmedData, ">")) {
            grbl.handleStatusReport(parseStatusReport(trimmedData));

            /* Received Grbl header */
        } else if (StringUtils.startsWith(trimmedData, "Grbl")) {
            handleHeader(trimmedData);
            grbl.initialiseConnectedState();
            //   refreshStatus();

            /* Received a configuration confirmation */
        } else if (StringUtils.defaultString(trimmedData).matches("\\$[0-9]*=.*")) {
            grbl.handleConfigurationReading(trimmedData);

            /* Received an offset position report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[(G5|G28|G30|G92).*\\]")) {
            Tuple6b targetPoint = new Tuple6b().setNull();
            String offsetName = parseCoordinateSystem(trimmedData, targetPoint);
            grbl.setOffsetCoordinate(offsetName, targetPoint);

            /* Parser state report */
        } else if (StringUtils.defaultString(trimmedData).matches("\\[(G0|G1|G2|G3).*\\]")) {
            grbl.receiveParserState(StringUtils.substringBetween(trimmedData, "[", "]"));
            /* Unkown format received */
        } else {
            LOG.error("Ignoring received data " + trimmedData);
            grbl.getApplicativeLogService().warning("Ignoring received data " + trimmedData,
                    GrblControllerService.SERVICE_ID);
        }
    }
}

From source file:org.gvnix.web.datatables.util.QuerydslUtils.java

/**
 * Return where clause expression for number properties by casting it to
 * string before check its value./* ww  w.  java  2  s  .  com*/
 * <p/>
 * Querydsl Expr:
 * {@code entityPath.fieldName.stringValue() like ('%' + searchStr + '%')}
 * Database operation:
 * {@code str(entity.fieldName) like ('%' + searchStr + '%')}
 * <p/>
 * Like operation is case sensitive.
 * 
 * @param entityPath Full path to entity and associations. For example:
 *        {@code Pet} , {@code Pet.owner}
 * @param fieldName Property name in the given entity path. For example:
 *        {@code weight} in {@code Pet} entity, {@code age} in
 *        {@code Pet.owner} entity.
 * @param searchStr the value to find, may be null
 * @return PredicateOperation
 */
public static <T, N extends java.lang.Number & java.lang.Comparable<?>> BooleanExpression createNumberExpression(
        PathBuilder<T> entityPath, String fieldName, Class<N> fieldType, TypeDescriptor descriptor,
        String searchStr, ConversionService conversionService) {
    if (StringUtils.isBlank(searchStr)) {
        return null;
    }
    NumberPath<N> numberExpression = entityPath.getNumber(fieldName, fieldType);

    BooleanExpression expression = null;

    if (conversionService != null) {
        try {
            Object number = conversionService.convert(searchStr, STRING_TYPE_DESCRIPTOR, descriptor);
            if (number == null) {
                expression = numberExpression.stringValue().like("%".concat(searchStr).concat("%"));
            } else {
                String toSearch = number.toString();
                if (number instanceof BigDecimal && ((BigDecimal) number).scale() > 1) {
                    // For bigDecimal trim 0 in decimal part
                    toSearch = StringUtils.stripEnd(toSearch, "0");
                    if (StringUtils.endsWith(toSearch, ".")) {
                        // prevent "#." strings
                        toSearch = toSearch.concat("0");
                    }
                }
                expression = numberExpression.stringValue().like("%".concat(toSearch).concat("%"));
            }
        } catch (ConversionException e) {
            expression = numberExpression.stringValue().like("%".concat(searchStr).concat("%"));
        }
    } else {
        expression = numberExpression.stringValue().like("%".concat(searchStr).concat("%"));
    }
    return expression;
}

From source file:org.kuali.coeus.propdev.impl.core.ProposalDevelopmentControllerBase.java

public AuditHelper.ValidationState getValidationState(ProposalDevelopmentDocumentForm form) {
    AuditHelper.ValidationState severityLevel = AuditHelper.ValidationState.OK;
    form.setAuditActivated(true);/*  ww w.  j  a va2 s  .co m*/
    List<DataValidationItem> dataValidationItems = ((ProposalDevelopmentViewHelperServiceImpl) form
            .getViewHelperService()).populateDataValidation(form);
    if (dataValidationItems != null && dataValidationItems.size() > 0) {
        for (DataValidationItem validationItem : dataValidationItems) {
            if (StringUtils.endsWith(validationItem.getSeverity(), Constants.AUDIT_ERRORS)) {
                severityLevel = AuditHelper.ValidationState.ERROR;
                break;
            }
            if (StringUtils.equals(validationItem.getSeverity(), Constants.AUDIT_WARNINGS)) {
                severityLevel = AuditHelper.ValidationState.WARNING;
            }
        }
        form.setDataValidationItems(dataValidationItems);
    }
    getGlobalVariableService().getMessageMap().clearErrorMessages();
    return severityLevel;
}

From source file:org.kuali.kra.award.paymentreports.awardreports.reporting.service.ReportTrackingServiceImpl.java

@Override
public boolean autoRegenerateReports(Award award) {
    boolean retVal = StringUtils.endsWith(award.getAwardNumber(), ROOT_AWARD_SUFFIX);
    if (!retVal) {
        for (AwardReportTerm term : award.getAwardReportTermItems()) {
            List<ReportTracking> tracking = getReportTacking(term);
            if (!tracking.isEmpty()) {
                return true;
            }//from w  w  w  .j  a va  2s  .  co m
        }
    }
    return retVal;
}