Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.intuit.ipp.query.expr.CalendarPath Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2017 Intuit
*
* 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 com.intuit.ipp.query.expr;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import com.intuit.ipp.query.Operation;
import com.intuit.ipp.query.Path;
/**
* Class to generate the query string for calendar or date value
*
*/
public class CalendarPath extends Path {
/**
* Constructor CalendarPath
*
* @param path the path
* @param entity the entity
*/
public CalendarPath(String path, String entity) {
super(path, entity);
}
/**
* Method to get simple date format
*
* @return SimpleDateFormat
*/
private SimpleDateFormat getDateTimeFormatter() {
SimpleDateFormat formatter = new SimpleDateFormat();
formatter.applyPattern("yyyy-MM-dd'T'HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
return formatter;
}
/**
* Method to get simple date format
*
* @return SimpleDateFormat
*/
private SimpleDateFormat getDateFormatter() {
SimpleDateFormat formatter = new SimpleDateFormat();
formatter.applyPattern("yyyy-MM-dd");
return formatter;
}
/**
* Method to get string value of date from Calendar
*
* @return String the date
*/
private String getCalendarAsString(Calendar cal) {
SimpleDateFormat formatter = getDateTimeFormatter();
Date date = cal.getTime();
return formatter.format(date).concat("Z");
}
/**
* Method to construct the equals expression for Calendar
*
* @param value the calendar value
* @return Expression
*/
public Expression eq(Calendar value) {
String valueString = "'" + getCalendarAsString(value) + "'";
return new Expression(this, Operation.eq, valueString);
}
/**
* Method to construct the equals expression for date
*
* @param value the date value
* @return Expression
*/
public Expression eq(java.util.Date value) {
SimpleDateFormat formatter = getDateTimeFormatter();
String valueString = "'" + formatter.format(value).concat("Z") + "'";
return new Expression(this, Operation.eq, valueString);
}
/**
* Method to construct the equals expression for date
*
* @param value the date value
* @return Expression
*/
public Expression eq(java.sql.Date value) {
SimpleDateFormat formatter = getDateFormatter();
String valueString = "'" + formatter.format(value) + "'";
return new Expression(this, Operation.eq, valueString);
}
/**
* Method to construct the not equals expression for Calendar
*
* @param value the calendar value
* @return Expression
*/
public Expression neq(Calendar value) {
String valueString = "'" + getCalendarAsString(value) + "'";
return new Expression(this, Operation.neq, valueString);
}
/**
* Method to construct the not equals expression for date
*
* @param value the date value
* @return Expression
*/
public Expression neq(java.util.Date value) {
SimpleDateFormat formatter = getDateTimeFormatter();
String valueString = "'" + formatter.format(value).concat("Z") + "'";
return new Expression(this, Operation.neq, valueString);
}
/**
* Method to construct the not equals expression for date
*
* @param value the date value
* @return Expression
*/
public Expression neq(java.sql.Date value) {
SimpleDateFormat formatter = getDateFormatter();
String valueString = "'" + formatter.format(value) + "'";
return new Expression(this, Operation.neq, valueString);
}
/**
* Method to construct the less than expression for calendar
*
* @param value the calendar value
* @return Expression
*/
public Expression lt(Calendar value) {
String valueString = "'" + getCalendarAsString(value) + "'";
return new Expression(this, Operation.lt, valueString);
}
/**
* Method to construct the less than expression for date
*
* @param value the date value
* @return Expression
*/
public Expression lt(java.util.Date value) {
SimpleDateFormat formatter = getDateTimeFormatter();
String valueString = "'" + formatter.format(value).concat("Z") + "'";
return new Expression(this, Operation.lt, valueString);
}
/**
* Method to construct the less than expression for date
*
* @param value the date value
* @return Expression
*/
public Expression lt(java.sql.Date value) {
SimpleDateFormat formatter = getDateFormatter();
String valueString = "'" + formatter.format(value) + "'";
return new Expression(this, Operation.lt, valueString);
}
/**
* Method to construct the less than or equals expression for calendar
*
* @param value the calendar value
* @return Expression
*/
public Expression lte(Calendar value) {
String valueString = "'" + getCalendarAsString(value) + "'";
return new Expression(this, Operation.lte, valueString);
}
/**
* Method to construct the less than or equals expression for date
*
* @param value the date value
* @return Expression
*/
public Expression lte(java.util.Date value) {
SimpleDateFormat formatter = getDateTimeFormatter();
String valueString = "'" + formatter.format(value).concat("Z") + "'";
return new Expression(this, Operation.lte, valueString);
}
/**
* Method to construct the less than or equals expression for date
*
* @param value the date value
* @return Expression
*/
public Expression lte(java.sql.Date value) {
SimpleDateFormat formatter = getDateFormatter();
String valueString = "'" + formatter.format(value) + "'";
return new Expression(this, Operation.lte, valueString);
}
/**
* Method to construct the greater than expression for calendar
*
* @param value the calendar value
* @return Expression
*/
public Expression gt(Calendar value) {
String valueString = "'" + getCalendarAsString(value) + "'";
return new Expression(this, Operation.gt, valueString);
}
/**
* Method to construct the greater than expression for date
*
* @param value the date value
* @return Expression
*/
public Expression gt(java.util.Date value) {
SimpleDateFormat formatter = getDateTimeFormatter();
String valueString = "'" + formatter.format(value).concat("Z") + "'";
return new Expression(this, Operation.gt, valueString);
}
/**
* Method to construct the greater than expression for date
*
* @param value the date value
* @return Expression
*/
public Expression gt(java.sql.Date value) {
SimpleDateFormat formatter = getDateFormatter();
String valueString = "'" + formatter.format(value) + "'";
return new Expression(this, Operation.gt, valueString);
}
/**
* Method to construct the greater than or equals expression for calendar
*
* @param value the calendar value
* @return Expression
*/
public Expression gte(Calendar value) {
String valueString = "'" + getCalendarAsString(value) + "'";
return new Expression(this, Operation.gte, valueString);
}
/**
* Method to construct the greater than or equals expression for date
*
* @param value the date value
* @return Expression
*/
public Expression gte(java.util.Date value) {
SimpleDateFormat formatter = getDateTimeFormatter();
String valueString = "'" + formatter.format(value).concat("Z") + "'";
return new Expression(this, Operation.gte, valueString);
}
/**
* Method to construct the greater than or equals expression for date
*
* @param value the date value
* @return Expression
*/
public Expression gte(java.sql.Date value) {
SimpleDateFormat formatter = getDateFormatter();
String valueString = "'" + formatter.format(value) + "'";
return new Expression(this, Operation.gte, valueString);
}
/**
* Method to construct the in expression for calendar
*
* @param value the calendar array
* @return Expression
*/
public Expression in(Calendar[] value) {
String valueString = "";
Boolean firstCalendar = true;
for (Calendar v : value) {
if (firstCalendar) {
valueString = valueString.concat("('").concat(getCalendarAsString(v)).concat("'");
firstCalendar = false;
} else {
valueString = valueString.concat(", '").concat(getCalendarAsString(v)).concat("'");
}
}
valueString = valueString.concat(")");
return new Expression(this, Operation.in, valueString);
}
/**
* Method to construct the in expression for date
*
* @param value the date array
* @return Expression
*/
public Expression in(java.util.Date[] value) {
SimpleDateFormat formatter = getDateTimeFormatter();
String valueString = "";
Boolean firstCalendar = true;
for (Date v : value) {
if (firstCalendar) {
valueString = valueString.concat("('").concat(formatter.format(v).concat("Z")).concat("'");
firstCalendar = false;
} else {
valueString = valueString.concat(", '").concat(formatter.format(v).concat("Z")).concat("'");
}
}
valueString = valueString.concat(")");
return new Expression(this, Operation.in, valueString);
}
/**
* Method to construct the in expression for date
*
* @param value the date array
* @return Expression
*/
public Expression in(java.sql.Date[] value) {
SimpleDateFormat formatter = getDateFormatter();
String valueString = "";
Boolean firstCalendar = true;
for (Date v : value) {
if (firstCalendar) {
valueString = valueString.concat("('").concat(formatter.format(v)).concat("'");
firstCalendar = false;
} else {
valueString = valueString.concat(", '").concat(formatter.format(v)).concat("'");
}
}
valueString = valueString.concat(")");
return new Expression(this, Operation.in, valueString);
}
/**
* Method to construct the between expression for calendar
*
* @param startValue the start value
* @param endValue the end value
* @return Expression
*/
public Expression between(Calendar startValue, Calendar endValue) {
String valueString = "'" + getCalendarAsString(startValue).concat("Z") + "' AND '" + getCalendarAsString(endValue) + "'";
return new Expression(this, Operation.between, valueString);
}
/**
* Method to construct the between expression for date
*
* @param startValue the start value
* @param endValue the end value
* @return Expression
*/
public Expression between(java.util.Date startValue, java.util.Date endValue) {
SimpleDateFormat formatter = getDateTimeFormatter();
String valueString = "'" + formatter.format(startValue).concat("Z") + "' AND '" + formatter.format(endValue) + "'";
return new Expression(this, Operation.between, valueString);
}
/**
* Method to construct the between expression for date
*
* @param startValue the start value
* @param endValue the end value
* @return Expression
*/
public Expression between(java.sql.Date startValue, java.sql.Date endValue) {
SimpleDateFormat formatter = getDateFormatter();
String valueString = "'" + formatter.format(startValue).concat("Z") + "' AND '" + formatter.format(endValue) + "'";
return new Expression(this, Operation.between, valueString);
}
}