FilteredSlice.java

/*
 * Copyright 2018 Global Crop Diversity Trust
 *
 * 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 org.genesys.server.api;

import java.io.Serializable;
import java.util.Iterator;

import org.genesys.blocks.model.filters.EmptyModelFilter;

import com.fasterxml.jackson.annotation.JsonUnwrapped;

/**
 * The Class FilteredSlice.
 *
 * @param <T> the generic type
 */
public class FilteredSlice<T> implements Serializable, Iterable<T> {

	private static final long serialVersionUID = 6965069448240229428L;

	/** The data is serialized on the base JSON level. */
	@JsonUnwrapped
	public Slice<T> slice;

	/** The filter. */
	public EmptyModelFilter<?, ?> filter;

	public String filterCode;

	/**
	 * Instantiates a new filtered page.
	 *
	 * @param filter the filter
	 * @param data the data
	 */
	public FilteredSlice(final EmptyModelFilter<?, ?> filter, final Slice<T> data) {
		this.filter = filter;
		this.slice = data;
	}

	/**
	 * Instantiates a new filtered page.
	 *
	 * @param filterCode the filter code
	 * @param filter the filter
	 * @param data the data
	 */
	public FilteredSlice(final String filterCode, final EmptyModelFilter<?, ?> filter, final Slice<T> data) {
		this.filterCode = filterCode;
		this.filter = filter;
		this.slice = data;
	}

	@Override
	public Iterator<T> iterator() {
		return slice.iterator();
	}
}