List of usage examples for org.apache.commons.lang StringUtils isNumeric
public static boolean isNumeric(String str)
Checks if the String contains only unicode digits.
From source file:gov.nih.nci.caarray.application.GenericDataServiceBean.java
/** * {@inheritDoc}/* www . ja v a 2 s. c o m*/ */ @Override public String getIncrementingCopyName(Class<?> entityClass, String fieldName, String name) { final String alphaPrefix = StringUtils.stripEnd(name, "0123456789"); final String numericSuffix = StringUtils.substringAfter(name, alphaPrefix); int maxSuffix = StringUtils.isEmpty(numericSuffix) ? 1 : Integer.parseInt(numericSuffix); final List<String> currentNames = this.searchDao.findValuesWithSamePrefix(entityClass, fieldName, alphaPrefix); for (final String currentName : currentNames) { final String suffix = StringUtils.substringAfter(currentName, alphaPrefix); if (!StringUtils.isNumeric(suffix) || StringUtils.isEmpty(suffix)) { continue; } maxSuffix = Math.max(maxSuffix, Integer.parseInt(suffix)); } return alphaPrefix + (maxSuffix + 1); }
From source file:net.mindengine.oculus.frontend.web.controllers.project.ProjectSearchAjaxController.java
@SuppressWarnings("unchecked") @Override/*ww w . j av a 2 s . com*/ protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { ProjectSearchFilter filter = (ProjectSearchFilter) command; filter.setColumns(columnFactory.getColumnList()); Map map = new HashMap<String, Object>(); map.put("columns", columnFactory.getColumnList()); if (filter.getProject() != null && filter.getProject().equals("0")) { filter.setProject(""); } /* * Collecting customization search criteria parameters */ filter.setCustomizations(CustomizationUtils.collectCustomizationSearchCriteriaParameters(request)); if (filter.getProject() != null && !filter.getProject().isEmpty()) { if (StringUtils.isNumeric(filter.getProject())) { map.put("customizations", CustomizationUtils.fetchCustomizationGroups(customizationDAO, userDAO, Long.parseLong(filter.getProject()), Customization.UNIT_PROJECT, filter.getCustomizations())); } } map.put("projects", projectDAO.searchSubprojects(filter)); map.put("rootProjects", projectDAO.getRootProjects()); map.put("columnFactory", columnFactory); map.put("searchFilter", filter); map.put("title", getTitle()); return map; }
From source file:com.wasteofplastic.askyblock.panels.BiomesPanel.java
/** * Returns a customized panel of available Biomes for the player * /* w ww.ja v a2s . c o m*/ * @param player * @return custom Inventory object */ public Inventory getBiomePanel(Player player) { // Go through the available biomes and check permission int slot = 0; List<BiomeItem> items = new ArrayList<BiomeItem>(); for (String biomeName : plugin.getConfig().getConfigurationSection("biomes").getKeys(false)) { // Check the biome is actually real try { Biome biome = Biome.valueOf(biomeName); // Check permission String permission = plugin.getConfig().getString("biomes." + biomeName + ".permission", ""); if (permission.isEmpty() || VaultHelper.permission.has(player, permission)) { // Build inventory item // Get icon String icon = plugin.getConfig().getString("biomes." + biomeName + ".icon", "SAPLING"); Material material = null; try { if (StringUtils.isNumeric(icon)) { material = Material.getMaterial(Integer.parseInt(icon)); } else { material = Material.valueOf(icon.toUpperCase()); } } catch (Exception e) { plugin.getLogger() .warning("Error parsing biome icon value " + icon + ". Using default SAPLING."); material = Material.SAPLING; } // Get cost double cost = plugin.getConfig().getDouble("biomes." + biomeName + ".cost", Settings.biomeCost); // Get friendly name String name = ChatColor.translateAlternateColorCodes('&', plugin.getConfig() .getString("biomes." + biomeName + ".friendlyname", Util.prettifyText(biomeName))); // Get description String description = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("biomes." + biomeName + ".description", "")); // Get confirmation or not boolean confirm = plugin.getConfig().getBoolean("biomes." + biomeName + ".confirm", false); // Add item to list // plugin.getLogger().info("DEBUG: " + description + name + // confirm); BiomeItem item = new BiomeItem(material, slot++, cost, description, name, confirm, biome); // Add to item list items.add(item); } } catch (Exception e) { e.printStackTrace(); plugin.getLogger().severe("Could not recognize " + biomeName + " as valid Biome! Skipping..."); plugin.getLogger().severe( "For V1.9, some biome names do not exist anymore. Change config.yml to the latest."); } } // Now create the inventory panel if (items.size() > 0) { // Save the items for later retrieval when the player clicks on them biomeItems.put(player.getUniqueId(), items); // Make sure size is a multiple of 9 int size = items.size() + 8; size -= (size % 9); Inventory newPanel = Bukkit.createInventory(null, size, plugin.myLocale().biomePanelTitle); // Fill the inventory and return for (BiomeItem i : items) { newPanel.addItem(i.getItem()); } return newPanel; } else { player.sendMessage(ChatColor.RED + plugin.myLocale().errorCommandNotReady); plugin.getLogger().warning("There are no biomes in config.yml so /island biomes will not work!"); } return null; }
From source file:cn.vlabs.duckling.vwb.ui.action.emailnotify.EmailSubscribeSettingAction.java
private boolean isValidPageName(String pagename) { if ("*".equals(pagename)) return true; return StringUtils.isNumeric(pagename); }
From source file:fr.paris.lutece.plugins.directory.service.record.DirectoryRecordExtendableResourceService.java
/** * {@inheritDoc}//from w w w. ja v a2 s.c om */ @Override public IExtendableResource getResource(String strIdResource, String strResourceType) { if (StringUtils.isNotBlank(strIdResource) && StringUtils.isNumeric(strIdResource)) { int nIdRecord = Integer.parseInt(strIdResource); Plugin plugin = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME); Record record = RecordHome.findByPrimaryKey(nIdRecord, plugin); List<Integer> listIdRecord = new ArrayList<Integer>(1); listIdRecord.add(nIdRecord); record.setListRecordField(RecordFieldHome.getRecordFieldListByRecordIdList(listIdRecord, plugin)); return record; } return null; }
From source file:elaborate.editor.resources.orm.SearchResource.java
@GET @Path("{search_id:[0-9]+}") @Produces(UTF8MediaType.APPLICATION_JSON) public Response getSearchResults(// @PathParam("project_id") long projectId, // @PathParam("search_id") long searchId, // @QueryParam("start") @DefaultValue("0") String startString, // @QueryParam("rows") @DefaultValue("25") String rowsString// // @QueryParam("verbose") @DefaultValue("false") boolean verbose// ) {//from www . j a v a 2 s . c o m if (!StringUtils.isNumeric(startString) || !StringUtils.isNumeric(rowsString)) { throw new BadRequestException(); } int start = Integer.valueOf(startString); int rows = Integer.valueOf(rowsString); Map<String, Object> searchResult = searchService.getSearchResult(projectId, searchId, start, rows, user); addPrevNextURIs(searchResult, projectId, searchId, start, rows); ResponseBuilder builder = Response.ok(searchResult); return builder.build(); }
From source file:net.mindengine.oculus.frontend.web.controllers.issue.IssueSearchController.java
@SuppressWarnings("unchecked") @Override//from w w w . j a v a2s . co m protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { IssueSearchFilter filter = (IssueSearchFilter) command; filter.setColumns(columnFactory.getColumnList()); Map map = new HashMap<String, Object>(); map.put("columns", columnFactory.getColumnList()); if (filter.getProject() != null && filter.getProject().equals("0")) { filter.setProject(""); } /* * Collecting customization search criteria parameters */ filter.setCustomizations(CustomizationUtils.collectCustomizationSearchCriteriaParameters(request)); if (filter.getProject() != null && !filter.getProject().isEmpty()) { if (StringUtils.isNumeric(filter.getProject())) { map.put("customizations", CustomizationUtils.fetchCustomizationGroups(customizationDAO, userDAO, Long.parseLong(filter.getProject()), Customization.UNIT_ISSUE, filter.getCustomizations())); } } map.put("issues", issueDAO.searchIssues(filter)); map.put("rootProjects", projectDAO.getRootProjects()); map.put("columnFactory", columnFactory); map.put("searchFilter", filter); map.put("title", getTitle()); return map; }
From source file:net.mindengine.oculus.frontend.web.controllers.project.build.BuildSearchController.java
@SuppressWarnings("unchecked") @Override//from ww w . j a v a 2s.c om protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { BuildSearchFilter filter = (BuildSearchFilter) command; filter.setColumns(columnFactory.getColumnList()); Map map = new HashMap<String, Object>(); map.put("columns", columnFactory.getColumnList()); if (filter.getProject() != null && filter.getProject().equals("0")) { filter.setProject(""); } /* * Collecting customization search criteria parameters */ filter.setCustomizations(CustomizationUtils.collectCustomizationSearchCriteriaParameters(request)); if (filter.getProject() != null && !filter.getProject().isEmpty()) { if (StringUtils.isNumeric(filter.getProject())) { map.put("customizations", CustomizationUtils.fetchCustomizationGroups(customizationDAO, userDAO, Long.parseLong(filter.getProject()), Customization.UNIT_BUILD, filter.getCustomizations())); } } map.put("builds", buildDAO.searchBuilds(filter)); map.put("rootProjects", projectDAO.getRootProjects()); map.put("columnFactory", columnFactory); map.put("searchFilter", filter); map.put("title", getTitle()); return map; }
From source file:morphy.command.SetCommand.java
public void process(String arguments, UserSession userSession) { int pos = arguments.indexOf(" "); if (!arguments.startsWith("busy") && pos == -1) { userSession.send(getContext().getUsage()); return;//from w w w . j av a 2 s . c o m } if (arguments.equals("busy")) { pos = arguments.length(); } String setWhat = arguments.substring(0, pos).trim(); String message = arguments.substring(pos).trim(); variables[] varr = variables.values(); java.util.Arrays.sort(varr); variables[] v = findAllMatches(varr, setWhat); //System.out.println(java.util.Arrays.toString(v)); if (StringUtils.isNumeric(setWhat)) { // finger notes int val = Integer.parseInt(setWhat); if (val >= 1 && val <= UserInfoList.MAX_NOTES) { List<String> notes = userSession.getUser().getUserInfoLists().get(UserInfoList.notes); if (notes == null) { notes = new ArrayList<String>(UserInfoList.MAX_NOTES); userSession.getUser().getUserInfoLists().put(UserInfoList.notes, notes); } if (notes.size() == 0) { while (notes.size() < 10) { notes.add(""); } } notes.set(val - 1, message); //Plan line 6 changed to 'hi'. //Plan line 6 cleared. String returnmess = (message.equals("") ? "Plan line " + val + " cleared." : "Plan line " + val + " changed to '" + message + "'."); userSession.send(returnmess); return; } else { userSession.send("No such variable \"" + val + "\"."); return; } } else if (setWhat.matches("f[1-9]")) { // var notes } else if (v.length > 0) { // variables if (v.length > 1) { StringBuilder errmess = new StringBuilder("Ambiguous variable \"" + setWhat + "\". Matches: "); for (int i = 0; i < v.length; i++) { variables elem = v[i]; errmess.append(elem.name()); if (i != v.length - 1) errmess.append(" "); } userSession.send(errmess.toString()); return; } if (v.length == 1) { variables var = v[0]; if (var.getType().equals(Integer.class) && !StringUtils.isNumeric(message)) { if (message.equalsIgnoreCase("true")) message = "1"; else if (message.equalsIgnoreCase("false")) message = "0"; else { userSession.send("Bad value given for variable \"" + var.getName() + "\"."); return; } } // no validation for string inputs... morphy.user.UserVars uv = userSession.getUser().getUserVars(); // TODO finish this. String returnmessage = ""; String setOrUnset = (message.equals("1") ? "set" : "unset"); String nowOrNot = (message.equals("1") ? "now" : "not"); String onOrOff = (message.equals("1") ? "on" : "off"); try { switch (var) { case time: if (!StringUtils.isNumeric(message)) throw new BadValueException("time"); returnmessage = "Default time set to " + message + "."; break; case inc: if (!StringUtils.isNumeric(message)) throw new BadValueException("time"); returnmessage = "Default increment set to " + message + "."; break; case rated: if (!is0or1(message)) throw new BadValueException("rated"); if (!userSession.getUser().isRegistered()) returnmessage = "Unregistered users cannot change their rated status."; else returnmessage = "Games will be " + (message.equals("1") ? "rated" : "unrated") + " by default."; break; case open: if (!is0or1(message)) throw new BadValueException("open"); returnmessage = "You are " + (message.equals("1") ? "now open to receive" : "no longer receiving") + " match requests."; break; case tourney: if (!is0or1(message)) throw new BadValueException("tourney"); returnmessage = "Your tournament variable is " + (message.equals("1") ? "now" : "no longer") + " set."; break; case provshow: if (!is0or1(message)) throw new BadValueException("provshow"); returnmessage = "Provisional or inactive ratings will now" + (message.equals("0") ? " not" : "") + " be marked."; break; case autoflag: if (!is0or1(message)) throw new BadValueException("autoflag"); returnmessage = "Auto-flagging " + (message.equals("1") ? "enabled" : "disabled") + "."; break; case minmovetime: if (!is0or1(message)) throw new BadValueException("minmovetime"); returnmessage = "You will" + (message.equals("1") ? "" : " not") + " request minimum move time when games start."; break; case myprivate: if (!is0or1(message)) throw new BadValueException("private"); returnmessage = "Your games will" + (message.equals("1") ? "" : " not") + " be private."; break; case jprivate: if (!userSession.getUser().isRegistered()) returnmessage = "Only registered players may keep a journal."; else returnmessage = "Your journal will" + (message.equals("1") ? "" : " not") + " be private."; if (!is0or1(message)) throw new BadValueException("jprivate"); break; case automail: if (!userSession.getUser().isRegistered()) returnmessage = "Unregistered players may not have games mailed."; else returnmessage = ""; if (!is0or1(message)) throw new BadValueException("automail"); break; case pgn: if (!is0or1(message)) throw new BadValueException("pgn"); returnmessage = "Games will now be mailed to you in " + (message.equals("1") ? "PGN" : "server format") + "."; break; case mailmess: if (!userSession.getUser().isRegistered()) returnmessage = "Unregistered players may not receive messages."; else returnmessage = ""; if (!is0or1(message)) throw new BadValueException("mailmess"); break; case messreply: if (!userSession.getUser().isRegistered()) returnmessage = "Unregistered players cannot use this variable."; else returnmessage = ""; if (!is0or1(message)) throw new BadValueException("messreply"); break; case unobserve: if (message.equals("1")) returnmessage = "You will now only auto unobserve on matches."; if (message.equals("2")) returnmessage = "You will now only auto unobserve on examine."; if (message.equals("3")) returnmessage = "You will not auto unobserve."; if (!message.matches("[1|2|3]")) throw new BadValueException("unobserve"); break; case shout: if (!is0or1(message)) throw new BadValueException("shout"); returnmessage = "You will " + nowOrNot + " hear shouts."; break; case cshout: if (!is0or1(message)) throw new BadValueException("cshout"); returnmessage = "You will " + nowOrNot + " hear cshouts."; break; case kibitz: if (!is0or1(message)) throw new BadValueException("kibitz"); returnmessage = "You will " + nowOrNot + " hear kibitzes."; break; case kiblevel: if (Integer.parseInt(message) < 0 || Integer.parseInt(message) >= 10000) throw new BadValueException("kiblevel"); returnmessage = "Kibitz level now set to " + message + "."; break; case tell: if (!is0or1(message)) throw new BadValueException("tell"); if (message.equals("0")) returnmessage = "You will not hear direct tells from unregistered users."; if (message.equals("1")) returnmessage = "You will now hear direct tells from all users."; break; case ctell: if (!is0or1(message)) throw new BadValueException("ctell"); if (message.equals("0")) returnmessage = "You will not hear channel tells from unregistered users."; if (message.equals("1")) returnmessage = "You will now hear channel tells from all users."; break; case chanoff: if (!is0or1(message)) throw new BadValueException("chanoff"); returnmessage = "You will " + nowOrNot + " hear channel tells."; break; case silence: if (!is0or1(message)) throw new BadValueException("silence"); returnmessage = "You will now" + (message.equals("0") ? " not" : "") + " play games in silence."; break; case echo: if (!is0or1(message)) throw new BadValueException("echo"); returnmessage = "You will now" + (message.equals("0") ? " not" : "") + " hear communications echoed."; break; case pin: if (!is0or1(message)) throw new BadValueException("pin"); returnmessage = "You will " + nowOrNot + " hear logins/logouts."; break; case notifiedby: if (!is0or1(message)) throw new BadValueException("notifiedby"); returnmessage = "You will " + nowOrNot + " hear if people notify you, but you don't notify them."; break; case availinfo: if (!is0or1(message)) throw new BadValueException("availinfo"); returnmessage = "You will" + (message.equals("0") ? " not" : "") + " receive info on who is available to play."; break; case seek: if (!is0or1(message)) throw new BadValueException("seek"); returnmessage = "You will " + nowOrNot + " see seek ads."; break; case bugopen: if (!is0or1(message)) throw new BadValueException("bugopen"); returnmessage = "You are " + nowOrNot + " open for bughouse."; break; case tolerance: if (!message.matches("[1|2|3|4|5]")) throw new BadValueException("tolerance"); returnmessage = "Tolerance level set to " + message + "."; break; case bell: if (!is0or1(message)) throw new BadValueException("bell"); returnmessage = "Bell " + onOrOff + "."; break; case availmin: case availmax: if (!is0or1(message)) throw new BadValueException(var.name()); if (Integer.parseInt(uv.getVariables().get("availmin")) > Integer .parseInt(uv.getVariables().get("availmax"))) returnmessage = "You can't set availmin to more than availmax."; else returnmessage = "You will be notified of availability with blitz ratings " + uv.getVariables().get("availmin") + " - " + uv.getVariables().get("availmax") + "."; break; case gin: if (!is0or1(message)) throw new BadValueException("gin"); returnmessage = "You will " + nowOrNot + " hear game results."; break; case showownseek: if (!is0or1(message)) throw new BadValueException("showownseek"); returnmessage = "You will " + nowOrNot + " see your own seeks."; break; case examine: if (!is0or1(message)) throw new BadValueException("examine"); returnmessage = "You will now" + (message.equals("0") ? " not" : "") + " enter examine mode after a game."; break; case noescape: if (!is0or1(message)) throw new BadValueException("noescape"); returnmessage = "You will" + (message.equals("0") ? " not" : "") + " request noescape when games start."; break; case style: if (!StringUtils.isNumeric(message)) throw new BadValueException("style"); int style = Integer.parseInt(message); if (style < 1 || style > 13) throw new BadValueException("style"); returnmessage = "Style " + message + " set."; break; case flip: if (!is0or1(message)) throw new BadValueException("flip"); returnmessage = "Flip " + onOrOff + "."; break; case highlight: if (Integer.parseInt(message) < 1 || Integer.parseInt(message) > 15) throw new BadValueException("highlight"); returnmessage = "Highlight is now style " + message + "."; break; case width: if (Integer.parseInt(message) < 32 || Integer.parseInt(message) > 240) throw new BadValueException("width"); returnmessage = "Width set to " + message + "."; break; case height: if (Integer.parseInt(message) < 5 || Integer.parseInt(message) > 240) throw new BadValueException("width"); returnmessage = "Height set to " + message + "."; break; case ptime: if (!is0or1(message)) throw new BadValueException("ptime"); if (message.equals("0")) returnmessage = "Your prompt will now not show the time."; if (message.equals("1")) returnmessage = "Your prompt will now show the time (SERVER)."; break; case tzone: { message = message.toUpperCase(); TimeZone tz = TimeZoneUtils.getTimeZone(message); if (message.equals("GMT") && tz.equals(TimeZone.getTimeZone("GMT"))) returnmessage = "Invalid timezone - see 'help timezones'"; returnmessage = "Timezone set to " + message.toUpperCase() + " (GMT ...)."; break; } case lang: { String[] arr = getDistinctLocalesByLanguage(); java.util.Arrays.sort(arr); int index = java.util.Arrays.binarySearch(arr, message); if (index != Math.abs(index)) { throw new BadValueException("lang"); } else { returnmessage = "Language set to " + message + "."; } break; } case notakeback: if (!is0or1(message)) throw new BadValueException("notakeback"); returnmessage = "You will " + nowOrNot + " allow takebacks."; break; case myinterface: returnmessage = ""; break; case prompt: returnmessage = "Prompt set to \"" + message + "\""; break; case busy: { if (message.equals("")) { returnmessage = "Your \"busy\" string was cleared."; break; } else { returnmessage = "Your \"busy\" string was set to \"" + message + "\"."; break; } } default: returnmessage = var.getName() + " " + setOrUnset + "."; } uv.update(setWhat.toLowerCase(), message); if (var == variables.style) { int style = Integer.parseInt(message); StyleInterface si = null; si = getStyle(style); if (si == null) { userSession.send("That style is not available at this time, please try again later."); } else { userSession.getUser().getUserVars().setStyle(si); } } RequestService rq = RequestService.getInstance(); if (var == VariablesCommand.variables.open && message.equals("0")) { final String myUsername = userSession.getUser().getUserName(); List<Request> list = rq.findAllToRequestsByType(userSession, MatchRequest.class); if (list != null) { for (Request r : list) { r.getFrom().send(String.format( "%s, whom you were challenging, has become unavailable for matches.\nChallenge to %s withdrawn.", myUsername, myUsername)); rq.removeRequest(r); userSession.send(String.format("Challenge from %s removed.", r.getFrom().getUser().getUserName())); } } } if (var == variables.bugopen && message.equals("0")) { final String myUsername = userSession.getUser().getUserName(); List<Request> list = rq.findAllToRequestsByType(userSession, PartnershipRequest.class); for (Request r : list) { r.getFrom().send(String.format( "%s, whom you were offering a partnership with, has become unavailable for bughouse.\n" + "Partnership offer to %s withdrawn.", myUsername, myUsername)); rq.removeRequest(r); userSession.send(String.format("Partnership offer from %s removed.", r.getFrom().getUser().getUserName())); } } userSession.send(returnmessage); } catch (BadValueException e) { userSession.send(e.getMessage()); } } } else { userSession.send(String.format("No such variable \"%s\".", setWhat)); } }
From source file:com.hmsinc.epicenter.integrator.service.event.DischargeService.java
public Discharge handleEvent(HL7Message message, PatientDetail details) throws Exception { Validate.notNull(message);/*from w w w. ja v a 2 s. c om*/ Validate.notNull(details); // Make sure we have a patientId if (details.getPatient().getPatientId() == null) { throw new IncompleteDataException("No patient ID in message.", IncompleteDataType.PATIENT_ID); } final Discharge discharge = new Discharge(); configureInteraction(message, discharge, details); Validate.isTrue(message.getMessage() instanceof ADT_A03); final ADT_A03 adt = (ADT_A03) message.getMessage(); // Visit number (PV1-19) - REQUIRED FOR DISCHARGE discharge.setVisitNumber(StringUtils.trimToNull(adt.getPV1().getVisitNumber().getIDNumber().getValue())); if (discharge.getVisitNumber() == null) { throw new IncompleteDataException("No visit number in message.", IncompleteDataType.VISIT_NUMBER); } // Disposition (PV1-36) final IS disposition = adt.getPV1().getDischargeDisposition(); if (disposition == null) { throw new IncompleteDataException("No discharge disposition in message.", IncompleteDataType.DISCHARGE_DISPOSITION); } discharge.setDisposition(disposition.getValue()); // Parse integer since that's the main thing we'll use here. if (StringUtils.isNumeric(discharge.getDisposition())) { discharge.setDisposition(Integer.valueOf(discharge.getDisposition()).toString()); } // Discharge date (PV1-44) discharge.setInteractionDate(extractDate(adt.getPV1().getDischargeDateTime(0).getTime(), message)); if (logger.isDebugEnabled()) { logger.debug(discharge.toString()); } return discharge; }