org.semanticweb.elk.util.collections.chains
Class AbstractChain<T extends ModifiableLink<T>>

java.lang.Object
  extended by org.semanticweb.elk.util.collections.chains.AbstractChain<T>
Type Parameters:
T - The type of elements in the chain.
All Implemented Interfaces:
Chain<T>, ModifiableLink<T>

public abstract class AbstractChain<T extends ModifiableLink<T>>
extends Object
implements Chain<T>

This class provides a skeletal implementation of the Chain interface to minimize the effort required to implement this interface. Essentially, one has to provide only the implementation of the Link interface.

Author:
"Yevgeny Kazakov"

Constructor Summary
AbstractChain()
           
 
Method Summary
<S extends T>
S
find(Matcher<T,S> matcher)
          Finds the first element in the chain that satisfies the provided Matcher.
<S extends T>
S
getCreate(Matcher<T,S> matcher, ReferenceFactory<T,S> factory)
          Finds an element in the chain satisfies the provided Matcher, or if no such element is found, creates a new element using the provided ReferenceFactory and inserts it into the chain.
static
<K,T extends ModifiableLink<T>>
Chain<T>
getMapBackedChain(Map<K,T> map, K key)
          Creates a Chain view of the value associated with the given key in the given Map.
<S extends T>
S
remove(Matcher<T,S> matcher)
          Removes the first element in the chain that satisfies the provided Matcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.semanticweb.elk.util.collections.chains.ModifiableLink
next, setNext
 

Constructor Detail

AbstractChain

public AbstractChain()
Method Detail

find

public <S extends T> S find(Matcher<T,S> matcher)
Description copied from interface: Chain
Finds the first element in the chain that satisfies the provided Matcher. This function does not modify the chain. If the chain is modified during calling of this function, the behavior of the function is not specified.

Specified by:
find in interface Chain<T extends ModifiableLink<T>>
Parameters:
matcher - the object describing an element to search for
Returns:
the object contained in the chain that satisfies the provided Matcher or null if no such element is found

getCreate

public <S extends T> S getCreate(Matcher<T,S> matcher,
                                 ReferenceFactory<T,S> factory)
Description copied from interface: Chain
Finds an element in the chain satisfies the provided Matcher, or if no such element is found, creates a new element using the provided ReferenceFactory and inserts it into the chain. In the letter case, the chain is modified.

Specified by:
getCreate in interface Chain<T extends ModifiableLink<T>>
Parameters:
matcher - the object describing the element to search for
factory - the factory for creating references
Returns:
the object that satisfies the provided Matcher if found in the chain, or the newly created and inserted element object otherwise

remove

public <S extends T> S remove(Matcher<T,S> matcher)
Description copied from interface: Chain
Removes the first element in the chain that satisfies the provided Matcher. If such element is found, the chain is modified.

Specified by:
remove in interface Chain<T extends ModifiableLink<T>>
Parameters:
matcher - the object describing the element to search for
Returns:
the removed element, if found, or null if not found

getMapBackedChain

public static <K,T extends ModifiableLink<T>> Chain<T> getMapBackedChain(Map<K,T> map,
                                                                         K key)
Creates a Chain view of the value associated with the given key in the given Map. The values of the map must be instances of the type that can be used in the Chain interface. All operations with the returned Chain, such as addition or removal, will be reflected accordingly in the corresponding value in the Map.

Parameters:
map - the Map that backs the data
key - the key for which to return the Chain view of the data
Returns:
the Chain view of the data associated with key in map


Copyright © 2011-2013 Department of Computer Science, University of Oxford. All Rights Reserved.