org.apache.stanbol.entityhub.servicesapi.util
Class ModelUtils

java.lang.Object
  extended by org.apache.stanbol.entityhub.servicesapi.util.ModelUtils

public final class ModelUtils
extends Object

Utilities useful for implementations of the Entityhub Model

Author:
Rupert Westenthaler

Field Summary
static Comparator<Representation> RESULT_SCORE_COMPARATOR
          Comparator based on the RdfResourceEnum.resultScore property that assumes that values of this property implement Comparable.
 
Method Summary
static
<T> Collection<T>
addToCollection(Iterator<? extends T> it, Collection<T> c)
          Adds the elements of the Iterator to the parsed Collection
static
<T> Set<T>
addToSet(Iterator<? extends T> it, Set<T> set)
          Adds the elements of the Iterator to the parsed Set
static
<T> Collection<T>
asCollection(Iterator<? extends T> it)
          Copies all elements of the parsed Iterator to a ArrayList.
static
<T> Set<T>
asSet(Iterator<? extends T> it)
          Copies all elements of the parsed Iterator to a HashSet.
static void checkValues(ValueFactory valueFactory, Object value, Collection<Object> results)
          Processes a value parsed as object to the representation.
static String getAboutRepresentation(Representation metadata)
          Getter for the id of the Entity the parsed metadata are about.
static String[] getNamespaceLocalName(String uri)
          Splits up a URI in local name and namespace based on the following rules If URI starts with "urn:" and last index of ':' == 3 than the there is no namespace and the whole URI is a local name if the uri starts with "urn:" and the last index of ':' ia > 3, than the last index ':' is used.
static QName getQName(String uri)
          This Method uses getNamespaceLocalName(String) to split up namespace and local name.
static String getRepresentationInfo(Representation rep)
          String representation of the parsed Representation inteded for DEBUG level loggings.
static UUID randomUUID()
          TODO: Maybe we need a better way to generate unique IDs
static void setSeed(long seed)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESULT_SCORE_COMPARATOR

public static final Comparator<Representation> RESULT_SCORE_COMPARATOR
Comparator based on the RdfResourceEnum.resultScore property that assumes that values of this property implement Comparable. The Representation with the highest score will be first

Method Detail

randomUUID

public static UUID randomUUID()
TODO: Maybe we need a better way to generate unique IDs

Returns:

setSeed

public static void setSeed(long seed)

checkValues

public static void checkValues(ValueFactory valueFactory,
                               Object value,
                               Collection<Object> results)
Processes a value parsed as object to the representation. This processing includes: TODO: Maybe we need to enable an option to throw IllegalArgumentException in case any of the parsed values is invalid. Currently invalid values are just ignored.

Parameters:
value - the value to parse
results - the collections the results of the parsing are added to.

getRepresentationInfo

public static String getRepresentationInfo(Representation rep)
String representation of the parsed Representation inteded for DEBUG level loggings.

Parameters:
rep - the representation
Returns:
the string

asCollection

public static <T> Collection<T> asCollection(Iterator<? extends T> it)
Copies all elements of the parsed Iterator to a ArrayList. To use other Set implementations that ArrayList you can use {@link #addToCollection(Iterator, Collection)

Type Parameters:
T - the generic type of the returned Collection
Parameters:
it - the Iterator with elements compatible to T
Returns:
the collection containing all elements of the iterator
Throws:
IllegalArgumentException - if the parsed Iterator is null

addToCollection

public static <T> Collection<T> addToCollection(Iterator<? extends T> it,
                                                Collection<T> c)
Adds the elements of the Iterator to the parsed Collection

Type Parameters:
T - the type of the collection
Parameters:
it - the iterator over elements that are compatible to T
c - the collection to add the elements
Returns:
the parsed Collections with the added Elements
Throws:
IllegalArgumentException - if the parsed Collection is null.

asSet

public static <T> Set<T> asSet(Iterator<? extends T> it)
Copies all elements of the parsed Iterator to a HashSet. To use other Set implementations that HashSet you can use addToSet(Iterator, Set)

Type Parameters:
T - the generic type of the returned set
Parameters:
it - the Iterator with elements compatible to T
Returns:
the set containing all elements of the iterator
Throws:
IllegalArgumentException - if the parsed Iterator is null

addToSet

public static <T> Set<T> addToSet(Iterator<? extends T> it,
                                  Set<T> set)
Adds the elements of the Iterator to the parsed Set

Type Parameters:
T - the type of the set
Parameters:
it - the iterator over elements that are compatible to T
set - the set to add the elements
Returns:
the parsed Set with the added Elements
Throws:
IllegalArgumentException - if the parsed Set is null.

getNamespaceLocalName

public static String[] getNamespaceLocalName(String uri)
Splits up a URI in local name and namespace based on the following rules

Parameters:
uri - The uri
Returns:
A array with two fields. In the first the namespace is stored ( might be null. In the second the local name is stored.

getQName

public static QName getQName(String uri)
This Method uses getNamespaceLocalName(String) to split up namespace and local name. It uses also the Data in the NamespaceEnum to retrieve prefixes for Namespaces.

Parameters:
uri - the URI
Returns:
the QName

getAboutRepresentation

public static String getAboutRepresentation(Representation metadata)
                                     throws IllegalStateException
Getter for the id of the Entity the parsed metadata are about.

Parameters:
metadata - the metadata
Returns:
the id of the entity or null if the parsed Representation is null or does not define a value for RdfResourceEnum.aboutRepresentation
Throws:
IllegalStateException


Copyright © 2010-2013 The Apache Software Foundation. All Rights Reserved.