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

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

Introduction

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

Prototype

public static boolean startsWith(String str, String prefix) 

Source Link

Document

Check if a String starts with a specified prefix.

Usage

From source file:com.tesora.dve.db.NativeType.java

/**
 * This method is to make sure that when mapping a string to a type (through, say, enum.valueOf), the format is always
 * the same. Inherited classes should use this to set up their own enum's of valid types.
 * //ww  w  .  j  a  v  a  2 s.c om
 * Does the 'opposite' of fixName.
 * 
 * @param name
 * @return
 */
public static String fixNameForType(String name) {
    if (StringUtils.startsWith(StringUtils.lowerCase(name, Locale.ENGLISH), "enum")) {
        return "ENUM";
    }

    return name == null ? null : StringUtils.replace(name.toUpperCase(Locale.ENGLISH), " ", "_");
}

From source file:com.fengduo.bee.commons.velocity.Widget.java

private String buildViewName(String url) {
    if (StringUtils.startsWith(url, "/")) {
        url = url.substring(1, url.length());
    }/*from  ww  w .jav a 2 s. c  o m*/
    return CustomVelocityLayoutView.DEFAULT_WIDGET_DIRECTORY + "/" + url;
}

From source file:com.taobao.tdhs.jdbc.util.StringUtil.java

public static String[] escapeIn(String value) {
    value = StringUtils.trim(value);// w ww  . j  a va  2 s. com
    if (!StringUtils.startsWith(value, "(") || !StringUtils.endsWith(value, ")")) {
        return null;
    }
    value = value.substring(1, value.length() - 1);
    String[] split = StringUtils.split(value, ",");
    String[] result = new String[split.length];
    int i = 0;
    for (String s : split) {
        String str = escapeValue(s);
        if (StringUtils.isBlank(str)) {
            return null;
        }
        result[i++] = str;
    }
    return result;
}

From source file:com.fengduo.bee.commons.util.ObjectUtils.java

/**
 * ????//from   w ww  . j  a  v a  2  s .  c  om
 * 
 * @param annotation
 * @param object
 */
public static void annotationToObject(Object annotation, Object object) {
    if (annotation != null) {
        Class<?> annotationClass = annotation.getClass();
        Class<?> objectClass = object.getClass();
        for (Method m : objectClass.getMethods()) {
            if (StringUtils.startsWith(m.getName(), "set")) {
                try {
                    String s = StringUtils.uncapitalize(StringUtils.substring(m.getName(), 3));
                    Object obj = annotationClass.getMethod(s).invoke(annotation);
                    if (obj != null && !"".equals(obj.toString())) {
                        if (object == null) {
                            object = objectClass.newInstance();
                        }
                        m.invoke(object, obj);
                    }
                } catch (Exception e) {
                    // 
                }
            }
        }
    }
}

From source file:com.microsoft.alm.plugin.external.commands.SyncCommand.java

/**
 * Example output from TF Get://from  w ww .j  a v a  2  s. c o  m
 * D:\tmp\test:
 * Getting addFold
 * Getting addFold-branch
 * <p/>
 * D:\tmp\test\addFold-branch:
 * Getting testHereRename.txt
 * <p/>
 * D:\tmp\test\addFold:
 * Getting testHere3
 * Getting testHereRename7.txt
 * <p/>
 * D:\tmp\test:
 * Getting Rename2.txt
 * Getting test3.txt
 * Conflict test_renamed.txt - Unable to perform the get operation because you have a conflicting rename, edit
 * Getting TestAdd.txt
 * <p/>
 * ---- Summary: 1 conflicts, 0 warnings, 0 errors ----
 * Conflict D:\tmp\test\test_renamed.txt - Unable to perform the get operation because you have a conflicting rename, edit
 *
 * @param stdout
 * @param stderr
 * @return
 */
@Override
public SyncResults parseOutput(final String stdout, final String stderr) {
    final List<String> updatedFiles = new ArrayList<String>();
    final List<String> newFiles = new ArrayList<String>();
    final List<String> deletedFiles = new ArrayList<String>();
    final List<SyncException> exceptions = new ArrayList<SyncException>();

    if (StringUtils.contains(stdout, UP_TO_DATE_MSG)) {
        return new SyncResults();
    }

    // make note that conflicts exist but to get conflicts use resolve command
    final boolean conflictsExist = StringUtils.contains(stderr, CONFLICT_MESSAGE);

    // parse the exception to get individual exceptions instead of 1 large one
    exceptions.addAll(parseException(stderr));

    // parse output for file changes
    final String[] lines = getLines(stdout);
    String path = StringUtils.EMPTY;
    for (final String line : lines) {
        if (StringUtils.isNotEmpty(line) || StringUtils.startsWith(line, SUMMARY_PREFIX)) {
            if (isFilePath(line)) {
                path = getFilePath(line, StringUtils.EMPTY, StringUtils.EMPTY);
            } else if (StringUtils.startsWith(line, NEW_FILE_PREFIX)) {
                newFiles.add((new File(path, line.replaceFirst(NEW_FILE_PREFIX, StringUtils.EMPTY)).getPath()));
            } else if (StringUtils.startsWith(line, UPDATED_FILE_PREFIX)) {
                updatedFiles.add(
                        (new File(path, line.replaceFirst(UPDATED_FILE_PREFIX, StringUtils.EMPTY)).getPath()));
            } else if (StringUtils.startsWith(line, DELETED_FILE_PREFIX)) {
                deletedFiles.add(
                        (new File(path, line.replaceFirst(DELETED_FILE_PREFIX, StringUtils.EMPTY)).getPath()));
            } else {
                // TODO: check for other cases to cover here but no need to hinder user if case not covered
                logger.warn("Unknown response from 'tf get' command: " + line);
            }
        }
    }

    return new SyncResults(conflictsExist, updatedFiles, newFiles, deletedFiles, exceptions);
}

From source file:com.inktomi.wxmetar.MetarParser.java

static boolean parseWinds(String token, final Metar metar) {
    boolean rval = Boolean.FALSE;

    // Winds will be the only element that ends in knots
    if (StringUtils.endsWith(token, "KT")) {

        // At this point, we know we should handle this token
        rval = Boolean.TRUE;/*from w  w w . java2 s .  c  o m*/

        // Remove the KT
        token = StringUtils.remove(token, "KT");

        // Is it variable?
        if (StringUtils.startsWith(token, "VRB")) {
            metar.winds.variable = Boolean.TRUE;

            // Trim of the VRB
            token = StringUtils.remove(token, "VRB");

            metar.winds.windSpeed = Float.parseFloat(token);

            // Stop processing this token
            return rval;
        }

        // At this point, we know the first 3 chars are wind direction
        metar.winds.windDirection = Integer.parseInt(StringUtils.substring(token, 0, 3));

        // Is it gusting? 17012G24
        int postionOfG = StringUtils.indexOf(token, "G");
        if (postionOfG > -1) {
            metar.winds.windGusts = Float
                    .parseFloat(StringUtils.substring(token, postionOfG + 1, token.length()));
            metar.winds.windSpeed = Float.parseFloat(StringUtils.substring(token, 3, postionOfG));
        }

        // Is it just a normal wind measurement?
        // 26006
        if (postionOfG == -1 && !metar.winds.variable) {
            metar.winds.windSpeed = Float.parseFloat(StringUtils.substring(token, 2, token.length()));
        }
    }

    return rval;
}

From source file:com.htmlhifive.tools.jslint.engine.option.CheckOptionPropertyWrapper.java

/**
 * ??./*from   w  ww  .j a  v  a2 s  .  com*/
 * 
 * @param enable ????????.
 * @return ?.
 */
private CheckOption[] getOptions(boolean enable) {

    Set<Object> keySet = optionProp.keySet();
    List<CheckOption> optionList = new ArrayList<CheckOption>();
    for (Object obj : keySet) {
        String key = (String) obj;
        if (StringUtils.startsWith(key, getPrefix())) {
            String optionKey = StringUtils.remove(key, getPrefix());
            CheckOption option = getOption(optionKey, "engine");
            if (!enable) {
                optionList.add(option);
            } else if (option.isEnable()) {
                optionList.add(option);
            }

        }

    }
    return (CheckOption[]) optionList.toArray(new CheckOption[optionList.size()]);
}

From source file:jenkins.plugins.tanaguru.TanaguruRunner.java

/**
 * /*w ww  . j  av a2s.c  o m*/
 * @param logFile
 * @param ps
 * @throws IOException 
 */
public void extractDataAndPrintOut(File logFile, PrintStream ps) throws IOException {
    ps.println("");
    boolean isFirstMark = true;
    boolean isFirstNbPassed = true;
    boolean isFirstNbFailed = true;
    boolean isFirstNbFailedOccurences = true;
    boolean isFirstNbNmi = true;
    boolean isFirstNbNa = true;
    boolean isFirstNbNt = true;
    for (String line : FileUtils.readLines(logFile)) {
        if (StringUtils.startsWith(line, "Subject")) {
            ps.println("");
            ps.println(line);
        } else if (StringUtils.startsWith(line, "Audit terminated")) {
            ps.println(line);
        } else if (StringUtils.startsWith(line, "RawMark")) {
            ps.println(line.replace("RawMark", "Mark"));
            if (isFirstMark) {
                mark = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).replaceAll("%", "")
                        .trim();
                isFirstMark = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Passed")) {
            ps.println(line);
            if (isFirstNbPassed) {
                nbPassed = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbPassed = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Failed test")) {
            ps.println(line);
            if (isFirstNbFailed) {
                nbFailed = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbFailed = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Failed occurences")) {
            ps.println(line);
            if (isFirstNbFailedOccurences) {
                nbFailedOccurences = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbFailedOccurences = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Pre-qualified")) {
            ps.println(line);
            if (isFirstNbNmi) {
                nbNmi = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbNmi = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Not Applicable")) {
            ps.println(line);
            if (isFirstNbNa) {
                nbNa = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbNa = false;
            }
        } else if (StringUtils.startsWith(line, "Nb Not Tested")) {
            ps.println(line);
            if (isFirstNbNt) {
                nbNt = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
                isFirstNbNt = false;
            }
        } else if (StringUtils.startsWith(line, "Audit Id")) {
            ps.println(line);
            auditId = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
        }
    }
    ps.println("");
}

From source file:hydrograph.ui.expression.editor.composites.FunctionsComposite.java

private void addDragSupport() {
    ExpressionEditorUtil.INSTANCE.getDragSource(methodList).addDragListener(new DragSourceAdapter() {
        public void dragSetData(DragSourceEvent event) {
            if (methodList.getItemCount() != 0
                    && !StringUtils.startsWith(methodList.getItem(0), Messages.CANNOT_SEARCH_INPUT_STRING)) {
                MethodDetails methodDetails = (MethodDetails) methodList
                        .getData(String.valueOf(methodList.getSelectionIndex()));
                event.data = methodDetails.getPlaceHolder();
            } else
                event.data = StringUtils.EMPTY + "#" + StringUtils.EMPTY;
        }/*from w ww.j  a va 2 s .com*/
    });
}

From source file:com.cognifide.actions.core.ActionRegistryService.java

private String createPath(String relPath) {
    String path;// w  w w  .  j av  a  2 s . c om
    if (StringUtils.startsWith(relPath, "/")) {
        path = relPath;
    } else {
        final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd/");
        path = actionRoot + dateFormat.format(new Date()) + relPath;
    }

    if (path.endsWith("/*")) {
        String generated = StringUtils.EMPTY + new Date().getTime() + "-" + random.nextInt(100);
        path = StringUtils.removeEnd(path, "*") + generated;
    }
    return path;
}