git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/storagehub-model@167132 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
fdbc419887
commit
7c6a489248
|
@ -15,7 +15,14 @@ public final class SearchableField<T> {
|
|||
public String toString() {
|
||||
return "[" + name +"]";
|
||||
}
|
||||
|
||||
|
||||
public Class<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -9,13 +9,17 @@ import org.gcube.common.storagehub.model.expressions.Expression;
|
|||
|
||||
public class And implements Expression<Boolean>{
|
||||
|
||||
List<Expression<Boolean>> expressions = new ArrayList<>();
|
||||
private List<Expression<Boolean>> expressions = new ArrayList<>();
|
||||
|
||||
public And(Expression<Boolean> first , Expression<Boolean> second , Expression<Boolean> ... others ) {
|
||||
expressions = Arrays.asList(first, second);
|
||||
if (others !=null && others.length>0)
|
||||
expressions.addAll(Arrays.asList(others));
|
||||
}
|
||||
|
||||
public List<Expression<Boolean>> getExpressions() {
|
||||
return expressions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -16,6 +16,10 @@ public class Or implements Expression<Boolean>{
|
|||
if (others !=null && others.length>0)
|
||||
expressions.addAll(Arrays.asList(others));
|
||||
}
|
||||
|
||||
public List<Expression<Boolean>> getExpressions() {
|
||||
return expressions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.common.storagehub.model.query;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
|
||||
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
|
||||
public class Queries {
|
||||
|
||||
private static Map<Class<?>,SearchableItem<?>> searchableRegistry = new HashMap<>();
|
||||
|
||||
static {
|
||||
searchableRegistry.put(GenericSearchableItem.class, GenericSearchableItem.get());
|
||||
}
|
||||
|
||||
public static <T extends Item> Query<SearchableItem<?>> queryFor(Class<T> searchable) {
|
||||
return new Query<>(searchableRegistry.get(searchable));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package org.gcube.common.storagehub.model.query;
|
||||
|
||||
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
||||
|
||||
public class Query<T extends SearchableItem<?>> {
|
||||
|
||||
private T searchableItem;
|
||||
|
||||
public Query(T searchableItem) {
|
||||
this.searchableItem = searchableItem;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,11 @@
|
|||
package org.gcube.storagehub.model.expressions;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.gcube.common.storagehub.model.expressions.Expression;
|
||||
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
|
||||
import org.gcube.common.storagehub.model.expressions.date.Before;
|
||||
import org.gcube.common.storagehub.model.expressions.logical.And;
|
||||
import org.gcube.common.storagehub.model.expressions.text.Contains;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -12,7 +16,15 @@ public class ExpressionsTest {
|
|||
public void contains() {
|
||||
Expression<Boolean> expr = new Contains(GenericSearchableItem.get().title, "Data");
|
||||
System.out.println( expr.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void and() {
|
||||
|
||||
Expression<Boolean> cont1 = new Contains(GenericSearchableItem.get().title, "Data");
|
||||
Expression<Boolean> before = new Before(GenericSearchableItem.get().creationTime, Calendar.getInstance());
|
||||
Expression<Boolean> andExpr = new And(cont1, before);
|
||||
System.out.println( andExpr.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue