org.weblab_project.core.helper.impl
Class WTripleMap

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,java.util.LinkedHashMap<java.lang.String,java.lang.Object>>
              extended by org.weblab_project.core.helper.impl.WTripleMap
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.util.LinkedHashMap<java.lang.String,java.lang.Object>>

public class WTripleMap
extends java.util.LinkedHashMap<java.lang.String,java.util.LinkedHashMap<java.lang.String,java.lang.Object>>

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
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"
 
Constructor Summary
WTripleMap()
           
 
Method Summary
protected  void add(WTriple wt)
           
 void addAll(java.util.List<WTriple> wtl)
           
 org.weblab_project.core.model.Resource getAnnotatedResourceWith(java.lang.String uri)
           
 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.
 org.weblab_project.core.model.Resource getResource(java.lang.String uri)
          Return the WebLab Resource associated with the given URI.
<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)
          Return 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)
          Return a list of URI in the order of predicates sorted by a comparator.
 java.lang.String toString()
           
 
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"

Constructor Detail

WTripleMap

public WTripleMap()
Method Detail

addAll

public void addAll(java.util.List<WTriple> wtl)

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)

add

protected void add(WTriple wt)

toString

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

sortBy

public java.util.LinkedList<java.lang.String> sortBy(java.lang.String predicate,
                                                     java.util.Comparator<java.lang.String> comparable,
                                                     boolean defined)
Return 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 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)
Return 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

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 -
Parameters:
subject -
property -
clazz -
Returns:

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.


Copyright © 2004-2009. All Rights Reserved.