jInfer

cz.cuni.mff.ksi.jinfer.base.utils
Class BaseUtils

java.lang.Object
  extended by cz.cuni.mff.ksi.jinfer.base.utils.BaseUtils

public final class BaseUtils
extends Object

Various utility functions for jInfer. Library class.


Nested Class Summary
static interface BaseUtils.Predicate<T>
          Interface describing an object that decides whether the predicate (described by this object) applies to an argument or not.
 
Field Summary
static Comparator<AbstractNamedNode> NAMED_NODE_COMPARATOR
          Comparator for AbstractNamedNodes, based on their AbstractNamedNode.name.
 
Method Summary
static
<T> List<T>
cloneList(List<T> l, int n)
          Creates a list containing the specified list N times in a row.
static
<X> boolean
equal(X arg1, X arg2)
          Checks whether two objects are equal in the following sense.
static
<T> List<T>
filter(List<T> target, BaseUtils.Predicate<T> predicate)
          Filters the collection, leaving only elements where predicate applies.
static
<T> Set<T>
intersect(Set<T> set1, Set<T> set2)
          Calculates and returns the intersection of the two specified sets.
static
<T> boolean
isEmpty(Collection<T> c)
          Checks whether the collection is empty, that means NULL or empty as in "no elements within".
static boolean isEmpty(String s)
          Checks whether the string is empty, that means NULL or equal to "".
static
<T> boolean
isSubset(Collection<T> l1, Collection<T> l2)
          Checks whether the first collection provided is a subset of the second collection provided.
static
<T> List<T>
rndSubset(Collection<T> c, double ratio)
          Returns a random subset of the specified collection, so that its size is a specified ratio of the original collection size.
static
<T> List<T>
rndSubset(Collection<T> c, int count)
          Returns a random subset of the specified collection of requested size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMED_NODE_COMPARATOR

public static final Comparator<AbstractNamedNode> NAMED_NODE_COMPARATOR
Comparator for AbstractNamedNodes, based on their AbstractNamedNode.name. Potential null values will be sorted last.

Method Detail

filter

public static <T> List<T> filter(List<T> target,
                                 BaseUtils.Predicate<T> predicate)
Filters the collection, leaving only elements where predicate applies.

Type Parameters:
T -
Parameters:
target - Collection to be filtered.
predicate - Predicate determining whether to accept current element.
Returns:
A new collection with selected elements.

isEmpty

public static <T> boolean isEmpty(Collection<T> c)
Checks whether the collection is empty, that means NULL or empty as in "no elements within".

Type Parameters:
T -
Parameters:
c - Collection to check.
Returns:
True if the collection is NULL or contains no elements.

isEmpty

public static boolean isEmpty(String s)
Checks whether the string is empty, that means NULL or equal to "".

Parameters:
s - String to check.
Returns:
True if the string is NULL or has no characters.

cloneList

public static <T> List<T> cloneList(List<T> l,
                                    int n)
Creates a list containing the specified list N times in a row.

Parameters:
l - List to be cloned. Must not be null.
n - How many times should the list be cloned. Must be non-negative.
Returns:
Flat list containing the input list N times in a row. If the input list is empty, or N = 0, the result is an empty list.

intersect

public static <T> Set<T> intersect(Set<T> set1,
                                   Set<T> set2)
Calculates and returns the intersection of the two specified sets.

Parameters:
set1 - First set to interset, must not be null.
set2 - Second set to interset, must not be null.
Returns:
A new set containing the intersection of these two sets. Might be empty, if the two parameters have no intersection.

rndSubset

public static <T> List<T> rndSubset(Collection<T> c,
                                    double ratio)
Returns a random subset of the specified collection, so that its size is a specified ratio of the original collection size.

Type Parameters:
T - Type parameter.
Parameters:
c - Collection to pick from.
ratio - Requested ratio.
Returns:
List of randomly picked elements of the collection.

rndSubset

public static <T> List<T> rndSubset(Collection<T> c,
                                    int count)
Returns a random subset of the specified collection of requested size.

Type Parameters:
T - Type parameter.
Parameters:
c - Collection to pick from.
count - Requested size of the subset.
Returns:
List of randomly picked elements of the collection.

isSubset

public static <T> boolean isSubset(Collection<T> l1,
                                   Collection<T> l2)
Checks whether the first collection provided is a subset of the second collection provided.

Type Parameters:
T - Type of the collections.
Parameters:
l1 - First collection.
l2 - Second collection.
Returns:
true if the first collection is a subset of the second (every item of the first is contained in the second), false otherwise.

equal

public static <X> boolean equal(X arg1,
                                X arg2)
Checks whether two objects are equal in the following sense.

Type Parameters:
X - Type of both objects to be checked.
Parameters:
arg1 - First object to be checked.
arg2 - Second object to be checked.
Returns:
True if the specified objects are equal in the sense described above, false otherwise.

jInfer

Generated on Fri Dec 9 00:01:25 CET 2011