www.sdmetrics.com

com.sdmetrics.metrics
Class MetricTools

java.lang.Object
  extended by com.sdmetrics.metrics.MetricTools

public class MetricTools
extends java.lang.Object

Collection of static helper methods that are useful for the implementation of calculation procedures.


Constructor Summary
MetricTools()
           
 
Method Summary
static java.util.Collection<?> createHashSet(boolean multi)
          Creates a new empty set or multiset.
static java.util.Collection<?> createHashSet(boolean multi, java.util.Collection<?> contents)
          Creates a new set or multiset with initial contents.
static int elementCount(java.util.Collection<?> c, java.lang.Object element)
          Counts the number of occurrences of an element in a set or multiset.
static
<T> java.util.Iterator<T>
getFlatIterator(java.util.Collection<T> c)
          Obtains an iterator over the unique elements of a set or multiset.
static java.lang.Number getNumber(float f)
          Optimizes a float return value for a metric.
static boolean isEmptyElement(java.lang.Object o)
          Checks if an object represents an empty model element reference.
static boolean isMultiSet(java.util.Collection<?> c)
          Tests if a collection is a multiset.
static void removeAny(java.util.Collection<?> c, java.lang.Object element)
          Removes all occurrences of an element in a set or multiset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetricTools

public MetricTools()
Method Detail

createHashSet

public static java.util.Collection<?> createHashSet(boolean multi)
Creates a new empty set or multiset.

Parameters:
multi - true to create a multiset, false to create a regular set.
Returns:
New empty HashSet or HashMultiSet

createHashSet

public static java.util.Collection<?> createHashSet(boolean multi,
                                                    java.util.Collection<?> contents)
Creates a new set or multiset with initial contents.

Parameters:
multi - true to create a multiset, false to create a regular set.
contents - Initial contents of the (multi) set.
Returns:
New HashSet or HashMultiSet with initial contents.
Since:
2.3

isMultiSet

public static boolean isMultiSet(java.util.Collection<?> c)
Tests if a collection is a multiset.

Parameters:
c - Collection to test.
Returns:
true if c is an instance of HashMultiSet.

elementCount

public static int elementCount(java.util.Collection<?> c,
                               java.lang.Object element)
Counts the number of occurrences of an element in a set or multiset.

Parameters:
c - The set or multiset. This must be an instance of java.util.Set or HashMultiSet.
element - The element to count.
Returns:
If c is a multiset, the cardinality of the element in c. Otherwise 1 if c contains the element, 0 if c does not contain the element.

removeAny

public static void removeAny(java.util.Collection<?> c,
                             java.lang.Object element)
Removes all occurrences of an element in a set or multiset.

Parameters:
c - The set or multiset. This must be an instance of java.util.Set or HashMultiSet.
element - The element to remove.

getFlatIterator

public static <T> java.util.Iterator<T> getFlatIterator(java.util.Collection<T> c)
Obtains an iterator over the unique elements of a set or multiset.

Type Parameters:
T - Type of the elements in the set
Parameters:
c - The set or multiset.
Returns:
An iterator that, in the case of multisets, ignores the cardinality of elements and returns each element only once.

getNumber

public static java.lang.Number getNumber(float f)
Optimizes a float return value for a metric.

If the value has no fractional part and less than 6 significant digits, its value is wrapped in an Integer.

Parameters:
f - The return value of the metric
Returns:
If possible, an Integer with the value of the float, otherwise a Float instance

isEmptyElement

public static boolean isEmptyElement(java.lang.Object o)
Checks if an object represents an empty model element reference. Empty model element references are represented by empty strings.

Parameters:
o - Object to test
Returns:
true if o is an empty String
Since:
2.3

www.sdmetrics.com