Example usage for org.apache.commons.lang StringUtils trimToEmpty

List of usage examples for org.apache.commons.lang StringUtils trimToEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils trimToEmpty.

Prototype

public static String trimToEmpty(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null.

Usage

From source file:ips1ap101.lib.core.db.util.DBUtils.java

private static boolean isKey(String string) {
    String key = StringUtils.trimToEmpty(string);
    return key.startsWith("<") && key.endsWith(">");
}

From source file:com.prowidesoftware.swift.model.field.Field94D.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *//*from  www .  j a  va  2  s .  c  o m*/
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(":");
    result.append(StringUtils.trimToEmpty(getComponent1()));
    result.append("//");
    if (StringUtils.isNotEmpty(getComponent2())) {
        result.append(StringUtils.trimToEmpty(getComponent2()));
    }
    result.append("/");
    result.append(StringUtils.trimToEmpty(getComponent3()));
    return result.toString();
}

From source file:com.hmsinc.epicenter.webapp.remoting.GeographyService.java

/**
 * Automagically completes a Geography name.
 * // w  w w . j  a  v a 2 s.  c o  m
 * If entity is null, the current user's visible region is used as bounds.
 * 
 * @param query
 * @return
 */
@Secured("ROLE_USER")
@Transactional(readOnly = true)
@RemoteMethod
public Collection<GeographyDTO> autocompleteGeography(final Long orgId, String query) {

    logger.debug(query);

    Organization entity = null;
    if (orgId != null) {
        entity = permissionRepository.load(orgId, Organization.class);
        Validate.notNull(entity, "Invalid organization id: " + orgId);
        SpatialSecurity.checkPermission(getPrincipal(), entity);
    }

    final Set<Geography> geolist = new LinkedHashSet<Geography>();

    if (query.equals("ALL")) {

        geolist.addAll(getVisibleRegions(entity));

    } else {

        final String q = StringUtils.trimToNull(StringUtils.trimToEmpty(query).replaceAll(",+$", ""));

        if (q != null) {

            if (q.matches("^\\w\\w$")) {

                // match single state by abbreviatation
                final State state = geographyRepository.getStateByAbbreviation(q);
                if (state != null) {
                    geolist.add(state);
                }
            } else if (q.matches("^\\w\\w,.*")) {

                // match something starting with state abbreviation
                final String[] fragments = q.split(",");
                final State state = geographyRepository.getStateByAbbreviation(fragments[0]);
                if (state != null) {
                    if (fragments.length > 1 && StringUtils.trimToNull(fragments[1]) != null) {
                        geolist.addAll(getGeographiesInState(state, fragments[1]));
                    } else {
                        geolist.add(state);
                    }
                }
            } else if (q.matches("^\\w.*,\\s*\\w\\w$")) {

                // match something comma state abbreviation
                final String[] fragments = q.split(",");
                final String first = StringUtils.trimToNull(fragments[0]);
                if (first != null && fragments.length > 1) {
                    final String second = StringUtils.trimToNull(fragments[1]);
                    if (second != null) {
                        final State state = geographyRepository.getStateByAbbreviation(second);
                        if (state != null) {
                            geolist.addAll(getGeographiesInState(state, first));
                        }
                    }
                }

            } else if (q.matches("^\\w\\w\\w.*,\\s*\\w\\w\\w.*")) {

                // match something comma something, each part being > 2
                // characters
                final String[] fragments = q.split(",");
                final String first = StringUtils.trimToNull(fragments[0]);
                if (first != null && fragments.length > 1) {
                    final String second = StringUtils.trimToNull(fragments[1]);
                    if (second != null) {

                        String other = null;
                        State state = null;

                        // Find out which one is a state
                        State s = geographyRepository.getGeography(first, State.class);
                        if (s != null) {
                            state = s;
                            other = second;
                        } else {
                            s = geographyRepository.getGeography(second, State.class);
                            if (s != null) {
                                state = s;
                                other = first;
                            }
                        }

                        if (other != null && state != null) {
                            geolist.addAll(getGeographiesInState(state, other));
                        }
                    }
                }
            } else {

                // Match anything
                final List<Geography> g = new ArrayList<Geography>();

                // Search region, state, county, zipcode
                if (StringUtils.isNumeric(q)) {
                    g.addAll(geographyRepository.searchGeographies(q, Zipcode.class));
                } else {
                    g.addAll(geographyRepository.searchGeographies(q, Region.class));
                    if (g.size() != 1) {
                        final List<State> states = geographyRepository.searchGeographies(q, State.class);
                        if (states.size() == 1) {
                            g.clear();
                        }
                        g.addAll(states);
                    }
                    if (g.size() != 1) {
                        g.addAll(geographyRepository.searchGeographies(stripCountyFromQuery(q), County.class));
                    }
                }

                geolist.addAll(g);
            }

            // If we have a single match, find the objects contained inside
            // it.
            if (geolist.size() == 1) {
                geolist.addAll(getContainedGeographies(geolist.iterator().next()));
            }

            if (entity == null) {
                for (Organization org : getPrincipal().getOrganizations()) {
                    geolist.addAll(getVisibleRegions(org));
                }
            } else {
                geolist.addAll(getVisibleRegions(entity));
            }
        }

    }

    // Filter the list to the user's permissions
    // TODO: Unwind the collection and drill down if limited visibility.
    return entity == null ? filterSpatialCollection(getPrincipal(), geolist, true)
            : filterSpatialCollection(entity, geolist, true);
}

From source file:com.prowidesoftware.swift.model.field.Field95U.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *///  www . jav a  2 s  .  co  m
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(":");
    result.append(StringUtils.trimToEmpty(getComponent1()));
    result.append("//");
    result.append(StringUtils.trimToEmpty(getComponent2()));
    appendInLines(result, 3, 4);
    return result.toString();
}

From source file:com.prowidesoftware.swift.model.field.Field82S.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *///from   w  w  w. j a v  a2 s.  c o  m
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(StringUtils.trimToEmpty(getComponent1()));
    if (org.apache.commons.lang.StringUtils.isNotEmpty(getComponent2())) {
        result.append(com.prowidesoftware.swift.io.writer.FINWriterVisitor.SWIFT_EOL);
        result.append("/");
        result.append(StringUtils.trimToEmpty(getComponent2()));
    }
    appendInLines(result, 3, 6);
    return result.toString();
}

From source file:com.prowidesoftware.swift.model.field.Field77R.java

/**
 * Serializes the fields' components into the single string value (SWIFT format)
 *///from  w  w  w.j ava 2s. c  o m
@Override
public String getValue() {
    final StringBuilder result = new StringBuilder();
    result.append(StringUtils.trimToEmpty(getComponent1()));
    appendInLines(result, 2, 11);
    return result.toString();
}

From source file:nc.noumea.mairie.appock.core.utility.AppockUtil.java

/**
 * Construit un texte tronqu s'il dpasse la longueur du texte indique
 * @param texte texte//  ww  w  .j  ava  2s  .  com
 * @param longueurMaxTexte longueur max.
 * @param suffixeSiTronque suffixe  utiliser en fin de rsultat si le texte dpasse la longueur max.
 * @return texte tronqu
 */
public static String construitTexteTronque(String texte, int longueurMaxTexte, String suffixeSiTronque) {
    if (texte == null) {
        return null;
    }
    if (StringUtils.isBlank(texte)) {
        return "";
    }
    String result = StringUtils.trimToEmpty(texte);
    if (result.length() <= longueurMaxTexte) {
        return result;
    }
    return StringUtils.left(result, longueurMaxTexte) + ((suffixeSiTronque == null) ? "" : suffixeSiTronque);
}

From source file:ml.shifu.shifu.actor.worker.ScoreModelWorker.java

@Override
public void handleMsg(Object message) throws IOException {
    if (message instanceof RunModelResultMessage) {
        log.debug("Received model score data for evaluation");
        RunModelResultMessage msg = (RunModelResultMessage) message;
        if (!resultMap.containsKey(msg.getStreamId())) {
            receivedStreamCnt++;/*  www .  jav  a2  s .c o m*/
            resultMap.put(msg.getStreamId(), new StreamBulletin(msg.getStreamId()));
        }
        resultMap.get(msg.getStreamId()).receiveMsge(msg.getMsgId(), msg.isLastMsg());

        List<CaseScoreResult> caseScoreResultList = msg.getScoreResultList();

        StringBuilder buf = new StringBuilder();
        for (CaseScoreResult csResult : caseScoreResultList) {
            buf.setLength(0);

            Map<String, String> rawDataMap = CommonUtils.convertDataIntoMap(csResult.getInputData(),
                    evalConfig.getDataSet().getDataDelimiter(), header);

            // get the tag
            String tag = CommonUtils.trimTag(rawDataMap.get(modelConfig.getTargetColumnName(evalConfig)));
            buf.append(tag);

            // append weight column value
            if (StringUtils.isNotBlank(evalConfig.getDataSet().getWeightColumnName())) {
                String metric = rawDataMap.get(evalConfig.getDataSet().getWeightColumnName());
                buf.append("|" + StringUtils.trimToEmpty(metric));
            } else {
                buf.append("|" + "1.0");
            }

            if (CollectionUtils.isNotEmpty(csResult.getScores())) {
                addModelScoreData(buf, csResult);
            }

            Map<String, CaseScoreResult> subModelScores = csResult.getSubModelScores();
            if (MapUtils.isNotEmpty(subModelScores)) {
                Iterator<Map.Entry<String, CaseScoreResult>> iterator = subModelScores.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, CaseScoreResult> entry = iterator.next();
                    CaseScoreResult subCs = entry.getValue();
                    addModelScoreData(buf, subCs);
                }
            }

            // append meta data
            List<String> metaColumns = evalConfig.getAllMetaColumns(modelConfig);
            if (CollectionUtils.isNotEmpty(metaColumns)) {
                for (String columnName : metaColumns) {
                    String value = rawDataMap.get(columnName);
                    buf.append("|" + StringUtils.trimToEmpty(value));
                }
            }

            scoreWriter.write(buf.toString() + "\n");
        }

        if (receivedStreamCnt == msg.getTotalStreamCnt() && hasAllMessageResult(resultMap)) {
            log.info("Finish running scoring, the score file - {} is stored in {}.",
                    new PathFinder(modelConfig).getEvalScorePath(evalConfig).toString(),
                    evalConfig.getDataSet().getSource().name());
            scoreWriter.close();

            // only one message will be sent
            nextActorRef.tell(new EvalResultMessage(1), this.getSelf());
        }
    } else {
        unhandled(message);
    }
}

From source file:com.edgenius.wiki.render.impl.LinkRenderHelperImpl.java

public boolean exists(String title) {
    title = StringUtils.trimToEmpty(title);
    if (!StringUtils.isBlank(title)) {
        //mandatory create validate.
        //0:link create new page
        //2:link create new home page
        if (title.startsWith(LinkModel.LINK_TO_CREATE_FLAG + ":")
                || title.startsWith(LinkModel.LINK_TO_CREATE_HOME_FLAG + ":")) {
            return false;
        }//w  w  w  .  ja  va 2 s.  c o  m
    }

    // Is there a page is current version and non-draft exist by given pageTitle and spaceUname?
    return pageDAO.getCurrentPageByTitle(spaceUname, title) == null ? false : true;

}

From source file:com.mysoft.b2b.basicsystem.settings.provider.VerifyCodeServiceImpl.java

/**???0  ??  1???2: ?? 3??? 4 5 ??
 * @param token//from   w  w  w.java  2  s.c  om
 * @param code
 * @return
 */
public Integer checkVerifyCode(String token, String code) {
    if (StringUtils.isEmpty(code)) {
        return 0;
    }
    VerifyCode verifyCode = new VerifyCode();
    verifyCode.setToken(token);
    VerifyCode verifyCode1 = getVerifyCode(verifyCode);
    try {
        if (null != verifyCode1) {
            if (verifyCode1.getLastValidatedTime().before(new Date())) {
                //??
                updateSysCode(verifyCode1, 3);
                return 1;
            }
            if (!verifyCode1.getCode().equalsIgnoreCase(StringUtils.trimToEmpty(code))) {
                //??
                updateSysCode(verifyCode1, 2);
                return 2;
            }
        } else {
            return 3;
        }
    } catch (Exception e) {
        log.error("???" + e);
        return 4;
    }
    updateSysCode(verifyCode1, 1);
    return 5;
}