List of usage examples for java.lang Float toString
public static String toString(float f)
From source file:org.apache.tika.parser.pdf.EnhancedPDFParser.java
@SuppressWarnings("deprecation") private void extractMetadata(PDDocument document, Metadata metadata) throws TikaException { XMPMetadata xmp = null;/*from w w w. j a v a 2 s .c o m*/ XMPSchemaDublinCore dcSchema = null; try { if (document.getDocumentCatalog().getMetadata() != null) { xmp = XMPMetadata.load(document.getDocumentCatalog().getMetadata().exportXMPMetadata()); } if (xmp != null) { dcSchema = xmp.getDublinCoreSchema(); } } catch (IOException e) { //swallow } PDDocumentInformation info = document.getDocumentInformation(); metadata.set(PagedText.N_PAGES, document.getNumberOfPages()); extractMultilingualItems(metadata, TikaCoreProperties.TITLE, info.getTitle(), dcSchema); extractDublinCoreListItems(metadata, TikaCoreProperties.CREATOR, info.getAuthor(), dcSchema); extractDublinCoreListItems(metadata, TikaCoreProperties.CONTRIBUTOR, null, dcSchema); addMetadata(metadata, TikaCoreProperties.CREATOR_TOOL, info.getCreator()); addMetadata(metadata, TikaCoreProperties.KEYWORDS, info.getKeywords()); addMetadata(metadata, "producer", info.getProducer()); extractMultilingualItems(metadata, TikaCoreProperties.DESCRIPTION, null, dcSchema); // TODO: Move to description in Tika 2.0 addMetadata(metadata, TikaCoreProperties.TRANSITION_SUBJECT_TO_OO_SUBJECT, info.getSubject()); addMetadata(metadata, "trapped", info.getTrapped()); // TODO Remove these in Tika 2.0 addMetadata(metadata, "created", info.getCreationDate()); addMetadata(metadata, TikaCoreProperties.CREATED, info.getCreationDate()); Calendar modified = info.getModificationDate(); addMetadata(metadata, Metadata.LAST_MODIFIED, modified); addMetadata(metadata, TikaCoreProperties.MODIFIED, modified); // All remaining metadata is custom // Copy this over as-is List<String> handledMetadata = Arrays.asList("Author", "Creator", "CreationDate", "ModDate", "Keywords", "Producer", "Subject", "Title", "Trapped"); for (COSName key : info.getDictionary().keySet()) { String name = key.getName(); if (!handledMetadata.contains(name)) { addMetadata(metadata, name, info.getDictionary().getDictionaryObject(key)); } } //try to get the various versions //Caveats: // there is currently a fair amount of redundancy // TikaCoreProperties.FORMAT can be multivalued // There are also three potential pdf specific version keys: pdf:PDFVersion, pdfa:PDFVersion, pdf:PDFExtensionVersion metadata.set("pdf:PDFVersion", Float.toString(document.getDocument().getVersion())); metadata.add(TikaCoreProperties.FORMAT.getName(), MEDIA_TYPE.toString() + "; version=" + Float.toString(document.getDocument().getVersion())); try { if (xmp != null) { xmp.addXMLNSMapping(XMPSchemaPDFAId.NAMESPACE, XMPSchemaPDFAId.class); XMPSchemaPDFAId pdfaxmp = (XMPSchemaPDFAId) xmp.getSchemaByClass(XMPSchemaPDFAId.class); if (pdfaxmp != null) { metadata.set("pdfaid:part", Integer.toString(pdfaxmp.getPart())); if (pdfaxmp.getConformance() != null) { metadata.set("pdfaid:conformance", pdfaxmp.getConformance()); String version = "A-" + pdfaxmp.getPart() + pdfaxmp.getConformance().toLowerCase(Locale.ROOT); metadata.set("pdfa:PDFVersion", version); metadata.add(TikaCoreProperties.FORMAT.getName(), MEDIA_TYPE.toString() + "; version=\"" + version + "\""); } } // TODO WARN if this XMP version is inconsistent with document header version? } } catch (IOException e) { metadata.set(TikaCoreProperties.TIKA_META_PREFIX + "pdf:metadata-xmp-parse-failed", "" + e); } //TODO: Let's try to move this into PDFBox. //Attempt to determine Adobe extension level, if present: COSDictionary root = document.getDocumentCatalog().getCOSObject(); COSDictionary extensions = (COSDictionary) root.getDictionaryObject(COSName.getPDFName("Extensions")); if (extensions != null) { for (COSName extName : extensions.keySet()) { // If it's an Adobe one, interpret it to determine the extension level: if (extName.equals(COSName.getPDFName("ADBE"))) { COSDictionary adobeExt = (COSDictionary) extensions.getDictionaryObject(extName); if (adobeExt != null) { String baseVersion = adobeExt.getNameAsString(COSName.getPDFName("BaseVersion")); int el = adobeExt.getInt(COSName.getPDFName("ExtensionLevel")); //-1 is sentinel value that something went wrong in getInt if (el != -1) { metadata.set("pdf:PDFExtensionVersion", baseVersion + " Adobe Extension Level " + el); metadata.add(TikaCoreProperties.FORMAT.getName(), MEDIA_TYPE.toString() + "; version=\"" + baseVersion + " Adobe Extension Level " + el + "\""); } } } else { // WARN that there is an Extension, but it's not Adobe's, and so is a 'new' format'. metadata.set("pdf:foundNonAdobeExtensionName", extName.getName()); } } } }
From source file:org.apache.geode.management.internal.cli.domain.RegionAttributesInfo.java
/*** * Returns Map of the non default Attributes and its values *///from w w w . j a v a2s. co m public Map<String, String> getNonDefaultAttributes() { if (nonDefaultAttributes == null) { nonDefaultAttributes = new HashMap<String, String>(); if (cloningEnabled != RegionAttributesDefault.CLONING_ENABLED) { nonDefaultAttributes.put(RegionAttributesNames.CLONING_ENABLED, Boolean.toString(cloningEnabled)); } if (!StringUtils.equals(RegionAttributesDefault.COMPRESSOR_CLASS_NAME, compressorClassName)) { nonDefaultAttributes.put(RegionAttributesNames.COMPRESSOR, compressorClassName); } if (concurrencyChecksEnabled != RegionAttributesDefault.CONCURRENCY_CHECK_ENABLED) { nonDefaultAttributes.put(RegionAttributesNames.CONCURRENCY_CHECK_ENABLED, Boolean.toString(concurrencyChecksEnabled)); } if (concurrencyLevel != RegionAttributesDefault.CONCURRENCY_LEVEL) { nonDefaultAttributes.put(RegionAttributesNames.CONCURRENCY_LEVEL, Integer.toString(concurrencyLevel)); } if (!dataPolicy.equals(RegionAttributesDefault.DATA_POLICY)) { nonDefaultAttributes.put(RegionAttributesNames.DATA_POLICY, dataPolicy.toString()); } if (diskStoreName != null && !diskStoreName.equals(RegionAttributesDefault.DISK_STORE_NAME)) { nonDefaultAttributes.put(RegionAttributesNames.DISK_STORE_NAME, diskStoreName); } if (enableAsyncConflation != RegionAttributesDefault.ENABLE_ASYNC_CONFLATION) { nonDefaultAttributes.put(RegionAttributesNames.ENABLE_ASYNC_CONFLATION, Boolean.toString(enableAsyncConflation)); } if (enableSubscriptionConflation != RegionAttributesDefault.ENABLE_SUBSCRIPTION_CONFLATION) { nonDefaultAttributes.put(RegionAttributesNames.ENABLE_SUBSCRIPTION_CONFLATION, Boolean.toString(enableSubscriptionConflation)); } if (entryIdleTimeout != RegionAttributesDefault.ENTRY_IDLE_TIMEOUT) { nonDefaultAttributes.put(RegionAttributesNames.ENTRY_IDLE_TIMEOUT, Integer.toString(entryIdleTimeout)); } if (ignoreJTA != RegionAttributesDefault.IGNORE_JTA) { nonDefaultAttributes.put(RegionAttributesNames.IGNORE_JTA, Boolean.toString(ignoreJTA)); } if (indexMaintenanceSynchronous != RegionAttributesDefault.INDEX_MAINTENANCE_SYNCHRONOUS) { nonDefaultAttributes.put(RegionAttributesNames.INDEX_MAINTENANCE_SYNCHRONOUS, Boolean.toString(indexMaintenanceSynchronous)); } if (initialCapacity != RegionAttributesDefault.INITIAL_CAPACITY) { nonDefaultAttributes.put(RegionAttributesNames.INITIAL_CAPACITY, Integer.toString(initialCapacity)); } if (loadFactor != RegionAttributesDefault.LOAD_FACTOR) { nonDefaultAttributes.put(RegionAttributesNames.LOAD_FACTOR, Float.toString(loadFactor)); } if (multicastEnabled != RegionAttributesDefault.MULTICAST_ENABLED) { nonDefaultAttributes.put(RegionAttributesNames.MULTICAST_ENABLED, Boolean.toString(multicastEnabled)); } if (poolName != null && !poolName.equals(RegionAttributesDefault.POOL_NAME)) { nonDefaultAttributes.put(RegionAttributesNames.POOL_NAME, poolName); } if (!scope.equals(RegionAttributesDefault.SCOPE)) { nonDefaultAttributes.put(RegionAttributesNames.SCOPE, scope.toString()); } if (statisticsEnabled != RegionAttributesDefault.STATISTICS_ENABLED) { nonDefaultAttributes.put(RegionAttributesNames.STATISTICS_ENABLED, Boolean.toString(statisticsEnabled)); } if (isLockGrantor != RegionAttributesDefault.IS_LOCK_GRANTOR) { nonDefaultAttributes.put(RegionAttributesNames.IS_LOCK_GRANTOR, Boolean.toString(isLockGrantor)); } if (entryIdleTimeout != RegionAttributesDefault.ENTRY_IDLE_TIMEOUT) { nonDefaultAttributes.put(RegionAttributesNames.ENTRY_IDLE_TIMEOUT, Integer.toString(entryIdleTimeout)); } if (entryIdleTimeoutAction != null && !entryIdleTimeoutAction.equals(RegionAttributesDefault.ENTRY_IDLE_TIMEOUT_ACTION)) { nonDefaultAttributes.put(RegionAttributesNames.ENTRY_IDLE_TIMEOUT_ACTION, entryIdleTimeoutAction); } if (entryTimeToLive != RegionAttributesDefault.ENTRY_TIME_TO_LIVE) { nonDefaultAttributes.put(RegionAttributesNames.ENTRY_TIME_TO_LIVE, Integer.toString(entryTimeToLive)); } if (entryTimeToLiveAction != null && !entryTimeToLiveAction.equals(RegionAttributesDefault.ENTRY_TIME_TO_LIVE_ACTION)) { nonDefaultAttributes.put(RegionAttributesNames.ENTRY_TIME_TO_LIVE_ACTION, entryTimeToLiveAction); } if (regionIdleTimeout != RegionAttributesDefault.REGION_IDLE_TIMEOUT) { nonDefaultAttributes.put(RegionAttributesNames.REGION_IDLE_TIMEOUT, Integer.toString(regionIdleTimeout)); } if (regionIdleTimeoutAction != null && !regionIdleTimeoutAction.equals(RegionAttributesDefault.REGION_IDLE_TIMEOUT_ACTION)) { nonDefaultAttributes.put(RegionAttributesNames.REGION_IDLE_TIMEOUT_ACTION, regionIdleTimeoutAction); } if (regionTimeToLive != RegionAttributesDefault.REGION_TIME_TO_LIVE) { nonDefaultAttributes.put(RegionAttributesNames.REGION_TIME_TO_LIVE, Integer.toString(regionTimeToLive)); } if (regionTimeToLiveAction != null && !regionTimeToLiveAction.equals(RegionAttributesDefault.REGION_TIME_TO_LIVE_ACTION)) { nonDefaultAttributes.put(RegionAttributesNames.REGION_TIME_TO_LIVE_ACTION, regionTimeToLiveAction); } if (cacheListenerClassNames != null && !cacheListenerClassNames.isEmpty()) { nonDefaultAttributes.put(RegionAttributesNames.CACHE_LISTENERS, CliUtil.convertStringListToString(cacheListenerClassNames, ',')); } if (cacheLoaderClassName != null && !cacheLoaderClassName.isEmpty()) { nonDefaultAttributes.put(RegionAttributesNames.CACHE_LOADER, cacheLoaderClassName); } if (cacheWriterClassName != null && !cacheWriterClassName.isEmpty()) { nonDefaultAttributes.put(RegionAttributesNames.CACHE_WRITER, cacheWriterClassName); } if (this.offHeap != RegionAttributesDefault.OFF_HEAP) { nonDefaultAttributes.put(RegionAttributesNames.OFF_HEAP, Boolean.toString(this.offHeap)); } } return this.nonDefaultAttributes; }
From source file:eu.itesla_project.eurostag.EurostagImpactAnalysis.java
private static void writeLimits(Network network, EurostagDictionary dictionary, Domain domain, OutputStream os) throws IOException { GenericArchive archive = domain.getArchiveFactory().create(GenericArchive.class); try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) { Path rootDir = fileSystem.getPath("/"); // dump first current limits for each of the branches try (BufferedWriter writer = Files.newBufferedWriter(rootDir.resolve(CURRENT_LIMITS_CSV), StandardCharsets.UTF_8)) { for (Line l : network.getLines()) { dumpLimits(dictionary, writer, l); }//from ww w . ja v a 2 s . c o m for (TwoWindingsTransformer twt : network.getTwoWindingsTransformers()) { dumpLimits(dictionary, writer, twt); } for (DanglingLine dl : network.getDanglingLines()) { dumpLimits(dictionary, writer, dl.getId(), dl.getCurrentLimits(), null, dl.getTerminal().getVoltageLevel().getNominalV(), dl.getTerminal().getVoltageLevel().getNominalV()); } } try (BufferedWriter writer = Files.newBufferedWriter(rootDir.resolve(VOLTAGE_LIMITS_CSV), StandardCharsets.UTF_8)) { for (Bus b : network.getBusBreakerView().getBuses()) { VoltageLevel vl = b.getVoltageLevel(); if (!Float.isNaN(vl.getLowVoltageLimit()) && !Float.isNaN(vl.getHighVoltageLimit())) { writer.write(dictionary.getEsgId(b.getId())); writer.write(";"); writer.write(Float.toString(vl.getLowVoltageLimit())); writer.write(";"); writer.write(Float.toString(vl.getHighVoltageLimit())); writer.write(";"); writer.write(Float.toString(vl.getNominalV())); writer.newLine(); } } } //dump lines dictionary, for WP43 integration dumpLinesDictionary(network, dictionary, rootDir); //dump buses dictionary, for WP43 integration dumpBusesDictionary(network, dictionary, rootDir); } archive.as(ZipExporter.class).exportTo(os); }
From source file:org.latticesoft.util.common.NumeralUtil.java
/** * Compares 2 float value based on the given number of decimal * place to compare.//w ww .j a v a 2 s.c om * @param f1 float variable 1 * @param f2 float variable 2 * @param decimalPlace the number of dp to compare * @return 0 if they are the same, 1 if f1 */ public static int compareFloat(float f1, float f2, int decimalPlace) { String[][] s = new String[2][]; s[0] = StringUtil.tokenizeIntoStringArray(Float.toString(f1), "."); s[1] = StringUtil.tokenizeIntoStringArray(Float.toString(f2), "."); if (s[0] == null || s[1] == null) return 0; int[] x = new int[2]; x[0] = NumeralUtil.parseInt(s[0][0]); x[1] = NumeralUtil.parseInt(s[1][0]); if (x[0] > x[1]) return 1; if (x[0] < x[1]) return -1; // they are equal in whole number // now compare decimal point up the the stated decimal places StringBuffer sb = new StringBuffer(); for (int i = 0; i < 2; i++) { sb.setLength(0); int nextPoint = 0; if (s[0][1].length() < decimalPlace) { sb.append(s[i][1]); for (int j = s[i][1].length(); j < decimalPlace; j++) { sb.append("0"); } nextPoint = 0; } else { sb.append(s[i][1].substring(0, decimalPlace)); if (s[i][1].length() >= decimalPlace + 1) { nextPoint = NumeralUtil.parseInt(s[i][1].substring(decimalPlace, decimalPlace + 1)); } else { nextPoint = 0; } } x[i] = NumeralUtil.parseInt(sb.toString()); if (nextPoint >= 5) x[i]++; } if (x[0] > x[1]) return 1; else if (x[0] < x[1]) return -1; else return 0; }
From source file:com.createtank.payments.coinbase.CoinbaseApi.java
/** * Purchase bitcoin by debiting the user's U.S. bank account. * @param qty the number of bitcoins to buy * @return A Transfer object containing information about the purchase * @throws IOException//from w ww. j a v a 2s .com */ public Transfer buyBitcoins(float qty) throws IOException { Map<String, String> params = new HashMap<String, String>(); if (apiKey != null) params.put("api_key", apiKey); params.put("qty", Float.toString(qty)); params.put("agree_btc_amount_varies", Boolean.toString(true)); JsonObject response = RequestClient.post(this, "buys", params, accessToken); boolean success = response.get("success").getAsBoolean(); return success ? Transfer.fromJson(response.getAsJsonObject("transfer")) : null; }
From source file:com.twitter.ambrose.pig.AmbrosePigProgressNotificationListener.java
@SuppressWarnings("deprecation") private Map<JobProgressField, String> buildJobStatusMap(String jobId) { JobClient jobClient = PigStats.get().getJobClient(); try {//from w ww. j a v a2s. co m RunningJob rj = jobClient.getJob(jobId); if (rj == null) { log.warn("Couldn't find job status for jobId=" + jobId); return null; } JobID jobID = rj.getID(); TaskReport[] mapTaskReport = jobClient.getMapTaskReports(jobID); TaskReport[] reduceTaskReport = jobClient.getReduceTaskReports(jobID); Map<JobProgressField, String> progressMap = new HashMap<JobProgressField, String>(); progressMap.put(JobProgressField.jobId, jobId.toString()); progressMap.put(JobProgressField.jobName, rj.getJobName()); progressMap.put(JobProgressField.trackingUrl, rj.getTrackingURL()); progressMap.put(JobProgressField.isComplete, Boolean.toString(rj.isComplete())); progressMap.put(JobProgressField.isSuccessful, Boolean.toString(rj.isSuccessful())); progressMap.put(JobProgressField.mapProgress, Float.toString(rj.mapProgress())); progressMap.put(JobProgressField.reduceProgress, Float.toString(rj.reduceProgress())); progressMap.put(JobProgressField.totalMappers, Integer.toString(mapTaskReport.length)); progressMap.put(JobProgressField.totalReducers, Integer.toString(reduceTaskReport.length)); return progressMap; } catch (IOException e) { log.error("Error getting job info.", e); } return null; }
From source file:model.experiments.tuningRuns.CompetitiveAveragingGridSearch.java
/** * Round to certain number of decimals//from www .ja v a 2 s.c o m * * @param d * @param decimalPlace * @return */ public static float round(float d, int decimalPlace) { BigDecimal bd = new BigDecimal(Float.toString(d)); bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP); return bd.floatValue(); }
From source file:com.gmail.srivi.sundaram.locgenie.MainActivity.java
public void getSuggestion(View v) { if (servicesConnected()) { Log.d(" ", "In getSuggestions_new"); EditText radius = (EditText) findViewById(R.id.editText1); String radiusCheck = radius.getText().toString(); // Getting the Selected Activity RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1); RadioButton selected = (RadioButton) findViewById(rg.getCheckedRadioButtonId()); String activity = (String) selected.getText(); if (radiusCheck.isEmpty()) { Toast.makeText(this, "Please Enter Radius", Toast.LENGTH_SHORT).show(); } else {/*w ww. ja va2 s . c o m*/ float miles = Float.valueOf(radius.getText().toString()); float meters = (float) (miles * 1609.344); String radiusInMeters = Float.toString(meters); Location currentLocation = mLocationClient.getLastLocation(); Intent intent = new Intent(getBaseContext(), DisplayPlacesActivity.class); intent.putExtra(EXTRA_MESSAGE, currentLocation); intent.putExtra(RADIUS, radiusInMeters); intent.putExtra(ACTIVITY, activity); startActivity(intent); } } }
From source file:co.foldingmap.mapImportExport.SvgExporter.java
/** * Generates the SVG style string from a given ColorStyle * /* ww w .j ava 2 s.c o m*/ * @param style * @return */ private String generateLineStyleString(ColorStyle style, boolean isOutline) { Color strokeColor; float width; LineStyle lineStyle; StringBuilder sb; lineStyle = (LineStyle) style; sb = new StringBuilder(); width = lineStyle.getLineWidth(); if (isOutline) { width += 1.2f; strokeColor = lineStyle.getOutlineColor(); } else { strokeColor = lineStyle.getFillColor(); } sb.append("fill-opacity:0;"); sb.append("stroke:#"); sb.append(getHexColor(strokeColor)); sb.append(";"); sb.append("stroke-width:"); sb.append(Float.toString(width)); sb.append(";"); sb.append("stroke-linecap:round;"); return sb.toString(); }
From source file:org.openhab.habdroid.ui.OpenHABWidgetArrayAdapter.java
@Override public String getNewValueAsFullText(String currentFullTextValue, float value) { String textValue = getRegExMatch(currentFullTextValue, Pattern.compile("\\d*\\[.,]?\\d*", Pattern.CASE_INSENSITIVE)); return currentFullTextValue.replaceFirst("\\d*\\[.,]?\\d*", Float.toString(value)); }