Package it.unipd.dei.eis.data.sources
Class DataSource<E extends DataEntity,D>
- java.lang.Object
-
- it.unipd.dei.eis.data.sources.DataSource<E,D>
-
- Type Parameters:
E- the type of the data entityD- the type of the codecs data
- Direct Known Subclasses:
CsvDataSource,JsonDataSource,TermsDataSource,TheGuardianDataSource
public abstract class DataSource<E extends DataEntity,D> extends Object
DataSource is the abstract class for data sources.
-
-
Constructor Summary
Constructors Constructor Description DataSource(String id, IDecoder<D> decoder)DataSource constructor.DataSource(String id, IDecoder<D> decoder, IEncoder<D> encoder)DataSource constructor.DataSource(String id, IEncoder<D> encoder)DataSource constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private List<E>filter(Context context, List<E> data)Filters the list of data entities by query, from date and to date, if supported.List<E>get(Context context)Returns the list of data entities from the data source.(package private) List<E>getData(Context context)Returns the list of data entities.voidset(Context context, List<E> data)Sets the list of data entities.(package private) voidsetData(Context context, List<E> data)Sets the list of data entities.
-
-
-
Constructor Detail
-
DataSource
DataSource(String id, IDecoder<D> decoder, IEncoder<D> encoder)
DataSource constructor.- Parameters:
id- the ID of the data sourcedecoder- the decoder of the data sourceencoder- the encoder of the data source
-
DataSource
DataSource(String id, IDecoder<D> decoder)
DataSource constructor.- Parameters:
id- the ID of the data sourcedecoder- the decoder of the data source
-
-
Method Detail
-
get
public final List<E> get(Context context) throws Exception
Returns the list of data entities from the data source. Data entities are filtered byfilter(Context, List).- Parameters:
context- the context of the request- Returns:
- the list of data entities
- Throws:
UnsupportedOperationException- if not implementedException- if an error occurs
-
getData
List<E> getData(Context context) throws Exception
Returns the list of data entities. Override this method to implement the get operation.- Parameters:
context- the context of the request- Returns:
- the list of data entities
- Throws:
UnsupportedOperationException- if not implementedException- if an error occurs
-
set
public final void set(Context context, List<E> data) throws Exception
Sets the list of data entities.- Parameters:
context- the context of the requestdata- the list of data entities- Throws:
UnsupportedOperationException- if not implementedException- if an error occurs
-
setData
void setData(Context context, List<E> data) throws Exception
Sets the list of data entities. Override this method to implement the set operation.- Parameters:
context- the context of the requestdata- the list of data entities- Throws:
UnsupportedOperationException- if not implementedException- if an error occurs
-
filter
private List<E> filter(Context context, List<E> data)
Filters the list of data entities by query, from date and to date, if supported. Uses parallel streams to filter the list of data entities in a faster way. Internally used byget(Context).- Parameters:
context- the context of the requestdata- the list of data entities- Returns:
- the filtered list of data entities
-
-