public OidValue(Identifier id, NumericValue nr) { grammarSet = true; name = id; if (name != null) name.setParent(this); numval = nr; if (numval != null) numval.setParent(this); }
/** * Format a number supplied as a integer * * @param value the integer value * @param fsb the FastStringBuffer to contain the result */ private void formatInteger(NumericValue value, FastStringBuffer fsb) { fsb.append(value.getStringValueCS()); int leadingZeroes = minWholePartSize - fsb.length(); fsb.prependRepeated('0', leadingZeroes); if (minFractionPartSize != 0) { fsb.append('.'); for (int i = 0; i < minFractionPartSize; i++) { fsb.append('0'); } } }
/** * Format a number, given the two subpictures and the decimal format symbols * * @param number the number to be formatted * @param subPictures the negative and positive subPictures * @param dfs the decimal format symbols to be used * @return the formatted number */ private CharSequence formatNumber( NumericValue number, SubPicture[] subPictures, DecimalSymbols dfs) { NumericValue absN = number; SubPicture pic; String minusSign = ""; if (number.signum() < 0) { absN = number.negate(); if (subPictures[1] == null) { pic = subPictures[0]; minusSign = "" + unicodeChar(dfs.minusSign); } else { pic = subPictures[1]; } } else { pic = subPictures[0]; } return pic.format(absN, dfs, minusSign); }
/** * Set a numeric value for the cell * * @param value the numeric value to set this cell to. For formulas we'll set the precalculated * value, for numerics we'll set its value. For other types we will change the cell to a * numeric cell and set its value. */ public void setCellValue(double value) { if (Double.isInfinite(value)) { // Excel does not support positive/negative infinities, // rather, it gives a #DIV/0! error in these cases. setCellErrorValue(FormulaError.DIV0.getCode()); } else if (Double.isNaN(value)) { setCellErrorValue(FormulaError.NUM.getCode()); } else { ensureTypeOrFormulaType(CELL_TYPE_NUMERIC); if (_value.getType() == CELL_TYPE_FORMULA) ((NumericFormulaValue) _value).setPreEvaluatedValue(value); else ((NumericValue) _value).setValue(value); } }
@Override public NumericValue<? extends Number> multiply(NumericValue<? extends Number> other) { Number otherNumber = other.getValue(); if (otherNumber instanceof Integer) { return new IntegerValue(value * otherNumber.intValue()); } if (otherNumber instanceof Double) { return new DoubleValue(value * otherNumber.doubleValue()); } if (otherNumber instanceof Long) { return new LongValue(value * otherNumber.longValue()); } throw new AssertionError("The type " + otherNumber.getClass() + " was not expected"); }
/** * Format a number using this sub-picture * * @param value the absolute value of the number to be formatted * @param dfs the decimal format symbols to be used * @param minusSign the representation of a minus sign to be used * @return the formatted number */ public CharSequence format(NumericValue value, DecimalSymbols dfs, String minusSign) { // System.err.println("Formatting " + value); if (value.isNaN()) { return dfs.NaN; // changed by W3C Bugzilla 2712 } if ((value instanceof DoubleValue || value instanceof FloatValue) && Double.isInfinite(value.getDoubleValue())) { return minusSign + prefix + dfs.infinity + suffix; } int multiplier = 1; if (isPercent) { multiplier = 100; } else if (isPerMille) { multiplier = 1000; } if (multiplier != 1) { try { // value = value.arithmetic(Token.MULT, new Int64Value(multiplier), null); value = (NumericValue) ArithmeticExpression.compute( value, Calculator.TIMES, new Int64Value(multiplier), null); } catch (XPathException e) { value = new DoubleValue(value.getDoubleValue() * multiplier); } } FastStringBuffer sb = new FastStringBuffer(20); if (value instanceof DoubleValue || value instanceof FloatValue) { BigDecimal dec = adjustToDecimal(value.getDoubleValue(), 2); formatDecimal(dec, sb); // formatDouble(value.getDoubleValue(), sb); } else if (value instanceof Int64Value || value instanceof BigIntegerValue) { formatInteger(value, sb); } else if (value instanceof DecimalValue) { //noinspection RedundantCast formatDecimal(((DecimalValue) value).getDecimalValue(), sb); } // System.err.println("Justified number: " + sb.toString()); // Map the digits and decimal point to use the selected characters int[] ib = StringValue.expand(sb); int ibused = ib.length; int point = sb.indexOf('.'); if (point == -1) { point = sb.length(); } else { ib[point] = dfs.decimalSeparator; // If there is no fractional part, delete the decimal point if (maxFractionPartSize == 0) { ibused--; } } // Map the digits if (dfs.zeroDigit != '0') { int newZero = dfs.zeroDigit; for (int i = 0; i < ibused; i++) { int c = ib[i]; if (c >= '0' && c <= '9') { ib[i] = (c - '0' + newZero); } } } // Add the whole-part grouping separators if (wholePartGroupingPositions != null) { if (wholePartGroupingPositions.length == 1) { // grouping separators are at regular positions int g = wholePartGroupingPositions[0]; int p = point - g; while (p > 0) { ib = insert(ib, ibused++, dfs.groupingSeparator, p); // sb.insert(p, unicodeChar(dfs.groupingSeparator)); p -= g; } } else { // grouping separators are at irregular positions for (int i = 0; i < wholePartGroupingPositions.length; i++) { int p = point - wholePartGroupingPositions[i]; if (p > 0) { ib = insert(ib, ibused++, dfs.groupingSeparator, p); // sb.insert(p, unicodeChar(dfs.groupingSeparator)); } } } } // Add the fractional-part grouping separators if (fractionalPartGroupingPositions != null) { // grouping separators are at irregular positions. for (int i = 0; i < fractionalPartGroupingPositions.length; i++) { int p = point + 1 + fractionalPartGroupingPositions[i] + i; if (p < ibused - 1) { ib = insert(ib, ibused++, dfs.groupingSeparator, p); // sb.insert(p, dfs.groupingSeparator); } else { break; } } } // System.err.println("Grouped number: " + sb.toString()); // sb.insert(0, prefix); // sb.insert(0, minusSign); // sb.append(suffix); FastStringBuffer res = new FastStringBuffer(prefix.length() + minusSign.length() + suffix.length() + ibused); res.append(minusSign); res.append(prefix); res.append(StringValue.contract(ib, ibused)); res.append(suffix); return res; }
public boolean hasNumber() { return (numval != null) && (numval.getValue() > -1); }
public void setNumber(NumericValue nr) { numval = nr; if (numval != null) numval.setParent(this); }
public int line() { if (name != null) { return name.line(); } return numval.line(); }
public String toString() { if (name != null) { return name.toString(); } return numval.toString(); }
public OidValue(NumericValue nr) { grammarSet = false; name = null; numval = nr; if (numval != null) numval.setParent(this); }