Github user meiercaleb commented on a diff in the pull request: https://github.com/apache/incubator-rya/pull/237#discussion_r143054724 --- Diff: common/rya.api/src/main/java/org/apache/rya/api/functions/DateTimeWithinPeriod.java --- @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.rya.api.functions; + +import org.apache.rya.api.functions.OWLTime.Duration; +import org.openrdf.model.Literal; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.datatypes.XMLDatatypeUtil; +import org.openrdf.model.vocabulary.FN; +import org.openrdf.model.vocabulary.XMLSchema; +import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException; +import org.openrdf.query.algebra.evaluation.function.Function; + +import com.google.common.base.Preconditions; + +/** + * This {@link Function} determines whether two datetimes occur within a specified period of time of one another. The + * method {@link Function#evaluate(ValueFactory, Value...)} expects four values, where the first two values are the + * datetimes, the third value is an integer indicating the period, and the fourth value is a URI indicating the time + * unit of the period. The URI must be of Type DurationDescription in the OWL-Time ontology (see + * <a href ="https://www.w3.org/TR/owl-time/">https://www.w3.org/TR/owl-time/</a>). Examples of valid time unit URIs + * can be found in the class {@link OWLTime} and below + * <ul> + * <li>http://www.w3.org/2006/time#days</li> + * <li>http://www.w3.org/2006/time#hours</li> + * <li>http://www.w3.org/2006/time#minutes</li> + * <li>http://www.w3.org/2006/time#seconds</li> + * </ul> + * + */ +public class DateTimeWithinPeriod implements Function { + + private static final String DATE_TIME_WITHIN = "dateTimeWithin"; + + @Override + public String getURI() { + return FN.NAMESPACE.toString() + DATE_TIME_WITHIN; + } + + /** + * Determines whether two datetimes occur within a specified period of time of one another. This method expects four + * values, where the first two values are the datetimes, the third value is an integer indicating the period, and + * the fourth value is a URI indicating the time unit of the period. The URI must be of Type DurationDescription in + * the OWL-Time ontology (see <a href ="https://www.w3.org/TR/owl-time/">https://www.w3.org/TR/owl-time/</a>). + * Examples of valid time unit URIs can be found in the class {@link OWLTime} and below + * <ul> + * <li>http://www.w3.org/2006/time#days</li> + * <li>http://www.w3.org/2006/time#hours</li> + * <li>http://www.w3.org/2006/time#minutes</li> + * <li>http://www.w3.org/2006/time#seconds</li> + * </ul> + * + * @param valueFactory - factory for creating values + * @param values - array of Value arguments for this Function. + */ + @Override + public Value evaluate(ValueFactory valueFactory, Value... values) throws ValueExprEvaluationException { + + // general validation of input + Preconditions.checkArgument(values.length == 4); --- End diff -- Done
---