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:com.kegare.caveworld.util.CaveConfiguration.java
@Override public int compare(String o1, String o2) { int result = CaveUtils.compareWithNull(o1, o2); if (result == 0 && o1 != null && o2 != null) { boolean flag1 = NumberUtils.isNumber(o1); boolean flag2 = NumberUtils.isNumber(o2); result = Boolean.compare(flag1, flag2); if (result == 0) { if (flag1 && flag2) { result = Integer.compare(NumberUtils.toInt(o1), NumberUtils.toInt(o2)); } else if (!flag1 && !flag2) { result = o1.compareTo(o2); }/* w w w .j a va 2 s . co m*/ } } return result; }
From source file:lineage2.gameserver.handler.admincommands.impl.AdminDelete.java
/** * Method useAdminCommand./* ww w . j a v a 2 s. c om*/ * @param comm Enum<?> * @param wordList String[] * @param fullString String * @param activeChar Player * @return boolean * @see lineage2.gameserver.handler.admincommands.IAdminCommandHandler#useAdminCommand(Enum<?>, String[], String, Player) */ @Override public boolean useAdminCommand(Enum<?> comm, String[] wordList, String fullString, Player activeChar) { Commands command = (Commands) comm; if (!activeChar.getPlayerAccess().CanEditNPC) { return false; } switch (command) { case admin_delete: GameObject obj = wordList.length == 1 ? activeChar.getTarget() : GameObjectsStorage.getNpc(NumberUtils.toInt(wordList[1])); if ((obj != null) && obj.isNpc()) { NpcInstance target = (NpcInstance) obj; target.deleteMe(); Spawner spawn = target.getSpawn(); if (spawn != null) { spawn.stopRespawn(); } CustomSpawnTable.getInstance().deleteSpawn(target); } else { activeChar.sendPacket(Msg.INVALID_TARGET); } break; } return true; }
From source file:io.servicecomb.swagger.SwaggerUtils.java
public static void correctResponses(Operation operation) { int okCode = Status.OK.getStatusCode(); String strOkCode = String.valueOf(okCode); Response okResponse = null;/*from www . j a v a 2s . c om*/ for (Entry<String, Response> responseEntry : operation.getResponses().entrySet()) { Response response = responseEntry.getValue(); if (StringUtils.isEmpty(response.getDescription())) { response.setDescription("response of " + responseEntry.getKey()); } if (operation.getResponses().get(strOkCode) != null) { continue; } int statusCode = NumberUtils.toInt(responseEntry.getKey()); if ("default".equals(responseEntry.getKey())) { statusCode = okCode; } if (Family.SUCCESSFUL.equals(Family.familyOf(statusCode))) { okResponse = response; } } if (okResponse != null) { operation.addResponse(strOkCode, okResponse); } }
From source file:gov.nih.nci.caintegrator.domain.genomic.ChromosomalLocation.java
private int compareChromosomeStrings(ChromosomalLocation location) { if (NumberUtils.isNumber(getChromosome()) && NumberUtils.isNumber(location.getChromosome())) { return Ints.compare(NumberUtils.toInt(getChromosome()), NumberUtils.toInt(location.getChromosome())); } else {/*from ww w. j av a 2s .co m*/ return getChromosome().compareTo(location.getChromosome()); } }
From source file:com.cognifide.aet.job.common.modifiers.resolution.ResolutionModifier.java
@Override public void setParameters(Map<String, String> params) throws ParametersException { String paramValue = params.get(PARAM_MAXIMIZE); maximize = Boolean.valueOf(paramValue); if (params.containsKey(WIDTH_PARAM) && params.containsKey(HEIGHT_PARAM)) { width = NumberUtils.toInt(params.get(WIDTH_PARAM)); ParametersValidator.checkRange(width, 1, MAX_SIZE, "Width should be greater than 0"); height = NumberUtils.toInt(params.get(HEIGHT_PARAM)); ParametersValidator.checkRange(height, 1, MAX_SIZE, "Height should be greater than 0"); ParametersValidator.checkParameter(!maximize, "You cannot maximize the window and specify the dimension"); } else if (params.containsKey(WIDTH_PARAM) || params.containsKey(HEIGHT_PARAM)) { throw new ParametersException("You have to specify both width and height"); }//from ww w .j a v a 2s.c om }
From source file:com.moviejukebox.plugin.MovieMeterPlugin.java
private static boolean updateMediaInfo(Movie movie, String moviemeterId) { FilmInfo filmInfo;// w ww . j a v a2s . co m try { filmInfo = api.getFilm(NumberUtils.toInt(moviemeterId)); } catch (MovieMeterException ex) { LOG.warn("Failed to get MovieMeter information for ID '{}', error: {}", moviemeterId, ex.getMessage(), ex); return false; } movie.setId(IMDB_PLUGIN_ID, filmInfo.getImdbId()); if (OverrideTools.checkOverwriteTitle(movie, MOVIEMETER_PLUGIN_ID)) { movie.setTitle(filmInfo.getDisplayTitle(), MOVIEMETER_PLUGIN_ID); } if (OverrideTools.checkOverwriteOriginalTitle(movie, MOVIEMETER_PLUGIN_ID)) { movie.setOriginalTitle(filmInfo.getAlternativeTitle(), MOVIEMETER_PLUGIN_ID); } if (OverrideTools.checkOverwriteYear(movie, MOVIEMETER_PLUGIN_ID)) { movie.setYear(Integer.toString(filmInfo.getYear()), MOVIEMETER_PLUGIN_ID); } if (OverrideTools.checkOverwritePlot(movie, MOVIEMETER_PLUGIN_ID)) { movie.setPlot(filmInfo.getPlot(), MOVIEMETER_PLUGIN_ID); } if (OverrideTools.checkOverwriteOutline(movie, MOVIEMETER_PLUGIN_ID)) { movie.setOutline(filmInfo.getPlot(), MOVIEMETER_PLUGIN_ID); } if (OverrideTools.checkOverwriteRuntime(movie, MOVIEMETER_PLUGIN_ID)) { movie.setRuntime(Integer.toString(filmInfo.getDuration()), MOVIEMETER_PLUGIN_ID); } movie.addRating(MOVIEMETER_PLUGIN_ID, (int) (filmInfo.getAverage() * 10f)); if (OverrideTools.checkOverwriteCountry(movie, MOVIEMETER_PLUGIN_ID)) { movie.setCountries(filmInfo.getCountries(), MOVIEMETER_PLUGIN_ID); } if (OverrideTools.checkOverwriteGenres(movie, MOVIEMETER_PLUGIN_ID)) { movie.setGenres(filmInfo.getGenres(), MOVIEMETER_PLUGIN_ID); } if (OverrideTools.checkOverwriteActors(movie, MOVIEMETER_PLUGIN_ID)) { for (Actor a : filmInfo.getActors()) { movie.addActor(a.getName(), MOVIEMETER_PLUGIN_ID); } } if (OverrideTools.checkOverwriteDirectors(movie, MOVIEMETER_PLUGIN_ID)) { for (String d : filmInfo.getDirectors()) { movie.addDirector(d, MOVIEMETER_PLUGIN_ID); } } return true; }
From source file:io.wcm.handler.media.impl.ImageFileServlet.java
@Override protected byte[] getBinaryData(Resource resource, SlingHttpServletRequest request) throws IOException { // get media app config MediaHandlerConfig config = AdaptTo.notNull(request, MediaHandlerConfig.class); // check for image scaling parameters int width = 0; int height = 0; String[] selectors = request.getRequestPathInfo().getSelectors(); if (selectors.length >= 3) { width = NumberUtils.toInt(selectors[1]); height = NumberUtils.toInt(selectors[2]); }//from w ww . j av a 2 s . c o m if (width <= 0 || height <= 0) { return null; } // check for cropping parameter CropDimension cropDimension = null; if (selectors.length >= 4) { String cropString = selectors[3]; try { cropDimension = CropDimension.fromCropString(cropString); } catch (IllegalArgumentException ex) { // ignore } } // if resizing requested rescale via layer Layer layer = resource.adaptTo(Layer.class); if (layer == null) { return null; } // if required: crop image if (cropDimension != null) { layer.crop(cropDimension.getRectangle()); } // resize layer if (width <= layer.getWidth() && height <= layer.getHeight()) { layer.resize(width, height); } // stream to byte array ByteArrayOutputStream bos = new ByteArrayOutputStream(); String contentType = getContentType(resource, request); layer.write(contentType, config.getDefaultImageQuality(contentType), bos); bos.flush(); return bos.toByteArray(); }
From source file:com.uwsoft.editor.view.ui.box.UIZoomBoxMediator.java
@Override public void handleNotification(Notification notification) { super.handleNotification(notification); Sandbox sandbox = Sandbox.getInstance(); switch (notification.getName()) { case ProjectManager.PROJECT_OPENED: viewComponent.update();// w w w. j ava 2s.c o m viewComponent.setCurrentZoom(sandbox.getZoomPercent() + ""); break; case UIZoomBox.ZOOM_SHIFT_REQUESTED: float zoomDevider = notification.getBody(); sandbox.zoomDevideBy(zoomDevider); break; case UIZoomBox.ZOOM_VALUE_CHANGED: sandbox.setZoomPercent(NumberUtils.toInt(viewComponent.getCurrentZoom())); facade.sendNotification(MsgAPI.ZOOM_CHANGED); break; case MsgAPI.ZOOM_CHANGED: viewComponent.setCurrentZoom(sandbox.getZoomPercent() + ""); break; } }
From source file:com.o2d.pkayjava.editor.view.ui.box.UIZoomBoxMediator.java
@Override public void handleNotification(Notification notification) { super.handleNotification(notification); Sandbox sandbox = Sandbox.getInstance(); if (ProjectManager.PROJECT_OPENED.equals(notification.getName())) { viewComponent.update();/* w ww . j a va 2s . c o m*/ viewComponent.setCurrentZoom(sandbox.getZoomPercent() + ""); } else if (UIZoomBox.ZOOM_SHIFT_REQUESTED.equals(notification.getName())) { float zoomDevider = notification.getBody(); sandbox.zoomDevideBy(zoomDevider); } else if (UIZoomBox.ZOOM_VALUE_CHANGED.equals(notification.getName())) { sandbox.setZoomPercent(NumberUtils.toInt(viewComponent.getCurrentZoom())); facade.sendNotification(Overlap2D.ZOOM_CHANGED); } else if (Overlap2D.ZOOM_CHANGED.equals(notification.getName())) viewComponent.setCurrentZoom(sandbox.getZoomPercent() + ""); }
From source file:com.blackducksoftware.integration.hub.detect.property.PropertyConverter.java
private Integer convertToInt(final String integerString) { if (null == integerString) { return null; }/*from w w w . ja v a2s . c o m*/ return NumberUtils.toInt(integerString); }