SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.datastructure.list
Class NumberList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<java.lang.Number>
              extended by com.numericalmethod.suanshu.datastructure.list.NumberList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<java.lang.Number>, java.util.Collection<java.lang.Number>, java.util.List<java.lang.Number>, java.util.RandomAccess

public class NumberList
extends java.util.ArrayList<java.lang.Number>

This data structure represents a list of Numbers.

It is a wrapper for ArrayList<Number> and has a set of utility functions for convenient.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
NumberList()
          Construct an empty list of numbers.
NumberList(java.util.Collection<? extends java.lang.Number> c)
          Copy constructor to copy from another collection of numbers.
NumberList(java.lang.Number... numbers)
          Construct a list of numbers from the inputs.
NumberList(java.lang.String... numbers)
          Construct a list of numbers from the inputs.
 
Method Summary
 void add(java.lang.Number... numbers)
          Add new numbers to the list.
 void add(java.lang.String... numbers)
          Add new numbers to the list.
 double[] doubleArray()
          Convert this list of numbers to a double array, if all its elements are real.
 boolean hasApproximately(double precision, java.lang.Number... numbers)
          Check whether the list contains the numbers.
 boolean hasApproximately(double precision, java.lang.String... numbers)
          Check whether the list contains the numbers.
 boolean hasExactly(java.lang.Number... numbers)
          Check whether the list contains the numbers.
 boolean hasExactly(java.lang.String... numbers)
          Check whether the list contains the numbers.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

NumberList

public NumberList()
Construct an empty list of numbers.


NumberList

public NumberList(java.util.Collection<? extends java.lang.Number> c)
Copy constructor to copy from another collection of numbers. The two data structures reference the same instances of numbers, hence a shallow copy.

Parameters:
c - a collection of Numbers

NumberList

public NumberList(java.lang.Number... numbers)
Construct a list of numbers from the inputs.

Parameters:
numbers - an array of Numbers

NumberList

public NumberList(java.lang.String... numbers)
Construct a list of numbers from the inputs.

Parameters:
numbers - an array of numbers in String
Method Detail

add

public void add(java.lang.Number... numbers)
Add new numbers to the list.

Parameters:
numbers - an array of Numbers

add

public void add(java.lang.String... numbers)
Add new numbers to the list.

Parameters:
numbers - an array of numbers in String

hasExactly

public boolean hasExactly(java.lang.Number... numbers)
Check whether the list contains the numbers.

A match is true iff

  1. the type is the same, e.g., Double == Double; Double != Integer
  2. the value is exactly the same (by their equal and hashcode functions), e.g., (1.5 == 1.5); (1.5 != 1.5 + ε)

Parameters:
numbers - an array of Numbers
Returns:
true iff the matching criteria is met

hasExactly

public boolean hasExactly(java.lang.String... numbers)
Check whether the list contains the numbers.

A match is true iff

Parameters:
numbers - an array of numbers in String
Returns:
true iff the matching criteria is met

hasApproximately

public boolean hasApproximately(double precision,
                                java.lang.Number... numbers)
Check whether the list contains the numbers.

A match is true iff

Note that the matched numbers do not need to be of the same type, or exactly identical in value.

Parameters:
precision - two numbers are considered the same if their absolute difference is less than or equal to precision
numbers - an array of Numbers
Returns:
true iff the matching criteria is met

hasApproximately

public boolean hasApproximately(double precision,
                                java.lang.String... numbers)
Check whether the list contains the numbers.

A match is true iff

Note that the matched numbers do not need to be of the same type, or exactly identical in value.

Parameters:
precision - two numbers are considered the same if their absolute difference is less than or equal to precision
numbers - an array of numbers in String
Returns:
true iff the matching criteria is met

doubleArray

public double[] doubleArray()
Convert this list of numbers to a double array, if all its elements are real.

Returns:
a double[] array
Throws:
java.lang.IllegalArgumentException - if the list consists of not entirely doubles

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.