Search in sources :

Example 46 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project MyPet by xXKeyleXx.

the class Heal method verifyInput.

@Override
public void verifyInput() {
    timeInput.setText(timeInput.getText().replaceAll("[^0-9]*", ""));
    if (timeInput.getText().length() == 0) {
        timeInput.setText("0");
    }
    healthInput.setText(healthInput.getText().replaceAll("[^0-9\\.]*", ""));
    if (healthInput.getText().length() > 0) {
        if (healthInput.getText().matches("\\.+")) {
            healthInput.setText("0.0");
        } else {
            try {
                Pattern regex = Pattern.compile("[0-9]+(\\.[0-9]+)?");
                Matcher regexMatcher = regex.matcher(healthInput.getText());
                regexMatcher.find();
                healthInput.setText(regexMatcher.group());
            } catch (PatternSyntaxException ignored) {
                healthInput.setText("0.0");
            }
        }
    } else {
        healthInput.setText("0.0");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 47 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project MyPet by xXKeyleXx.

the class Pickup method verifyInput.

@Override
public void verifyInput() {
    rangeInput.setText(rangeInput.getText().replaceAll("[^0-9\\.]*", ""));
    if (rangeInput.getText().length() > 0) {
        if (rangeInput.getText().matches("\\.+")) {
            rangeInput.setText("0.0");
        } else {
            try {
                Pattern regex = Pattern.compile("[0-9]+(\\.[0-9]+)?");
                Matcher regexMatcher = regex.matcher(rangeInput.getText());
                regexMatcher.find();
                rangeInput.setText(regexMatcher.group());
            } catch (PatternSyntaxException ignored) {
                rangeInput.setText("0.0");
            }
        }
    } else {
        rangeInput.setText("0.0");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 48 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project MyPet by xXKeyleXx.

the class Ranged method verifyInput.

@Override
public void verifyInput() {
    if (!rateOfFireInput.getText().replaceAll("[^0-9]*", "").equals(rateOfFireInput.getText())) {
        rateOfFireInput.setText(rateOfFireInput.getText().replaceAll("[^0-9]*", ""));
    }
    if (!rateOfFireInput.getText().matches("[1-9][0-9]*")) {
        rateOfFireInput.setText("1");
    }
    damageInput.setText(damageInput.getText().replaceAll("[^0-9\\.]*", ""));
    if (damageInput.getText().length() > 0) {
        if (damageInput.getText().matches("\\.+")) {
            damageInput.setText("0.0");
        } else {
            try {
                Pattern regex = Pattern.compile("[0-9]+(\\.[0-9]+)?");
                Matcher regexMatcher = regex.matcher(damageInput.getText());
                regexMatcher.find();
                damageInput.setText(regexMatcher.group());
            } catch (PatternSyntaxException ignored) {
                damageInput.setText("0.0");
            }
        }
    } else {
        damageInput.setText("0.0");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 49 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project MyPet by xXKeyleXx.

the class Stomp method verifyInput.

@Override
public void verifyInput() {
    chanceInput.setText(chanceInput.getText().replaceAll("[^0-9]*", ""));
    if (chanceInput.getText().length() == 0) {
        chanceInput.setText("0");
    }
    damageInput.setText(damageInput.getText().replaceAll("[^0-9\\.]*", ""));
    if (damageInput.getText().length() > 0) {
        if (damageInput.getText().matches("\\.+")) {
            damageInput.setText("0.0");
        } else {
            try {
                Pattern regex = Pattern.compile("[0-9]+(\\.[0-9]+)?");
                Matcher regexMatcher = regex.matcher(damageInput.getText());
                regexMatcher.find();
                damageInput.setText(regexMatcher.group());
            } catch (PatternSyntaxException ignored) {
                damageInput.setText("0.0");
            }
        }
    } else {
        damageInput.setText("0.0");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 50 with PatternSyntaxException

use of java.util.regex.PatternSyntaxException in project linuxtools by eclipse.

the class ChangeLogExtensionManager method getFormatterContributor.

/**
 * Fetches formatterName formatter from extension, but if there exists a inline
 * formatter for entryFileName, then it uses that inline formatter.
 * @param entryFilePath The full file name.
 * @param formatterName The formatter name.
 * @return The changelog formatter.
 */
public IFormatterChangeLogContrib getFormatterContributor(String entryFilePath, String formatterName) {
    // extract just file name;
    String fileName;
    int lastDir = entryFilePath.lastIndexOf('/');
    if ((lastDir >= 0) && (lastDir + 1 <= entryFilePath.length()))
        fileName = entryFilePath.substring(lastDir + 1, entryFilePath.length());
    else
        fileName = entryFilePath;
    // We don't yet know which formatter to use
    formatterConfigElementToUse = null;
    if (formatterExtensions != null) {
        IConfigurationElement[] elements = formatterExtensions.getConfigurationElements();
        // cache the in-file formatters on the first run
        if (cachedInFileFormateters == null) {
            List<IConfigurationElement> inFileFormatters = new LinkedList<>();
            for (int i = 0; i < elements.length; i++) {
                IConfigurationElement formatterConfigElement = elements[i];
                if (// $NON-NLS-1$
                formatterConfigElement.getName().equals("formatter") && // $NON-NLS-1$
                formatterConfigElement.getAttribute("inFile").equalsIgnoreCase("true")) {
                    // $NON-NLS-1$
                    inFileFormatters.add(elements[i]);
                }
            }
            cachedInFileFormateters = inFileFormatters.toArray(new IConfigurationElement[] {});
        }
        // edited file
        for (int i = 0; i < cachedInFileFormateters.length; i++) {
            IConfigurationElement formatterConfigElement = cachedInFileFormateters[i];
            IConfigurationElement[] patternElementTmp = formatterConfigElement.getChildren();
            // error check
            if (patternElementTmp == null)
                continue;
            IConfigurationElement patternElement = patternElementTmp[0];
            if (patternElement.getAttribute("pattern") == null) {
                // $NON-NLS-1$
                ChangelogPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, // $NON-NLS-1$
                Messages.getString("ChangeLog.ErrNonPattern"), // $NON-NLS-1$
                new Exception(Messages.getString("ChangeLog.ErrNonPattern"))));
            } else {
                // $NON-NLS-1$
                String filePattern = patternElement.getAttribute("pattern");
                try {
                    Pattern pattern = Pattern.compile(filePattern);
                    Matcher fileMatcher = pattern.matcher(fileName);
                    // pattern then we're done
                    if (fileMatcher.matches()) {
                        formatterConfigElementToUse = formatterConfigElement;
                        break;
                    }
                } catch (PatternSyntaxException e) {
                    ChangelogPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
                }
            }
        }
        // prefered formatter
        if (formatterConfigElementToUse == null) {
            // whenever it changes
            if (cachedPrefFormatter == null || !// $NON-NLS-1$
            cachedPrefFormatter.getAttribute("name").equals(formatterName)) {
                for (int i = 0; i < elements.length; i++) {
                    IConfigurationElement formatterConfigElement = elements[i];
                    if (formatterConfigElement.getName().equals("formatter") && formatterConfigElement.getAttribute("inFile").equalsIgnoreCase("false")) {
                        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                        if (// $NON-NLS-1$
                        formatterConfigElement.getAttribute("name").equals(formatterName))
                            cachedPrefFormatter = formatterConfigElement;
                        break;
                    }
                }
            }
            formatterConfigElementToUse = cachedPrefFormatter;
            if (formatterConfigElementToUse == null) {
                ChangelogPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, // $NON-NLS-1$
                Messages.getString("ChangeLog.ErrRetrieveFormatter"), // $NON-NLS-1$
                new Exception(Messages.getString("ChangeLog.ErrRetrieveFormatter"))));
                return null;
            }
        }
    }
    try {
        return (IFormatterChangeLogContrib) formatterConfigElementToUse.createExecutableExtension(// $NON-NLS-1$
        "class");
    } catch (CoreException e) {
        ChangelogPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
        e.printStackTrace();
    }
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) LinkedList(java.util.LinkedList) PatternSyntaxException(java.util.regex.PatternSyntaxException) CoreException(org.eclipse.core.runtime.CoreException) CoreException(org.eclipse.core.runtime.CoreException) IFormatterChangeLogContrib(org.eclipse.linuxtools.changelog.core.IFormatterChangeLogContrib) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Aggregations

PatternSyntaxException (java.util.regex.PatternSyntaxException)355 Pattern (java.util.regex.Pattern)190 Matcher (java.util.regex.Matcher)115 ArrayList (java.util.ArrayList)46 IOException (java.io.IOException)25 List (java.util.List)19 File (java.io.File)14 Map (java.util.Map)12 HashMap (java.util.HashMap)9 URL (java.net.URL)7 HashSet (java.util.HashSet)7 Iterator (java.util.Iterator)7 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)7 BufferedReader (java.io.BufferedReader)6 Collection (java.util.Collection)6 LinkedList (java.util.LinkedList)5 Test (org.junit.Test)5 InputStreamReader (java.io.InputStreamReader)4 SQLException (java.sql.SQLException)4 LinkedHashMap (java.util.LinkedHashMap)4