List of usage examples for java.lang Number floatValue
public abstract float floatValue();
From source file:org.apache.fontbox.cff.CharStringRenderer.java
private void rrcurveTo(Number dx1, Number dy1, Number dx2, Number dy2, Number dx3, Number dy3) { Point2D point = path.getCurrentPoint(); float x1 = (float) point.getX() + dx1.floatValue(); float y1 = (float) point.getY() + dy1.floatValue(); float x2 = x1 + dx2.floatValue(); float y2 = y1 + dy2.floatValue(); float x3 = x2 + dx3.floatValue(); float y3 = y2 + dy3.floatValue(); path.curveTo(x1, y1, x2, y2, x3, y3); }
From source file:org.polymap.kaps.ui.MyNumberValidator.java
public Object transform2Model(Object fieldValue) throws Exception { if (fieldValue == null) { return null; } else if (fieldValue instanceof String) { if (((String) fieldValue).isEmpty()) { return null; }/*from ww w. ja v a 2 s . c o m*/ ParsePosition pp = new ParsePosition(0); Number result = nf.parse((String) fieldValue, pp); if (pp.getErrorIndex() > -1 || pp.getIndex() < ((String) fieldValue).length()) { throw new ParseException("field value: " + fieldValue + " for targetClass " + targetClass.getName(), pp.getErrorIndex()); } log.debug("value: " + fieldValue + " -> " + result.doubleValue()); // XXX check max digits if (Float.class.isAssignableFrom(targetClass)) { return Float.valueOf(result.floatValue()); } else if (Double.class.isAssignableFrom(targetClass)) { return Double.valueOf(result.doubleValue()); } else if (Integer.class.isAssignableFrom(targetClass)) { return Integer.valueOf(result.intValue()); } else if (Long.class.isAssignableFrom(targetClass)) { return Long.valueOf(result.longValue()); } else { throw new RuntimeException("Unsupported target type: " + targetClass); } } else { throw new RuntimeException("Unhandled field value type: " + fieldValue); } }
From source file:org.diorite.config.impl.ConfigPropertyValueImpl.java
@SuppressWarnings("unchecked") @Override//from w ww .j ava2 s .co m public void setRawValue(@Nullable T value) { Class<T> rawType = this.template.getRawType(); Class<?> primitiveRawType = DioriteReflectionUtils.getPrimitive(rawType); if (!primitiveRawType.isPrimitive()) { if (value != null) { if (!rawType.isInstance(value) && !DioriteReflectionUtils.getWrapperClass(rawType).isInstance(value)) { throw new IllegalArgumentException("Invalid object type: " + value + " in template property: " + this.template.getName() + " (" + this.template.getGenericType() + ")"); } } else { // keep collections not null if possible. try { if (Collection.class.isAssignableFrom(rawType) || (Map.class.isAssignableFrom(rawType) && !Config.class.isAssignableFrom(rawType))) { this.rawValue = YamlCollectionCreator.createCollection(rawType, 10); return; } } catch (Exception e) { e.printStackTrace(); } } } else if (value instanceof Number) { Number num = (Number) value; if (primitiveRawType == byte.class) { num = num.byteValue(); } if (primitiveRawType == short.class) { num = num.shortValue(); } if (primitiveRawType == int.class) { num = num.intValue(); } if (primitiveRawType == long.class) { num = num.longValue(); } if (primitiveRawType == float.class) { num = num.floatValue(); } if (primitiveRawType == double.class) { num = num.doubleValue(); } this.rawValue = (T) num; return; } else { throw new IllegalArgumentException("Invalid object type: " + value + " in template property: " + this.template.getName() + " (" + this.template.getGenericType() + ")"); } this.rawValue = value; }
From source file:org.nd4j.linalg.api.complex.BaseComplexFloat.java
@Override public IComplexNumber subi(Number a, IComplexNumber result) { return result.set(realComponent().floatValue() - a.floatValue(), imaginaryComponent()); }
From source file:org.nd4j.linalg.api.complex.BaseComplexFloat.java
/** * Add a realComponent number to a complex number in-place. * * @param a/*from w w w. j a va 2s. c om*/ * @param result */ @Override public IComplexNumber addi(Number a, IComplexNumber result) { return result.set(realComponent().floatValue() + a.floatValue(), imaginaryComponent().floatValue()); }
From source file:org.nd4j.linalg.api.complex.BaseComplexFloat.java
@Override public IComplexNumber muli(Number v, IComplexNumber result) { return result.set(realComponent().floatValue() * v.floatValue(), imaginaryComponent().floatValue() * v.floatValue()); }
From source file:org.nd4j.linalg.api.complex.BaseComplexFloat.java
@Override public IComplexNumber divi(Number v, IComplexNumber result) { return result.set(realComponent().floatValue() / v.floatValue(), imaginaryComponent().floatValue() / v.floatValue()); }
From source file:org.apache.pdfbox.pdmodel.font.PDType1CFont.java
private void load() throws IOException { byte[] cffBytes = loadBytes(); CFFParser cffParser = new CFFParser(); List<CFFFont> fonts = cffParser.parse(cffBytes); this.cffFont = (CFFFont) fonts.get(0); CFFEncoding encoding = this.cffFont.getEncoding(); PDFEncoding pdfEncoding = new PDFEncoding(encoding); CFFCharset charset = this.cffFont.getCharset(); PDFCharset pdfCharset = new PDFCharset(charset); Map<String, byte[]> charStringsDict = this.cffFont.getCharStringsDict(); Map<String, byte[]> pdfCharStringsDict = new LinkedHashMap<String, byte[]>(); pdfCharStringsDict.put(".notdef", charStringsDict.get(".notdef")); Map<Integer, String> codeToNameMap = new LinkedHashMap<Integer, String>(); Collection<CFFFont.Mapping> mappings = this.cffFont.getMappings(); for (Iterator<CFFFont.Mapping> it = mappings.iterator(); it.hasNext();) { CFFFont.Mapping mapping = it.next(); Integer code = Integer.valueOf(mapping.getCode()); String name = mapping.getName(); codeToNameMap.put(code, name);/*from www . j av a 2s .c o m*/ } Set<String> knownNames = new HashSet<String>(codeToNameMap.values()); Map<Integer, String> codeToNameOverride = loadOverride(); for (Iterator<Map.Entry<Integer, String>> it = (codeToNameOverride.entrySet()).iterator(); it.hasNext();) { Map.Entry<Integer, String> entry = it.next(); Integer code = (Integer) entry.getKey(); String name = (String) entry.getValue(); if (knownNames.contains(name)) { codeToNameMap.put(code, name); } } Map nameToCharacter; try { // TODO remove access by reflection Field nameToCharacterField = Encoding.class.getDeclaredField("NAME_TO_CHARACTER"); nameToCharacterField.setAccessible(true); nameToCharacter = (Map) nameToCharacterField.get(null); } catch (Exception e) { throw new RuntimeException(e); } for (Iterator<Map.Entry<Integer, String>> it = (codeToNameMap.entrySet()).iterator(); it.hasNext();) { Map.Entry<Integer, String> entry = it.next(); Integer code = (Integer) entry.getKey(); String name = (String) entry.getValue(); String uniName = "uni"; String character = (String) nameToCharacter.get(name); if (character != null) { for (int j = 0; j < character.length(); j++) { uniName += hexString(character.charAt(j), 4); } } else { uniName += hexString(code.intValue(), 4); character = String.valueOf((char) code.intValue()); } pdfEncoding.register(code.intValue(), code.intValue()); pdfCharset.register(code.intValue(), uniName); this.codeToName.put(code, uniName); this.codeToCharacter.put(code, character); this.characterToCode.put(character, code); pdfCharStringsDict.put(uniName, charStringsDict.get(name)); } this.cffFont.setEncoding(pdfEncoding); this.cffFont.setCharset(pdfCharset); charStringsDict.clear(); charStringsDict.putAll(pdfCharStringsDict); Number defaultWidthX = (Number) this.cffFont.getProperty("defaultWidthX"); this.glyphWidths.put(null, Float.valueOf(defaultWidthX.floatValue())); }
From source file:boundary.GraphPane.java
private Node addThresholdSlider(float min, float max) { HBox hBox = new HBox(); hBox.setPadding(new Insets(15, 12, 15, 12)); hBox.setStyle("-fx-background-color: #66FFFF;"); Label lblThreshold = new Label("Threshold: "); lblThreshold.setPrefSize(100, 20);//from w w w . j av a 2 s . c o m Label lblValue = new Label("Value: "); lblValue.setPrefSize(50, 20); TextField tfValue = new TextField(String.valueOf(min)); Slider thresholdSlider = new Slider(); thresholdSlider.setMin(Math.floor(min)); thresholdSlider.setMax(Math.ceil(max)); thresholdSlider.setMajorTickUnit(Math.ceil((max - min) / 5)); thresholdSlider.setMinorTickCount(1); thresholdSlider.setBlockIncrement(1); thresholdSlider.setSnapToTicks(true); thresholdSlider.setShowTickMarks(true); thresholdSlider.valueProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { edgePredicate.setThreshold(newValue.floatValue()); vertexPredicate.setThreshold(newValue.floatValue()); vv.repaint(); tfValue.setText(String.format(Locale.US, "%.2f", newValue.floatValue())); } }); tfValue.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { float value; try { value = Float.parseFloat(tfValue.getText()); } catch (Exception ex) { value = 0; } edgePredicate.setThreshold(value); vertexPredicate.setThreshold(value); vv.repaint(); thresholdSlider.setValue(value); } }); Label lblSearch = new Label("Search: "); lblSearch.setPrefSize(70, 20); TextField tf = new TextField(); tf.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { String toFind = tf.getText().toLowerCase(); for (NodeInfo nodeInfo : nodesHighlighted) nodeInfo.setHighlighted(false); if (nodesHighlighted.size() > 0) { nodesHighlighted.clear(); vv.repaint(); } if (toFind.length() > 2) { for (NodeInfo nodeInfo : nodes.values()) { if (nodeInfo.getUserData().toLowerCase().contains((toFind))) { nodeInfo.setHighlighted(true); nodesHighlighted.add(nodeInfo); } } if (nodesHighlighted.size() == 1) { Layout<String, String> layout = vv.getGraphLayout(); Point2D q = layout.transform(nodesHighlighted.get(0).id); Point2D lvc = vv.getRenderContext().getMultiLayerTransformer() .inverseTransform(vv.getCenter()); final double dx = (lvc.getX() - q.getX()) / 10; final double dy = (lvc.getY() - q.getY()) / 10; Runnable animator = new Runnable() { public void run() { for (int i = 0; i < 10; i++) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT) .translate(dx, dy); try { Thread.sleep(100); } catch (InterruptedException ex) { } } } }; Thread thread = new Thread(animator); thread.start(); } vv.repaint(); } } }); hBox.getChildren().addAll(lblThreshold, thresholdSlider, lblValue, tfValue, lblSearch, tf); return hBox; }
From source file:org.apache.lucene.index.FieldsWriter.java
final void writeField(FieldInfo fi, Fieldable field) throws IOException { fieldsStream.writeVInt(fi.number);//from w w w. j a v a 2 s . com int bits = 0; if (field.isTokenized()) bits |= FIELD_IS_TOKENIZED; if (field.isBinary()) bits |= FIELD_IS_BINARY; if (field instanceof NumericField) { switch (((NumericField) field).getDataType()) { case INT: bits |= FIELD_IS_NUMERIC_INT; break; case LONG: bits |= FIELD_IS_NUMERIC_LONG; break; case FLOAT: bits |= FIELD_IS_NUMERIC_FLOAT; break; case DOUBLE: bits |= FIELD_IS_NUMERIC_DOUBLE; break; default: assert false : "Should never get here"; } } fieldsStream.writeByte((byte) bits); if (field.isBinary()) { final byte[] data; final int len; final int offset; data = field.getBinaryValue(); len = field.getBinaryLength(); offset = field.getBinaryOffset(); fieldsStream.writeVInt(len); fieldsStream.writeBytes(data, offset, len); } else if (field instanceof NumericField) { final NumericField nf = (NumericField) field; final Number n = nf.getNumericValue(); switch (nf.getDataType()) { case INT: fieldsStream.writeVVInt(n.intValue()); break; case LONG: fieldsStream.writeVVLong(n.longValue()); break; case FLOAT: fieldsStream.writeVVVInt(Float.floatToIntBits(n.floatValue())); break; case DOUBLE: fieldsStream.writeVVVLong(Double.doubleToLongBits(n.doubleValue())); break; default: assert false : "Should never get here"; } } else { fieldsStream.writeString(field.stringValue()); } }