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

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

Introduction

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

Prototype

public static boolean isNumeric(String str) 

Source Link

Document

Checks if the String contains only unicode digits.

Usage

From source file:com.receipts.backingbeans.StoreView.java

public String goToReceipt() {
    int selectedStoreId = selectedStore.getId();
    Store refreshStore = storesService.getStoreById(selectedStoreId);
    selectedStore = refreshStore;//from   www. ja va  2s .c o m

    if (goToReceiptType != null && goToReceiptInput != null) {
        boolean found = false;
        for (Receipt receipt : selectedStore.getReceipts()) {
            switch (goToReceiptType) {
            case "img":
                if (receipt.getImgName().contains(goToReceiptInput)) {
                    selectedReceipt = receiptsService.getReceiptById(receipt.getId());
                    found = true;
                }
                break;
            case "id":
                if (StringUtils.isNumeric(goToReceiptInput)) {
                    Integer goToReceiptId = Integer.parseInt(goToReceiptInput);
                    if (receipt.getId().equals(goToReceiptId)) {
                        selectedReceipt = receiptsService.getReceiptById(goToReceiptId);
                        found = true;
                    }
                }
                break;
            }

            if (found) {
                break;
            }
        }
    }

    goToReceiptInput = null;
    warningAlreadyShown = false;
    receiptTotalToCompare = null;

    return null;
}

From source file:de.ma.it.common.excel.ExcelFileManager.java

/**
 * /*from www . j a v a  2 s . co  m*/
 * @param row
 * @param cellIdx
 * @return
 * @throws IllegalArgumentException
 */
public Float readCellAsFloat(HSSFRow row, int cellIdx) throws IllegalArgumentException {
    HSSFCell cell = getCell(row, cellIdx);
    if (cell == null) {
        return null;
    }

    int cellType = cell.getCellType();
    // First evaluate formula if present
    if (cellType == HSSFCell.CELL_TYPE_FORMULA) {
        cellType = evaluator.evaluateFormulaCell(cell);
    }

    Float result;
    switch (cellType) {
    case HSSFCell.CELL_TYPE_NUMERIC:
        double numericCellValue = cell.getNumericCellValue();
        if (numericCellValue > Float.MAX_VALUE) {
            throw new IllegalArgumentException("Value " + numericCellValue + " to big for integer!");
        }
        result = Double.valueOf(numericCellValue).floatValue();
        break;
    case HSSFCell.CELL_TYPE_STRING:
        String stringCellValue = cell.getStringCellValue();
        if (!StringUtils.isNumeric(stringCellValue)) {
            throw new IllegalArgumentException("Value " + stringCellValue + " is not numeric!");
        }
        result = Double.valueOf(stringCellValue).floatValue();
        break;
    default:
        result = Float.MIN_VALUE;
        break;
    }

    return result;
}

From source file:com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor.java

private int parseMultiplicity(String maxOccursString, Element element) throws SchemaException {
    if (PrismConstants.MULTIPLICITY_UNBONUNDED.equals(maxOccursString)) {
        return -1;
    }/* www.  ja  v a  2 s .c  om*/
    if (maxOccursString.startsWith("-")) {
        return -1;
    }
    if (StringUtils.isNumeric(maxOccursString)) {
        return Integer.valueOf(maxOccursString);
    } else {
        throw new SchemaException("Expected numeric value for " + PrismConstants.A_MAX_OCCURS.getLocalPart()
                + " attribute on " + DOMUtil.getQName(element) + " but got " + maxOccursString);
    }
}

From source file:com.googlecode.osde.internal.runtime.RunExternalApplicationDialog.java

private void setDefaultValues() {
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    boolean measurePerformance = store.getBoolean(PREF_MEASURE_PERFORMANCE);
    measurePerformanceCheck.setSelection(measurePerformance);
    measurePerformanceCheck.notifyListeners(SWT.Selection, null);

    String joinedUrls = store.getString(PREF_URL);
    if (StringUtils.isNotEmpty(joinedUrls)) {
        String[] urls = StringUtils.split(joinedUrls, "|");
        Arrays.sort(urls);/*  w  ww  .  ja  v a  2  s.  co  m*/
        for (String url : urls) {
            urlCombo.add(url);
            this.urls.add(url);
        }
    } else {
        urlCombo.add(DEV_APP);
        this.urls.add(DEV_APP);
    }
    String prevCountry = store.getString(PREF_COUNTRY);
    if (StringUtils.isNotEmpty(prevCountry) && StringUtils.isNumeric(prevCountry)) {
        countries.select(Integer.parseInt(prevCountry));
    }
    String prevLang = store.getString(PREF_LANG);
    if (StringUtils.isNotEmpty(prevLang) && StringUtils.isNumeric(prevLang)) {
        languages.select(Integer.parseInt(prevLang));
    }
    String prevOwner = store.getString(PREF_OWNER);
    if (StringUtils.isNotEmpty(prevOwner) && StringUtils.isNumeric(prevOwner)) {
        owners.select(Integer.parseInt(prevOwner));
    }
    String prevViewer = store.getString(PREF_VIEWER);
    if (StringUtils.isNotEmpty(prevViewer) && StringUtils.isNumeric(prevViewer)) {
        viewers.select(Integer.parseInt(prevViewer));
    }
    String prevView = store.getString(PREF_VIEW);
    if (StringUtils.isNotEmpty(prevView) && StringUtils.isNumeric(prevView)) {
        viewKind.select(Integer.parseInt(prevView));
    }
    String prevWidth = store.getString(PREF_WIDTH);
    if (StringUtils.isNotEmpty(prevWidth) && StringUtils.isNumeric(prevWidth)) {
        widths.setSelection(Integer.parseInt(prevWidth));
    }
    String prevNotUseSecurityToken = store.getString(PREF_NOT_USE_SECURITY_TOKEN);
    if (StringUtils.isNotEmpty(prevNotUseSecurityToken)) {
        notUseSecurityTokenCheck.setSelection(Boolean.parseBoolean(prevNotUseSecurityToken));
    }
}

From source file:net.sourceforge.fenixedu.domain.teacher.evaluation.FacultyEvaluationProcess.java

private Person findPerson(final String string) {
    if (string != null) {
        final User user = User.findByUsername(string);
        if (user != null) {
            return user.getPerson();
        }//from  w w  w. j ava  2 s  . co  m
        if (!string.isEmpty() && StringUtils.isNumeric(string)) {
            final int number = Integer.parseInt(string);
            if (number > 0) {
                Employee employee = Employee.readByNumber(new Integer(number));
                if (employee != null && employee.getPerson() != null
                        && employee.getPerson().getTeacher() != null) {
                    return employee.getPerson();
                }
            }
        }
    }
    return null;
}

From source file:br.com.nordestefomento.jrimum.bopepo.campolivre.CLSicredi.java

InnerCooperativaDeCredito loadCooperativaDeCredito(Agencia agencia) {

    InnerCooperativaDeCredito cooperativa = null;

    if (isNotNull(agencia.getCodigo(), "Nmero da Agncia Sicredi")) {

        if (agencia.getCodigo() > 0) {

            if (String.valueOf(agencia.getCodigo()).length() <= 4) {

                cooperativa = new InnerCooperativaDeCredito();

                cooperativa.codigo = "" + agencia.getCodigo();

            } else {
                new IllegalArgumentException(
                        "Nmero da Agncia Sicredi deve conter no mximo 4 dgitos (SEM O DIGITO VERIFICADOR) e no: "
                                + agencia.getCodigo());
            }//from  w  w w.j a va 2  s.  c  o m

        } else {
            new IllegalArgumentException(
                    "Nmero da Agncia Sicredi com valor invlido: " + agencia.getCodigo());
        }
    }

    if (isNotNull(agencia.getDigitoVerificador(), "Dgito da Agncia Sicredi")) {
        if (StringUtils.isNumeric(agencia.getDigitoVerificador())) {

            if (String.valueOf(agencia.getDigitoVerificador()).length() <= 2) {

                Integer digitoDaAgencia = Integer.valueOf(agencia.getDigitoVerificador());

                if (digitoDaAgencia >= 0) {
                    cooperativa.posto = digitoDaAgencia.toString();
                } else {
                    new IllegalArgumentException(
                            "O dgito da Agncia Sicredi deve ser um nmero natural no-negativo, e no: ["
                                    + agencia.getDigitoVerificador() + "]");
                }

            } else {
                new IllegalArgumentException(
                        "Dgito da Agncia Sicredi deve conter no mximo 2 dgitos e no: "
                                + agencia.getCodigo());
            }

        } else {
            new IllegalArgumentException("O dgito da Agncia Sicredi deve ser numrico, e no: ["
                    + agencia.getDigitoVerificador() + "]");
        }
    }

    return cooperativa;
}

From source file:com.intellectualcrafters.plot.commands.Setup.java

@Override
public boolean execute(final Player plr, final String... args) {
    String plrname;//from w  w  w.j a  va  2  s  .co m

    if (plr == null) {
        plrname = "";
    } else {
        plrname = plr.getName();
    }

    if (setupMap.containsKey(plrname)) {
        final SetupObject object = setupMap.get(plrname);
        if (object.getCurrent() == object.getMax()) {
            final ConfigurationNode[] steps = object.step;
            final String world = object.world;
            for (final ConfigurationNode step : steps) {
                PlotMain.config.set("worlds." + world + "." + step.getConstant(), step.getValue());
            }
            try {
                PlotMain.config.save(PlotMain.configFile);
            } catch (final IOException e) {
                e.printStackTrace();
            }

            // Creating the worlds
            if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null)
                    && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
                Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
                        "mv create " + world + " normal -g " + object.plugin);
            } else {
                if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null)
                        && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
                    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
                            "mw create " + world + " plugin:" + object.plugin);
                } else {
                    for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
                        if (plugin.isEnabled()) {
                            if (plugin.getDefaultWorldGenerator("world", "") != null) {
                                final String name = plugin.getDescription().getName();
                                if (object.plugin.equals(name)) {
                                    final ChunkGenerator generator = plugin.getDefaultWorldGenerator(world, "");
                                    final World myworld = WorldCreator.name(world).generator(generator)
                                            .createWorld();
                                    PlayerFunctions.sendMessage(plr, "&aLoaded world.");
                                    if (plr != null) {
                                        plr.teleport(myworld.getSpawnLocation());
                                    }
                                    break;
                                }
                            }

                        }
                    }
                }
            }
            sendMessage(plr, C.SETUP_FINISHED, object.world);

            setupMap.remove(plrname);

            return true;
        }
        ConfigurationNode step = object.step[object.current];
        if (args.length < 1) {
            sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(),
                    step.getType().getType(), step.getDefaultValue() + "");
            return true;
        } else {
            if (args[0].equalsIgnoreCase("cancel")) {
                setupMap.remove(plrname);
                PlayerFunctions.sendMessage(plr, "&cCancelled setup.");
                return true;
            }
            if (args[0].equalsIgnoreCase("back")) {
                if (object.current > 0) {
                    object.current--;
                    step = object.step[object.current];
                    sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(),
                            step.getType().getType(), step.getDefaultValue() + "");
                    return true;
                } else {
                    sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(),
                            step.getType().getType(), step.getDefaultValue() + "");
                    return true;
                }
            }
            final boolean valid = step.isValid(args[0]);
            if (valid) {
                sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
                step.setValue(args[0]);
                object.current++;
                if (object.getCurrent() == object.getMax()) {
                    execute(plr, args);
                    return true;
                }
                step = object.step[object.current];
                sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(),
                        step.getType().getType(), step.getDefaultValue() + "");
                return true;
            } else {
                sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant());
                sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(),
                        step.getType().getType(), step.getDefaultValue() + "");
                return true;
            }
        }
    } else {
        if (args.length < 1) {
            sendMessage(plr, C.SETUP_MISSING_WORLD);
            return true;
        }
        if (args.length < 2) {
            sendMessage(plr, C.SETUP_MISSING_GENERATOR);
            return true;
        }
        final String world = args[0];
        if (StringUtils.isNumeric(args[0])) {
            sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
            return true;
        }

        if (PlotMain.getWorldSettings(world) != null) {
            sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
            return true;
        }

        final ArrayList<String> generators = new ArrayList<>();

        ChunkGenerator generator = null;

        for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
            if (plugin.isEnabled()) {
                if (plugin.getDefaultWorldGenerator("world", "") != null) {
                    final String name = plugin.getDescription().getName();
                    generators.add(name);
                    if (args[1].equals(name)) {
                        generator = plugin.getDefaultWorldGenerator(world, "");
                        break;
                    }
                }

            }
        }
        if (generator == null) {
            sendMessage(plr, C.SETUP_INVALID_GENERATOR,
                    StringUtils.join(generators, C.BLOCK_LIST_SEPARATER.s()));
            return true;
        }
        PlotWorld plotworld;
        if (generator instanceof PlotGenerator) {
            plotworld = ((PlotGenerator) generator).getNewPlotWorld(world);
        } else {
            plotworld = new DefaultPlotWorld(world);
        }

        setupMap.put(plrname, new SetupObject(world, plotworld, args[1]));
        sendMessage(plr, C.SETUP_INIT);
        final SetupObject object = setupMap.get(plrname);
        final ConfigurationNode step = object.step[object.current];
        sendMessage(plr, C.SETUP_STEP, object.current + 1 + "", step.getDescription(), step.getType().getType(),
                step.getDefaultValue() + "");
        return true;
    }
}

From source file:es.emergya.cliente.constants.LogicConstants.java

public static boolean isNumeric(String i) {
    return (i != null && StringUtils.isNumeric(i) && !i.trim().equals(""));
}

From source file:fr.paris.lutece.plugins.genericattributes.service.entrytype.AbstractEntryTypeImage.java

/**
 * {@inheritDoc}//from   ww w.  j ava2s  . com
 */
@Override
public GenericAttributeError canUploadFiles(Entry entry, List<FileItem> listUploadedFileItems,
        List<FileItem> listFileItemsToUpload, Locale locale) {
    /** 1) Check max files */
    Field fieldMaxFiles = GenericAttributesUtils.findFieldByTitleInTheList(CONSTANT_MAX_FILES,
            entry.getFields());

    // By default, max file is set at 1
    int nMaxFiles = 1;

    if ((fieldMaxFiles != null) && StringUtils.isNotBlank(fieldMaxFiles.getValue())
            && StringUtils.isNumeric(fieldMaxFiles.getValue())) {
        nMaxFiles = GenericAttributesUtils.convertStringToInt(fieldMaxFiles.getValue());
    }

    if ((listUploadedFileItems != null) && (listFileItemsToUpload != null)) {
        int nNbFiles = listUploadedFileItems.size() + listFileItemsToUpload.size();

        if (nNbFiles > nMaxFiles) {
            Object[] params = { nMaxFiles };
            String strMessage = I18nService.getLocalizedString(PROPERTY_MESSAGE_ERROR_UPLOADING_FILE_MAX_FILES,
                    params, locale);
            GenericAttributeError error = new GenericAttributeError();
            error.setMandatoryError(false);
            error.setTitleQuestion(entry.getTitle());
            error.setErrorMessage(strMessage);

            return error;
        }
    }

    /** 2) Check files size */
    Field fieldFileMaxSize = GenericAttributesUtils.findFieldByTitleInTheList(CONSTANT_FILE_MAX_SIZE,
            entry.getFields());
    int nMaxSize = GenericAttributesUtils.CONSTANT_ID_NULL;

    if ((fieldFileMaxSize != null) && StringUtils.isNotBlank(fieldFileMaxSize.getValue())
            && StringUtils.isNumeric(fieldFileMaxSize.getValue())) {
        nMaxSize = GenericAttributesUtils.convertStringToInt(fieldFileMaxSize.getValue());
    }

    // If no max size defined in the db, then fetch the default max size from the properties file
    if (nMaxSize == GenericAttributesUtils.CONSTANT_ID_NULL) {
        nMaxSize = AppPropertiesService.getPropertyInt(PROPERTY_UPLOAD_FILE_DEFAULT_MAX_SIZE, 5242880);
    }

    // If nMaxSize == -1, then no size limit
    if ((nMaxSize != GenericAttributesUtils.CONSTANT_ID_NULL) && (listFileItemsToUpload != null)
            && (listUploadedFileItems != null)) {
        boolean bHasFileMaxSizeError = false;
        List<FileItem> listFileItems = new ArrayList<FileItem>();
        listFileItems.addAll(listUploadedFileItems);
        listFileItems.addAll(listFileItemsToUpload);

        for (FileItem fileItem : listFileItems) {
            if (fileItem.getSize() > nMaxSize) {
                bHasFileMaxSizeError = true;

                break;
            }
        }

        if (bHasFileMaxSizeError) {
            Object[] params = { nMaxSize };
            String strMessage = I18nService
                    .getLocalizedString(PROPERTY_MESSAGE_ERROR_UPLOADING_FILE_FILE_MAX_SIZE, params, locale);
            GenericAttributeError error = new GenericAttributeError();
            error.setMandatoryError(false);
            error.setTitleQuestion(entry.getTitle());
            error.setErrorMessage(strMessage);

            return error;
        }
    }

    if (listFileItemsToUpload != null) {
        for (FileItem fileItem : listFileItemsToUpload) {
            if (checkForImages()) {
                GenericAttributeError error = doCheckforImages(fileItem, entry, locale);

                if (error != null) {
                    return error;
                }
            }
        }
    }

    return null;
}

From source file:au.org.ala.bhl.service.IndexingService.java

public static YearRange parseYearRange(String range) {

    if (StringUtils.isEmpty(range)) {
        return null;
    }/*ww  w .  j  a va 2s.co m*/

    if (StringUtils.isNumeric(range)) {
        return new YearRange(range, range);
    }

    // Look for YYYY-YYYY
    Matcher m = YEAR_RANGE_PATTERN.matcher(range);
    if (m.find()) {
        return new YearRange(m.group(1), m.group(2));
    }

    // Look for YYYY-YY
    m = ABBREV_RANGE_PATTERN.matcher(range);
    if (m.find()) {
        String start = m.group(1);
        return new YearRange(start, start.substring(0, 2) + m.group(2));
    }

    // Look for any for 4 consecutive digits!
    m = SINGLE_YEAR_PATTERN.matcher(range);
    if (m.find()) {
        return new YearRange(m.group(1), m.group(1));
    }

    return null;
}