List of usage examples for java.lang Float toString
public static String toString(float f)
From source file:com.farmerbb.notepad.fragment.NoteViewFragment.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override// w w w . jav a 2 s . co m public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Set values setRetainInstance(true); setHasOptionsMenu(true); // Get filename of saved note filename = getArguments().getString("filename"); // Change window title String title; try { title = listener.loadNoteTitle(filename); } catch (IOException e) { title = getResources().getString(R.string.view_note); } getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.ic_recents_logo)) .getBitmap(); ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, bitmap, ContextCompat.getColor(getActivity(), R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Show the Up button in the action bar. ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Animate elevation change if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LinearLayout noteViewEdit = getActivity().findViewById(R.id.noteViewEdit); LinearLayout noteList = getActivity().findViewById(R.id.noteList); noteList.animate().z(0f); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) noteViewEdit.animate() .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land)); else noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation)); } // Set up content view TextView noteContents = getActivity().findViewById(R.id.textView); markdownView = getActivity().findViewById(R.id.markdownView); // Apply theme SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences", Context.MODE_PRIVATE); ScrollView scrollView = getActivity().findViewById(R.id.scrollView); String theme = pref.getString("theme", "light-sans"); int textSize = -1; int textColor = -1; String fontFamily = null; if (theme.contains("light")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary)); noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (markdownView != null) { markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (theme.contains("dark")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark)); noteContents .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (markdownView != null) { markdownView .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (theme.contains("sans")) { if (noteContents != null) noteContents.setTypeface(Typeface.SANS_SERIF); if (markdownView != null) fontFamily = "sans-serif"; } if (theme.contains("serif")) { if (noteContents != null) noteContents.setTypeface(Typeface.SERIF); if (markdownView != null) fontFamily = "serif"; } if (theme.contains("monospace")) { if (noteContents != null) noteContents.setTypeface(Typeface.MONOSPACE); if (markdownView != null) fontFamily = "monospace"; } switch (pref.getString("font_size", "normal")) { case "smallest": textSize = 12; break; case "small": textSize = 14; break; case "normal": textSize = 16; break; case "large": textSize = 18; break; case "largest": textSize = 20; break; } if (noteContents != null) noteContents.setTextSize(textSize); String css = ""; if (markdownView != null) { String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom) / getResources().getDisplayMetrics().density) + "px"; String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right) / getResources().getDisplayMetrics().density) + "px"; String fontSize = " " + Integer.toString(textSize) + "px"; String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff"); String linkColor = " #" + StringUtils.remove( Integer.toHexString(new TextView(getActivity()).getLinkTextColors().getDefaultColor()), "ff"); css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:" + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor + "; " + "}" + "a { " + "color:" + linkColor + "; " + "}"; markdownView.getSettings().setJavaScriptEnabled(false); markdownView.getSettings().setLoadsImagesAutomatically(false); markdownView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) try { startActivity(intent); } catch (ActivityNotFoundException | FileUriExposedException e) { /* Gracefully fail */ } else try { startActivity(intent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } return true; } }); } // Load note contents try { contentsOnLoad = listener.loadNote(filename); } catch (IOException e) { showToast(R.string.error_loading_note); // Add NoteListFragment or WelcomeFragment Fragment fragment; if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal")) fragment = new NoteListFragment(); else fragment = new WelcomeFragment(); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit(); } // Set TextView contents if (noteContents != null) noteContents.setText(contentsOnLoad); if (markdownView != null) markdownView.loadMarkdown(contentsOnLoad, "data:text/css;base64," + Base64.encodeToString(css.getBytes(), Base64.DEFAULT)); // Show a toast message if this is the user's first time viewing a note final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); firstLoad = sharedPref.getInt("first-load", 0); if (firstLoad == 0) { // Show dialog with info DialogFragment firstLoad = new FirstViewDialogFragment(); firstLoad.show(getFragmentManager(), "firstloadfragment"); // Set first-load preference to 1; we don't need to show the dialog anymore SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("first-load", 1); editor.apply(); } // Detect single and double-taps using GestureDetector final GestureDetector detector = new GestureDetector(getActivity(), new GestureDetector.OnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } @Override public boolean onDown(MotionEvent e) { return false; } }); detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() { @Override public boolean onDoubleTap(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true)) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("show_double_tap_message", false); editor.apply(); } Bundle bundle = new Bundle(); bundle.putString("filename", filename); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .commit(); return false; } @Override public boolean onDoubleTapEvent(MotionEvent e) { return false; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) { showToastLong(R.string.double_tap); showMessage = false; } return false; } }); if (noteContents != null) noteContents.setOnTouchListener((v, event) -> { detector.onTouchEvent(event); return false; }); if (markdownView != null) markdownView.setOnTouchListener((v, event) -> { detector.onTouchEvent(event); return false; }); }
From source file:JVMSimulator.java
void ExecuteNextInstruction() { int a, b, result, i, operand0, operand1, operand2, offset; float fa, fb, fresult; Float f;/* www . j av a 2 s . com*/ int nextOpCode = methodAreaMemorySection.getAtAddress(pcRegister); switch (nextOpCode) { case OpCode.AALOAD: executeAaload(); break; case OpCode.ALOAD_0: executeAload_n(0); break; case OpCode.ASTORE_0: executeAstore_n(0); break; case OpCode.BIPUSH: operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 1); stackMemorySection.setAtAddress(optopRegister, operand0); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(operand0)); optopRegister += 4; pcRegister += 2; break; // The BREAKPOINT opcode will serve as a stop sign for a running simulation. case OpCode.BREAKPOINT: stopButton.disable(); runButton.disable(); stepButton.disable(); resetButton.enable(); if (runner != null) { // If runner is not null, then this is probably the thread that // we want to stop. Therefore, as soon as stop has been executed, // nothing else will happen. So we must set runner to null before // we call runner.stop(). Therefore I copy runner to temp, assign // null to runner, and call stop() on temp. Thread temp = runner; runner = null; temp.stop(); } break; case OpCode.FCONST_0: stackMemorySection.setAtAddress(optopRegister, Float.floatToIntBits((float) 0)); stackMemorySection.setLogicalValueAtAddress(optopRegister, "0"); optopRegister += 4; ++pcRegister; break; case OpCode.FCONST_2: stackMemorySection.setAtAddress(optopRegister, Float.floatToIntBits((float) 2)); stackMemorySection.setLogicalValueAtAddress(optopRegister, "2"); optopRegister += 4; ++pcRegister; break; case OpCode.FLOAD_0: a = stackMemorySection.getAtAddress(varsRegister); stackMemorySection.setAtAddress(optopRegister, a); fa = Float.intBitsToFloat(a); stackMemorySection.setLogicalValueAtAddress(optopRegister, Float.toString(fa)); optopRegister += 4; ++pcRegister; break; case OpCode.FMUL: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); fa = Float.intBitsToFloat(a); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); fb = Float.intBitsToFloat(b); fresult = fa * fb; result = Float.floatToIntBits(fresult); stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Float.toString(fresult)); optopRegister += 4; ++pcRegister; break; case OpCode.FSTORE_0: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); stackMemorySection.setAtAddress(varsRegister, a); fa = Float.intBitsToFloat(a); stackMemorySection.setLogicalValueAtAddress(varsRegister, Float.toString(fa)); ++pcRegister; break; case OpCode.FSUB: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); fa = Float.intBitsToFloat(a); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); fb = Float.intBitsToFloat(b); fresult = fb - fa; result = Float.floatToIntBits(fresult); stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Float.toString(fresult)); optopRegister += 4; ++pcRegister; break; case OpCode.GOTO: operand1 = methodAreaMemorySection.getAtAddress(pcRegister + 1); operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 2); offset = (operand1 << 8) | (operand0 & 0xff); pcRegister += offset; break; case OpCode.IADD: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = a + b; stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.IAND: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = a & b; stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.IASTORE: executeIastore(); break; case OpCode.ICONST_M1: stackMemorySection.setAtAddress(optopRegister, -1); stackMemorySection.setLogicalValueAtAddress(optopRegister, "-1"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_0: stackMemorySection.setAtAddress(optopRegister, 0); stackMemorySection.setLogicalValueAtAddress(optopRegister, "0"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_1: stackMemorySection.setAtAddress(optopRegister, 1); stackMemorySection.setLogicalValueAtAddress(optopRegister, "1"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_2: stackMemorySection.setAtAddress(optopRegister, 2); stackMemorySection.setLogicalValueAtAddress(optopRegister, "2"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_3: stackMemorySection.setAtAddress(optopRegister, 3); stackMemorySection.setLogicalValueAtAddress(optopRegister, "3"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_4: stackMemorySection.setAtAddress(optopRegister, 4); stackMemorySection.setLogicalValueAtAddress(optopRegister, "4"); optopRegister += 4; ++pcRegister; break; case OpCode.ICONST_5: stackMemorySection.setAtAddress(optopRegister, 5); stackMemorySection.setLogicalValueAtAddress(optopRegister, "5"); optopRegister += 4; ++pcRegister; break; case OpCode.IFNE: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); // If a != 0 jump, else go on if (a != 0) { operand1 = methodAreaMemorySection.getAtAddress(pcRegister + 1); operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 2); offset = (operand1 << 8) | (operand0 & 0xff); pcRegister += offset; } else { pcRegister += 3; } break; case OpCode.IF_ICMPLT: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); // If b < a jump, else go on if (b < a) { operand1 = methodAreaMemorySection.getAtAddress(pcRegister + 1); operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 2); offset = (operand1 << 8) | (operand0 & 0xff); pcRegister += offset; } else { pcRegister += 3; } break; case OpCode.IINC: operand0 = methodAreaMemorySection.getAtAddress(pcRegister + 1); operand1 = methodAreaMemorySection.getAtAddress(pcRegister + 2); a = stackMemorySection.getAtAddress(varsRegister + (operand0 * 4)); a += operand1; stackMemorySection.setAtAddress(varsRegister + (operand0 * 4), a); stackMemorySection.setLogicalValueAtAddress(varsRegister + (operand0 * 4), Integer.toString(a)); pcRegister += 3; break; case OpCode.ILOAD_0: a = stackMemorySection.getAtAddress(varsRegister); stackMemorySection.setAtAddress(optopRegister, a); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(a)); optopRegister += 4; ++pcRegister; break; case OpCode.ILOAD_1: a = stackMemorySection.getAtAddress(varsRegister + 4); stackMemorySection.setAtAddress(optopRegister, a); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(a)); optopRegister += 4; ++pcRegister; break; case OpCode.ILOAD_2: a = stackMemorySection.getAtAddress(varsRegister + 8); stackMemorySection.setAtAddress(optopRegister, a); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(a)); optopRegister += 4; ++pcRegister; break; case OpCode.ILOAD_3: a = stackMemorySection.getAtAddress(varsRegister + 12); stackMemorySection.setAtAddress(optopRegister, a); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(a)); optopRegister += 4; ++pcRegister; break; case OpCode.IMUL: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = a * b; stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.INT2BYTE: a = stackMemorySection.getAtAddress(optopRegister - 4); a = (byte) a; stackMemorySection.setAtAddress(optopRegister - 4, a); stackMemorySection.setLogicalValueAtAddress(optopRegister - 4, Integer.toString(a)); ++pcRegister; break; case OpCode.IOR: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = a | b; stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.ISHL: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = b << (a & 0x1f); stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.ISTORE_0: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); stackMemorySection.setAtAddress(varsRegister, a); stackMemorySection.setLogicalValueAtAddress(varsRegister, Integer.toString(a)); ++pcRegister; break; case OpCode.ISTORE_1: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); stackMemorySection.setAtAddress(varsRegister + 4, a); stackMemorySection.setLogicalValueAtAddress(varsRegister + 4, Integer.toString(a)); ++pcRegister; break; case OpCode.ISTORE_2: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); stackMemorySection.setAtAddress(varsRegister + 8, a); stackMemorySection.setLogicalValueAtAddress(varsRegister + 8, Integer.toString(a)); ++pcRegister; break; case OpCode.ISTORE_3: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); stackMemorySection.setAtAddress(varsRegister + 12, a); stackMemorySection.setLogicalValueAtAddress(varsRegister + 12, Integer.toString(a)); ++pcRegister; break; case OpCode.IXOR: optopRegister -= 4; a = stackMemorySection.getAtAddress(optopRegister); stackMemorySection.setLogicalValueAtAddress(optopRegister, ""); optopRegister -= 4; b = stackMemorySection.getAtAddress(optopRegister); result = a ^ b; stackMemorySection.setAtAddress(optopRegister, result); stackMemorySection.setLogicalValueAtAddress(optopRegister, Integer.toString(result)); optopRegister += 4; ++pcRegister; break; case OpCode.MULTIANEWARRAY: executeMultianewarray(); pcRegister += 4; break; } }
From source file:gov.nih.nci.caarray.application.translation.magetab.MageTabExporterBean.java
private void addBiomaterialAttributes(AbstractBioMaterial biomaterial, gov.nih.nci.caarray.magetab.sdrf.AbstractBioMaterial sdrfBiomaterial) { // Set material type. final Term term = biomaterial.getMaterialType(); if (term != null) { final OntologyTerm sdrfTerm = getSdrfTerm(term); sdrfBiomaterial.setMaterialType(sdrfTerm); }/* ww w .j av a 2 s. co m*/ // Set all other characteristics. addPredefinedCharacteristics(biomaterial, sdrfBiomaterial); for (final AbstractCharacteristic characteristic : biomaterial.getCharacteristics()) { final String category = characteristic.getCategory().getName(); final Characteristic sdrfCharacteristic = new Characteristic(); if (characteristic instanceof TermBasedCharacteristic) { final Term characteristicTerm = ((TermBasedCharacteristic) characteristic).getTerm(); final OntologyTerm sdrfTerm = getSdrfTerm(characteristicTerm); sdrfCharacteristic.setTerm(sdrfTerm); } else if (characteristic instanceof MeasurementCharacteristic) { final float value = ((MeasurementCharacteristic) characteristic).getValue(); sdrfCharacteristic.setValue(Float.toString(value)); } else { sdrfCharacteristic.setValue(((UserDefinedCharacteristic) characteristic).getValue()); } sdrfCharacteristic.setCategory(category); final OntologyTerm sdrfUnit = getSdrfTerm(characteristic.getUnit()); sdrfCharacteristic.setUnit(sdrfUnit); sdrfBiomaterial.getCharacteristics().add(sdrfCharacteristic); } if (StringUtils.isNotEmpty(biomaterial.getExternalId())) { final Characteristic sdrfCharacteristic = new Characteristic(); sdrfCharacteristic.setCategory(ExperimentOntologyCategory.EXTERNAL_ID.getCategoryName()); sdrfCharacteristic.setValue(biomaterial.getExternalId()); sdrfBiomaterial.getCharacteristics().add(sdrfCharacteristic); } // TODO Organism and ProtocolApplications }
From source file:co.foldingmap.mapImportExport.SvgExporter.java
public void exportMap(DigitalMap mapData, File outputFile) { BufferedWriter outputStream;/*from w w w .ja v a2 s .c o m*/ float height, width, maxX; LabelManager labelManager; LatLonAltBox mapBounds; Layer currentLayer; MapView mapView; try { height = 600; width = 1200; mapView = mapData.getLastMapView(); mapBounds = mapData.getBoundary(); outputStream = new BufferedWriter(new FileWriter(outputFile)); labelManager = mapView.getLabelManager(); //mapView.getMapProjection().setReference(new Coordinate(0, 90, -180)); mapData.calculateCoordinateLocations(mapView); height = mapView.getY(mapBounds.getSouthWestCoordinate()); maxX = mapView.getX(mapBounds.getNorthEastCoordinate(), MapView.NO_WRAP); outputStream.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); outputStream.write("<!-- Created with FoldingMap (http://www.foldingmap.co/) -->\n\n"); outputStream.write("<svg\n"); addIndent(); outputStream.write(getIndent()); outputStream.write("xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"); outputStream.write(getIndent()); outputStream.write("xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"); outputStream.write(getIndent()); outputStream.write("xmlns:svg=\"http://www.w3.org/2000/svg\"\n"); outputStream.write(getIndent()); outputStream.write("xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"); outputStream.write(getIndent()); outputStream.write("xmlns=\"http://www.w3.org/2000/svg\"\n"); //height and width outputStream.write(getIndent()); outputStream.write("width=\""); outputStream.write(Float.toString(width)); outputStream.write("\"\n"); outputStream.write(getIndent()); outputStream.write("height=\""); outputStream.write(Float.toString(height)); outputStream.write("\"\n"); outputStream.write(getIndent()); outputStream.write("id=\""); outputStream.write(mapData.getName()); outputStream.write("\">\n\n"); //loop backwards through the layers, since the first layer is on the bottom. for (int i = mapData.getLayers().size() - 1; i >= 0; i--) { currentLayer = mapData.getLayer(i); exportLayer(outputStream, currentLayer, mapData.getTheme(), height); } //write Labels for (MapLabel label : labelManager.getLabels()) { exportMapLabel(outputStream, label); } removeIndent(); outputStream.write("</svg>"); outputStream.close(); } catch (Exception e) { Logger.log(Logger.ERR, "Error in SvgExporter.exportMap(DigitalMap) - " + e); } }
From source file:com.yanzhenjie.nohttp.BasicRequest.java
@Override public IBasicRequest add(String key, float value) { add(key, Float.toString(value)); return this; }
From source file:org.apache.samza.sql.avro.AvroRelConverter.java
public static Object convertToJavaObject(Object avroObj, Schema schema) { if (avroObj == null) { return null; }//from w ww. j a v a 2 s . c o m switch (schema.getType()) { case RECORD: return convertToRelRecord((IndexedRecord) avroObj); case ARRAY: { ArrayList<Object> retVal = new ArrayList<>(); List<Object> avroArray; if (avroObj instanceof GenericData.Array) { avroArray = (GenericData.Array) avroObj; } else if (avroObj instanceof List) { avroArray = (List) avroObj; } else { throw new SamzaException("Unsupported array type " + avroObj.getClass().getSimpleName()); } retVal.addAll(avroArray.stream() .map(v -> convertToJavaObject(v, getNonNullUnionSchema(schema).getElementType())) .collect(Collectors.toList())); return retVal; } case MAP: { Map<String, Object> retVal = new HashMap<>(); retVal.putAll(((Map<String, ?>) avroObj).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> convertToJavaObject(e.getValue(), getNonNullUnionSchema(schema).getValueType())))); return retVal; } case UNION: for (Schema unionSchema : schema.getTypes()) { if (isSchemaCompatibleWithAvroObj(avroObj, unionSchema)) { return convertToJavaObject(avroObj, unionSchema); } } return null; case ENUM: return avroObj.toString(); case FIXED: GenericData.Fixed fixed = (GenericData.Fixed) avroObj; return new ByteString(fixed.bytes()); case BYTES: return new ByteString(((ByteBuffer) avroObj).array()); case FLOAT: // Convert Float to Double similar to how JavaTypeFactoryImpl represents Float type return Double.parseDouble(Float.toString((Float) avroObj)); default: return avroObj; } }
From source file:org.apache.flink.api.java.utils.ParameterTool.java
/** * Returns the Float value for the given key. If the key does not exists it will return the default value given. * The method fails if the value is not a Float. *///from w ww. ja v a2s . co m public float getFloat(String key, float defaultValue) { addToDefaults(key, Float.toString(defaultValue)); String value = get(key); if (value == null) { return defaultValue; } else { return Float.valueOf(value); } }
From source file:org.fudgemsg.xml.FudgeXMLStreamWriter.java
protected void writeArray(final float[] array) throws XMLStreamException { boolean first = true; for (float value : array) { if (first) first = false;/*from w w w.j av a 2 s . c o m*/ else getWriter().writeCharacters(","); getWriter().writeCharacters(Float.toString(value)); } }
From source file:org.apache.tika.parser.pdf18.PDFParser.java
private void extractMetadata(PDDocument document, Metadata metadata) throws TikaException { //first extract AccessPermissions AccessPermission ap = document.getCurrentAccessPermission(); metadata.set(AccessPermissions.EXTRACT_FOR_ACCESSIBILITY, Boolean.toString(ap.canExtractForAccessibility())); metadata.set(AccessPermissions.EXTRACT_CONTENT, Boolean.toString(ap.canExtractContent())); metadata.set(AccessPermissions.ASSEMBLE_DOCUMENT, Boolean.toString(ap.canAssembleDocument())); metadata.set(AccessPermissions.FILL_IN_FORM, Boolean.toString(ap.canFillInForm())); metadata.set(AccessPermissions.CAN_MODIFY, Boolean.toString(ap.canModify())); metadata.set(AccessPermissions.CAN_MODIFY_ANNOTATIONS, Boolean.toString(ap.canModifyAnnotations())); metadata.set(AccessPermissions.CAN_PRINT, Boolean.toString(ap.canPrint())); metadata.set(AccessPermissions.CAN_PRINT_DEGRADED, Boolean.toString(ap.canPrintDegraded())); //now go for the XMP org.apache.jempbox.xmp.XMPMetadata xmp = null; XMPSchemaDublinCore dcSchema = null; XMPSchemaMediaManagement mmSchema = null; try {//w w w .ja v a2s. com if (document.getDocumentCatalog().getMetadata() != null) { xmp = document.getDocumentCatalog().getMetadata().exportXMPMetadata(); } } catch (IOException e) { } if (xmp != null) { try { dcSchema = xmp.getDublinCoreSchema(); } catch (IOException e) { } JempboxExtractor.extractXMPMM(xmp, metadata); } 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()); try { // TODO Remove these in Tika 2.0 addMetadata(metadata, "created", info.getCreationDate()); addMetadata(metadata, TikaCoreProperties.CREATED, info.getCreationDate()); } catch (IOException e) { // Invalid date format, just ignore } try { Calendar modified = info.getModificationDate(); addMetadata(metadata, Metadata.LAST_MODIFIED, modified); addMetadata(metadata, TikaCoreProperties.MODIFIED, modified); } catch (IOException e) { // Invalid date format, just ignore } // 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) { if (pdfaxmp.getPart() != 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().getCOSDictionary(); 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.tika.parser.pdf.PDFParser.java
private void extractMetadata(PDDocument document, Metadata metadata, ParseContext context) throws TikaException { //first extract AccessPermissions AccessPermission ap = document.getCurrentAccessPermission(); metadata.set(AccessPermissions.EXTRACT_FOR_ACCESSIBILITY, Boolean.toString(ap.canExtractForAccessibility())); metadata.set(AccessPermissions.EXTRACT_CONTENT, Boolean.toString(ap.canExtractContent())); metadata.set(AccessPermissions.ASSEMBLE_DOCUMENT, Boolean.toString(ap.canAssembleDocument())); metadata.set(AccessPermissions.FILL_IN_FORM, Boolean.toString(ap.canFillInForm())); metadata.set(AccessPermissions.CAN_MODIFY, Boolean.toString(ap.canModify())); metadata.set(AccessPermissions.CAN_MODIFY_ANNOTATIONS, Boolean.toString(ap.canModifyAnnotations())); metadata.set(AccessPermissions.CAN_PRINT, Boolean.toString(ap.canPrint())); metadata.set(AccessPermissions.CAN_PRINT_DEGRADED, Boolean.toString(ap.canPrintDegraded())); //now go for the XMP Document dom = loadDOM(document.getDocumentCatalog().getMetadata(), metadata, context); XMPMetadata xmp = null;//from w w w . j a v a2 s .c om if (dom != null) { xmp = new XMPMetadata(dom); } XMPSchemaDublinCore dcSchema = null; if (xmp != null) { try { dcSchema = xmp.getDublinCoreSchema(); } catch (IOException e) { } JempboxExtractor.extractXMPMM(xmp, metadata); } PDDocumentInformation info = document.getDocumentInformation(); metadata.set(PagedText.N_PAGES, document.getNumberOfPages()); extractMultilingualItems(metadata, TikaCoreProperties.TITLE, info.getTitle(), dcSchema); addMetadata(metadata, PDF.DOC_INFO_TITLE, info.getTitle()); extractDublinCoreListItems(metadata, TikaCoreProperties.CREATOR, info.getAuthor(), dcSchema); addMetadata(metadata, PDF.DOC_INFO_CREATOR, info.getAuthor()); extractDublinCoreListItems(metadata, TikaCoreProperties.CONTRIBUTOR, null, dcSchema); addMetadata(metadata, TikaCoreProperties.CREATOR_TOOL, info.getCreator()); addMetadata(metadata, PDF.DOC_INFO_CREATOR_TOOL, info.getCreator()); addMetadata(metadata, TikaCoreProperties.KEYWORDS, info.getKeywords()); addMetadata(metadata, PDF.DOC_INFO_KEY_WORDS, info.getKeywords()); addMetadata(metadata, "producer", info.getProducer()); addMetadata(metadata, PDF.DOC_INFO_PRODUCER, info.getProducer()); extractMultilingualItems(metadata, TikaCoreProperties.DESCRIPTION, null, dcSchema); addMetadata(metadata, PDF.DOC_INFO_SUBJECT, info.getSubject()); // TODO: Move to description in Tika 2.0 addMetadata(metadata, TikaCoreProperties.TRANSITION_SUBJECT_TO_OO_SUBJECT, info.getSubject()); addMetadata(metadata, "trapped", info.getTrapped()); addMetadata(metadata, PDF.DOC_INFO_TRAPPED, info.getTrapped()); // TODO Remove these in Tika 2.0 addMetadata(metadata, "created", info.getCreationDate()); addMetadata(metadata, PDF.DOC_INFO_CREATED, info.getCreationDate()); addMetadata(metadata, TikaCoreProperties.CREATED, info.getCreationDate()); Calendar modified = info.getModificationDate(); addMetadata(metadata, Metadata.LAST_MODIFIED, modified); addMetadata(metadata, TikaCoreProperties.MODIFIED, modified); addMetadata(metadata, PDF.DOC_INFO_MODIFICATION_DATE, info.getModificationDate()); // 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.getCOSObject().keySet()) { String name = key.getName(); if (!handledMetadata.contains(name)) { addMetadata(metadata, name, info.getCOSObject().getDictionaryObject(key)); addMetadata(metadata, PDF.PDF_DOC_INFO_CUSTOM_PREFIX + name, info.getCOSObject().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.PDF_VERSION, 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) { if (pdfaxmp.getPart() != null) { metadata.set(PDF.PDFAID_PART, Integer.toString(pdfaxmp.getPart())); } if (pdfaxmp.getConformance() != null) { metadata.set(PDF.PDFAID_CONFORMANCE, pdfaxmp.getConformance()); String version = "A-" + pdfaxmp.getPart() + pdfaxmp.getConformance().toLowerCase(Locale.ROOT); metadata.set(PDF.PDFA_VERSION, 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.PDF_EXTENSION_VERSION, 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()); } } } }