Java Examples for org.apache.commons.lang3.StringUtils.startsWith

The following java examples will help you to understand the usage of org.apache.commons.lang3.StringUtils.startsWith. These source code samples are taken from different open source projects.

Example 1
Project: eclipse3-master  File: PrefixSearchPattern.java View source code
@Override
public MatchQuality matches(Element element) {
    if (element == null) {
        return null;
    }
    String name = element.getDisplayName();
    if (name == null) {
        return null;
    }
    if (caseSensitive && startsWith(name, prefix)) {
        return MatchQuality.EXACT;
    }
    if (!caseSensitive && startsWithIgnoreCase(name, prefix)) {
        return MatchQuality.EXACT;
    }
    return null;
}
Example 2
Project: gazetteer-master  File: ReplacersCompiler.java View source code
public static void compile(List<Replacer> replacers, List<String> text) {
    State state = new State();
    for (String line : text) {
        if (!startsWith(line, "#") && !startsWith(line, "@") && isNotBlank(line)) {
            if (!state.multiline) {
                state.pattern = strip(substringBefore(line, "=>"));
                state.template = strip(substringAfter(line, "=>"));
            }
            if (startsWith(state.template, "///") || startsWith(line, "///")) {
                if (!state.multiline) {
                    state.multiline = true;
                    state.template = substringAfter(state.template, "///");
                    state.sb = new StringBuilder(state.template);
                } else {
                    state.multiline = false;
                    add(replacers, state.pattern, state.sb.toString());
                    state.sb = new StringBuilder();
                }
            } else if (state.multiline) {
                state.sb.append(line).append("\n");
            } else {
                add(replacers, state.pattern, state.template);
            }
        } else if (startsWith(line, "@")) {
            String include = substringAfter(line, "include").trim();
            if (isNotBlank(include)) {
                compile(replacers, new File(include));
            }
        }
    }
}
Example 3
Project: migration-tools-master  File: MSSQLServerColumnInspector.java View source code
@Override
protected void processColumn(InspectionContext inspectionContext, ResultSet columns, Column column) throws SQLException {
    super.processColumn(inspectionContext, columns, column);
    DefaultValue defaultValue = column.getDefaultValue();
    if (defaultValue != null && !defaultValue.isProcessed()) {
        String value = defaultValue.getScript();
        while (startsWith(value, "(") && endsWith(value, ")")) {
            value = value.substring(1, value.length() - 1);
        }
        column.setDefaultValue(valueOf(value, true));
    }
}
Example 4
Project: jDTO-Binder-master  File: StringUtils.java View source code
/**
     * <p>Check if a String starts with any of an array of specified
     * strings.</p>
     *
     * <pre>
     * StringUtils.startsWithAny(null, null)      = false
     * StringUtils.startsWithAny(null, new String[] {"abc"})  = false
     * StringUtils.startsWithAny("abcxyz", null)     = false
     * StringUtils.startsWithAny("abcxyz", new String[] {""}) = false
     * StringUtils.startsWithAny("abcxyz", new String[] {"abc"}) = true
     * StringUtils.startsWithAny("abcxyz", new String[] {null, "xyz", "abc"}) = true
     * </pre>
     *
     * @see #startsWith(String, String)
     * @param string the String to check, may be null
     * @param searchStrings the Strings to find, may be null or empty
     * @return
     * <code>true</code> if the String starts with any of the the prefixes, case
     * insensitive, or both
     * <code>null</code>
     * @since 2.5
     */
public static boolean startsWithAny(String string, String[] searchStrings) {
    if (isEmpty(string) || ArrayUtils.isEmpty(searchStrings)) {
        return false;
    }
    for (int i = 0; i < searchStrings.length; i++) {
        String searchString = searchStrings[i];
        if (org.apache.commons.lang3.StringUtils.startsWith(string, searchString)) {
            return true;
        }
    }
    return false;
}
Example 5
Project: test-streamer-master  File: StringUtilsStartsEndsWithTest.java View source code
//-----------------------------------------------------------------------
/**
     * Test StringUtils.startsWith()
     */
@Test
public void testStartsWith() {
    assertTrue("startsWith(null, null)", StringUtils.startsWith(null, (String) null));
    assertFalse("startsWith(FOOBAR, null)", StringUtils.startsWith(FOOBAR, (String) null));
    assertFalse("startsWith(null, FOO)", StringUtils.startsWith(null, FOO));
    assertTrue("startsWith(FOOBAR, \"\")", StringUtils.startsWith(FOOBAR, ""));
    assertTrue("startsWith(foobar, foo)", StringUtils.startsWith(foobar, foo));
    assertTrue("startsWith(FOOBAR, FOO)", StringUtils.startsWith(FOOBAR, FOO));
    assertFalse("startsWith(foobar, FOO)", StringUtils.startsWith(foobar, FOO));
    assertFalse("startsWith(FOOBAR, foo)", StringUtils.startsWith(FOOBAR, foo));
    assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(foo, foobar));
    assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(bar, foobar));
    assertFalse("startsWith(foobar, bar)", StringUtils.startsWith(foobar, bar));
    assertFalse("startsWith(FOOBAR, BAR)", StringUtils.startsWith(FOOBAR, BAR));
    assertFalse("startsWith(foobar, BAR)", StringUtils.startsWith(foobar, BAR));
    assertFalse("startsWith(FOOBAR, bar)", StringUtils.startsWith(FOOBAR, bar));
}
Example 6
Project: raml-jaxrs-codegen-master  File: Types.java View source code
public JType getRequestEntityClass(final MimeType mimeType) throws IOException {
    final JClass schemaClass = getSchemaClass(mimeType);
    if (schemaClass != null) {
        return schemaClass;
    } else if (startsWith(mimeType.getType(), "text/")) {
        return getGeneratorType(String.class);
    } else if (MediaType.APPLICATION_OCTET_STREAM.equals(mimeType.getType())) {
        return getGeneratorType(InputStream.class);
    } else {
        // fallback to a generic reader
        return getGeneratorType(Reader.class);
    }
}
Example 7
Project: dkpro-core-master  File: NegraExportReader.java View source code
/**
     * Read the originId from the #BOS line that is expected to follow.
     *
     * @param aPeek
     *            if true, stream will not advance
     * @return the next origin id or null if there is none
     */
private String readSentenceHeader(int aField, boolean aPeek) throws IOException {
    if (aPeek) {
        br.mark(16000);
    }
    String line = br.readLine();
    while (line != null) {
        if (!line.startsWith("%%")) {
            String[] parts = line.split("\\s+");
            if (aPeek) {
                br.reset();
            }
            return parts[aField];
        }
        line = br.readLine();
    }
    return null;
}
Example 8
Project: ps3mediaserver-master  File: MEncoderVideo.java View source code
@Override
public void actionPerformed(ActionEvent e) {
    JPanel codecPanel = new JPanel(new BorderLayout());
    final JTextArea textArea = new JTextArea();
    textArea.setText(configuration.getMencoderCodecSpecificConfig());
    textArea.setFont(new Font("Courier", Font.PLAIN, 12));
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setPreferredSize(new java.awt.Dimension(900, 100));
    final JTextArea textAreaDefault = new JTextArea();
    textAreaDefault.setText(DEFAULT_CODEC_CONF_SCRIPT);
    textAreaDefault.setBackground(Color.WHITE);
    textAreaDefault.setFont(new Font("Courier", Font.PLAIN, 12));
    textAreaDefault.setEditable(false);
    textAreaDefault.setEnabled(configuration.isMencoderIntelligentSync());
    JScrollPane scrollPaneDefault = new JScrollPane(textAreaDefault);
    scrollPaneDefault.setPreferredSize(new java.awt.Dimension(900, 450));
    JPanel customPanel = new JPanel(new BorderLayout());
    intelligentsync = new JCheckBox(Messages.getString("MEncoderVideo.3"));
    intelligentsync.setContentAreaFilled(false);
    if (configuration.isMencoderIntelligentSync()) {
        intelligentsync.setSelected(true);
    }
    intelligentsync.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderIntelligentSync((e.getStateChange() == ItemEvent.SELECTED));
            textAreaDefault.setEnabled(configuration.isMencoderIntelligentSync());
        }
    });
    JLabel label = new JLabel(Messages.getString("MEncoderVideo.33"));
    customPanel.add(label, BorderLayout.NORTH);
    customPanel.add(scrollPane, BorderLayout.SOUTH);
    codecPanel.add(intelligentsync, BorderLayout.NORTH);
    codecPanel.add(scrollPaneDefault, BorderLayout.CENTER);
    codecPanel.add(customPanel, BorderLayout.SOUTH);
    while (JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), codecPanel, Messages.getString("MEncoderVideo.34"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null) == JOptionPane.OK_OPTION) {
        String newCodecparam = textArea.getText();
        DLNAMediaInfo fakemedia = new DLNAMediaInfo();
        DLNAMediaAudio audio = new DLNAMediaAudio();
        audio.setCodecA("ac3");
        fakemedia.setCodecV("mpeg4");
        fakemedia.setContainer("matroska");
        fakemedia.setDuration(45d * 60);
        audio.getAudioProperties().setNumberOfChannels(2);
        fakemedia.setWidth(1280);
        fakemedia.setHeight(720);
        audio.setSampleFrequency("48000");
        fakemedia.setFrameRate("23.976");
        fakemedia.getAudioTracksList().add(audio);
        String result[] = getSpecificCodecOptions(newCodecparam, fakemedia, new OutputParams(configuration), "dummy.mpg", "dummy.srt", false, true);
        if (result.length > 0 && result[0].startsWith("@@")) {
            String errorMessage = result[0].substring(2);
            JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), errorMessage, Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE);
        } else {
            configuration.setMencoderCodecSpecificConfig(newCodecparam);
            break;
        }
    }
}
Example 9
Project: commons-lang-master  File: StringUtilsStartsEndsWithTest.java View source code
//-----------------------------------------------------------------------
/**
     * Test StringUtils.startsWith()
     */
@Test
public void testStartsWith() {
    assertTrue("startsWith(null, null)", StringUtils.startsWith(null, null));
    assertFalse("startsWith(FOOBAR, null)", StringUtils.startsWith(FOOBAR, null));
    assertFalse("startsWith(null, FOO)", StringUtils.startsWith(null, FOO));
    assertTrue("startsWith(FOOBAR, \"\")", StringUtils.startsWith(FOOBAR, ""));
    assertTrue("startsWith(foobar, foo)", StringUtils.startsWith(foobar, foo));
    assertTrue("startsWith(FOOBAR, FOO)", StringUtils.startsWith(FOOBAR, FOO));
    assertFalse("startsWith(foobar, FOO)", StringUtils.startsWith(foobar, FOO));
    assertFalse("startsWith(FOOBAR, foo)", StringUtils.startsWith(FOOBAR, foo));
    assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(foo, foobar));
    assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(bar, foobar));
    assertFalse("startsWith(foobar, bar)", StringUtils.startsWith(foobar, bar));
    assertFalse("startsWith(FOOBAR, BAR)", StringUtils.startsWith(FOOBAR, BAR));
    assertFalse("startsWith(foobar, BAR)", StringUtils.startsWith(foobar, BAR));
    assertFalse("startsWith(FOOBAR, bar)", StringUtils.startsWith(FOOBAR, bar));
}
Example 10
Project: gwt-commons-lang3-master  File: StringUtilsStartsEndsWithTest.java View source code
//-----------------------------------------------------------------------
/**
     * Test StringUtils.startsWith()
     */
@Test
public void testStartsWith() {
    assertTrue("startsWith(null, null)", StringUtils.startsWith(null, (String) null));
    assertFalse("startsWith(FOOBAR, null)", StringUtils.startsWith(FOOBAR, (String) null));
    assertFalse("startsWith(null, FOO)", StringUtils.startsWith(null, FOO));
    assertTrue("startsWith(FOOBAR, \"\")", StringUtils.startsWith(FOOBAR, ""));
    assertTrue("startsWith(foobar, foo)", StringUtils.startsWith(foobar, foo));
    assertTrue("startsWith(FOOBAR, FOO)", StringUtils.startsWith(FOOBAR, FOO));
    assertFalse("startsWith(foobar, FOO)", StringUtils.startsWith(foobar, FOO));
    assertFalse("startsWith(FOOBAR, foo)", StringUtils.startsWith(FOOBAR, foo));
    assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(foo, foobar));
    assertFalse("startsWith(foo, foobar)", StringUtils.startsWith(bar, foobar));
    assertFalse("startsWith(foobar, bar)", StringUtils.startsWith(foobar, bar));
    assertFalse("startsWith(FOOBAR, BAR)", StringUtils.startsWith(FOOBAR, BAR));
    assertFalse("startsWith(foobar, BAR)", StringUtils.startsWith(foobar, BAR));
    assertFalse("startsWith(FOOBAR, bar)", StringUtils.startsWith(FOOBAR, bar));
}
Example 11
Project: sonarqube-master  File: EmbeddedDatabaseFactory.java View source code
@Override
public void start() {
    if (embeddedDatabase == null) {
        String jdbcUrl = settings.getString(DatabaseProperties.PROP_URL);
        if (startsWith(jdbcUrl, URL_PREFIX)) {
            embeddedDatabase = createEmbeddedDatabase();
            embeddedDatabase.start();
        }
    }
}