List of usage examples for java.lang Short parseShort
public static short parseShort(String s) throws NumberFormatException
From source file:ddf.catalog.impl.operations.OverrideAttributesSupport.java
private static AttributeImpl overrideAttributeValue(AttributeDescriptor attributeDescriptor, Serializable overrideValue) { List<Serializable> newValue = new ArrayList<>(); for (Object o : overrideValue instanceof List ? (List) overrideValue : Collections.singletonList(overrideValue)) { try {//from www. j a va2s. co m String override = String.valueOf(o); switch (attributeDescriptor.getType().getAttributeFormat()) { case INTEGER: newValue.add(Integer.parseInt(override)); break; case FLOAT: newValue.add(Float.parseFloat(override)); break; case DOUBLE: newValue.add(Double.parseDouble(override)); break; case SHORT: newValue.add(Short.parseShort(override)); break; case LONG: newValue.add(Long.parseLong(override)); break; case DATE: Calendar calendar = DatatypeConverter.parseDateTime(override); newValue.add(calendar.getTime()); break; case BOOLEAN: newValue.add(Boolean.parseBoolean(override)); break; case BINARY: newValue.add(override.getBytes(Charset.forName("UTF-8"))); break; case OBJECT: case STRING: case GEOMETRY: case XML: newValue.add(override); break; } } catch (IllegalArgumentException e) { return null; } } return new AttributeImpl(attributeDescriptor.getName(), newValue); }
From source file:com.ocdsoft.bacta.soe.json.schema.SoeDefaultRule.java
private JExpression getDefaultValue(JType fieldType, JsonNode node) { fieldType = fieldType.unboxify();/*w w w .ja va 2 s . co m*/ if (fieldType.fullName().equals(String.class.getName())) { return JExpr.lit(node.asText()); } else if (fieldType.fullName().equals(int.class.getName())) { return JExpr.lit(Integer.parseInt(node.asText())); } else if (fieldType.fullName().equals(short.class.getName())) { return JExpr.lit(Short.parseShort(node.asText())); } else if (fieldType.fullName().equals(byte.class.getName())) { return JExpr.lit(Byte.parseByte(node.asText())); } else if (fieldType.fullName().equals(double.class.getName())) { return JExpr.lit(Double.parseDouble(node.asText())); } else if (fieldType.fullName().equals(boolean.class.getName())) { return JExpr.lit(Boolean.parseBoolean(node.asText())); } else if (fieldType.fullName().equals(getDateType().getName())) { long millisecs = parseDateToMillisecs(node.asText()); JInvocation newDate = JExpr._new(fieldType); newDate.arg(JExpr.lit(millisecs)); return newDate; } else if (fieldType.fullName().equals(long.class.getName())) { return JExpr.lit(Long.parseLong(node.asText())); } else if (fieldType.fullName().equals(float.class.getName())) { return JExpr.lit(Float.parseFloat(node.asText())); } else if (fieldType instanceof JDefinedClass && ((JDefinedClass) fieldType).getClassType().equals(ClassType.ENUM)) { return getDefaultEnum(fieldType, node); } else { return JExpr._null(); } }
From source file:net.floodlightcontroller.loadbalancer.MembersResource.java
protected LBMember jsonToMember(String json) throws IOException { MappingJsonFactory f = new MappingJsonFactory(); JsonParser jp;//from w w w . j ava2 s .c om LBMember member = new LBMember(); try { jp = f.createJsonParser(json); } catch (JsonParseException e) { throw new IOException(e); } jp.nextToken(); if (jp.getCurrentToken() != JsonToken.START_OBJECT) { throw new IOException("Expected START_OBJECT"); } while (jp.nextToken() != JsonToken.END_OBJECT) { if (jp.getCurrentToken() != JsonToken.FIELD_NAME) { throw new IOException("Expected FIELD_NAME"); } String n = jp.getCurrentName(); jp.nextToken(); if (jp.getText().equals("")) continue; if (n.equals("id")) { member.id = jp.getText(); continue; } else if (n.equals("address")) { member.address = IPv4.toIPv4Address(jp.getText()); continue; } else if (n.equals("port")) { member.port = Short.parseShort(jp.getText()); continue; } else if (n.equals("connection_limit")) { member.connectionLimit = Integer.parseInt(jp.getText()); continue; } else if (n.equals("admin_state")) { member.adminState = Short.parseShort(jp.getText()); continue; } else if (n.equals("status")) { member.status = Short.parseShort(jp.getText()); continue; } else if (n.equals("pool_id")) { member.poolId = jp.getText(); continue; } log.warn("Unrecognized field {} in " + "parsing Members", jp.getText()); } jp.close(); return member; }
From source file:com.srotya.tau.ui.rules.RulesManager.java
public short saveRule(UserBean ub, Tenant tenant, Rule currRule) throws Exception { if (currRule == null || tenant == null) { logger.info("Rule was null can't save"); return -1; }/* w w w. ja v a 2 s.co m*/ RuleValidator.getInstance().validate(currRule); logger.info("Rule is valid attempting to save"); CloseableHttpClient client = Utils.buildClient(am.getBaseUrl(), am.getConnectTimeout(), am.getRequestTimeout()); HttpPut put = new HttpPut( am.getBaseUrl() + RULES_URL + "/" + tenant.getTenantId() + "/" + currRule.getRuleId()); if (am.isEnableAuth()) { put.addHeader(BapiLoginDAO.X_SUBJECT_TOKEN, ub.getToken()); put.addHeader(BapiLoginDAO.HMAC, ub.getHmac()); } StringEntity entity = new StringEntity(RuleSerializer.serializeRuleToJSONString(currRule, false), ContentType.APPLICATION_JSON); put.setEntity(entity); CloseableHttpResponse resp = client.execute(put); String result = EntityUtils.toString(resp.getEntity()); return Short.parseShort(result); }
From source file:com.nkapps.billing.controllers.OverpaymentController.java
@RequestMapping(value = "/return-save", method = RequestMethod.POST) public @ResponseBody HashMap<String, Object> returnSave(HttpServletRequest request, HttpServletResponse response) {/* w w w. j av a2 s . c om*/ HashMap<String, Object> resMap = new LinkedHashMap<String, Object>(); try { String bankStatementId = request.getParameter("bankStatementId"); Short returnState = Short.parseShort(request.getParameter("returnState")); BigDecimal returnSum = new BigDecimal(request.getParameter("returnSum")); Long issuerSerialNumber = authService.getCertificateInfo().getSerialNumber().longValue(); String issuerIp = authService.getClientIp(request); overpaymentService.saveReturnState(bankStatementId, returnState, returnSum, issuerSerialNumber, issuerIp); resMap.put("success", true); } catch (Exception e) { logger.error(e.getMessage()); resMap.put("success", false); resMap.put("reason", e.getMessage()); } return resMap; }
From source file:com.espertech.esper.regression.expr.TestPerRowFunc.java
public void testCoalesceLong() { EPStatement selectTestView = setupCoalesce("coalesce(longBoxed, intBoxed, shortBoxed)"); assertEquals(Long.class, selectTestView.getEventType().getPropertyType("result")); sendEvent(1L, 2, (short) 3); assertEquals(1L, testListener.assertOneGetNewAndReset().get("result")); sendBoxedEvent(null, 2, null);/* w w w. j a v a2 s.c o m*/ assertEquals(2L, testListener.assertOneGetNewAndReset().get("result")); sendBoxedEvent(null, null, Short.parseShort("3")); assertEquals(3L, testListener.assertOneGetNewAndReset().get("result")); sendBoxedEvent(null, null, null); assertEquals(null, testListener.assertOneGetNewAndReset().get("result")); }
From source file:net.floodlightcontroller.loadbalancer.PoolsResource.java
protected LBPool jsonToPool(String json) throws IOException { if (json == null) return null; MappingJsonFactory f = new MappingJsonFactory(); JsonParser jp;//w w w.java2s . co m LBPool pool = new LBPool(); try { jp = f.createJsonParser(json); } catch (JsonParseException e) { throw new IOException(e); } jp.nextToken(); if (jp.getCurrentToken() != JsonToken.START_OBJECT) { throw new IOException("Expected START_OBJECT"); } while (jp.nextToken() != JsonToken.END_OBJECT) { if (jp.getCurrentToken() != JsonToken.FIELD_NAME) { throw new IOException("Expected FIELD_NAME"); } String n = jp.getCurrentName(); jp.nextToken(); if (jp.getText().equals("")) continue; if (n.equals("id")) { pool.id = jp.getText(); continue; } if (n.equals("tenant_id")) { pool.tenantId = jp.getText(); continue; } if (n.equals("name")) { pool.name = jp.getText(); continue; } if (n.equals("network_id")) { pool.netId = jp.getText(); continue; } if (n.equals("lb_method")) { pool.lbMethod = Short.parseShort(jp.getText()); continue; } if (n.equals("protocol")) { String tmp = jp.getText(); if (tmp.equalsIgnoreCase("TCP")) { pool.protocol = IPv4.PROTOCOL_TCP; } else if (tmp.equalsIgnoreCase("UDP")) { pool.protocol = IPv4.PROTOCOL_UDP; } else if (tmp.equalsIgnoreCase("ICMP")) { pool.protocol = IPv4.PROTOCOL_ICMP; } continue; } if (n.equals("vip_id")) { pool.vipId = jp.getText(); continue; } log.warn("Unrecognized field {} in " + "parsing Pools", jp.getText()); } jp.close(); return pool; }
From source file:net.floodlightcontroller.loadbalancer.MonitorsResource.java
protected LBMonitor jsonToMonitor(String json) throws IOException { MappingJsonFactory f = new MappingJsonFactory(); JsonParser jp;/*w w w . j a v a 2 s . co m*/ LBMonitor monitor = new LBMonitor(); try { jp = f.createJsonParser(json); } catch (JsonParseException e) { throw new IOException(e); } jp.nextToken(); if (jp.getCurrentToken() != JsonToken.START_OBJECT) { throw new IOException("Expected START_OBJECT"); } while (jp.nextToken() != JsonToken.END_OBJECT) { if (jp.getCurrentToken() != JsonToken.FIELD_NAME) { throw new IOException("Expected FIELD_NAME"); } String n = jp.getCurrentName(); jp.nextToken(); if (jp.getText().equals("")) continue; else if (n.equals("monitor")) { while (jp.nextToken() != JsonToken.END_OBJECT) { String field = jp.getCurrentName(); if (field.equals("id")) { monitor.id = jp.getText(); continue; } if (field.equals("name")) { monitor.name = jp.getText(); continue; } if (field.equals("type")) { monitor.type = Short.parseShort(jp.getText()); continue; } if (field.equals("delay")) { monitor.delay = Short.parseShort(jp.getText()); continue; } if (field.equals("timeout")) { monitor.timeout = Short.parseShort(jp.getText()); continue; } if (field.equals("attempts_before_deactivation")) { monitor.attemptsBeforeDeactivation = Short.parseShort(jp.getText()); continue; } if (field.equals("network_id")) { monitor.netId = jp.getText(); continue; } if (field.equals("address")) { monitor.address = Integer.parseInt(jp.getText()); continue; } if (field.equals("protocol")) { monitor.protocol = Byte.parseByte(jp.getText()); continue; } if (field.equals("port")) { monitor.port = Short.parseShort(jp.getText()); continue; } if (field.equals("admin_state")) { monitor.adminState = Short.parseShort(jp.getText()); continue; } if (field.equals("status")) { monitor.status = Short.parseShort(jp.getText()); continue; } log.warn("Unrecognized field {} in " + "parsing Vips", jp.getText()); } } } jp.close(); return monitor; }
From source file:com.zimbra.cs.store.file.BlobDeduperUtil.java
private void parseArgs(String[] args) throws ParseException { GnuParser parser = new GnuParser(); CommandLine cl = parser.parse(options, args); if (CliUtil.hasOption(cl, LO_HELP)) { usage(null);//from w w w. j ava 2 s . c o m } // Require the "start" command, so that someone doesn't inadvertently // kick of a dedupe. if (cl.getArgs().length == 0) { usage(null); } else if (cl.getArgs()[0].equals("stop")) { action = DedupeBlobsRequest.DedupAction.stop; return; } else if (cl.getArgs()[0].equals("status")) { action = DedupeBlobsRequest.DedupAction.status; return; } else if (cl.getArgs()[0].equals("start")) { action = DedupeBlobsRequest.DedupAction.start; } else if (cl.getArgs()[0].equals("reset")) { if (CliUtil.confirm("This will remove all the metadata used by dedupe process. Continue?")) { action = DedupeBlobsRequest.DedupAction.reset; } else { System.exit(0); } } else { usage(null); } verbose = CliUtil.hasOption(cl, LO_VERBOSE); String volumeList = CliUtil.getOptionValue(cl, LO_VOLUMES); if (volumeList != null) { for (String id : volumeList.split(",")) { try { volumeIds.add(Short.parseShort(id)); } catch (NumberFormatException e) { usage("Invalid volume id: " + id); } } } }
From source file:com.aoindustries.website.clientarea.accounting.AddCreditCardCompletedAction.java
@Override public ActionForward executePermissionGranted(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, SiteSettings siteSettings, Locale locale, Skin skin, AOServConnector aoConn) throws Exception { AddCreditCardForm addCreditCardForm = (AddCreditCardForm) form; String accounting = addCreditCardForm.getAccounting(); if (GenericValidator.isBlankOrNull(accounting)) { // Redirect back to credit-card-manager it no accounting selected return mapping.findForward("credit-card-manager"); }/* ww w.j a va2s . c o m*/ // Validation ActionMessages errors = addCreditCardForm.validate(mapping, request); if (errors != null && !errors.isEmpty()) { saveErrors(request, errors); // Init request values before showing input initRequestAttributes(request, getServlet().getServletContext()); return mapping.findForward("input"); } // Get the credit card processor for the root connector of this website AOServConnector rootConn = siteSettings.getRootAOServConnector(); CreditCardProcessor creditCardProcessor = CreditCardProcessorFactory.getCreditCardProcessor(rootConn); if (creditCardProcessor == null) throw new SQLException("Unable to find enabled CreditCardProcessor for root connector"); // Add card if (!creditCardProcessor.canStoreCreditCards()) throw new SQLException("CreditCardProcessor indicates it does not support storing credit cards."); creditCardProcessor.storeCreditCard( new AOServConnectorPrincipal(rootConn, aoConn.getThisBusinessAdministrator().getUsername().getUsername().toString()), new BusinessGroup(aoConn.getBusinesses().get(AccountingCode.valueOf(accounting)), accounting), new CreditCard(null, // persistenceUniqueId null, // principalName null, // groupName null, // providerId null, // providerUniqueId addCreditCardForm.getCardNumber(), null, // maskedCardNumber Byte.parseByte(addCreditCardForm.getExpirationMonth()), Short.parseShort(addCreditCardForm.getExpirationYear()), addCreditCardForm.getCardCode(), addCreditCardForm.getFirstName(), addCreditCardForm.getLastName(), addCreditCardForm.getCompanyName(), null, null, null, null, null, addCreditCardForm.getStreetAddress1(), addCreditCardForm.getStreetAddress2(), addCreditCardForm.getCity(), addCreditCardForm.getState(), addCreditCardForm.getPostalCode(), addCreditCardForm.getCountryCode(), addCreditCardForm.getDescription())); request.setAttribute("cardNumber", CreditCard.maskCreditCardNumber(addCreditCardForm.getCardNumber())); return mapping.findForward("success"); }