List of usage examples for org.apache.commons.lang3.math NumberUtils toInt
public static int toInt(final String str)
Convert a String
to an int
, returning zero
if the conversion fails.
If the string is null
, zero
is returned.
NumberUtils.toInt(null) = 0 NumberUtils.toInt("") = 0 NumberUtils.toInt("1") = 1
From source file:org.mariotaku.twidere.fragment.card.CardPollFragment.java
private int getChoicesCount(ParcelableCardEntity card) { final Matcher matcher = PATTERN_POLL_TEXT_ONLY.matcher(card.name); if (!matcher.matches()) throw new IllegalStateException(); return NumberUtils.toInt(matcher.group(1)); }
From source file:org.mashupmedia.encode.ProcessManager.java
public int getMaximumConcurrentProcesses() { int totalFfMpegProcesses = NumberUtils .toInt(configurationManager.getConfigurationValue(KEY_TOTAL_FFMPEG_PROCESSES)); return totalFfMpegProcesses; }
From source file:org.primefaces.extensions.component.tristatecheckbox.TriStateCheckboxRenderer.java
protected void encodeMarkup(final FacesContext context, final TriStateCheckbox checkbox) throws IOException { ResponseWriter writer = context.getResponseWriter(); String clientId = checkbox.getClientId(context); int valCheck = NumberUtils.toInt(ComponentUtils.getValueToRender(context, checkbox)); if (valCheck > 2 || valCheck < 0) { valCheck = 0;/*from w w w. j ava 2s .c om*/ } boolean disabled = checkbox.isDisabled(); String style = checkbox.getStyle(); String styleClass = checkbox.getStyleClass(); styleClass = styleClass == null ? HTML.CHECKBOX_CLASS : HTML.CHECKBOX_CLASS + " " + styleClass; writer.startElement("div", checkbox); writer.writeAttribute("id", clientId, "id"); writer.writeAttribute("class", styleClass, "styleClass"); if (style != null) { writer.writeAttribute("style", style, "style"); } encodeInput(context, checkbox, clientId, valCheck, disabled); encodeOutput(context, checkbox, valCheck, disabled); encodeItemLabel(context, checkbox); writer.endElement("div"); }
From source file:org.qifu.controller.SystemProgramAction.java
private void save(DefaultControllerJsonResultObj<SysProgVO> result, SysProgVO sysProg, String sysOid, String iconOid, String w, String h) throws AuthorityException, ControllerException, ServiceException, Exception { this.checkFields(result, sysProg, sysOid, iconOid, w, h); sysProg.setDialogW(NumberUtils.toInt(w)); sysProg.setDialogH(NumberUtils.toInt(h)); DefaultResult<SysProgVO> progResult = this.systemProgramLogicService.create(sysProg, sysOid, iconOid); if (progResult.getValue() != null) { result.setValue(progResult.getValue()); result.setSuccess(YES);/* w w w .j a v a 2 s .c o m*/ } result.setMessage(progResult.getSystemMessage().getValue()); }
From source file:org.qifu.controller.SystemProgramAction.java
private void update(DefaultControllerJsonResultObj<SysProgVO> result, SysProgVO sysProg, String sysOid, String iconOid, String w, String h) throws AuthorityException, ControllerException, ServiceException, Exception { this.checkFields(result, sysProg, sysOid, iconOid, w, h); sysProg.setDialogW(NumberUtils.toInt(w)); sysProg.setDialogH(NumberUtils.toInt(h)); DefaultResult<SysProgVO> progResult = this.systemProgramLogicService.update(sysProg, sysOid, iconOid); if (progResult.getValue() != null) { result.setValue(progResult.getValue()); result.setSuccess(YES);// w ww. jav a 2s.c om } result.setMessage(progResult.getSystemMessage().getValue()); }
From source file:org.springrain.weixin.util.WeiXinUtils.java
/** * ??, 5.0 ??/*from w w w .j a v a2 s. c om*/ * @param request * @return */ public static boolean isWeiXin(HttpServletRequest request) { String userAgent = request.getHeader("User-Agent"); if (StringUtils.isNotBlank(userAgent)) { Pattern p = Pattern.compile("MicroMessenger/(\\d+).+"); Matcher m = p.matcher(userAgent); String version = null; if (m.find()) { version = m.group(1); } return (null != version && NumberUtils.toInt(version) >= 5); } return false; }
From source file:org.tinymediamanager.scraper.util.DOMUtils.java
/** * Gets the element int value./* w w w . j a v a 2 s . c om*/ * * @param el * the el * @param tag * the tag * @return the element int value */ public static int getElementIntValue(Element el, String tag) { NodeList nl = el.getElementsByTagName(tag); if (nl.getLength() > 0) { Node n = nl.item(0); return NumberUtils.toInt(StringUtils.trim(n.getTextContent())); } return 0; }
From source file:password.pwm.util.PwmPasswordRuleValidator.java
public List<ErrorInformation> internalPwmPolicyValidator(final String passwordString, final String oldPasswordString, final UserInfo userInfo, final Flag... flags) throws PwmUnrecoverableException { final boolean failFast = flags != null && Arrays.asList(flags).contains(Flag.FailFast); // null check if (passwordString == null) { return Collections .singletonList(new ErrorInformation(PwmError.ERROR_UNKNOWN, "empty (null) new password")); }/*from www.ja v a 2 s. c o m*/ final List<ErrorInformation> errorList = new ArrayList<>(); final PwmPasswordPolicy.RuleHelper ruleHelper = policy.getRuleHelper(); final MacroMachine macroMachine = userInfo == null || userInfo.getUserIdentity() == null ? MacroMachine.forNonUserSpecific(pwmApplication, SessionLabel.SYSTEM_LABEL) : MacroMachine.forUser(pwmApplication, PwmConstants.DEFAULT_LOCALE, SessionLabel.SYSTEM_LABEL, userInfo.getUserIdentity()); //check against old password if (oldPasswordString != null && oldPasswordString.length() > 0 && ruleHelper.readBooleanValue(PwmPasswordRule.DisallowCurrent)) { if (oldPasswordString.length() > 0) { if (oldPasswordString.equalsIgnoreCase(passwordString)) { errorList.add(new ErrorInformation(PwmError.PASSWORD_SAMEASOLD)); } } //check chars from old password final int maxOldAllowed = ruleHelper.readIntValue(PwmPasswordRule.MaximumOldChars); if (maxOldAllowed > 0) { if (oldPasswordString.length() > 0) { final String lPassword = passwordString.toLowerCase(); final Set<Character> dupeChars = new HashSet<>(); //add all dupes to the set. for (final char loopChar : oldPasswordString.toLowerCase().toCharArray()) { if (lPassword.indexOf(loopChar) != -1) { dupeChars.add(loopChar); } } //count the number of (unique) set elements. if (dupeChars.size() >= maxOldAllowed) { errorList.add(new ErrorInformation(PwmError.PASSWORD_TOO_MANY_OLD_CHARS)); } } } } if (failFast && errorList.size() > 1) { return errorList; } errorList.addAll(basicSyntaxRuleChecks(passwordString, policy, userInfo)); if (failFast && errorList.size() > 1) { return errorList; } // check against disallowed values; if (!ruleHelper.getDisallowedValues().isEmpty()) { final String lcasePwd = passwordString.toLowerCase(); final Set<String> paramValues = new HashSet<>(ruleHelper.getDisallowedValues()); for (final String loopValue : paramValues) { if (loopValue != null && loopValue.length() > 0) { final String expandedValue = macroMachine.expandMacros(loopValue); if (StringUtils.isNotBlank(expandedValue)) { final String loweredLoop = expandedValue.toLowerCase(); if (lcasePwd.contains(loweredLoop)) { errorList.add(new ErrorInformation(PwmError.PASSWORD_USING_DISALLOWED)); } } } } } if (failFast && errorList.size() > 1) { return errorList; } // check disallowed attributes. if (!policy.getRuleHelper().getDisallowedAttributes().isEmpty()) { final List<String> paramConfigs = policy.getRuleHelper() .getDisallowedAttributes(RuleHelper.Flag.KeepThresholds); if (userInfo != null) { final Map<String, String> userValues = userInfo.getCachedPasswordRuleAttributes(); for (final String paramConfig : paramConfigs) { final String[] parts = paramConfig.split(":"); final String attrName = parts[0]; final String disallowedValue = StringUtils.defaultString(userValues.get(attrName)); final int threshold = parts.length > 1 ? NumberUtils.toInt(parts[1]) : 0; if (containsDisallowedValue(passwordString, disallowedValue, threshold)) { LOGGER.trace("password rejected, same as user attr " + attrName); errorList.add(new ErrorInformation(PwmError.PASSWORD_SAMEASATTR)); } } } } if (failFast && errorList.size() > 1) { return errorList; } { // check password strength final int requiredPasswordStrength = ruleHelper.readIntValue(PwmPasswordRule.MinimumStrength); if (requiredPasswordStrength > 0) { if (pwmApplication != null) { final int passwordStrength = PasswordUtility.judgePasswordStrength(passwordString); if (passwordStrength < requiredPasswordStrength) { errorList.add(new ErrorInformation(PwmError.PASSWORD_TOO_WEAK)); //LOGGER.trace(pwmSession, "password rejected, password strength of " + passwordStrength + " is lower than policy requirement of " + requiredPasswordStrength); } } } } if (failFast && errorList.size() > 1) { return errorList; } // check regex matches. for (final Pattern pattern : ruleHelper.getRegExMatch(macroMachine)) { if (!pattern.matcher(passwordString).matches()) { errorList.add(new ErrorInformation(PwmError.PASSWORD_INVALID_CHAR)); //LOGGER.trace(pwmSession, "password rejected, does not match configured regex pattern: " + pattern.toString()); } } if (failFast && errorList.size() > 1) { return errorList; } // check no-regex matches. for (final Pattern pattern : ruleHelper.getRegExNoMatch(macroMachine)) { if (pattern.matcher(passwordString).matches()) { errorList.add(new ErrorInformation(PwmError.PASSWORD_INVALID_CHAR)); //LOGGER.trace(pwmSession, "password rejected, matches configured no-regex pattern: " + pattern.toString()); } } if (failFast && errorList.size() > 1) { return errorList; } // check char group matches if (ruleHelper.readIntValue(PwmPasswordRule.CharGroupsMinMatch) > 0) { final List<Pattern> ruleGroups = ruleHelper.getCharGroupValues(); if (ruleGroups != null && !ruleGroups.isEmpty()) { final int requiredMatches = ruleHelper.readIntValue(PwmPasswordRule.CharGroupsMinMatch); int matches = 0; for (final Pattern pattern : ruleGroups) { if (pattern.matcher(passwordString).find()) { matches++; } } if (matches < requiredMatches) { errorList.add(new ErrorInformation(PwmError.PASSWORD_NOT_ENOUGH_GROUPS)); } } if (failFast && errorList.size() > 1) { return errorList; } } if (failFast && errorList.size() > 1) { return errorList; } // check if the password is in the dictionary. if (ruleHelper.readBooleanValue(PwmPasswordRule.EnableWordlist)) { if (pwmApplication != null) { if (pwmApplication.getWordlistManager() != null && pwmApplication.getWordlistManager().status() == PwmService.STATUS.OPEN) { final boolean found = pwmApplication.getWordlistManager().containsWord(passwordString); if (found) { //LOGGER.trace(pwmSession, "password rejected, in wordlist file"); errorList.add(new ErrorInformation(PwmError.PASSWORD_INWORDLIST)); } } else { /* noop */ //LOGGER.warn(pwmSession, "password wordlist checking enabled, but wordlist is not available, skipping wordlist check"); } } if (failFast && errorList.size() > 1) { return errorList; } } if (failFast && errorList.size() > 1) { return errorList; } // check for shared (global) password history if (pwmApplication != null) { if (pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.PASSWORD_SHAREDHISTORY_ENABLE) && pwmApplication.getSharedHistoryManager().status() == PwmService.STATUS.OPEN) { final boolean found = pwmApplication.getSharedHistoryManager().containsWord(passwordString); if (found) { //LOGGER.trace(pwmSession, "password rejected, in global shared history"); errorList.add(new ErrorInformation(PwmError.PASSWORD_INWORDLIST)); } } if (failFast && errorList.size() > 1) { return errorList; } } return errorList; }
From source file:pcgen.gui2.dialog.CharacterHPDialog.java
private void initComponents() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); Container pane = getContentPane(); pane.setLayout(new BorderLayout()); JTable table = new JTable(tableModel) { @Override//from ww w. j a v a 2 s . c om public TableCellEditor getCellEditor(int row, int column) { if (column == 5) {//TODO: the max roll should be calculated in a different manner String hd = levels.getClassTaken(levels.getElementAt(row)).getHD(); int max = NumberUtils.toInt(hd); return new IntegerEditor(1, max); } else { return super.getCellEditor(row, column); } } }; table.setDefaultRenderer(JButton.class, new Renderer()); table.setDefaultEditor(JButton.class, new Editor()); table.setCellSelectionEnabled(false); table.setRowHeight(new IntegerEditor(1, 10).getPreferredSize().height); JTableHeader header = table.getTableHeader(); header.setReorderingAllowed(false); JScrollPane scrollPane = new JScrollPane(table); pane.add(scrollPane, BorderLayout.CENTER); Box box = Box.createHorizontalBox(); box.add(new JLabel("Total Hp:")); box.add(Box.createHorizontalStrut(3)); final ReferenceListener<Integer> hpListener = new ReferenceListener<Integer>() { @Override public void referenceChanged(ReferenceEvent<Integer> e) { totalHp.setText(e.getNewReference().toString()); } }; ReferenceFacade<Integer> hpRef = character.getTotalHPRef(); totalHp.setText(hpRef.get().toString()); hpRef.addReferenceListener(hpListener); box.add(totalHp); box.add(Box.createHorizontalStrut(5)); JButton button = new JButton("Reroll All"); button.setActionCommand("Reroll"); button.addActionListener(this); box.add(button); box.add(Box.createHorizontalGlue()); button = new JButton("Close"); button.setActionCommand("Close"); button.addActionListener(this); box.add(button); pane.add(box, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { //Make sure to remove the listeners so that the garbage collector can //dispose of this dialog and prevent a memory leak levels.removeHitPointListener(tableModel); character.getTotalHPRef().removeReferenceListener(hpListener); } }); Utility.installEscapeCloseOperation(this); }
From source file:pcgen.gui2.dialog.PostLevelUpDialog.java
private void initComponents() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); Container pane = getContentPane(); pane.setLayout(new BorderLayout()); JTable table = new JTable(tableModel) { @Override//from w w w . j a va 2s. c om public TableCellEditor getCellEditor(int row, int column) { if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) {//TODO: the max roll should be calculated in a different manner String hd = levels.getClassTaken(levels.getElementAt(row + oldLevel)).getHD(); int max = NumberUtils.toInt(hd); return new SpinnerEditor(new SpinnerNumberModel(1, 1, max, 1)); } return super.getCellEditor(row, column); } @Override public TableCellRenderer getCellRenderer(int row, int column) { if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) { return new SpinnerRenderer(); } return super.getCellRenderer(row, column); } }; table.setCellSelectionEnabled(false); table.setRowHeight(new JSpinner().getPreferredSize().height); JTableHeader header = table.getTableHeader(); header.setReorderingAllowed(false); JScrollPane scrollPane = new JScrollPane(table); pane.add(scrollPane, BorderLayout.CENTER); Box box = Box.createHorizontalBox(); box.add(Box.createHorizontalGlue()); JButton button = new JButton(LanguageBundle.getString("in_close")); //$NON-NLS-1$ button.setMnemonic(LanguageBundle.getMnemonic("in_mn_close")); //$NON-NLS-1$ button.setActionCommand("Close"); //$NON-NLS-1$ button.addActionListener(this); box.add(button); pane.add(box, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { //Make sure to remove the listeners so that the garbage collector can //dispose of this dialog and prevent a memory leak levels.removeHitPointListener(tableModel); } }); Utility.installEscapeCloseOperation(this); }