下面列出了org.apache.commons.lang3.math.NumberUtils#toInt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Update the order of an assignment in the gradebook This is a per site setting.
*
* @param ref
* @param params map, must include: siteId assignmentId new order
*
* an assignmentorder object will be created and saved as a list in the XML property 'gbng_assignment_order'
*/
@SuppressWarnings("unused")
@EntityCustomAction(action = "assignment-order", viewKey = EntityView.VIEW_NEW)
public void updateAssignmentOrder(final EntityReference ref, final Map<String, Object> params) {
// get params
final String siteId = (String) params.get("siteId");
final long assignmentId = NumberUtils.toLong((String) params.get("assignmentId"));
final int order = NumberUtils.toInt((String) params.get("order"));
// check params supplied are valid
if (StringUtils.isBlank(siteId) || assignmentId == 0 || order < 0) {
throw new IllegalArgumentException(
"Request data was missing / invalid");
}
checkValidSite(siteId);
// check instructor
checkInstructor(siteId);
// update the order
this.businessService.updateAssignmentOrder(siteId, assignmentId, order);
}
/**
* Creates instance of the adaptor.
* @param def broker definition
* @throws IllegalArgumentException if invalid broker definition
*/
public AgpInputBrokerDefinitionAdaptor(EntityDefinition def) throws InvalidDefinitionException {
super(def);
this.credAdaptor =new CredentialsDefinitionAdaptor(def);
this.botsAdaptor = new BotsBrokerDefinitionAdaptor(def);
if (StringUtils.trimToEmpty(def.getType()).isEmpty()) {
def.setType(AgpInputConnector.TYPE);
} else if (!AgpInputConnector.TYPE.equals(def.getType())) {
throw new InvalidDefinitionException("Broker definition doesn't match");
} else {
try {
hostUrl = new URL(get(P_HOST_URL));
} catch (MalformedURLException ex) {
throw new InvalidDefinitionException(String.format("Invalid %s: %s", P_HOST_URL,get(P_HOST_URL)), ex);
}
folderId = get(P_FOLDER_ID);
emitXml = BooleanUtils.toBooleanDefaultIfNull(BooleanUtils.toBooleanObject(get(P_EMIT_XML)), true);
emitJson = BooleanUtils.toBooleanDefaultIfNull(BooleanUtils.toBooleanObject(get(P_EMIT_JSON)), false);
metaFormat = MetadataFormat.parse(get(P_EMIT_XML_FMT), MetadataFormat.DEFAULT);
maxRedirects = NumberUtils.toInt(get(P_MAX_REDIRECTS), DEFAULT_MAX_REDIRECTS);
}
}
public Object find(String[] paths) throws Exception {
Object o = this;
for (String path : paths) {
if (StringUtils.isEmpty(path) || (null == o)) {
o = null;
break;
}
if (StringUtils.isNumeric(path)) {
if (o instanceof List) {
int idx = NumberUtils.toInt(path);
List<?> c = (List<?>) o;
if ((idx >= c.size()) || (idx < 0)) {
o = null;
break;
}
o = c.get(idx);
} else {
o = null;
break;
}
} else {
o = PropertyUtils.getProperty(o, path);
}
}
return o;
}
public void onPersist() throws Exception {
this.path0 = StringUtils.trimToEmpty(this.path0);
this.path1 = StringUtils.trimToEmpty(this.path1);
this.path2 = StringUtils.trimToEmpty(this.path2);
this.path3 = StringUtils.trimToEmpty(this.path3);
this.path4 = StringUtils.trimToEmpty(this.path4);
this.path5 = StringUtils.trimToEmpty(this.path5);
this.path6 = StringUtils.trimToEmpty(this.path6);
this.path7 = StringUtils.trimToEmpty(this.path7);
this.path0Location = NumberUtils.toInt(this.path0, -1);
this.path1Location = NumberUtils.toInt(this.path1, -1);
this.path2Location = NumberUtils.toInt(this.path2, -1);
this.path3Location = NumberUtils.toInt(this.path3, -1);
this.path4Location = NumberUtils.toInt(this.path4, -1);
this.path5Location = NumberUtils.toInt(this.path5, -1);
this.path6Location = NumberUtils.toInt(this.path6, -1);
this.path7Location = NumberUtils.toInt(this.path7, -1);
}
public void onPersist() throws Exception {
this.path0 = StringUtils.trimToEmpty(this.path0);
this.path1 = StringUtils.trimToEmpty(this.path1);
this.path2 = StringUtils.trimToEmpty(this.path2);
this.path3 = StringUtils.trimToEmpty(this.path3);
this.path4 = StringUtils.trimToEmpty(this.path4);
this.path5 = StringUtils.trimToEmpty(this.path5);
this.path6 = StringUtils.trimToEmpty(this.path6);
this.path7 = StringUtils.trimToEmpty(this.path7);
this.path0Location = NumberUtils.toInt(this.path0, -1);
this.path1Location = NumberUtils.toInt(this.path1, -1);
this.path2Location = NumberUtils.toInt(this.path2, -1);
this.path3Location = NumberUtils.toInt(this.path3, -1);
this.path4Location = NumberUtils.toInt(this.path4, -1);
this.path5Location = NumberUtils.toInt(this.path5, -1);
this.path6Location = NumberUtils.toInt(this.path6, -1);
this.path7Location = NumberUtils.toInt(this.path7, -1);
}
TagTab load(String tag)
{
TagTab tagTab = find(tag);
if (tagTab == null)
{
tag = Text.standardize(tag);
String item = configManager.getConfiguration(CONFIG_GROUP, ICON_SEARCH + tag);
int itemid = NumberUtils.toInt(item, ItemID.SPADE);
tagTab = new TagTab(itemid, tag);
}
return tagTab;
}
private static <P extends ParaObject> List<P> findNearbyQuery(MultivaluedMap<String, String> params,
String appid, String type, String query, Pager pager) {
String latlng = params.getFirst("latlng");
if (StringUtils.contains(latlng, ",")) {
String[] coords = latlng.split(",", 2);
String rad = paramOrDefault(params, "radius", null);
int radius = NumberUtils.toInt(rad, 10);
double lat = NumberUtils.toDouble(coords[0], 0);
double lng = NumberUtils.toDouble(coords[1], 0);
return Para.getSearch().findNearby(appid, type, query, radius, lat, lng, pager);
}
return Collections.emptyList();
}
private void createImage(HttpServletRequest request,
HttpServletResponse response) throws IOException {
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
/*
* 得到参数高,宽,都为数字时,则使用设置高宽,否则使用默认值
*/
String width = request.getParameter("width");
String height = request.getParameter("height");
if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) {
w = NumberUtils.toInt(width);
h = NumberUtils.toInt(height);
}
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
/*
* 生成背景
*/
createBackground(g);
/*
* 生成字符
*/
String s = createCharacter(g);
request.getSession().setAttribute(VALIDATE_CODE, s);
g.dispose();
OutputStream out = response.getOutputStream();
ImageIO.write(image, "JPEG", out);
out.close();
}
@Override
protected int getBulkCompanyId(HttpServletRequest req) {
final Object bulkGenerate = req.getSession().getAttribute("bulkGenerate");
if (bulkGenerate != null){
String companyIdString = req.getParameter("previewCompanyId");
return NumberUtils.toInt(companyIdString, -1);
}
return -1;
}
@FXML
public void updateMath1995() {
if( logger.isDebugEnabled() ) {
logger.debug("[UPD 1995]");
}
if( dao == null ) {
throw new IllegalArgumentException("dao has not been set; call setRecenteredDAO() before calling this method");
}
String recenteredScore_s = txtMathScoreRecentered.getText();
if(StringUtils.isNumeric(recenteredScore_s) ) {
Integer scoreRecentered = NumberUtils.toInt(recenteredScore_s);
if( withinRange(scoreRecentered) ) {
if( needsRound(scoreRecentered) ) {
scoreRecentered = round(scoreRecentered);
txtMathScoreRecentered.setText( String.valueOf(scoreRecentered));
}
resetErrMsgs();
Integer score1995 = dao.lookup1995MathScore(scoreRecentered);
txtMathScore1995.setText(String.valueOf(score1995));
} else {
errMsgMathRecentered.setVisible(true);
}
} else {
errMsgMathRecentered.setVisible(true);
}
}
@Override
public TargetSavingAndAnalysisResult saveTargetWithAnalysis(ComAdmin admin, ComTarget newTarget, ComTarget target, ActionMessages errors, UserActivityLog userActivityLog) throws Exception { // TODO: Remove "ActionMessages" to remove dependencies to Struts
if (target == null) {
// be sure to use id 0 if there is no existing object
newTarget.setId(0);
}
if (validateTargetDefinition(admin.getCompanyID(), newTarget.getEQL())) {
newTarget.setComplexityIndex(calculateComplexityIndex(newTarget.getEQL(), admin.getCompanyID()));
final int newId = targetDao.saveTarget(newTarget);
// Check for maximum "compare to"-value of gender equations
// Must be done after saveTarget(..)-call because there the new target sql expression is generated
if (newTarget.getTargetSQL().contains("cust.gender")) {
final int maxGenderValue = getMaxGenderValue(admin);
Matcher matcher = GENDER_EQUATION_PATTERN.matcher(newTarget.getTargetSQL());
while (matcher.find()) {
int genderValue = NumberUtils.toInt(matcher.group(1));
if (genderValue < 0 || genderValue > maxGenderValue) {
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.gender.invalid"));
break;
}
}
} else if (newTarget.getTargetSQL().equals("1=0")) {
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.target.definition"));
}
newTarget.setId(newId);
final EqlAnalysisResult analysisResultOrNull = this.eqlFacade.analyseEql(newTarget.getEQL());
logTargetGroupSave(admin, newTarget, target, userActivityLog);
return new TargetSavingAndAnalysisResult(newId, analysisResultOrNull);
} else {
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.target.definition"));
return new TargetSavingAndAnalysisResult(0, null);
}
}
@FXML
public void updateVerbalRecentered() {
if (logger.isDebugEnabled()) {
logger.debug("[UPD V RECENTERED]");
}
if( dao == null ) {
throw new IllegalArgumentException("dao has not been set; call setRecenteredDAO() before calling this method");
}
String score1995_s = txtVerbalScore1995.getText();
if(StringUtils.isNumeric(score1995_s) ) {
Integer score1995 = NumberUtils.toInt(score1995_s);
if( withinRange(score1995) ) {
if( needsRound(score1995) ) {
score1995 = round(score1995);
txtVerbalScore1995.setText( String.valueOf(score1995));
}
resetErrMsgs();
Integer scoreRecentered = dao.lookupRecenteredVerbalScore(score1995);
txtVerbalScoreRecentered.setText(String.valueOf(scoreRecentered));
} else {
errMsgVerbal1995.setVisible(true);
}
} else {
errMsgVerbal1995.setVisible(true);
}
}
/**
* 将10进制的String安全的转化为int,当str为空或非数字字符串时,返回default值
*/
public static int toInt(String str, int defaultValue) {
return NumberUtils.toInt(str, defaultValue);
}
public void setPage(String page) {
pageNumber = NumberUtils.toInt(page, 1);
this.page = page;
}
@Override
public Object filter(Object var, JinjavaInterpreter interpreter, String... args) {
ForLoop loop = ObjectIterator.getLoop(var);
if (args.length < 1) {
throw new TemplateSyntaxException(
interpreter,
getName(),
"requires 1 argument (number of slices)"
);
}
int slices = NumberUtils.toInt(args[0], 3);
if (slices <= 0) {
throw new InvalidArgumentException(
interpreter,
this,
InvalidReason.POSITIVE_NUMBER,
0,
args[0]
);
}
List<List<Object>> result = new ArrayList<>();
List<Object> currentList = null;
int i = 0;
while (loop.hasNext()) {
Object next = loop.next();
if (i % slices == 0) {
currentList = new ArrayList<>(slices);
result.add(currentList);
}
currentList.add(next);
i++;
}
if (args.length > 1 && currentList != null) {
Object fillWith = args[1];
while (currentList.size() < slices) {
currentList.add(fillWith);
}
}
return result;
}
public void setCompanyIdString(String companyId) {
this.companyId = NumberUtils.toInt(companyId);
}
/**
* @return the server port
*/
public static int getServerPort() {
int defaultPort = NumberUtils.toInt(System.getProperty("jetty.http.port"), Config.getConfigInt("port", 8080));
return NumberUtils.toInt(System.getProperty("server.port"), defaultPort);
}
public int getInt(String key)
{
return NumberUtils.toInt(getProperty(key));
}
public int getInt(String key, int defaultValue)
{
return NumberUtils.toInt(getProperty(key, Integer.toString(defaultValue)));
}
private void patchRemoveOperation(final String path, final Map<String, Object> matchedMap) {
if (path.contains("/")) {
final String[] paths = path.split("/");
Object obj = matchedMap;
for (int i=0; i < paths.length; i++) {
final String p = paths[i];
final boolean lastIteration = (i == (paths.length - 1));
if (obj instanceof List) {
final List l = ((List)obj);
if (lastIteration && "-".equals(p)) {
l.remove(0);
} else {
final int indx = NumberUtils.toInt(p, -1);
if (indx == -1) {
throw new StatefulValidationException(String.format(StatefulValidationException.PATH_STRUCTURE_MISALIGN, path));
}
if (l.size() <= indx) {
throw new StatefulValidationException(String.format(StatefulValidationException.PATH_OUT_OF_RANGE_LIST_INDEX, path, indx));
}
if (lastIteration) {
l.remove(indx);
} else {
obj = l.get(indx);
}
}
} else if (obj instanceof Map) {
final Map map = ((Map)obj);
if (lastIteration) {
if (!map.containsKey(p)) {
throw new StatefulValidationException(HttpStatus.SC_NOT_FOUND);
}
map.remove(p);
} else {
obj = map.get(p);
}
} else {
throw new StatefulValidationException(String.format(StatefulValidationException.PATH_STRUCTURE_MISALIGN, path));
}
}
} else {
if (!matchedMap.containsKey(path)) {
throw new StatefulValidationException(HttpStatus.SC_NOT_FOUND);
}
matchedMap.remove(path);
}
}