/*
 * Copyright 2011-2016 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * 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.b2international.index.query;

import java.util.Objects;

/**
 * @since 5.4
 */
public abstract class RangePredicate<T> extends Predicate {

	private final T lower;
	private final T upper;
	private final boolean includeLower;
	private final boolean includeUpper;

	protected RangePredicate(String field, T lower, T upper, boolean includeLower, boolean includeUpper) {
		super(field);
		this.lower = lower;
		this.upper = upper;
		this.includeLower = includeLower;
		this.includeUpper = includeUpper;
	}
	
	public final T lower() {
		return lower;
	}
	
	public final T upper() {
		return upper;
	}
	
	public final boolean isIncludeLower() {
		return includeLower;
	}
	
	public final boolean isIncludeUpper() {
		return includeUpper;
	}
	
	@Override
	public final int hashCode() {
		return Objects.hash(getField(), lower(), upper(), isIncludeLower(), isIncludeUpper());
	}
	
	@Override
	public final boolean equals(Object obj) {
		if (super.equals(obj)) {
			final RangePredicate<?> other = (RangePredicate<?>) obj;
			return Objects.equals(lower(), other.lower()) 
					&& Objects.equals(upper(), other.upper())
					&& Objects.equals(isIncludeLower(), other.isIncludeLower())
					&& Objects.equals(isIncludeUpper(), other.isIncludeUpper());
		} else {
			return false;
		}
	}
	
	@Override
	public final String toString() {
		return String.format("%s is %s(%s) and %s(%s)", getField(), isIncludeLower() ? "gte" : "gt", lower, isIncludeUpper() ? "lte" : "lt", upper);
	}

}

@@ -773,16 +773,178 @@
 cate %7B%0A%0A
+%09private static final String LT = %22%3C%22;%0A%09private static final String LTE = %22%3C=%22;%0A%09private static final String GT = %22%3E%22;%0A%09private static final String GTE = %22%3E=%22;%0A%09%0A
 %09private
@@ -2149,28 +2149,26 @@
 %22%25s 
-is 
 %25s
-(
+ 
 %25s
-)
  and %25s
-(%25s)
+ %25s %25s
 %22, g
@@ -2201,27 +2201,35 @@
 ) ? 
-%22gte%22 : %22gt%22, lower
+GTE : GT, lower, getField()
 , is
@@ -2249,20 +2249,16 @@
 ) ? 
-%22lte%22 : %22lt%22
+LTE : LT
 , up

improve toString of RangePredicate