/*
 * 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.List;
import java.util.Set;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;

/**
 * @since 5.0
 */
public abstract class SetPredicate<T> extends Predicate {
	
	private final Set<T> values;

	SetPredicate(String field, Iterable<T> values) {
		super(field);
		this.values = ImmutableSet.copyOf(values);
	}
	
	public Set<T> values() {
		return values;
	}
	
	@Override
	public String toString() {
		return String.format("%s IN(%s)", getField(), sublist());
	}
	
	private String sublist() {
		if (values.size() <= 10) {
			return values.toString();
		} else {
			final StringBuilder builder = new StringBuilder("[");
			final List<T> valuesList = Lists.newArrayList(values);
			
			for (int i = 0; i < 10; i++) {
				if (builder.length() != 1) {
					builder.append(", ");
				}
				
				builder.append(valuesList.get(i));
			}
			
			builder.append(String.format("... %d more items", values.size() - 10));
			builder.append("]");
			
			return builder.toString();
		}
	}

}

@@ -686,16 +686,42 @@
 l.List;%0A
+import java.util.Objects;%0A
 import j
@@ -1052,16 +1052,304 @@
 );%0A%09%7D%0A%09%0A
+%09@Override%0A%09public int hashCode() %7B%0A%09%09return Objects.hash(getField(), values);%0A%09%7D%0A%09%0A%09@Override%0A%09public boolean equals(Object obj) %7B%0A%09%09if (super.equals(obj)) %7B%0A%09%09%09final SetPredicate%3C?%3E other = (SetPredicate%3C?%3E) obj;%0A%09%09%09return Objects.equals(values, other.values);%0A%09%09%7D%0A%09%09return false;%0A%09%7D%0A%09%0A
 %09public 

implement equals/hashCode for SetPredicate