/*
 * Copyright 2015 Jens Walter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.trivium.anystore.query;

import io.trivium.extension._f70b024ca63f4b6b80427238bfff101f.TriviumObject;
import io.trivium.extension.fact.Fact;

public class Query<T extends Fact>{
    /**
     * get return type for this query
     * @return
     */
    public T castType(TriviumObject fact){
        try{
            T instance = (T) fact;
            return instance;
        }catch (ClassCastException cast){}
        try{
            T instance = (T) fact.getTypedData();
            return instance;
        }catch (ClassCastException cast){}
        return null;
    }

    /**
     * evaluates the condition for a query
     */
    public BooleanClosure<T> condition;

    /**
     * provides the context string
     */
    public StringClosure<T> context;

    /**
     * field the result set gets partitioned by
     */
    public StringClosure<T> partitionOver;

    /**
     * define order within the partition
     */
    public SortOrder partitionSortOrder =  SortOrder.DESCENDING;

    /**
     * field the order in the partition is determined by
     */
    public StringClosure<T> partitionOrderBy;

    /**
     * amount of result in one partition
     */
    public long partitionReduceTo = 1;

    public ConnectClosure<T,? extends Fact> connect;

    /**
     * dummy return method to ensure compile safety
     * @return always null
     */
    public T getObject() {
        return null;
    }

    /**
     * dummy return method to ensure compile safety
     * @return always null
     */
    public T[] getObjects() {
        return null;
    }

}

@@ -1270,16 +1270,33 @@
 ondition
+ = (item) -%3E true
 ;%0A%0A    /

empty condition defaults to true