org.weblab_project.core.helper.impl
Class Statements

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<java.lang.String,IPredicateValuePairs>
              extended by org.weblab_project.core.helper.impl.Statements
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,IPredicateValuePairs>

public class Statements
extends java.util.LinkedHashMap<java.lang.String,IPredicateValuePairs>

An efficient structure to gather and access triples and their subject/predicates/values This structure supports a list of values if multiple values are found for a given subject and predicate.

Author:
Arnaud
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
protected  java.util.Map<java.lang.String,org.weblab_project.core.model.Resource> annotatedOn
           
static java.util.Comparator<java.lang.String> ASC
          An ascending comparator the value "a" will be after the value "b"
static java.util.Comparator<java.lang.String> DESC
          A descending comparator the value "a" will be before the value "b"
protected  java.util.List<java.lang.String> namespaces
           
protected  java.util.Map<java.lang.String,org.weblab_project.core.model.Resource> resourcesMap
           
 
Constructor Summary
Statements(java.lang.String... namespaces)
           
 
Method Summary
protected  void add(WTriple wt)
           
 void addAll(java.util.List<WTriple> wtl)
          Add a list of WTriple in ths Statements
 org.weblab_project.core.model.Resource getAnnotatedResourceWith(java.lang.String uri)
          Returns a resource on which a statement with this uri has been found
 java.lang.String getFirstValue(java.lang.String subject, java.lang.String predicate, java.util.Locale locale)
          Returns the first value corresponding to the predicate given.
 java.util.LinkedHashMap<java.lang.String,java.util.LinkedHashMap<java.lang.String,java.lang.Object>> getMap()
          Deprecated. Please avoid to use this thing
 org.weblab_project.core.model.Resource getResource(java.lang.String uri)
          Return the WebLab Resource associated with the given URI.
 java.util.Set<java.lang.String> getSubjects(java.lang.String predicate, java.lang.String object)
          Returns all the subjects that matches the tuple (predicate,object)
<T> T
getTypedValue(java.lang.String subject, java.lang.String property, java.lang.Class<T> clazz)
          Return a typed value rather than an object.
<T> java.util.LinkedList<T>
getTypedValues(java.lang.String subject, java.lang.String property, java.lang.Class<T> clazz)
          Returns a list of typed values.
 java.util.LinkedList<java.lang.String> sortBy(java.lang.String predicate, java.util.Comparator<java.lang.String> comparable)
          Returns a list of URI in the order of predicates sorted by a comparator.
 java.util.LinkedList<java.lang.String> sortBy(java.lang.String predicate, java.util.Comparator<java.lang.String> comparable, boolean defined)
          Returns a list of URI in the order of predicates sorted by a comparator.
 java.lang.String toString()
           
 void writeAndAdd(Statements map, org.weblab_project.core.model.PieceOfKnowledge pok, java.lang.String... uris)
          Write all statements from a Statements on the given Pok and add these statements on this Statements.
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get, removeEldestEntry
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Field Detail

ASC

public static final java.util.Comparator<java.lang.String> ASC
An ascending comparator the value "a" will be after the value "b"


DESC

public static final java.util.Comparator<java.lang.String> DESC
A descending comparator the value "a" will be before the value "b"


resourcesMap

protected java.util.Map<java.lang.String,org.weblab_project.core.model.Resource> resourcesMap

annotatedOn

protected java.util.Map<java.lang.String,org.weblab_project.core.model.Resource> annotatedOn

namespaces

protected java.util.List<java.lang.String> namespaces
Constructor Detail

Statements

public Statements(java.lang.String... namespaces)
Method Detail

addAll

public void addAll(java.util.List<WTriple> wtl)
Add a list of WTriple in ths Statements

Parameters:
wtl - a list of Wtriple

getResource

public org.weblab_project.core.model.Resource getResource(java.lang.String uri)
Return the WebLab Resource associated with the given URI. If it was found during the search.

Parameters:
uri - an URI
Returns:
a WebLab Resource

getAnnotatedResourceWith

public org.weblab_project.core.model.Resource getAnnotatedResourceWith(java.lang.String uri)
Returns a resource on which a statement with this uri has been found

Parameters:
uri -
Returns:
a WebLab Resource annotated with a statement concerning this uri (subject or object)

add

protected void add(WTriple wt)

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractMap<java.lang.String,IPredicateValuePairs>

sortBy

public java.util.LinkedList<java.lang.String> sortBy(java.lang.String predicate,
                                                     java.util.Comparator<java.lang.String> comparable,
                                                     boolean defined)
Returns a list of URI in the order of predicates sorted by a comparator. If the value is not defined for a subject/predicate, its uri will be at the end if defined is false, else it will not be added in the final list.

Parameters:
predicate - the predicate on which value will be sorted
comparable - the sorter
defined - if false uri without predicate defined will be added at the end of the list, else it will be ignored
Returns:
a sorted list of URIs

sortBy

public java.util.LinkedList<java.lang.String> sortBy(java.lang.String predicate,
                                                     java.util.Comparator<java.lang.String> comparable)
Returns a list of URI in the order of predicates sorted by a comparator. If the value is not defined for a suject/predicate, its uri will be at the end.

Parameters:
predicate - the predicate on which value will be sorted
comparable - the sorter
Returns:
a sorted list of URIs

getFirstValue

public java.lang.String getFirstValue(java.lang.String subject,
                                      java.lang.String predicate,
                                      java.util.Locale locale)
Returns the first value corresponding to the predicate given. TODO: rewrite using getTypedValue(...)

Parameters:
subject - optional, use null as wildcard
predicate - the uri of predicate
locale - the locale, optional set to null as wildcard
Returns:
a value

getMap

public java.util.LinkedHashMap<java.lang.String,java.util.LinkedHashMap<java.lang.String,java.lang.Object>> getMap()
Deprecated. Please avoid to use this thing


getTypedValue

public <T> T getTypedValue(java.lang.String subject,
                           java.lang.String property,
                           java.lang.Class<T> clazz)
Return a typed value rather than an object.

Type Parameters:
T - the type to be returned
Parameters:
subject - a subject
property - a property
clazz - a class of the type of the value
Returns:
An instance of if the value can be mapped on this type, else null.

getTypedValues

public <T> java.util.LinkedList<T> getTypedValues(java.lang.String subject,
                                                  java.lang.String property,
                                                  java.lang.Class<T> clazz)
Returns a list of typed values.

Type Parameters:
T - the type of the value
Parameters:
subject - the uri of the subject
property - the uri of the subject
clazz - the class of the value
Returns:
a list of typed values.

getSubjects

public java.util.Set<java.lang.String> getSubjects(java.lang.String predicate,
                                                   java.lang.String object)
Returns all the subjects that matches the tuple (predicate,object)

Parameters:
predicate -
object -
Returns:
a set of subject

writeAndAdd

public void writeAndAdd(Statements map,
                        org.weblab_project.core.model.PieceOfKnowledge pok,
                        java.lang.String... uris)
                 throws org.weblab_project.core.exception.WebLabCheckedException
Write all statements from a Statements on the given Pok and add these statements on this Statements.

Parameters:
an - other Statements
pok - a PieceOfKnoelegde on which statements will be written
uris - a mapping of uris. Uris are mapped using couples (previous_uri,future_uri)
Throws:
org.weblab_project.core.exception.WebLabCheckedException


Copyright © 2004-2010. All Rights Reserved.