List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:com.bringcommunications.etherpay.SendActivity.java
public void do_pay(View view) { if (send_is_done) return;/*from ww w. j a va2 s .co m*/ //validate size... we check for sufficient balance later... EditText size_view = (EditText) findViewById(R.id.size); String user_size_str = size_view.getText().toString(); float user_size = Float.valueOf(user_size_str); eth_size = (denomination == Denomination.ETH) ? user_size : user_size / 1000; if (eth_size == 0) { Toast.makeText(context, "Cannot send zero ETH", Toast.LENGTH_LONG).show(); return; } if (show_gas) { TextView gas_view = (TextView) findViewById(R.id.gas); String gas_limit_str = gas_view.getText().toString().trim(); try { gas_limit = Long.valueOf(gas_limit_str); } catch (NumberFormatException e) { Toast.makeText(context, "Unable to parse Gas limit: " + gas_limit_str, Toast.LENGTH_LONG).show(); return; } } if (gas_limit < Util.DEFAULT_GAS_LIMIT) { Toast.makeText(context, "Gas limit is too low -- transaction might not succeed!", Toast.LENGTH_LONG) .show(); return; } //ensure sufficient funds long gas_price = preferences.getLong("gas_price", Util.DEFAULT_GAS_PRICE); float max_gas_eth = (gas_limit * gas_price) / WEI_PER_ETH; if (eth_size + max_gas_eth > eth_balance) { String balance_str = String.format("%1.06f", eth_balance); String size_str = String.format("%1.06f", eth_size); String gas_str = String.format("%1.08f", max_gas_eth); String msg = "Balance (" + balance_str + ") is not sufficient to cover " + size_str + " ETH, plus " + gas_str + " GAS"; Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); return; } //validate to_addr if (!to_addr.startsWith("0x") || to_addr.length() != 42) { Toast.makeText(context, "Recipient address is not valid; length is " + to_addr.length(), Toast.LENGTH_LONG).show(); return; } if (to_addr.equals(acct_addr)) { Toast.makeText(context, "Recipient cannot be the same as your account address", Toast.LENGTH_LONG) .show(); return; } EditText data_view = (EditText) findViewById(R.id.data); data = data_view.getText().toString(); long size_wei = (long) (eth_size * WEI_PER_ETH); Payment_Processor.send(this, context, "", to_addr, size_wei, gas_limit, data.getBytes(), false); send_is_done = true; Button pay_view = (Button) findViewById(R.id.pay_button); pay_view.setClickable(false); }
From source file:net.sf.ezmorph.bean.BeanMorpherTest.java
public void testMorph_PrimitiveBean_to_ObjectBean() { PrimitiveBean primitiveBean = new PrimitiveBean(); primitiveBean.setPclass(Object.class); primitiveBean.setPstring("MORPH"); morpherRegistry.registerMorpher(new BeanMorpher(ObjectBean.class, morpherRegistry)); ObjectBean objectBean = (ObjectBean) morpherRegistry.morph(ObjectBean.class, primitiveBean); assertNotNull(objectBean);//from w ww. j ava 2 s . co m assertEquals(Boolean.FALSE, objectBean.getPboolean()); assertEquals(Byte.valueOf("0"), objectBean.getPbyte()); assertEquals(Short.valueOf("0"), objectBean.getPshort()); assertEquals(Integer.valueOf("0"), objectBean.getPint()); assertEquals(Long.valueOf("0"), objectBean.getPlong()); assertEquals(Float.valueOf("0"), objectBean.getPfloat()); assertEquals(Double.valueOf("0"), objectBean.getPdouble()); assertEquals(new Character('\0'), objectBean.getPchar()); assertEquals(null, objectBean.getParray()); assertEquals(null, objectBean.getPlist()); assertEquals(null, objectBean.getPbean()); assertEquals(null, objectBean.getPmap()); assertEquals("MORPH", objectBean.getPstring()); assertEquals(Object.class, objectBean.getPclass()); }
From source file:com.confighub.core.repository.Property.java
public void setValue(String value, String encryptionSecret) throws ConfigException { if (repository.isValueTypeEnabled()) { PropertyKey.ValueDataType vdt = this.getPropertyKey().getValueDataType(); switch (vdt) { case Text: case Code: case FileRef: case FileEmbed: break; // anything goes. case JSON: if (null != value) { Utils.isJSONValid(value); }/*from ww w .jav a 2 s .co m*/ break; case Boolean: if (null != value && !"true".equals(value) && !"false".equals(value)) { throw new ConfigException(Error.Code.INVALID_VALUE_FOR_DATA_TYPE); } break; case Integer: if (null == value) { break; } try { Integer.valueOf(value); } catch (Exception ignore) { throw new ConfigException(Error.Code.INVALID_VALUE_FOR_DATA_TYPE); } break; case Long: if (null == value) { break; } try { Long.valueOf(value); } catch (Exception ignore) { throw new ConfigException(Error.Code.INVALID_VALUE_FOR_DATA_TYPE); } break; case Double: if (null == value) { break; } try { Double.valueOf(value); if (value.startsWith(".")) { value = "0" + value; } } catch (Exception ignore) { throw new ConfigException(Error.Code.INVALID_VALUE_FOR_DATA_TYPE); } break; case Float: if (null == value) { break; } try { Float.valueOf(value); if (value.startsWith(".")) { value = "0" + value; } } catch (Exception ignore) { throw new ConfigException(Error.Code.INVALID_VALUE_FOR_DATA_TYPE); } break; case Map: if (null == value) { break; } try { if (Utils.isBlank(value)) { value = "{}"; } else { new Gson().fromJson(value, JsonObject.class); } } catch (Exception ignore) { throw new ConfigException(Error.Code.INVALID_VALUE_FOR_DATA_TYPE); } break; case List: if (null == value) { break; } try { if (Utils.isBlank(value)) { value = "[]"; } else { new Gson().fromJson(value, JsonArray.class); } } catch (Exception ignore) { throw new ConfigException(Error.Code.INVALID_VALUE_FOR_DATA_TYPE); } break; } } this.absoluteFilePath = null; if (!this.isSecure()) { this.value = value; return; } if (this.repository.isSecurityProfilesEnabled()) { if (!this.getPropertyKey().getSecurityProfile().isSecretValid(encryptionSecret)) { throw new ConfigException(Error.Code.INVALID_PASSWORD); } if (this.isEncrypted()) { this.value = this.getPropertyKey().getSecurityProfile().encrypt(value, encryptionSecret); } else { this.value = value; } } else { this.value = value; } }
From source file:net.sf.jasperreports.engine.xml.JRAbstractStyleFactory.java
/** * *///from ww w . jav a2 s . c o m protected void setCommonStyle(JRStyle style, Attributes atts) { // get JRElement attributes ModeEnum mode = ModeEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_mode)); if (mode != null) { style.setMode(mode); } String forecolor = atts.getValue(JRXmlConstants.ATTRIBUTE_forecolor); style.setForecolor(JRColorUtil.getColor(forecolor, null)); String backcolor = atts.getValue(JRXmlConstants.ATTRIBUTE_backcolor); style.setBackcolor(JRColorUtil.getColor(backcolor, null)); // get graphic element attributes PenEnum pen = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_pen)); if (pen != null) { if (log.isWarnEnabled()) { log.warn("The 'pen' attribute is deprecated. Use the <pen> tag instead."); } JRPenUtil.setLinePenFromPen(pen, style.getLinePen()); } FillEnum fill = FillEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_fill)); if (fill != null) { style.setFill(fill); } // get rectangle attributes String radius = atts.getValue(JRXmlConstants.ATTRIBUTE_radius); if (radius != null && radius.length() > 0) { style.setRadius(Integer.valueOf(radius)); } // get image attributes ScaleImageEnum scaleImage = ScaleImageEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_scaleImage)); if (scaleImage != null) { style.setScaleImage(scaleImage); } HorizontalTextAlignEnum horizontalTextAlign = HorizontalTextAlignEnum .getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_hAlign)); if (horizontalTextAlign != null) { style.setHorizontalTextAlign(horizontalTextAlign); } horizontalTextAlign = HorizontalTextAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_hTextAlign)); if (horizontalTextAlign != null) { style.setHorizontalTextAlign(horizontalTextAlign); } VerticalTextAlignEnum verticalTextAlign = VerticalTextAlignEnum .getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_vAlign)); if (verticalTextAlign != null) { style.setVerticalTextAlign(verticalTextAlign); } verticalTextAlign = VerticalTextAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_vTextAlign)); if (verticalTextAlign != null) { style.setVerticalTextAlign(verticalTextAlign); } HorizontalImageAlignEnum horizontalImageAlign = HorizontalImageAlignEnum .getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_hAlign)); if (horizontalImageAlign != null) { style.setHorizontalImageAlign(horizontalImageAlign); } horizontalImageAlign = HorizontalImageAlignEnum .getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_hImageAlign)); if (horizontalImageAlign != null) { style.setHorizontalImageAlign(horizontalImageAlign); } VerticalImageAlignEnum verticalImageAlign = VerticalImageAlignEnum .getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_vAlign)); if (verticalImageAlign != null) { style.setVerticalImageAlign(verticalImageAlign); } verticalImageAlign = VerticalImageAlignEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_vImageAlign)); if (verticalImageAlign != null) { style.setVerticalImageAlign(verticalImageAlign); } // get box attributes PenEnum border = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_border)); if (border != null) { if (log.isWarnEnabled()) { log.warn("The 'border' attribute is deprecated. Use the <pen> tag instead."); } JRPenUtil.setLinePenFromPen(border, style.getLineBox().getPen()); } Color borderColor = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_borderColor), null); if (borderColor != null) { if (log.isWarnEnabled()) { log.warn("The 'borderColor' attribute is deprecated. Use the <pen> tag instead."); } style.getLineBox().getPen().setLineColor(borderColor); } String padding = atts.getValue(JRXmlConstants.ATTRIBUTE_padding); if (padding != null && padding.length() > 0) { if (log.isWarnEnabled()) { log.warn("The 'padding' attribute is deprecated. Use the <box> tag instead."); } style.getLineBox().setPadding(Integer.valueOf(padding)); } border = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_topBorder)); if (border != null) { if (log.isWarnEnabled()) { log.warn("The 'topBorder' attribute is deprecated. Use the <pen> tag instead."); } JRPenUtil.setLinePenFromPen(border, style.getLineBox().getTopPen()); } borderColor = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_topBorderColor), Color.black); if (borderColor != null) { if (log.isWarnEnabled()) { log.warn("The 'topBorderColor' attribute is deprecated. Use the <pen> tag instead."); } style.getLineBox().getTopPen().setLineColor(borderColor); } padding = atts.getValue(JRXmlConstants.ATTRIBUTE_topPadding); if (padding != null && padding.length() > 0) { if (log.isWarnEnabled()) { log.warn("The 'topPadding' attribute is deprecated. Use the <box> tag instead."); } style.getLineBox().setTopPadding(Integer.valueOf(padding)); } border = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_leftBorder)); if (border != null) { if (log.isWarnEnabled()) { log.warn("The 'leftBorder' attribute is deprecated. Use the <pen> tag instead."); } JRPenUtil.setLinePenFromPen(border, style.getLineBox().getLeftPen()); } borderColor = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_leftBorderColor), Color.black); if (borderColor != null) { if (log.isWarnEnabled()) { log.warn("The 'leftBorderColor' attribute is deprecated. Use the <pen> tag instead."); } style.getLineBox().getLeftPen().setLineColor(borderColor); } padding = atts.getValue(JRXmlConstants.ATTRIBUTE_leftPadding); if (padding != null && padding.length() > 0) { if (log.isWarnEnabled()) { log.warn("The 'leftPadding' attribute is deprecated. Use the <box> tag instead."); } style.getLineBox().setLeftPadding(Integer.valueOf(padding)); } border = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_bottomBorder)); if (border != null) { if (log.isWarnEnabled()) { log.warn("The 'bottomBorder' attribute is deprecated. Use the <pen> tag instead."); } JRPenUtil.setLinePenFromPen(border, style.getLineBox().getBottomPen()); } borderColor = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_bottomBorderColor), Color.black); if (borderColor != null) { if (log.isWarnEnabled()) { log.warn("The 'bottomBorderColor' attribute is deprecated. Use the <pen> tag instead."); } style.getLineBox().getBottomPen().setLineColor(borderColor); } padding = atts.getValue(JRXmlConstants.ATTRIBUTE_bottomPadding); if (padding != null && padding.length() > 0) { if (log.isWarnEnabled()) { log.warn("The 'bottomPadding' attribute is deprecated. Use the <box> tag instead."); } style.getLineBox().setBottomPadding(Integer.valueOf(padding)); } border = PenEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_rightBorder)); if (border != null) { if (log.isWarnEnabled()) { log.warn("The 'rightBorder' attribute is deprecated. Use the <pen> tag instead."); } JRPenUtil.setLinePenFromPen(border, style.getLineBox().getRightPen()); } borderColor = JRColorUtil.getColor(atts.getValue(JRXmlConstants.ATTRIBUTE_rightBorderColor), Color.black); if (borderColor != null) { if (log.isWarnEnabled()) { log.warn("The 'rightBorderColor' attribute is deprecated. Use the <pen> tag instead."); } style.getLineBox().getRightPen().setLineColor(borderColor); } padding = atts.getValue(JRXmlConstants.ATTRIBUTE_rightPadding); if (padding != null && padding.length() > 0) { if (log.isWarnEnabled()) { log.warn("The 'rightPadding' attribute is deprecated. Use the <box> tag instead."); } style.getLineBox().setRightPadding(Integer.valueOf(padding)); } RotationEnum rotation = RotationEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_rotation)); if (rotation != null) { style.setRotation(rotation); } LineSpacingEnum lineSpacing = LineSpacingEnum .getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_lineSpacing)); if (lineSpacing != null) { if (log.isWarnEnabled()) { log.warn("The 'lineSpacing' attribute is deprecated. Use the <paragraph> tag instead."); } style.getParagraph().setLineSpacing(lineSpacing); } style.setMarkup(atts.getValue(JRXmlConstants.ATTRIBUTE_markup)); String isStyledText = atts.getValue(JRXmlConstants.ATTRIBUTE_isStyledText); if (isStyledText != null && isStyledText.length() > 0) { if (log.isWarnEnabled()) { log.warn("The 'isStyledText' attribute is deprecated. Use the 'markup' attribute instead."); } style.setMarkup( Boolean.valueOf(isStyledText) ? JRCommonText.MARKUP_STYLED_TEXT : JRCommonText.MARKUP_NONE); } style.setPattern(atts.getValue(JRXmlConstants.ATTRIBUTE_pattern)); String isBlankWhenNull = atts.getValue(JRXmlConstants.ATTRIBUTE_isBlankWhenNull); if (isBlankWhenNull != null && isBlankWhenNull.length() > 0) { style.setBlankWhenNull(Boolean.valueOf(isBlankWhenNull)); } if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontName) != null) { style.setFontName(atts.getValue(JRXmlConstants.ATTRIBUTE_fontName)); } if (atts.getValue(JRXmlConstants.ATTRIBUTE_isBold) != null) { style.setBold(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isBold))); } if (atts.getValue(JRXmlConstants.ATTRIBUTE_isItalic) != null) { style.setItalic(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isItalic))); } if (atts.getValue(JRXmlConstants.ATTRIBUTE_isUnderline) != null) { style.setUnderline(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isUnderline))); } if (atts.getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough) != null) { style.setStrikeThrough(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isStrikeThrough))); } if (atts.getValue(JRXmlConstants.ATTRIBUTE_fontSize) != null) { style.setFontSize(Float.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_fontSize))); } if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfFontName) != null) { style.setPdfFontName(atts.getValue(JRXmlConstants.ATTRIBUTE_pdfFontName)); } if (atts.getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding) != null) { style.setPdfEncoding(atts.getValue(JRXmlConstants.ATTRIBUTE_pdfEncoding)); } if (atts.getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded) != null) { style.setPdfEmbedded(Boolean.valueOf(atts.getValue(JRXmlConstants.ATTRIBUTE_isPdfEmbedded))); } }
From source file:com.bosscs.spark.commons.utils.Utils.java
public static Object castingUtil(String value, Class classCasting) { Object object = value;// w w w . j a v a2 s . co m //Numeric if (Number.class.isAssignableFrom(classCasting)) { if (classCasting.isAssignableFrom(Double.class)) { return Double.valueOf(value); } else if (classCasting.isAssignableFrom(Long.class)) { return Long.valueOf(value); } else if (classCasting.isAssignableFrom(Float.class)) { return Float.valueOf(value); } else if (classCasting.isAssignableFrom(Integer.class)) { return Integer.valueOf(value); } else if (classCasting.isAssignableFrom(Short.class)) { return Short.valueOf(value); } else if (classCasting.isAssignableFrom(Byte.class)) { return Byte.valueOf(value); } } else if (String.class.isAssignableFrom(classCasting)) { return object.toString(); } //Class not recognise yet return null; }
From source file:com.orbar.pxdemo.Model.FiveZeroZeroImageBean.java
public void parseJSONObject(JSONObject imageObject) { userBean = new FiveZeroZeroUserBean(); try {//from w w w .ja v a 2s .c o m if (imageObject.has("id") && !imageObject.isNull("id")) id = imageObject.getInt("id"); if (imageObject.has("user_id") && !imageObject.isNull("user_id")) userId = imageObject.getInt("user_id"); if (imageObject.has("name") && !imageObject.isNull("name")) name = imageObject.getString("name"); if (imageObject.has("description") && !imageObject.isNull("description")) description = imageObject.getString("description"); if (imageObject.has("camera") && !imageObject.isNull("camera")) camera = imageObject.getString("camera"); if (imageObject.has("lens") && !imageObject.isNull("lens")) lens = imageObject.getString("lens"); if (imageObject.has("focal_length") && !imageObject.isNull("focal_length")) focalLength = imageObject.getString("focal_length"); if (imageObject.has("iso") && !imageObject.isNull("iso")) iso = imageObject.getString("iso"); if (imageObject.has("shutter_speed") && !imageObject.isNull("shutter_speed")) shutterSpeed = imageObject.getString("shutter_speed"); if (imageObject.has("aperture") && !imageObject.isNull("aperture")) aperture = imageObject.getString("aperture"); if (imageObject.has("times_viewed") && !imageObject.isNull("times_viewed")) timesViewed = imageObject.getInt("times_viewed"); if (imageObject.has("rating") && !imageObject.isNull("rating")) { rating = (float) imageObject.getDouble("rating"); rating = Float.valueOf(new BigDecimal(rating).setScale(2, RoundingMode.HALF_UP).toString()); } if (imageObject.has("status") && !imageObject.isNull("status")) status = imageObject.getInt("status"); if (imageObject.has("created_at") && !imageObject.isNull("created_at")) createdAt = imageObject.getString("created_at"); if (imageObject.has("category") && !imageObject.isNull("category")) category = imageObject.getInt("category"); if (imageObject.has("category") && !imageObject.isNull("category")) category = imageObject.getInt("category"); if (imageObject.has("location") && !imageObject.isNull("location")) location = imageObject.getString("location"); //if (imageObject.has("privacy") && !imageObject.isNull("privacy")) // privacy = imageObject.getBoolean("privacy"); if (imageObject.has("latitude") && !imageObject.isNull("latitude")) { latitude = imageObject.getString("latitude"); String sLat = imageObject.getString("latitude"); double dLat = Double.valueOf(sLat); DecimalFormat df = new DecimalFormat("#.###"); latitude = df.format(dLat); } if (imageObject.has("longitude") && !imageObject.isNull("longitude")) { String sLong = imageObject.getString("longitude"); double dLong = Double.valueOf(sLong); DecimalFormat df = new DecimalFormat("#.##"); longitude = df.format(dLong); } if (imageObject.has("taken_at") && !imageObject.isNull("taken_at")) takenAt = imageObject.getString("taken_at"); if (imageObject.has("hi_res_uploaded") && !imageObject.isNull("hi_res_uploaded")) hiResUploaded = imageObject.getInt("hi_res_uploaded"); if (imageObject.has("for_sale") && !imageObject.isNull("for_sale")) forSale = imageObject.getBoolean("for_sale"); if (imageObject.has("width") && !imageObject.isNull("width")) width = imageObject.getInt("width"); if (imageObject.has("height") && !imageObject.isNull("height")) height = imageObject.getInt("height"); if (imageObject.has("votes_count") && !imageObject.isNull("votes_count")) votesCount = imageObject.getInt("votes_count"); if (imageObject.has("favorites_count") && !imageObject.isNull("favorites_count")) favoritesCount = imageObject.getInt("favorites_count"); if (imageObject.has("comments_count") && !imageObject.isNull("comments_count")) commentsCount = imageObject.getInt("comments_count"); if (imageObject.has("nsfw") && !imageObject.isNull("nsfw")) nsfw = imageObject.getBoolean("nsfw"); if (imageObject.has("sales_count") && !imageObject.isNull("sales_count")) salesCount = imageObject.getInt("sales_count"); if (imageObject.has("highest_rating") && !imageObject.isNull("highest_rating")) { highestRating = (float) imageObject.getDouble("highest_rating"); highestRating = Float .valueOf(new BigDecimal(highestRating).setScale(2, RoundingMode.HALF_UP).toString()); } if (imageObject.has("highest_rating_date") && !imageObject.isNull("highest_rating_date")) highestRatingDate = imageObject.getString("highest_rating_date"); if (imageObject.has("license_type") && !imageObject.isNull("license_type")) licenseType = imageObject.getInt("license_type"); if (imageObject.has("store_download") && !imageObject.isNull("store_download")) storeDownload = imageObject.getBoolean("store_download"); if (imageObject.has("store_print") && !imageObject.isNull("store_print")) storePrint = imageObject.getBoolean("store_print"); if (imageObject.has("voted") && !imageObject.isNull("voted")) { voted = imageObject.getBoolean("voted"); } else { voted = false; } if (imageObject.has("favorited") && !imageObject.isNull("favorited")) { favorited = imageObject.getBoolean("favorited"); } else { favorited = false; } if (imageObject.has("purchased") && !imageObject.isNull("purchased")) { purchased = imageObject.getBoolean("purchased"); } else { purchased = false; } if (imageObject.has("image_url") && !imageObject.isNull("image_url")) { imageUrl = imageObject.getString("image_url"); imageUrl = imageUrl.substring(0, imageUrl.lastIndexOf("/") + 1); } if (imageObject.has("user") && !imageObject.isNull("user")) userBean.parseJSONObject(imageObject.getJSONObject("user")); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.vmware.o11n.plugin.powershell.model.RemotePsType.java
private Object convertPrimitiveType(String type, String value) { if (type.equals("C")) { //Char return (char) Integer.valueOf(value).intValue(); }/* w ww .ja v a 2s . co m*/ if (type.equals("B")) { //Boolean return Boolean.valueOf(value); } if (type.equals("By")) { //UnsignedByte return Short.valueOf(value); } if (type.equals("SB")) { //SignedByte return Byte.valueOf(value); } if (type.equals("U16")) { //UnsignedShort return Integer.valueOf(value); } if (type.equals("I16")) { //SignedShort return Short.valueOf(value); } if (type.equals("U32")) { //UnsignedInt return Long.valueOf(value); } if (type.equals("I32")) { //SignedInt return Integer.valueOf(value); } if (type.equals("I64")) { //SignedLong return Long.valueOf(value); } if (type.equals("Sg")) { //Float return Float.valueOf(value); } if (type.equals("Db")) { //Double return Double.valueOf(value); } else { return value; } }
From source file:com.hanuor.sapphire.utils.intentation.IntentationPrime.java
public Intent jsonToINTENT(String JSONString) throws JSONException { JSONObject jsonObject = new JSONObject(JSONString.toString()); String toArray = jsonObject.get("intentExtras").toString(); String contextName = jsonObject.get("context").toString(); String className = jsonObject.get("className").toString(); Log.d("Insass", className.toString()); Intent setIntent = new Intent(); setIntent.setClassName(contextName, className); HashMap<String, String> extrasHash = new HashMap<String, String>(); JSONObject issueObj = new JSONObject(toArray); for (int i = 0; i < issueObj.length(); i++) { extrasHash.put(issueObj.names().getString(i), issueObj.get(issueObj.names().getString(i)).toString()); }//from w w w . j a v a2 s . c o m Iterator it = extrasHash.entrySet().iterator(); while (it.hasNext()) { //add conditions and checks here Map.Entry pair = (Map.Entry) it.next(); String currentKey = (String) pair.getKey(); Log.d("HAHA", "" + currentKey); String[] getValuethroughSplit = pair.getValue().toString().split(LibraryDatabase.JSONSEPERATOR); String dataType = getValuethroughSplit[0]; String value = (String) getValuethroughSplit[2]; Log.d("Insamareen", getValuethroughSplit.length + " " + dataType + " " + value.toString()); switch (dataType) { case "String": setIntent.putExtra(currentKey, (String) value); break; case "String[]": String comp1 = value.substring(1, value.length() - 1); String[] comp2 = comp1.split(","); setIntent.putExtra(currentKey, comp2); break; case "Integer": setIntent.putExtra(currentKey, Integer.parseInt(value)); break; case "Double": setIntent.putExtra(currentKey, Double.parseDouble(value)); break; case "double[]": String compDouble1 = value.substring(1, value.length() - 1); String[] compDoub2 = compDouble1.split(","); double[] db = new double[compDoub2.length]; for (int i = 0; i < compDoub2.length; i++) { db[i] = Double.parseDouble(compDoub2[i]); } setIntent.putExtra(currentKey, db); break; case "int[]": String compInt1 = value.substring(1, value.length() - 1); String[] compInt2 = compInt1.split(","); int[] intVal = new int[compInt2.length]; for (int i = 0; i < compInt2.length; i++) { intVal[i] = Integer.parseInt(compInt2[i]); } Log.d("Hankey", intVal.toString()); setIntent.putExtra(currentKey, intVal); break; case "Boolean": setIntent.putExtra(currentKey, Boolean.valueOf(value)); break; case "boolean[]": String compB1 = value.substring(1, value.length() - 1); String[] compB2 = compB1.split(","); boolean[] BVal = new boolean[compB2.length]; for (int i = 0; i < compB2.length; i++) { BVal[i] = Boolean.parseBoolean(compB2[i]); } setIntent.putExtra(currentKey, value); break; case "Char": setIntent.putExtra(currentKey, value); break; case "char[]": String ch1 = value.substring(1, value.length() - 1); String[] ch2 = ch1.split(","); String newS = null; for (int i = 0; i < ch2.length; i++) { newS = newS + ch2[i]; } setIntent.putExtra(currentKey, newS.toCharArray()); break; case "CharSequence": setIntent.putExtra(currentKey, (CharSequence) value); break; case "Charsequence[]": setIntent.putExtra(currentKey, value.toString()); break; case "Byte": setIntent.putExtra(currentKey, Byte.valueOf(value)); break; case "byte[]": String by = value.substring(1, value.length() - 1); String[] by2 = by.split(","); byte[] by3 = new byte[by2.length]; for (int i = 0; i < by2.length; i++) { by3[i] = Byte.parseByte(by2[i]); } setIntent.putExtra(currentKey, by3); break; case "Float": setIntent.putExtra(currentKey, Float.valueOf(value)); break; case "float[]": String fl = value.substring(1, value.length() - 1); String[] fl2 = fl.split(","); float[] fl3 = new float[fl2.length]; for (int i = 0; i < fl2.length; i++) { fl3[i] = Float.parseFloat(fl2[i]); } setIntent.putExtra(currentKey, fl3); break; case "Short": setIntent.putExtra(currentKey, Short.valueOf(value)); break; case "short[]": String sh = value.substring(1, value.length() - 1); String[] sh2 = sh.split(","); short[] sh3 = new short[sh2.length]; for (int i = 0; i < sh2.length; i++) { sh3[i] = Short.parseShort(sh2[i]); } setIntent.putExtra(currentKey, sh3); break; case "Long": setIntent.putExtra(currentKey, Long.valueOf(value)); break; case "long[]": String ll = value.substring(1, value.length() - 1); String[] ll2 = ll.split(","); long[] ll3 = new long[ll2.length]; for (int i = 0; i < ll2.length; i++) { ll3[i] = Long.parseLong(ll2[i]); } setIntent.putExtra(currentKey, ll3); break; case "ArrayListString": Log.d("Hankey", currentKey + " "); String arrL = value.substring(1, value.length() - 1); String[] arrl2 = arrL.split(","); ArrayList<String> arrStr = new ArrayList<String>(); for (int i = 0; i < arrl2.length; i++) { arrStr.add(arrl2[i]); } setIntent.putStringArrayListExtra(currentKey, arrStr); break; case "ArrayListInteger": String arL = value.substring(1, value.length() - 1); String[] arl2 = arL.split(","); ArrayList<Integer> arrInt = new ArrayList<Integer>(); for (int i = 0; i < arl2.length; i++) { arrInt.add(Integer.parseInt(arl2[i])); } setIntent.putIntegerArrayListExtra(currentKey, arrInt); break; default: // whatever } } return setIntent; }
From source file:net.sf.ezmorph.bean.BeanMorpherTest.java
public void testMorph_PrimitiveBean_to_TypedBean() { PrimitiveBean primitiveBean = new PrimitiveBean(); primitiveBean.setPclass(Object.class); primitiveBean.setPstring("MORPH"); morpherRegistry.registerMorpher(new BeanMorpher(TypedBean.class, morpherRegistry)); TypedBean typedBean = (TypedBean) morpherRegistry.morph(TypedBean.class, primitiveBean); assertNotNull(typedBean);/*from w ww.j a v a2s.co m*/ assertEquals(Boolean.FALSE, typedBean.getPboolean()); assertEquals(Byte.valueOf("0"), typedBean.getPbyte()); assertEquals(Short.valueOf("0"), typedBean.getPshort()); assertEquals(Integer.valueOf("0"), typedBean.getPint()); assertEquals(Long.valueOf("0"), typedBean.getPlong()); assertEquals(Float.valueOf("0"), typedBean.getPfloat()); assertEquals(Double.valueOf("0"), typedBean.getPdouble()); assertEquals(new Character('\0'), typedBean.getPchar()); assertEquals(null, typedBean.getParray()); assertEquals(null, typedBean.getPlist()); assertEquals(null, typedBean.getPbean()); assertEquals(null, typedBean.getPmap()); assertEquals("MORPH", typedBean.getPstring()); assertEquals(Object.class, typedBean.getPclass()); }
From source file:ch.cyberduck.ui.cocoa.TransferController.java
@Action public void bandwidthPopupChanged(NSPopUpButton sender) { final NSIndexSet selected = transferTable.selectedRowIndexes(); final float bandwidth = Float.valueOf(sender.selectedItem().representedObject()); for (NSUInteger index = selected.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = selected .indexGreaterThanIndex(index)) { final Transfer transfer = collection.get(index.intValue()); transfer.setBandwidth(bandwidth); if (transfer.isRunning()) { final BackgroundActionRegistry registry = this.getActions(); // Find matching background task for (BackgroundAction action : registry.toArray(new BackgroundAction[registry.size()])) { if (action instanceof TransferBackgroundAction) { final TransferBackgroundAction t = (TransferBackgroundAction) action; if (t.getTransfer().equals(transfer)) { final TransferSpeedometer meter = t.getMeter(); meter.reset();// w w w . ja va 2 s . c om } } } } } this.updateBandwidthPopup(); }