List of usage examples for java.lang Float valueOf
@HotSpotIntrinsicCandidate public static Float valueOf(float f)
From source file:RealFunctionValidation.java
public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out, final Class<?> type) throws IOException { if (!type.isPrimitive()) { throw new IllegalArgumentException("type must be primitive"); }//from www . j av a 2 s. c o m if (type.equals(Boolean.TYPE)) { final boolean x = in.readBoolean(); out.writeBoolean(x); return Boolean.valueOf(x); } else if (type.equals(Byte.TYPE)) { final byte x = in.readByte(); out.writeByte(x); return Byte.valueOf(x); } else if (type.equals(Character.TYPE)) { final char x = in.readChar(); out.writeChar(x); return Character.valueOf(x); } else if (type.equals(Double.TYPE)) { final double x = in.readDouble(); out.writeDouble(x); return Double.valueOf(x); } else if (type.equals(Float.TYPE)) { final float x = in.readFloat(); out.writeFloat(x); return Float.valueOf(x); } else if (type.equals(Integer.TYPE)) { final int x = in.readInt(); out.writeInt(x); return Integer.valueOf(x); } else if (type.equals(Long.TYPE)) { final long x = in.readLong(); out.writeLong(x); return Long.valueOf(x); } else if (type.equals(Short.TYPE)) { final short x = in.readShort(); out.writeShort(x); return Short.valueOf(x); } else { // This should never occur. throw new IllegalStateException(); } }
From source file:gov.nih.nci.caintegrator.web.action.query.form.FoldChangeCriterionWrapper.java
private TextFieldParameter createFoldsDownParameter() { final String label = RegulationTypeEnum.UNCHANGED.equals(criterion.getRegulationType()) ? "Folds between" : "Down-regulation folds"; TextFieldParameter foldsParameter = new TextFieldParameter(getParameters().size(), getRow().getRowIndex(), criterion.getFoldsDown().toString()); foldsParameter.setLabel(label);// w w w. ja v a 2 s . co m ValueHandler foldsChangeHandler = new ValueHandlerAdapter() { @Override public boolean isValid(String value) { return NumberUtils.isNumber(value); } @Override public void validate(String formFieldName, String value, ValidationAware action) { if (!isValid(value)) { action.addActionError("Numeric value required for " + label); } } @Override public void valueChanged(String value) { criterion.setFoldsDown(Float.valueOf(value)); } }; foldsParameter.setValueHandler(foldsChangeHandler); return foldsParameter; }
From source file:it.unimi.dsi.util.Properties.java
public void setProperty(final Enum<?> key, final float f) { super.setProperty(key.name().toLowerCase(), Float.valueOf(f)); }
From source file:net.antidot.semantic.rdf.rdb2rdf.main.Db2triples.java
public static void main(String[] args) { // Get all options Options options = new Options(); Options r2rmlOptions = new Options(); Options dmOptions = new Options(); options.addOption(modeOpt);/*w ww. j a va 2s . c om*/ options.addOption(userNameOpt); r2rmlOptions.addOption(userNameOpt); dmOptions.addOption(userNameOpt); options.addOption(passwordOpt); r2rmlOptions.addOption(passwordOpt); dmOptions.addOption(passwordOpt); options.addOption(URLOpt); r2rmlOptions.addOption(URLOpt); dmOptions.addOption(URLOpt); options.addOption(driverOpt); r2rmlOptions.addOption(driverOpt); dmOptions.addOption(driverOpt); options.addOption(dbOpt); r2rmlOptions.addOption(dbOpt); dmOptions.addOption(dbOpt); options.addOption(baseURIOpt); r2rmlOptions.addOption(baseURIOpt); dmOptions.addOption(baseURIOpt); options.addOption(forceOpt); r2rmlOptions.addOption(forceOpt); dmOptions.addOption(forceOpt); options.addOption(nativeOpt); r2rmlOptions.addOption(nativeOpt); dmOptions.addOption(nativeOpt); options.addOption(nativeStoreNameOpt); r2rmlOptions.addOption(nativeStoreNameOpt); dmOptions.addOption(nativeStoreNameOpt); options.addOption(outputOpt); r2rmlOptions.addOption(outputOpt); dmOptions.addOption(outputOpt); options.addOption(transformSPARQLFile); dmOptions.addOption(transformSPARQLFile); options.addOption(transformOutputFile); dmOptions.addOption(transformOutputFile); options.addOption(rdfFormat); r2rmlOptions.addOption(rdfFormat); dmOptions.addOption(rdfFormat); options.addOption(versionOpt); dmOptions.addOption(versionOpt); options.addOption(r2rmlFileOpt); r2rmlOptions.addOption(r2rmlFileOpt); // Init parameters String mode = null; String userName = null; String password = null; String url = null; DriverType driver = null; String dbName = null; String baseURI = null; boolean useNativeStore = false; boolean forceExistingRep = false; String nativeOutput = null; String output = null; String sparql = null; String sparqlOutput = null; String format = null; String r2rmlFile = null; int int_version = 1; // RDF Format output RDFFormat rdfFormat = RDFFormat.TURTLE; // Turtle by default // Norm version Version version = Version.WD_20120529; // Option parsing // Create the parser CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); // Database settings // Mode if (!line.hasOption("mode")) { // automatically generate the help statement log.error("Mode is required. Use -m option to set it."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(projectName, options); System.exit(-1); } else { mode = line.getOptionValue("mode"); if (!mode.equals("r2rml") && !mode.equals("dm")) { log.error("Unkonw mode. Please select 'r2rml' or 'dm' mode."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(projectName, options); System.exit(-1); } } // user name if (!line.hasOption("user")) { // automatically generate the help statement log.error("User name is required. Use -u option to set it."); HelpFormatter formatter = new HelpFormatter(); if (mode.equals("r2rml")) { formatter.printHelp(projectNameR2RMLMode, r2rmlOptions); } else { formatter.printHelp(projectNameDirectMappingMode, dmOptions); } System.exit(-1); } else { userName = line.getOptionValue("user"); } // password if (!line.hasOption("pass")) { // automatically generate the help statement log.error("Password is required. Use -p option to set it."); HelpFormatter formatter = new HelpFormatter(); if (mode.equals("r2rml")) { formatter.printHelp(projectNameR2RMLMode, r2rmlOptions); } else { formatter.printHelp(projectNameDirectMappingMode, dmOptions); } System.exit(-1); } else { password = line.getOptionValue("pass"); } // Database URL url = line.getOptionValue("url", "jdbc:mysql://localhost/"); // driver driver = new DriverType(line.getOptionValue("driver", defaultDriver.getDriverName())); // Database name if (!line.hasOption("database")) { // automatically generate the help statement log.error("Database name is required. Use -b option to set it."); HelpFormatter formatter = new HelpFormatter(); if (mode.equals("r2rml")) { formatter.printHelp(projectNameR2RMLMode, r2rmlOptions); } else { formatter.printHelp(projectNameDirectMappingMode, dmOptions); } System.exit(-1); } else { dbName = line.getOptionValue("database"); } // Base URI baseURI = line.getOptionValue("base_uri", "http://foo.example/DB/"); // Use of native store ? useNativeStore = line.hasOption("n"); // Name of native store if (useNativeStore && !line.hasOption("native_output")) { // automatically generate the help statement log.error("Native triplestore path is required. Use -n option to set it."); HelpFormatter formatter = new HelpFormatter(); if (mode.equals("r2rml")) { formatter.printHelp(projectNameR2RMLMode, r2rmlOptions); } else { formatter.printHelp(projectNameDirectMappingMode, dmOptions); } System.exit(-1); } else { nativeOutput = line.getOptionValue("native_output"); } // Force loading of repository forceExistingRep = line.hasOption("f"); // Output output = line.getOptionValue("output", "output.ttl"); // SPARQL transformation if (line.hasOption("sparql")) { if (!mode.equals("dm")) { log.warn("sparql option is required only for 'dm' mode : it will be ignored..."); } else { sparql = line.getOptionValue("sparql"); sparqlOutput = line.getOptionValue("sparql_output", "output_sparql.ttl"); } } // RDF Format if (line.hasOption("format")) { format = line.getOptionValue("format"); if (format.equals("TURTLE")) rdfFormat = RDFFormat.TURTLE; else if (format.equals("RDFXML")) rdfFormat = RDFFormat.RDFXML; else if (format.equals("NTRIPLES")) rdfFormat = RDFFormat.NTRIPLES; else if (!format.equals("N3")) { log.error("Unknown RDF format. Please use RDFXML, TURTLE, N3 or NTRIPLES."); HelpFormatter formatter = new HelpFormatter(); if (mode.equals("r2rml")) { formatter.printHelp(projectNameR2RMLMode, r2rmlOptions); } else { formatter.printHelp(projectNameDirectMappingMode, dmOptions); } System.exit(-1); } } // Norm version if (line.hasOption("version")) { if (!mode.equals("dm")) { log.warn("version option is required only for 'dm' mode : it will be ignored..."); } switch (int_version) { case 1: version = Version.WD_20120529; break; case 2: version = Version.WD_20110324; // Check DB compatibilities if (!(driver.equals(DriverType.MysqlDriver) || driver.equals(DriverType.PostgreSQL))) { log.error( "Db2triples in Direct Mapping mode does'nt support this driver for the Working Draft" + " of 23 March 2011 (only MySQL and PostGreSQL for this time). " + "You can set the version option to select Working Draft of 20 September 2011."); System.exit(-1); } break; default: break; } } // r2rml instance if (mode.equals("r2rml")) { if (!line.hasOption("r2rml_file")) { log.error("R2RML config file is required. Use -r option to set it."); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(projectNameR2RMLMode, r2rmlOptions); System.exit(-1); } else { r2rmlFile = line.getOptionValue("r2rml_file"); File r2rmlFileTest = new File(r2rmlFile); if (!r2rmlFileTest.exists()) { log.error("R2RML file does not exists."); System.exit(-1); } } } } catch (ParseException exp) { // oops, something went wrong log.error("Parsing failed. Reason : " + exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(projectName, options); System.exit(-1); } // Open test database Connection conn = null; try { // Connect database conn = SQLConnector.connect(userName, password, url + dbName, driver); // Generate RDF graph SesameDataSet g = null; // Check nature of storage (memory by default) if (useNativeStore) { File pathToNativeOutputDir = new File(nativeOutput); if (pathToNativeOutputDir.exists() && !forceExistingRep) { log.error("Directory " + pathToNativeOutputDir + " already exists. Use -f option to force loading of existing repository."); System.exit(-1); } // Extract database model according to convert mode if (mode.equals("r2rml")) { g = R2RMLProcessor.convertDatabase(conn, r2rmlFile, baseURI, nativeOutput, driver); } else { g = DirectMapper.generateDirectMapping(conn, version, driver, baseURI, null, nativeOutput); } } else { File outputFile = new File(output); if (outputFile.exists() && !forceExistingRep) { log.error("Output file " + outputFile.getAbsolutePath() + " already exists. Please remove it or modify ouput name option."); System.exit(-1); } // Extract database model if (mode.equals("r2rml")) { g = R2RMLProcessor.convertDatabase(conn, r2rmlFile, baseURI, driver); } else { g = DirectMapper.generateDirectMapping(conn, version, driver, baseURI, null, null); } // Dump graph log.info("Serialize RDF graph..."); g.dumpRDF(output, rdfFormat); log.info("RDF graph serialized into " + outputFile.getAbsolutePath()); } if (sparql != null && mode.equals("dm")) { log.info("Execute SPARQL transformation..."); Long start = System.currentTimeMillis(); String result = g.runSPARQLFromFile(sparql, rdfFormat); SesameDataSet gResult = new SesameDataSet(); gResult.addString(result, rdfFormat); gResult.dumpRDF(sparqlOutput, rdfFormat); Float stop = Float.valueOf(System.currentTimeMillis() - start) / 1000; log.info("Direct Mapping SPARQL query executed in " + stop + " seconds."); log.info("[DirectMapping:main] Number of triples after transformation : " + gResult.getSize()); } } catch (Exception e) { e.printStackTrace(); } finally { try { // Close db connection conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:strat.mining.multipool.stats.builder.CoinshiftStatsBuilder.java
private AddressStats updateAddressStats(Address address, Date refreshDate) throws Exception { LOGGER.debug("Update addressStats for coinshift address {}.", address.getAddress()); long start = System.currentTimeMillis(); strat.mining.multipool.stats.jersey.model.coinshift.AddressStats rawAddressStats = coinshiftRestClient .getAddressStats(address.getAddress()); AddressStats result = null;/*from w w w. j a v a2 s. c o m*/ if (rawAddressStats != null) { result = new AddressStats(); result.setAddressId(address.getId()); result.setBalance(rawAddressStats.getExchanged_balance() == null ? 0 : Float.valueOf(rawAddressStats.getExchanged_balance())); result.setUnexchanged(rawAddressStats.getUnexchanged_balance() == null ? 0 : Float.valueOf(rawAddressStats.getUnexchanged_balance())); result.setPaidout( rawAddressStats.getPayout_sum() == null ? 0 : Float.valueOf(rawAddressStats.getPayout_sum())); result.setHashRate( rawAddressStats.getHashrate() == null ? 0 : rawAddressStats.getHashrate().floatValue()); result.setRejectedHashRate( rawAddressStats.getRejectrate() == null ? 0 : rawAddressStats.getRejectrate().floatValue()); result.setRefreshTime(refreshDate); addressStatsDao.insertAddressStats(result); Transaction lastTransaction = transactionDao.getLastTransaction(address.getId()); SimpleDateFormat dateFormat = new SimpleDateFormat(PAYEMENT_DATE_PATTERN); if (CollectionUtils.isNotEmpty(rawAddressStats.getPayouts())) { for (Payouts payement : rawAddressStats.getPayouts()) { Date payementDate = dateFormat.parse(payement.getTimestamp()); if (lastTransaction == null || lastTransaction.getDate().before(payementDate)) { Transaction transaction = new Transaction(); transaction.setAddressId(address.getId()); transaction.setAmount(payement.getValue() == null ? 0 : Float.valueOf(payement.getValue())); transaction.setDate(payementDate); transaction.setTransactionId(payement.getTx()); transactionDao.insertTransaction(transaction); } else { // When all last transactions are inserted, just break break; } } } } else { throw new Exception("Unable to retrieve coinshift raw stats for address " + address); } PERF_LOGGER.debug("coinshift address {} updated in {} ms.", address.getAddress(), System.currentTimeMillis() - start); return result; }
From source file:idgs.execution.InsertOperator.java
private Object getFieldValue(FieldDescriptor field, String stringValue) throws IdgsException { Object value = null;/* w w w . j av a 2 s. c o m*/ String errMsg = "Wrong object type used with protocol message reflection, field " + field.getName() + " + need type " + field.getJavaType().toString(); switch (field.getJavaType()) { case INT: if (!isNumeric(stringValue)) { throw new IdgsException(errMsg); } value = Integer.valueOf(stringValue); break; case LONG: if (!isNumeric(stringValue)) { throw new IdgsException(errMsg); } value = Long.valueOf(stringValue); break; case FLOAT: if (!isNumeric(stringValue)) { throw new IdgsException(errMsg); } value = Float.valueOf(stringValue); break; case DOUBLE: if (!isNumeric(stringValue)) { throw new IdgsException(errMsg); } value = Double.valueOf(stringValue); break; case BOOLEAN: value = Boolean.valueOf(stringValue); break; case STRING: value = stringValue; break; case BYTE_STRING: value = ByteString.copyFrom(stringValue.getBytes()); break; case ENUM: if (!isNumeric(stringValue)) { value = field.getEnumType().findValueByName(stringValue); } else { value = field.getEnumType().findValueByNumber(Integer.valueOf(stringValue)); } if (value == null) { throw new IdgsException(errMsg); } break; case MESSAGE: throw new IdgsException("Not supported Message type yet."); default: break; } return value; }
From source file:com.example.savedollars.ProductTotalPriceDisplay.java
private void parseJsonData(String data) { //Convert to JSON object for parsing JSONData = data;/*from w w w . j a va 2s . c o m*/ try { JSONObject jsonResponse = new JSONObject(data); //Get the names // JSONArray arr = jsonResponse.names(); JSONArray parsedItems = jsonResponse.getJSONArray("items"); JSONObject inventory = null; //JSONObject inventory = parsedItems.getJSONObject("inventories"); for (int j = 0; j < parsedItems.length(); j++) { inventory = parsedItems.getJSONObject(j); JSONObject objPrice = inventory.getJSONObject("product"); JSONObject merchant = objPrice.getJSONObject("author"); String merchantName = merchant.getString("name"); System.out.println("MERCHANT NAME = " + merchantName); //JSONArray merchantArray = merchant.getJSONArray("name"); JSONArray invObj = objPrice.getJSONArray("inventories"); System.out.println("merchant array length is : " + merchant.toString()); System.out.println("invObj length is : " + invObj.length()); for (int z = 0; z < invObj.length(); z++) { JSONObject price = invObj.getJSONObject(z); System.out.println(" Json object price is: " + price.toString()); String productPrice = price.getString("price"); String shipping = price.getString("shipping"); float finalPrice = Float.parseFloat(productPrice) + Float.parseFloat(shipping); System.out.println("Final price is " + finalPrice); merchantMap.put(merchantName, finalPrice); sortedList.add(Float.valueOf(finalPrice)); } //Bets Adding JSONArray imgObj = objPrice.getJSONArray("images"); for (int i = 0; i < imgObj.length(); i++) { JSONObject imgLink = imgObj.getJSONObject(i); System.out.println("<BETS> Json imgLink is: " + imgLink.toString()); String img = imgLink.getString("link"); System.out.println("<BETS> img Link : " + img); } pdtName = objPrice.getString("title"); System.out.println("<BETS> Pdt NAME :" + pdtName); } Collections.sort(sortedList); System.out.println("Lowest price is " + sortedList.get(0)); sortMerchantPrices(); merchantNameKeys = sortedMap.keySet(); merchantNames = Arrays.copyOf(merchantNameKeys.toArray(), merchantNameKeys.toArray().length, String[].class); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.siahmsoft.soundroid.sdk7.provider.tracks.SoundcloudTracksStore.java
@Override boolean parseTrack(JSONObject jsonTrack, Track track) throws JSONException { JSONObject jsonUser;/*from w ww . j a va 2 s.co m*/ // JSONObject jsonEvent; if (jsonTrack.has("type")) { // jsonEvent = jsonTrack.getJSONObject("event"); jsonTrack = jsonTrack.getJSONObject("track"); } if (jsonTrack.has(RESPONSE_TAG_USER)) { jsonUser = jsonTrack.getJSONObject(RESPONSE_TAG_USER); track.mUsername = jsonUser.getString(RESPONSE_TAG_USER_USERNAME); track.mUserPermalink = jsonUser.getString(RESPONSE_TAG_USER_PERMALINK); track.mUserPermalinkUrl = jsonUser.getString(RESPONSE_TAG_USER_PERMALINK_URL); track.mUserUri = jsonUser.getString(RESPONSE_TAG_USER_URI); } track.mArtworkPath = jsonTrack.getString(RESPONSE_TAG_ARTWORK_URL); track.mArtworkUrl = jsonTrack.getString(RESPONSE_TAG_ARTWORK_URL); track.mBpm = Float.valueOf("null".equals(jsonTrack.getString(RESPONSE_TAG_BPM)) ? "0.0" : jsonTrack.getString(RESPONSE_TAG_BPM)); track.mCommentCount = jsonTrack.getInt(RESPONSE_TAG_COMMENT_COUNT); track.mCreatedAt = jsonTrack.getString(RESPONSE_TAG_CREATED_AT); track.mDescription = jsonTrack.getString(RESPONSE_TAG_DESCRIPTION); track.mDownloadable = jsonTrack.getString(RESPONSE_TAG_DOWNLOADABLE); track.mDownloadCount = jsonTrack.getInt(RESPONSE_TAG_DOWNLOAD_COUNT); track.mDuration = Integer.valueOf("null".equals(jsonTrack.getString(RESPONSE_TAG_DURATION)) ? "0" : jsonTrack.getString(RESPONSE_TAG_DURATION)); track.mGenre = jsonTrack.getString(RESPONSE_TAG_GENRE); track.mIdTrack = Integer.valueOf( "null".equals(jsonTrack.getString(RESPONSE_TAG_ID)) ? "0" : jsonTrack.getString(RESPONSE_TAG_ID)); track.mIsrc = jsonTrack.getString(RESPONSE_TAG_ISRC); track.mKeySignature = jsonTrack.getString(RESPONSE_TAG_KEY_SIGNATURE); track.mLabelId = jsonTrack.getString(RESPONSE_TAG_LABEL_ID); track.mLabelName = jsonTrack.getString(RESPONSE_TAG_LABEL_NAME); track.mLicense = jsonTrack.getString(RESPONSE_TAG_LICENSE); track.mOriginalFormat = jsonTrack.getString(RESPONSE_TAG_ORIGINAL_FORMAT); track.mPermalink = jsonTrack.getString(RESPONSE_TAG_PERMALINK); track.mPermalinkUrl = jsonTrack.getString(RESPONSE_TAG_PERMALINK_URL); track.mPlaybackCount = Integer.valueOf("null".equals(jsonTrack.getString(RESPONSE_TAG_PLAYBACK_COUNT)) ? "0" : jsonTrack.getString(RESPONSE_TAG_PLAYBACK_COUNT)); track.mPurchaseUrl = jsonTrack.getString(RESPONSE_TAG_PURCHASE_URL); track.mRelease = jsonTrack.getString(RESPONSE_TAG_RELEASE); track.mReleaseDay = jsonTrack.getString(RESPONSE_TAG_RELEASE_DAY); track.mReleaseMonth = jsonTrack.getString(RESPONSE_TAG_RELEASE_MONTH); track.mReleaseYear = jsonTrack.getString(RESPONSE_TAG_RELEASE_YEAR); track.mSharing = jsonTrack.getString(RESPONSE_TAG_SHARING); track.mStreamable = jsonTrack.getString(RESPONSE_TAG_STREAMABLE); // TODO ver que hacer cuando la cancin no es streamable if ("true".equals(track.mStreamable)) { track.mStreamUrl = jsonTrack.getString(RESPONSE_TAG_STREAM_URL); } track.mTagList = jsonTrack.getString(RESPONSE_TAG_TAG_LIST); track.mTitle = jsonTrack.getString(RESPONSE_TAG_TITLE); track.mTrackType = jsonTrack.getString(RESPONSE_TAG_TRACK_TYPE); track.mUri = jsonTrack.getString(RESPONSE_TAG_URI); track.mUserId = jsonTrack.getString(RESPONSE_TAG_USER_ID); track.mVideoUrl = jsonTrack.getString(RESPONSE_TAG_VIDEO_URL); track.mWaveFormUrl = jsonTrack.getString(RESPONSE_TAG_WAVEFORM_URL); return track.mIdTrack > 0 && track.mUserId != null; }
From source file:com.cloudera.science.avro.common.JsonConverter.java
private Object typeConvert(Object value, String name, Schema schema) throws IOException { if (isNullableSchema(schema)) { if (value == null) { return null; } else {//from w w w . ja v a2 s . c om schema = getNonNull(schema); } } else if (value == null) { // Always fail on null for non-nullable schemas throw new JsonConversionException(value, name, schema); } switch (schema.getType()) { case BOOLEAN: if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof String) { return Boolean.valueOf((String) value); } else if (value instanceof Number) { return ((Number) value).intValue() == 0 ? Boolean.FALSE : Boolean.TRUE; } break; case DOUBLE: if (value instanceof Number) { return ((Number) value).doubleValue(); } else if (value instanceof String) { return Double.valueOf((String) value); } break; case FLOAT: if (value instanceof Number) { return ((Number) value).floatValue(); } else if (value instanceof String) { return Float.valueOf((String) value); } break; case INT: if (value instanceof Number) { return ((Number) value).intValue(); } else if (value instanceof String) { return Integer.valueOf((String) value); } break; case LONG: if (value instanceof Number) { return ((Number) value).longValue(); } else if (value instanceof String) { return Long.valueOf((String) value); } break; case STRING: return value.toString(); case RECORD: return convert((Map<String, Object>) value, schema); case ARRAY: Schema elementSchema = schema.getElementType(); List listRes = new ArrayList(); for (Object v : (List) value) { listRes.add(typeConvert(v, name, elementSchema)); } return listRes; case MAP: Schema valueSchema = schema.getValueType(); Map<String, Object> mapRes = new HashMap<String, Object>(); for (Map.Entry<String, Object> v : ((Map<String, Object>) value).entrySet()) { mapRes.put(v.getKey(), typeConvert(v.getValue(), name, valueSchema)); } return mapRes; default: throw new IllegalArgumentException("JsonConverter cannot handle type: " + schema.getType()); } throw new JsonConversionException(value, name, schema); }
From source file:zerogame.info.javapay.web.OrderPayWebCallBack.java
@RequestMapping(value = "/itools", method = RequestMethod.POST) @ResponseBody/*from w ww . j av a2 s . c o m*/ public String itoolsPayOrder(@RequestParam("sign") String sign, @RequestParam("notify_data") String notifyData) { logger.info("sign is " + sign + " notify is " + notifyData); boolean verified = false; String notifyJson = ""; try { //RSA?json //?json?: {"order_id_com":"???-accountID-time-goodid-serverid","user_id":"10010","amount":"0.10","account":"test001","order_id":"2013050900000713","result":"success"} notifyJson = RSASignature.decrypt(notifyData); //?RSA?? verified = RSASignature.verify(notifyJson, sign); logger.info("notify json is " + notifyJson + " verified is " + verified); if (verified) { IToolsNotify iToolsNotify = JSON.parseObject(notifyJson, IToolsNotify.class); String[] params = iToolsNotify.getOrderIdCom().split("-"); String channelId = params[0]; String accountId = params[1]; String time = params[2]; String goodId = params[3]; String serverId = params[4]; Player user = userDao.getPlayer(CHANNEL_ITOOLS, accountId, serverId); logger.info("user is " + user.getUin()); if (user != null) { PayOrder payOrder = new PayOrder(); payOrder.setUin(user.getUin()); payOrder.setAccountId(accountId); payOrder.setChannel(CHANNEL_ITOOLS); payOrder.setOrderId(iToolsNotify.getOrderIdCom()); payOrder.setProductId(goodId); payOrder.setServerId(Integer.valueOf(serverId)); float money = Float.valueOf(iToolsNotify.getAmount()); payOrder.setMoney(Math.round(money)); logger.info(payOrder.getAccountId()); this.payOrderDao.add(payOrder); } else { return "fail"; } } } catch (Exception e) { logger.warn("pay failed.", e); } if (verified) { //???, ??notifyJson, ??, ? return "success"; } else { return "fail"; } }