List of usage examples for java.lang Float toString
public static String toString(float f)
From source file:com.yolanda.nohttp.BasicRequest.java
@Override public void add(String key, float value) { add(key, Float.toString(value)); }
From source file:com.tapjoy.TapjoyConnectCore.java
/** * Constructs the generic URL parameters without an App ID. * This is the base method for generating the URL parameters. * Does NOT include:/* ww w .ja v a 2 s . c om*/ * app_id (App ID) * publisher_user_id (publisher user ID) * referrer (for referral tracking) * verifier/timestamp * @return Generic URL parameters without app ID. */ private static String getParamsWithoutAppID() { String urlParams = ""; // Construct the url parameters. urlParams += TapjoyConstants.TJC_ANDROID_ID + "=" + androidID + "&"; // If this flag is set, then send sha2_udid instead of udid. if (getFlagValue(TapjoyConnectFlag.SHA_2_UDID) != null && getFlagValue(TapjoyConnectFlag.SHA_2_UDID).equals("true")) { urlParams += TapjoyConstants.TJC_SHA2_DEVICE_ID_NAME + "=" + Uri.encode(sha2DeviceID) + "&"; } else { urlParams += TapjoyConstants.TJC_DEVICE_ID_NAME + "=" + Uri.encode(deviceID) + "&"; } // Mac address. if (macAddress != null && macAddress.length() > 0) { // Only send SHA-1 mac_address. //urlParams += TapjoyConstants.TJC_DEVICE_MAC_ADDRESS + "=" + Uri.encode(macAddress) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_SHA1_MAC_ADDRESS + "=" + Uri.encode(sha1MacAddress) + "&"; } // Serial ID. if (serialID != null && serialID.length() > 0) { urlParams += TapjoyConstants.TJC_DEVICE_SERIAL_ID + "=" + Uri.encode(serialID) + "&"; } urlParams += TapjoyConstants.TJC_DEVICE_NAME + "=" + Uri.encode(deviceModel) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_MANUFACTURER + "=" + Uri.encode(deviceManufacturer) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_TYPE_NAME + "=" + Uri.encode(deviceType) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_OS_VERSION_NAME + "=" + Uri.encode(deviceOSVersion) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_COUNTRY_CODE + "=" + Uri.encode(deviceCountryCode) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_LANGUAGE + "=" + Uri.encode(deviceLanguage) + "&"; urlParams += TapjoyConstants.TJC_APP_VERSION_NAME + "=" + Uri.encode(appVersion) + "&"; urlParams += TapjoyConstants.TJC_CONNECT_LIBRARY_VERSION_NAME + "=" + Uri.encode(libraryVersion) + "&"; urlParams += TapjoyConstants.TJC_PLATFORM + "=" + Uri.encode(platformName) + "&"; // Virtual Currency Multiplier urlParams += TapjoyConstants.TJC_CURRENCY_MULTIPLIER + "=" + Uri.encode(Float.toString(currencyMultiplier)); // Add carrier name. if (carrierName.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_CARRIER_NAME + "=" + Uri.encode(carrierName); } // Carrier country code. if (carrierCountryCode.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_CARRIER_COUNTRY_CODE + "=" + Uri.encode(carrierCountryCode); } // MCC if (mobileCountryCode.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_MOBILE_COUNTRY_CODE + "=" + Uri.encode(mobileCountryCode); } // MNC if (mobileNetworkCode.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_MOBILE_NETWORK_CODE + "=" + Uri.encode(mobileNetworkCode); } // Add device density and screen layout size. if (deviceScreenDensity.length() > 0 && deviceScreenLayoutSize.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_DEVICE_SCREEN_DENSITY + "=" + Uri.encode(deviceScreenDensity) + "&"; urlParams += TapjoyConstants.TJC_DEVICE_SCREEN_LAYOUT_SIZE + "=" + Uri.encode(deviceScreenLayoutSize); } // Connection type connectionType = getConnectionType(); if (connectionType.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_CONNECTION_TYPE + "=" + Uri.encode(connectionType); } // Plugin if (plugin.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_PLUGIN + "=" + Uri.encode(plugin); } // SDK type. if (sdkType.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_SDK_TYPE + "=" + Uri.encode(sdkType); } // App store/market name. if (marketName.length() > 0) { urlParams += "&"; urlParams += TapjoyConstants.TJC_MARKET_NAME + "=" + Uri.encode(marketName); } return urlParams; }
From source file:eu.stratosphere.configuration.Configuration.java
/** * Adds the given key/value pair to the configuration object. * /* www .j a v a 2s . c o m*/ * @param key * the key of the key/value pair to be added * @param value * the value of the key/value pair to be added */ public void setFloat(String key, float value) { setStringInternal(key, Float.toString(value)); }
From source file:fr.ritaly.dungeonmaster.item.ItemDef.java
public static void main(String[] args) throws Exception { final List<Item.Type> types = Arrays.asList(Item.Type.values()); Collections.sort(types, new Comparator<Item.Type>() { @Override/*from w w w . j a v a2 s .com*/ public int compare(Type o1, Type o2) { return o1.name().compareTo(o2.name()); } }); final StringWriter stringWriter = new StringWriter(32000); final XMLStreamWriter writer = new IndentingXMLStreamWriter( XMLOutputFactory.newFactory().createXMLStreamWriter(stringWriter)); writer.writeStartDocument(); writer.writeStartElement("items"); writer.writeDefaultNamespace("yadmjc:items:1.0"); for (Item.Type type : types) { writer.writeStartElement("item"); writer.writeAttribute("id", type.name()); writer.writeAttribute("weight", Float.toString(type.getWeight())); if (type.getDamage() != -1) { writer.writeAttribute("damage", Integer.toString(type.getDamage())); } if (type.getActivationBodyPart() != null) { writer.writeAttribute("activation", type.getActivationBodyPart().name()); } if (type.getShield() != 0) { writer.writeAttribute("shield", Integer.toString(type.getShield())); } if (type.getAntiMagic() != 0) { writer.writeAttribute("anti-magic", Integer.toString(type.getAntiMagic())); } if (type.getDecayRate() != -1) { writer.writeAttribute("decay-rate", Integer.toString(type.getDecayRate())); } if (type.getDistance() != -1) { writer.writeAttribute("distance", Integer.toString(type.getDistance())); } if (type.getShootDamage() != -1) { writer.writeAttribute("shoot-damage", Integer.toString(type.getShootDamage())); } if (!type.getCarryLocations().isEmpty()) { writer.writeStartElement("locations"); // Sort the locations to ensure they're always serialized in a consistent way for (CarryLocation location : new TreeSet<CarryLocation>(type.getCarryLocations())) { writer.writeEmptyElement("location"); writer.writeAttribute("id", location.name()); } writer.writeEndElement(); } if (!type.getActions().isEmpty()) { writer.writeStartElement("actions"); for (ActionDef actionDef : type.getActions()) { writer.writeEmptyElement("action"); writer.writeAttribute("id", actionDef.getAction().name()); if (actionDef.getMinLevel() != Champion.Level.NONE) { writer.writeAttribute("min-level", actionDef.getMinLevel().name()); } if (actionDef.isUseCharges()) { writer.writeAttribute("use-charges", Boolean.toString(actionDef.isUseCharges())); } } writer.writeEndElement(); // </actions> } if (!type.getEffects().isEmpty()) { writer.writeStartElement("effects"); for (Effect effect : type.getEffects()) { writer.writeEmptyElement("effect"); writer.writeAttribute("stat", effect.getStatistic().name()); writer.writeAttribute("strength", String.format("%+d", effect.getStrength())); } writer.writeEndElement(); // </effects> } writer.writeEndElement(); // </item> } writer.writeEndElement(); // </items> writer.writeEndDocument(); System.out.println(stringWriter); }
From source file:co.turnus.trace.io.XmlTraceStreamWriter.java
@SuppressWarnings("rawtypes") private void writeObject(Object v) { try {/*from w w w .ja va2s.co m*/ if (v instanceof Boolean) { writer.writeEmptyElement(TYPE_BOOLEAN); writer.writeAttribute(VALUE, Boolean.toString((Boolean) v)); } else if (v instanceof Byte || v instanceof Short || v instanceof Integer) { writer.writeEmptyElement(TYPE_INTEGER); writer.writeAttribute(VALUE, Integer.toString((Integer) v)); } else if (v instanceof Long) { writer.writeEmptyElement(TYPE_INTEGER); writer.writeAttribute(VALUE, Long.toString((Long) v)); } else if (v instanceof Float) { writer.writeEmptyElement(TYPE_REAL); writer.writeAttribute(VALUE, Float.toString((Float) v)); } else if (v instanceof Double) { writer.writeEmptyElement(TYPE_REAL); writer.writeAttribute(VALUE, Double.toString((Double) v)); } else if (v instanceof String) { writer.writeEmptyElement(TYPE_STRING); writer.writeAttribute(VALUE, (String) v); } else if (v instanceof List) { writer.writeStartElement(TYPE_LIST); for (Object o : (List) v) { writeObject(o); } writer.writeEndElement(); } else if (v instanceof Set) { writer.writeStartElement(TYPE_SET); for (Object o : (Set) v) { writeObject(o); } writer.writeEndElement(); } else if (v instanceof Map) { writer.writeStartElement(TYPE_MAP); for (Object k : ((Map) v).keySet()) { writer.writeStartElement(ENTRY); writeObject(k); writeObject(((Map) v).get(k)); writer.writeEndElement(); } writer.writeEndElement(); } } catch (XMLStreamException e) { throw new TurnusRuntimeException("Trace Writer Error: " + e.getLocalizedMessage(), e.getCause()); } }
From source file:org.lockss.pdf.PdfUtil.java
/** * <p>/*from w w w.j a va 2s . co m*/ * Convenience method to output a human-readable version of the * given token to the given string builder. * </p> * @param sb A string builder. * @param pdfToken A PDF token. * @since 1.57 */ public static void prettyPrint(StringBuilder sb, PdfToken pdfToken) { sb.append("["); if (pdfToken.isArray()) { sb.append("array:"); for (PdfToken arrayToken : pdfToken.getArray()) { prettyPrint(arrayToken); } } else if (pdfToken.isBoolean()) { sb.append("boolean:"); sb.append(Boolean.toString(pdfToken.getBoolean())); } else if (pdfToken.isDictionary()) { boolean first = true; sb.append("dictionary:"); for (Map.Entry<String, PdfToken> entry : pdfToken.getDictionary().entrySet()) { if (first) { first = false; } else { sb.append(";"); } sb.append(StringEscapeUtils.escapeJava(entry.getKey())); sb.append("="); prettyPrint(entry.getValue()); } } else if (pdfToken.isFloat()) { sb.append("float:"); sb.append(Float.toString(pdfToken.getFloat())); } else if (pdfToken.isInteger()) { sb.append("integer:"); sb.append(Long.toString(pdfToken.getInteger())); } else if (pdfToken.isName()) { sb.append("name:"); sb.append(StringEscapeUtils.escapeJava(pdfToken.getName())); } else if (pdfToken.isNull()) { sb.append("null"); } else if (pdfToken.isObject()) { sb.append("object:"); prettyPrint(sb, pdfToken.getObject()); } else if (pdfToken.isOperator()) { sb.append("operator:"); sb.append(StringEscapeUtils.escapeJava(pdfToken.getOperator())); } else if (pdfToken.isString()) { sb.append("string:\""); sb.append(StringEscapeUtils.escapeJava(pdfToken.getString())); sb.append("\""); } sb.append("]"); }
From source file:ExposedFloat.java
void updateNumberFields() { int intBits = Float.floatToIntBits(value); if (Float.isNaN(value)) { base10Field.setText(notANumberString); } else if (Float.isInfinite(value)) { if ((intBits >>> 31) == 1) { // This is a negative infinity base10Field.setText(negativeInfinityString); } else {//from w w w. ja va2s .com // This is a positive infinity base10Field.setText(positiveInfinityString); } } else if (intBits == (int) 0x80000000) { base10Field.setText("-0"); } else { base10Field.setText(Float.toString(value)); } int v = intBits; StringBuffer buf = new StringBuffer(); for (int i = 0; i < 8; ++i) { // Get lowest bit int remainder = v & 0xf; // Convert bit to a character and insert it into the beginning of the string switch (remainder) { case 0: buf.insert(0, "0"); break; case 1: buf.insert(0, "1"); break; case 2: buf.insert(0, "2"); break; case 3: buf.insert(0, "3"); break; case 4: buf.insert(0, "4"); break; case 5: buf.insert(0, "5"); break; case 6: buf.insert(0, "6"); break; case 7: buf.insert(0, "7"); break; case 8: buf.insert(0, "8"); break; case 9: buf.insert(0, "9"); break; case 10: buf.insert(0, "a"); break; case 11: buf.insert(0, "b"); break; case 12: buf.insert(0, "c"); break; case 13: buf.insert(0, "d"); break; case 14: buf.insert(0, "e"); break; case 15: buf.insert(0, "f"); break; } // Shift the int to the right one bit v >>>= 4; } hexField.setText(buf.toString()); v = intBits; buf.setLength(0); for (int i = 0; i < 32; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } binaryField.setText(buf.toString()); if (intBits < 0) { signField.setText("1"); } else { signField.setText("0"); } v = intBits >> 23; buf.setLength(0); for (int i = 0; i < 8; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } exponentField.setText(buf.toString()); // Do the mantissa v = intBits; buf.setLength(0); for (int i = 0; i < 23; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } if (((intBits >> 23) & 0xff) == 0) { // This is a denormalized number, first bit is 0 buf.insert(0, "0"); } else { // This is a normalized number, first bit is 1 buf.insert(0, "1"); } mantissaField.setText(buf.toString()); // Print out a denormalized base 2 version. buf.setLength(0); if (Float.isNaN(value)) { buf.append(notANumberString); } else if (Float.isInfinite(value)) { if ((intBits >>> 31) == 1) { // This is a negative infinity buf.append(negativeInfinityString); } else { // This is a positive infinity buf.append(positiveInfinityString); } } else { if ((intBits >>> 31) == 1) { // This is a negative number buf.append("-"); } // Convert mantissa to int. v = (intBits & 0x007fffff); if (((intBits >> 23) & 0xff) != 0) { // Set bit 23 if the number is normalized v |= 0x00800000; } buf.append(v); // print out the exponent v = (intBits >> 23) & 0xff; if (v != 150 && intBits != 0 && intBits != (int) 0x80000000) { if (v != 0) { // regular normalized number buf.append("e" + (v - 150)); } else { // denormalized number buf.append("e-149"); } } } base2Field.setText(buf.toString()); }
From source file:org.apache.xmlgraphics.ps.PSGenerator.java
/** * Converts a <real> value for use in DSC comments. * @param value the value to convert//w ww.j a v a2 s . co m * @return String The resulting String */ public static final String convertRealToDSC(float value) { return Float.toString(value); }
From source file:org.apache.hadoop.mapreduce.TestMapCollection.java
private static void runTest(String name, int keylen, int vallen, int records, int ioSortMB, float spillPer) throws Exception { Configuration conf = new Configuration(); conf.setInt(Job.COMPLETION_POLL_INTERVAL_KEY, 100); Job job = Job.getInstance(conf);//from w ww.ja v a 2s . c o m conf = job.getConfiguration(); conf.setInt(MRJobConfig.IO_SORT_MB, ioSortMB); conf.set(MRJobConfig.MAP_SORT_SPILL_PERCENT, Float.toString(spillPer)); conf.setClass("test.mapcollection.class", FixedRecordFactory.class, RecordFactory.class); FixedRecordFactory.setLengths(conf, keylen, vallen); conf.setInt("test.spillmap.records", records); runTest(name, job); }
From source file:sep.gaia.resources.poi.POILoaderWorker.java
/** * Returns an element to limit a query to a specific geographical area. * @param doc The document to create the element in. * @param bbox The boundaries of the queries area. * @return The bounding-box-element ready to be added to a query. *//*from www . j a va 2 s. com*/ private static Element createBBoxElement(Document doc, FloatBoundingBox bbox) { // The Overpass-API does use sides instead of corners, so convert them: float east = bbox.getUpperRight().getY(); float west = bbox.getLowerRight().getY(); float north = bbox.getUpperLeft().getX(); float south = bbox.getLowerRight().getX(); // Create the element and add the attributes describing the sides of the bbox: Element element = doc.createElement("bbox-query"); element.setAttribute("e", Float.toString(Math.max(east, west))); element.setAttribute("w", Float.toString(Math.min(east, west))); element.setAttribute("n", Float.toString(Math.max(north, south))); element.setAttribute("s", Float.toString(Math.min(north, south))); return element; }