List of usage examples for java.lang Number equals
public boolean equals(Object obj)
From source file:HexFormat.java
public static void main(String[] args) { String result;//from ww w . jav a 2 s . co m HexFormat format = new HexFormat(); // byte byte bNumber = 0x33; result = format.format(bNumber); if (result.equals("33")) { System.out.print("Success => "); } else { System.out.print("FAILURE => "); } System.out.println("Byte: " + bNumber + " (0x" + result + ")"); bNumber = (byte) 0x85; result = format.format(bNumber); if (result.equals("85")) { System.out.print("Success => "); } else { System.out.print("FAILURE => "); } System.out.println("Byte: " + bNumber + " (0x" + result + ")"); bNumber = (byte) 0x0f; result = format.format(bNumber); if (result.equals("0f")) { System.out.print("Success => "); } else { System.out.print("FAILURE => "); } System.out.println("Byte: " + bNumber + " (0x" + result + ")"); short sNumber = (short) 0xa2b6; result = format.format(sNumber); if (result.equals("a2b6")) { System.out.print("Success => "); } else { System.out.print("FAILURE => "); } System.out.println("Byte: " + bNumber + " (0x" + result + ")"); format.setUpperCase(true); int iNumber = (int) 0x4321fedc; result = format.format(iNumber); if (result.equals("4321FEDC")) { System.out.print("Success => "); } else { System.out.print("FAILURE => "); } System.out.println("Byte: " + bNumber + " (0x" + result + ")"); long lNumber = (long) 0x4321fedc4321fedcL; result = format.format(lNumber); if (result.equals("4321FEDC4321FEDC")) { System.out.print("Success => "); } else { System.out.print("FAILURE => "); } System.out.println("Byte: " + bNumber + " (0x" + result + ")"); String num = "0xfe"; Number number = null; Byte bExpect = new Byte((byte) 0xfe); try { number = format.parse(num); } catch (ParseException e) { System.out.println(e); e.printStackTrace(); } if ((number instanceof Byte) && (number.equals(bExpect))) { System.out.print("Success => "); } else { System.out.print("FAILURE => "); } System.out.println("Byte: " + bExpect + " result: " + number); num = "0xf"; number = null; bExpect = new Byte((byte) 0xf); try { number = format.parse(num); } catch (ParseException e) { System.out.println(e); e.printStackTrace(); } if ((number instanceof Byte) && (number.equals(bExpect))) { System.out.print("Success => "); } else { System.out.print("FAILURE => "); } System.out.println("Byte: " + bExpect + " result: " + number); num = "0xf0f0"; number = null; Short sExpect = new Short((short) 0xf0f0); try { number = format.parse(num); } catch (ParseException e) { System.out.println(e); e.printStackTrace(); } if ((number instanceof Short) && (number.equals(sExpect))) { System.out.print("Success => "); } else { System.out.print("FAILURE => "); } System.out.println("Short: " + sExpect + " result: " + number); num = "0xdEAdbEEf"; number = null; Integer iExpect = new Integer((int) 0xdEAdbEEf); try { number = format.parse(num); } catch (ParseException e) { System.out.println(e); e.printStackTrace(); } if ((number instanceof Integer) && (number.equals(iExpect))) { System.out.print("Success => "); } else { System.out.print("FAILURE => "); } System.out.println("Integer: " + iExpect + " result: " + number); }
From source file:com.fengduo.bee.commons.util.NumberParser.java
public static boolean isEqual(Number a, Number b) { return a == null ? b == null : a.equals(b); }
From source file:com.qtplaf.library.util.NumberUtils.java
/** * Check if the number is in the list of numbers. * /*from w w w . j a va 2 s.c om*/ * @param number The number to check. * @param numbers The list of numbers. * @return A boolean. */ public static boolean in(Number number, Number... numbers) { for (Number n : numbers) { if (n.equals(number)) { return true; } } return false; }
From source file:dk.nodes.webservice.parser.NJSONObject.java
/** * Encodes the number as a JSON string./*from w ww . j a v a 2s . c o m*/ * * @param number a finite value. May not be {@link Double#isNaN() NaNs} or * {@link Double#isInfinite() infinities}. */ public static String numberToString(Number number) throws JSONException { if (number == null) { throw new JSONException("Number must be non-null"); } double doubleValue = number.doubleValue(); NJSON.checkDouble(doubleValue); // the original returns "-0" instead of "-0.0" for negative zero if (number.equals(NEGATIVE_ZERO)) { return "-0"; } long longValue = number.longValue(); if (doubleValue == (double) longValue) { return Long.toString(longValue); } return number.toString(); }
From source file:caillou.company.clonemanager.gui.customComponent.transition.TransitionController.java
/** * Initializes the controller class./*from ww w . j av a2s.c om*/ */ @Override public void initialize(URL url, ResourceBundle rb) { progressBarFullHashId.progressProperty().addListener(new ChangeListener<Number>() { @Override public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { if (newValue.equals((double) 1)) { wrappingDialog.hide(); } } }); }
From source file:org.talend.dataprofiler.chart.preview.DQRuleItemLabelGenerator.java
@Override protected Object[] createItemArray(CategoryDataset dataset, int row, int column) { Object[] result = new Object[4]; result[0] = dataset.getRowKey(row).toString(); result[1] = dataset.getColumnKey(column).toString(); Number value = dataset.getValue(row, column); if (value != null && !value.equals(Double.NaN)) { if (super.getNumberFormat() != null) { result[2] = super.getNumberFormat().format(value); } else if (super.getDateFormat() != null) { result[2] = super.getDateFormat().format(value); }//from w w w .j ava 2s .co m double total = DataUtilities.calculateColumnTotal(dataset, column); double percent = value.doubleValue() / total; // MOD qiongli bug 21589,override for just changeing this line.avoid 99.99% to show 100% // result[3] = this.percentFormat.format(percent); result[3] = stringformat(percent, 0).toString(); } else { result[2] = "-"; //$NON-NLS-1$ result[3] = "-"; //$NON-NLS-1$ } return result; }
From source file:com.xpn.xwiki.objects.classes.NumberClass.java
@Override public void makeQuery(Map<String, Object> map, String prefix, XWikiCriteria query, List<String> criteriaList) { Number value = (Number) map.get(prefix); if ((value != null) && (!value.equals(""))) { criteriaList.add(getFullQueryPropertyName() + "=" + value.toString()); return;//from www. ja va 2 s. c o m } value = (Number) map.get(prefix + "lessthan"); if ((value != null) && (!value.equals(""))) { criteriaList.add(getFullQueryPropertyName() + "<=" + value.toString()); return; } value = (Number) map.get(prefix + "morethan"); if ((value != null) && (!value.equals(""))) { criteriaList.add(getFullQueryPropertyName() + ">=" + value.toString()); return; } }
From source file:com.datatorrent.apps.logstream.DimensionOperatorUnifier.java
@Override public void process(Map<String, DimensionObject<String>> tuple) { if (firstTuple) { extractType(tuple);/* w w w . j av a2 s .c o m*/ firstTuple = false; } // tuple will have one record each per metric type. currently 3 record one for each of SUM, COUNT, AVERAGE Iterator<Entry<String, DimensionObject<String>>> iterator = tuple.entrySet().iterator(); String randomKey = null; String key = null; if (iterator.hasNext()) { randomKey = iterator.next().getKey(); String[] split = randomKey.split("\\."); key = split[0]; } String[] split = randomKey.split("\\|"); Number receivedFilter = new Integer(split[3]); Number expectedFilter = recordType.get(LogstreamUtil.FILTER); if (!receivedFilter.equals(expectedFilter)) { logger.error("Unexpected tuple"); logger.error("expected filter = {} received = {}", expectedFilter, receivedFilter); } computeAddition(tuple, AggregateOperation.SUM, key); computeAddition(tuple, AggregateOperation.COUNT, key); computeAverage(tuple, AggregateOperation.AVERAGE, key); }
From source file:au.org.ala.delta.model.NumericRange.java
public Range getFullRange() { Number min = _range.getMinimumNumber(); Number max = _range.getMaximumNumber(); if (hasExtremeLow()) { min = _extremeLow;//w w w . j a v a 2 s .c o m } if (hasExtremeHigh()) { max = _extremeHigh; } if (min.equals(max)) { return createRangeForSingleValue(min); } return new NumberRange(min, max); }
From source file:com.gst.infrastructure.core.api.JsonQuery.java
private boolean differenceExists(final Number baseValue, final Number workingCopyValue) { boolean differenceExists = false; if (baseValue != null) { differenceExists = !baseValue.equals(workingCopyValue); } else {/* w w w . j a v a 2 s . c o m*/ differenceExists = workingCopyValue != null; } return differenceExists; }