Record Class NumberValue
- Record Components:
value- the numeric value; must not benull
- All Implemented Interfaces:
Value
BigDecimal.
Use of(String) to parse a numeric literal string (as produced
by NumberOperand.value()).
Two numbers are the same value when they are numerically equal, whatever
scale they were written or computed at: 5 and 5.0 are one value. That
is not what a record gives — BigDecimal.equals(java.lang.Object) is scale-sensitive — and the
difference is the whole reason this is written out. Comparison has always been
numeric, so leaving identity to the record left the engine holding two incompatible
answers to are these the same number, and which one applied depended on the
operator: σ x = 5 kept both rows while δ kept them apart, so DISTINCT
returned the same displayed number twice. Everything that hashes or sets a value —
δ, γ keys, the deduplicating set operations, join hash keys, a
closure's nodes — reads this, and every one of them now agrees with =.
The scale itself is kept. It is what the source supplied and it survives a round trip; it simply does not decide identity, exactly as it does not decide order.
-
Constructor Summary
ConstructorsConstructorDescriptionNumberValue(BigDecimal value) Creates an instance of aNumberValuerecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the number as a plain decimal string with no trailing zeros and no scientific notation, e.g.booleanReturns whetherobjis a numerically equal number.inthashCode()Returns a hash over the scale-normalised number, agreeing withequals(java.lang.Object).booleanisNull()Returnstrueif this value is null (absent).static NumberValueParses a numeric literal string into aNumberValue.final StringtoString()Returns a string representation of this record class.type()Returns theScalarTypethat describes this value's kind.value()Returns the value of thevaluerecord component.
-
Constructor Details
-
NumberValue
Creates an instance of aNumberValuerecord class.- Parameters:
value- the value for thevaluerecord component
-
-
Method Details
-
of
Parses a numeric literal string into aNumberValue.- Parameters:
text- the numeric literal, e.g."42"or"3.14"- Returns:
- a new
NumberValue - Throws:
NumberFormatException- iftextis not a valid decimal
-
equals
Returns whetherobjis a numerically equal number. Scale is not part of the answer, so5equals5.0. -
hashCode
public int hashCode()Returns a hash over the scale-normalised number, agreeing withequals(java.lang.Object).- Specified by:
hashCodein classRecord- Returns:
- a hash over the scale-normalised number, agreeing with
equals(java.lang.Object)
-
isNull
public boolean isNull()Description copied from interface:ValueReturnstrueif this value is null (absent). -
type
Description copied from interface:Value -
asDisplayString
Returns the number as a plain decimal string with no trailing zeros and no scientific notation, e.g."42","3.14","0".- Specified by:
asDisplayStringin interfaceValue- Returns:
- plain decimal string
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
value
Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-