ch.javasoft.math
Class LongOperations

java.lang.Object
  extended by ch.javasoft.math.AbstractNumberOps<Long>
      extended by ch.javasoft.math.LongOperations
All Implemented Interfaces:
NumberOperations<Long>, Comparator<Long>

public class LongOperations
extends AbstractNumberOps<Long>

Number operations for Long numbers. A singleton instance exists for this class.


Constructor Summary
LongOperations()
           
 
Method Summary
 Long abs(Long number)
          Returns the absolute value of the given number, i.e.
 Long add(Long numA, Long numB)
          Returns the sum of the two values, i.e.
 int byteLength()
          Returns the byte array length if NumberOperations.toByteArray(Number) is used and if this size is fixed, and -1 if the size may vary depending on the number instance
 int compare(Long o1, Long o2)
           
 Long divide(Long numA, Long numB)
          Returns the ratio of the two values, i.e.
 Long fromByteArray(byte[] bytes)
          Converts the byte array containing binary data into a new number instance.
static LongOperations instance()
          Returns the singleton instance
 Long invert(Long number)
          Returns the inverted value, i.e.
 boolean isNegative(Long number)
          Returns true if this value negative, i.e.
 boolean isNonZero(Long number)
          Returns true if this value is numerically unequal to zero, i.e.
 boolean isOne(Long number)
          Returns true if this value is numerically equal to one, i.e.
 boolean isPositive(Long number)
          Returns true if this value positive, i.e.
 boolean isZero(Long number)
          Returns true if this value is numerically equal to zero, i.e.
 Long multiply(Long numA, Long numB)
          Returns the product of the two values, i.e.
 Long negate(Long number)
          Returns the negated value, i.e.
 Long[] newArray(int size)
          Create a new array of the underlying number type
 Long[][] newArray(int rows, int cols)
          Create a new 2 dimensional array of the underlying number type
 Class<Long> numberClass()
          The class representing numbers of this number operations instance
 Long one()
          Returns the value representing one
 Long pow(Long numA, Long numB)
          Returns the powered value, i.e.
 Long readFrom(DataInput in)
          Reads binary data from the given data input.
 Long reduce(Long number)
          Converts the number into some reduced form.
 Long[] reduceVector(boolean cloneOnChange, Long... vector)
          Converts a vector into some reduced form.
 int signum(Long number)
          Returns signum of the value, i.e.
 Long subtract(Long numA, Long numB)
          Returns the difference of the two values, i.e.
 byte[] toByteArray(Long number)
          Converts this number to binary data and returns it as a byte array.
 Long valueOf(double value)
          Create an instance of the underlying number type based on the submitted double value
 Long valueOf(long value)
          Create an instance of the underlying number type based on the submitted long integer value
 Long valueOf(Number number)
          Create an instance of the underlying number type based on the submitted number
 Long valueOf(String s)
          Create an instance of the underlying number type based on the given string representation of the number
 void writeTo(Long number, DataOutput out)
          Converts this number to binary data and writes it to the data output.
 Long zero()
          Returns the value representing zero
 
Methods inherited from class ch.javasoft.math.AbstractNumberOps
isNonNegative, isNonPositive, max, max, min, min
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

LongOperations

public LongOperations()
Method Detail

instance

public static LongOperations instance()
Returns the singleton instance

Returns:
the singleton instance

numberClass

public Class<Long> numberClass()
Description copied from interface: NumberOperations
The class representing numbers of this number operations instance


abs

public Long abs(Long number)
Description copied from interface: NumberOperations
Returns the absolute value of the given number, i.e. a non-negative value abs(number)

Specified by:
abs in interface NumberOperations<Long>
Overrides:
abs in class AbstractNumberOps<Long>

add

public Long add(Long numA,
                Long numB)
Description copied from interface: NumberOperations
Returns the sum of the two values, i.e. numA + numB


newArray

public Long[] newArray(int size)
Description copied from interface: NumberOperations
Create a new array of the underlying number type


newArray

public Long[][] newArray(int rows,
                         int cols)
Description copied from interface: NumberOperations
Create a new 2 dimensional array of the underlying number type


valueOf

public Long valueOf(String s)
Description copied from interface: NumberOperations
Create an instance of the underlying number type based on the given string representation of the number


valueOf

public Long valueOf(Number number)
Description copied from interface: NumberOperations
Create an instance of the underlying number type based on the submitted number


valueOf

public Long valueOf(long value)
Description copied from interface: NumberOperations
Create an instance of the underlying number type based on the submitted long integer value


valueOf

public Long valueOf(double value)
Description copied from interface: NumberOperations
Create an instance of the underlying number type based on the submitted double value


divide

public Long divide(Long numA,
                   Long numB)
Description copied from interface: NumberOperations
Returns the ratio of the two values, i.e. numA / numB.

For integer types, an integer division is performed, ignoring possible remainders


invert

public Long invert(Long number)
Description copied from interface: NumberOperations
Returns the inverted value, i.e. 1 / number

Specified by:
invert in interface NumberOperations<Long>
Overrides:
invert in class AbstractNumberOps<Long>

isOne

public boolean isOne(Long number)
Description copied from interface: NumberOperations
Returns true if this value is numerically equal to one, i.e. number == 1

Specified by:
isOne in interface NumberOperations<Long>
Overrides:
isOne in class AbstractNumberOps<Long>

isZero

public boolean isZero(Long number)
Description copied from interface: NumberOperations
Returns true if this value is numerically equal to zero, i.e. number == 0

Specified by:
isZero in interface NumberOperations<Long>
Overrides:
isZero in class AbstractNumberOps<Long>

isNonZero

public boolean isNonZero(Long number)
Description copied from interface: NumberOperations
Returns true if this value is numerically unequal to zero, i.e. number != 0

Specified by:
isNonZero in interface NumberOperations<Long>
Overrides:
isNonZero in class AbstractNumberOps<Long>

isNegative

public boolean isNegative(Long number)
Description copied from interface: NumberOperations
Returns true if this value negative, i.e. number < 0

Specified by:
isNegative in interface NumberOperations<Long>
Overrides:
isNegative in class AbstractNumberOps<Long>

isPositive

public boolean isPositive(Long number)
Description copied from interface: NumberOperations
Returns true if this value positive, i.e. number > 0

Specified by:
isPositive in interface NumberOperations<Long>
Overrides:
isPositive in class AbstractNumberOps<Long>

multiply

public Long multiply(Long numA,
                     Long numB)
Description copied from interface: NumberOperations
Returns the product of the two values, i.e. numA * numB


negate

public Long negate(Long number)
Description copied from interface: NumberOperations
Returns the negated value, i.e. -number


reduce

public Long reduce(Long number)
Description copied from interface: NumberOperations
Converts the number into some reduced form. This can for instance mean reduction for fraction numbers. If no reduction can be made, the number is returned unchanged.


reduceVector

public Long[] reduceVector(boolean cloneOnChange,
                           Long... vector)
Description copied from interface: NumberOperations
Converts a vector into some reduced form. For integer or fraction number vectors, this can for instance mean that the vector is shortened by the greatest common divisor of all vector components.

Note that the vector length might change by this operation. If only individual components of the vector should be reduced, which is not affecting the vector's length, reduce each number separately.

Parameters:
cloneOnChange - if a reduction can be made, the array is cloned and the original array is not changed. If no reduction can be made, or if cloneOnChange is false, the original array will be returned, unmodified in the former case, and with reduced values in the latter case.
vector - the vector to reduce

one

public Long one()
Description copied from interface: NumberOperations
Returns the value representing one


pow

public Long pow(Long numA,
                Long numB)
Description copied from interface: NumberOperations
Returns the powered value, i.e. numAnumB. Negative exponents are allowed, also for integer types, without causing an exception. E.g. 3^-1 yields 0.


signum

public int signum(Long number)
Description copied from interface: NumberOperations
Returns signum of the value, i.e. -1, 0, 1 for negative, zero or positive values


subtract

public Long subtract(Long numA,
                     Long numB)
Description copied from interface: NumberOperations
Returns the difference of the two values, i.e. numA - numB


zero

public Long zero()
Description copied from interface: NumberOperations
Returns the value representing zero


compare

public int compare(Long o1,
                   Long o2)

toByteArray

public byte[] toByteArray(Long number)
Description copied from interface: NumberOperations
Converts this number to binary data and returns it as a byte array. Back-conversion is possible using the NumberOperations.fromByteArray(byte[]) method.


writeTo

public void writeTo(Long number,
                    DataOutput out)
             throws IOException
Description copied from interface: NumberOperations
Converts this number to binary data and writes it to the data output. The counterpart of this method reading binary data is NumberOperations.readFrom(DataInput).

Throws:
IOException

fromByteArray

public Long fromByteArray(byte[] bytes)
Description copied from interface: NumberOperations
Converts the byte array containing binary data into a new number instance. Forward-conversion is possible using the NumberOperations.toByteArray(Number) method.


readFrom

public Long readFrom(DataInput in)
              throws IOException
Description copied from interface: NumberOperations
Reads binary data from the given data input. Binary data is converted and a new number instance is returned. The counterpart of this method writing binary data is NumberOperations.writeTo(Number, DataOutput)

Throws:
IOException

byteLength

public int byteLength()
Description copied from interface: NumberOperations
Returns the byte array length if NumberOperations.toByteArray(Number) is used and if this size is fixed, and -1 if the size may vary depending on the number instance