Adding a reference implementation

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib@121996 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2015-12-21 09:43:05 +00:00
parent e502cfbae6
commit 5012f704a5
2 changed files with 34 additions and 39 deletions

View File

@ -12,8 +12,7 @@ import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*/
@SuppressWarnings("rawtypes")
public interface AggregatedRecord<A extends AggregatedRecord, R extends Record> extends Record {
public interface AggregatedRecord<A extends AggregatedRecord<A,R>, R extends Record> extends Record {
/**
* KEY : Indicate that this {@link Record} is an aggregation

View File

@ -254,20 +254,33 @@ public abstract class AbstractRecord implements Record {
// AGGREGATION
/* --------------------------------------- */
private static final String START_TIME = AggregatedRecord.START_TIME;
private static final String END_TIME = AggregatedRecord.END_TIME;
private static final String OPERATION_COUNT = AggregatedRecord.OPERATION_COUNT;
/**
* Return the left end of the time interval covered by this {#UsageRecord}
* @return Start Time
* Set the right end of the time interval covered by this Record
* @param endTime End Time
* @throws InvalidValueException
*/
protected long getStartTimeInMillis() {
return (Long) this.resourceProperties.get(START_TIME);
protected void setEndTime(Calendar endTime) throws InvalidValueException {
setResourceProperty(AggregatedRecord.END_TIME, endTime.getTimeInMillis());
}
protected int getOperationCount() {
return (Integer) this.resourceProperties.get(AggregatedRecord.OPERATION_COUNT);
}
protected void setOperationCount(int operationCount) throws InvalidValueException {
setResourceProperty(AggregatedRecord.OPERATION_COUNT, operationCount);
}
/**
* Return the left end of the time interval covered by this {#UsageRecord}
* Return the left end of the time interval covered by this Record
* @return Start Time
*/
protected long getStartTimeInMillis() {
return (Long) this.resourceProperties.get(AggregatedRecord.START_TIME);
}
/**
* Return the left end of the time interval covered by this Record
* @return Start Time
*/
protected Calendar getStartTimeAsCalendar() {
@ -276,24 +289,24 @@ public abstract class AbstractRecord implements Record {
}
/**
* Set the left end of the time interval covered by this {#UsageRecord}
* Set the left end of the time interval covered by this Record
* @param startTime Start Time
* @throws InvalidValueException
*/
protected void setStartTime(Calendar startTime) throws InvalidValueException {
setResourceProperty(START_TIME, startTime.getTimeInMillis());
setResourceProperty(AggregatedRecord.START_TIME, startTime.getTimeInMillis());
}
/**
* Return the right end of the time interval covered by this {#UsageRecord}
* Return the right end of the time interval covered by this Record
* @return End Time
*/
protected long getEndTimeInMillis() {
return (Long) this.resourceProperties.get(END_TIME);
return (Long) this.resourceProperties.get(AggregatedRecord.END_TIME);
}
/**
* Return the right end of the time interval covered by this {#UsageRecord}
* Return the right end of the time interval covered by this Record
* @return End Time
*/
protected Calendar getEndTimeAsCalendar() {
@ -301,23 +314,6 @@ public abstract class AbstractRecord implements Record {
return timestampStringToCalendar(millis);
}
/**
* Set the right end of the time interval covered by this {#UsageRecord}
* @param endTime End Time
* @throws InvalidValueException
*/
protected void setEndTime(Calendar endTime) throws InvalidValueException {
setResourceProperty(END_TIME, endTime.getTimeInMillis());
}
protected int getOperationCount() {
return (Integer) this.resourceProperties.get(OPERATION_COUNT);
}
protected void setOperationCount(int operationCount) throws InvalidValueException {
setResourceProperty(OPERATION_COUNT, operationCount);
}
protected Comparable<? extends Serializable> validateField(String key, Comparable<? extends Serializable> value) throws InvalidValueException {
if(key == null){
throw new InvalidValueException("The key of property to set cannot be null");
@ -378,22 +374,22 @@ public abstract class AbstractRecord implements Record {
/**
* Compare this Record instance with the one provided as argument
* @param record the Record to compare
* @return 0 is and only if the UsageRecord provided as parameter
* @return 0 is and only if the Record provided as parameter
* contains all and ONLY the parameters contained in this instance.
* If the number of parameters differs, the methods return the difference
* between the number of parameter in this instance and the ones in the
* UsageRecord provided as parameter.
* Record provided as parameter.
* If the size is the same but the Record provided as parameter does
* not contains all parameters in this instance, -1 is returned.
*/
@Override
public int compareTo(Record record) {
Set<Entry<String, Comparable<? extends Serializable>>> thisSet = this.resourceProperties.entrySet();
Set<Entry<String, Comparable<? extends Serializable>>> usageRecordSet = record.getResourceProperties().entrySet();
if(thisSet.size() != usageRecordSet.size()){
return thisSet.size() - usageRecordSet.size();
Set<Entry<String, Comparable<? extends Serializable>>> recordSet = record.getResourceProperties().entrySet();
if(thisSet.size() != recordSet.size()){
return thisSet.size() - recordSet.size();
}
if(usageRecordSet.containsAll(thisSet)){
if(recordSet.containsAll(thisSet)){
return 0;
}
return 1;