Package org.btrplace.btrpsl.element
Class BtrpNumber
java.lang.Object
org.btrplace.btrpsl.element.DefaultBtrpOperand
org.btrplace.btrpsl.element.BtrpNumber
- All Implemented Interfaces:
BtrpOperand
,Copyable<BtrpOperand>
public class BtrpNumber extends DefaultBtrpOperand
Denotes an number operand.
The value may an integer or a real, either positive or negative.
An integer can be expressed in base 10, 8 (octal) or 16 (hexadecimal) while
a real is necessarily expressed in base 10.
- Author:
- Fabien Hermenier
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BtrpNumber.Base
The number base.Nested classes/interfaces inherited from interface org.btrplace.btrpsl.element.BtrpOperand
BtrpOperand.Type
-
Field Summary
Fields Modifier and Type Field Description static BtrpNumber
FALSE
Pre-made false value.static BtrpNumber
TRUE
Pre-made true value. -
Constructor Summary
Constructors Constructor Description BtrpNumber(double d)
Make a float number.BtrpNumber(int v, BtrpNumber.Base b)
Make a new integer. -
Method Summary
Modifier and Type Method Description BtrpNumber
copy()
Make a deep copy of the object.int
degree()
Get the degree of the operand.BtrpNumber
div(BtrpOperand other)
Divides this operand by another one.BtrpNumber
eq(BtrpOperand other)
Check if this operand is equals to another one.boolean
equals(Object o)
Check the equality of two elements.BtrpNumber
geq(BtrpOperand other)
Check if this operand is greater or equals to another one.BtrpNumber.Base
getBase()
Get the current base for the numberdouble
getDoubleValue()
The real value of this operand.int
getIntValue()
The integer value of this operand.BtrpNumber
gt(BtrpOperand other)
Check if this operand is strictly greater than another one.int
hashCode()
boolean
isInteger()
Indicates whether or not the number is an integer.BtrpNumber
minus(BtrpOperand other)
Computes the difference between this operand and another one.BtrpNumber
negate()
Computes the negation of this operand.BtrpNumber
not()
Compute the opposite of the operand.BtrpNumber
plus(BtrpOperand other)
Computes the addition of this operand with another one.BtrpNumber
power(BtrpOperand nb)
Computes the power of this operand.BtrpNumber
remainder(BtrpOperand other)
Computes the remainder of this operand division by another oneBtrpNumber
times(BtrpOperand other)
Multiply this operand by another oneString
toString()
Textual representation of the integer.BtrpOperand.Type
type()
Get the type of the operand.Methods inherited from class org.btrplace.btrpsl.element.DefaultBtrpOperand
label, prettyType, prettyType, prettyType, setLabel
-
Field Details
-
Constructor Details
-
BtrpNumber
Make a new integer.- Parameters:
v
- the current valueb
- the base used when printing the value
-
BtrpNumber
public BtrpNumber(double d)Make a float number. The number will be represented in base 10.- Parameters:
d
- the value.
-
-
Method Details
-
type
Description copied from interface:BtrpOperand
Get the type of the operand.- Returns:
BtrpOperand.Type.NUMBER
-
getBase
Get the current base for the number- Returns:
- the base
-
power
Description copied from interface:BtrpOperand
Computes the power of this operand.- Specified by:
power
in interfaceBtrpOperand
- Overrides:
power
in classDefaultBtrpOperand
- Parameters:
nb
- the other value. Must be a number- Returns:
- an integer number if both operands are integer. A real number otherwise
-
plus
Description copied from interface:BtrpOperand
Computes the addition of this operand with another one.- Specified by:
plus
in interfaceBtrpOperand
- Overrides:
plus
in classDefaultBtrpOperand
- Parameters:
other
- the other value. Must be a number- Returns:
- the result of the addition
-
minus
Description copied from interface:BtrpOperand
Computes the difference between this operand and another one.- Specified by:
minus
in interfaceBtrpOperand
- Overrides:
minus
in classDefaultBtrpOperand
- Parameters:
other
- the other value. Must be a number- Returns:
- the result of the difference
-
negate
Description copied from interface:BtrpOperand
Computes the negation of this operand.- Specified by:
negate
in interfaceBtrpOperand
- Overrides:
negate
in classDefaultBtrpOperand
- Returns:
- the result of the negation
-
times
Description copied from interface:BtrpOperand
Multiply this operand by another one- Specified by:
times
in interfaceBtrpOperand
- Overrides:
times
in classDefaultBtrpOperand
- Parameters:
other
- the other value. Must be a number- Returns:
- the result of the negation
-
div
Description copied from interface:BtrpOperand
Divides this operand by another one.- Specified by:
div
in interfaceBtrpOperand
- Overrides:
div
in classDefaultBtrpOperand
- Parameters:
other
- the other value. Must be a number- Returns:
- the result of the division
-
remainder
Description copied from interface:BtrpOperand
Computes the remainder of this operand division by another one- Specified by:
remainder
in interfaceBtrpOperand
- Overrides:
remainder
in classDefaultBtrpOperand
- Parameters:
other
- the other value. Must be a number- Returns:
- the remainder of the division
-
equals
Check the equality of two elements. Both are equals if they are an instance of a same class and if they contains the same element. -
hashCode
public int hashCode() -
toString
Textual representation of the integer. The base is considered. -
degree
public int degree()Description copied from interface:BtrpOperand
Get the degree of the operand. A degree of 0 indicates a single value. A degree of 1 indicates a set of single value. A degree of 2 indicate a set of set of values. Basically. An operand with a degree n is a set of elements with all having the degree n - 1- Returns:
0
-
getIntValue
public int getIntValue()The integer value of this operand.- Returns:
- the integer given at instantiation if the number is an integer.
0
otherwise
-
getDoubleValue
public double getDoubleValue()The real value of this operand.- Returns:
- the real given at instantiation if the number is a real.
0
otherwise
-
eq
Description copied from interface:BtrpOperand
Check if this operand is equals to another one.- Specified by:
eq
in interfaceBtrpOperand
- Overrides:
eq
in classDefaultBtrpOperand
- Parameters:
other
- the operand to compare to- Returns:
TRUE
if both operand are equals,FALSE
otherwise
-
geq
Description copied from interface:BtrpOperand
Check if this operand is greater or equals to another one.- Specified by:
geq
in interfaceBtrpOperand
- Overrides:
geq
in classDefaultBtrpOperand
- Parameters:
other
- the operand to compare to- Returns:
TRUE
if this operand is greater or equals,FALSE
otherwise
-
gt
Description copied from interface:BtrpOperand
Check if this operand is strictly greater than another one.- Specified by:
gt
in interfaceBtrpOperand
- Overrides:
gt
in classDefaultBtrpOperand
- Parameters:
other
- the operand to compare to- Returns:
TRUE
if this operand is strictly greater,FALSE
otherwise
-
not
Description copied from interface:BtrpOperand
Compute the opposite of the operand.- Specified by:
not
in interfaceBtrpOperand
- Overrides:
not
in classDefaultBtrpOperand
- Returns:
- the opposite operand
-
copy
Description copied from interface:Copyable
Make a deep copy of the object.- Returns:
- a deep copy
-
isInteger
public boolean isInteger()Indicates whether or not the number is an integer.- Returns:
true
if the number is an integer.
-