List of usage examples for java.lang Number intValue
public abstract int intValue();
From source file:com.alibaba.wasp.plan.parser.druid.DruidParser.java
/** * The abstract class Number is the superclass of classes BigDecimal, * BigInteger, Byte, Double, Float, Integer, Long, and Short. Subclasses of * Number must provide methods to convert the represented numeric value to * byte, double, float, int, long, and short. *///from w w w . ja v a2 s .c o m public static byte[] convert(DataType type, Number number) throws UnsupportedException { // BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, and Short. if (number instanceof BigDecimal) { if (type == DataType.FLOAT) { return Bytes.toBytes(number.floatValue()); } else if (type == DataType.DOUBLE) { return Bytes.toBytes(number.doubleValue()); } else if (type == DataType.INT32) { return Bytes.toBytes(number.intValue()); } else if (type == DataType.INT64) { return Bytes.toBytes(number.longValue()); } return Bytes.toBytes((BigDecimal) number); } else if (number instanceof BigInteger) { throw new UnsupportedException(" BigInteger " + number + " Unsupported"); } else if (number instanceof Byte) { return Bytes.toBytes((Byte) number); } else if (number instanceof Double) { double value = number.doubleValue(); if (type == DataType.FLOAT) { return Bytes.toBytes((float) value); } else if (type == DataType.DOUBLE) { return Bytes.toBytes(value); } else if (type == DataType.INT32) { int iv = (int) value; return Bytes.toBytes(iv); } else if (type == DataType.INT64) { long lv = (long) value; return Bytes.toBytes(lv); } } else if (number instanceof Float) { float value = number.floatValue(); if (type == DataType.FLOAT) { return Bytes.toBytes(value); } else if (type == DataType.DOUBLE) { return Bytes.toBytes((float) value); } else if (type == DataType.INT32) { int iv = (int) value; return Bytes.toBytes(iv); } else if (type == DataType.INT64) { long lv = (long) value; return Bytes.toBytes(lv); } } else if (number instanceof Integer) { int value = number.intValue(); if (type == DataType.INT32) { return Bytes.toBytes((Integer) value); } else if (type == DataType.INT64) { return Bytes.toBytes((long) value); } else if (type == DataType.FLOAT) { float fv = (float) value; return Bytes.toBytes(fv); } else if (type == DataType.DOUBLE) { double fv = (double) value; return Bytes.toBytes(fv); } } else if (number instanceof Long) { long value = number.longValue(); if (type == DataType.INT32) { return Bytes.toBytes((int) value); } else if (type == DataType.INT64) { return Bytes.toBytes(value); } else if (type == DataType.FLOAT) { float fv = (float) value; return Bytes.toBytes(fv); } else if (type == DataType.DOUBLE) { double fv = (double) value; return Bytes.toBytes(fv); } } else if (number instanceof Short) { return Bytes.toBytes((Short) number); } throw new UnsupportedException("Unknown Number:" + number + " Type:" + type + " Unsupported "); }
From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java
/** * Transforms a Number into a valid javascript number.<br> * Float gets promoted to Double.<br> * Byte and Short get promoted to Integer.<br> * Long gets downgraded to Integer if possible.<br> *//*from ww w . jav a 2 s.c om*/ public static Number transformNumber(Number input) { if (input instanceof Float) { return new Double(input.toString()); } else if (input instanceof Short) { return new Integer(input.intValue()); } else if (input instanceof Byte) { return new Integer(input.intValue()); } else if (input instanceof Long) { Long max = new Long(Integer.MAX_VALUE); if (input.longValue() <= max.longValue() && input.longValue() >= Integer.MIN_VALUE) { return new Integer(input.intValue()); } } return input; }
From source file:demo.config.PropertyConverter.java
/** * Convert the specified object into an Integer. * //w ww . j a va2s.c om * @param value * the value to convert * @return the converted value * @throws ConversionException * thrown if the value cannot be converted to an integer */ public static Integer toInteger(Object value) throws ConversionException { Number n = toNumber(value, Integer.class); if (n instanceof Integer) { return (Integer) n; } else { return new Integer(n.intValue()); } }
From source file:Main.java
@Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root, 500, 200); stage.setScene(scene);// w w w .jav a2s .c o m Rectangle rect = new Rectangle(200, 200, Color.RED); ScrollPane s1 = new ScrollPane(); s1.setPrefSize(120, 120); s1.setContent(rect); s1.vvalueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { System.out.println(new_val.intValue()); } }); s1.hvalueProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) { System.out.println(new_val.intValue()); } }); root.getChildren().add(s1); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setScene(scene);// w ww. j a va 2 s. c o m stage.show(); stage.setWidth(300); stage.setHeight(200); final String[] greetings = new String[] { "Hello", "Hola", "1", "2" }; final ChoiceBox cb = new ChoiceBox(FXCollections.observableArrayList("1", "2", "3", "4")); cb.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue ov, Number value, Number new_value) { System.out.println(new_value.intValue()); } }); cb.setValue("2"); HBox hb = new HBox(); hb.getChildren().addAll(cb); hb.setSpacing(30); hb.setAlignment(Pos.CENTER); hb.setPadding(new Insets(10, 0, 0, 10)); ((Group) scene.getRoot()).getChildren().add(hb); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); scene.setFill(Color.ALICEBLUE); stage.setScene(scene);/* w w w . j a va 2 s . c o m*/ stage.show(); stage.setWidth(300); stage.setHeight(200); label.setStyle("-fx-font: 25 arial;"); label.setLayoutX(40); rect.setStroke(Color.BLUE); rect.setStrokeWidth(3); rect.setFill(Color.WHITE); final String[] greetings = new String[] { "A", "B", "C", "D", "E" }; final ChoiceBox<String> cb = new ChoiceBox<String>( FXCollections.observableArrayList("a", "b", "c", "d", "e")); cb.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { public void changed(ObservableValue ov, Number value, Number new_value) { label.setText(greetings[new_value.intValue()]); } }); cb.setTooltip(new Tooltip("Select the language")); cb.setValue("English"); HBox hb = new HBox(); hb.getChildren().addAll(cb, label); hb.setSpacing(30); hb.setAlignment(Pos.CENTER); hb.setPadding(new Insets(10, 0, 0, 10)); ((Group) scene.getRoot()).getChildren().add(hb); }
From source file:cz.jirutka.spring.data.jdbc.fixtures.CommentRepository.java
@Override protected <S extends Comment> S postInsert(S entity, Number generatedId) { entity.setId(generatedId.intValue()); return entity; }
From source file:cz.jirutka.spring.data.jdbc.fixtures.CommentWithUserRepository.java
@Override protected <S extends CommentWithUser> S postInsert(S entity, Number generatedId) { entity.setId(generatedId.intValue()); return entity; }
From source file:jenkins.plugins.livingdoc.chart.NumberLabelGenerator.java
public String generateLabel(CategoryDataset dataset, int row, int column) { Number value = dataset.getValue(row, column); return value == null || value.intValue() == 0 ? null : String.valueOf(value.intValue()); }
From source file:io.coala.random.impl.RandomNumberStreamFactoryWell19937c.java
@Override public RandomNumberStream create(final RandomNumberStreamID id, final Number seed) { final RandomGenerator rng = new Well19937c(); rng.setSeed(seed.intValue()); return RandomNumberStream.Util.asStream(id, rng); }