/**
 * Copyright 2008-2009 DRIVER PROJECT (ICM UW)
 * Original author: Marek Horst
 *
 * 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 eu.dnetlib.data.index.ws.dataprov;

import java.util.List;

/**
 * Data  provider browse properties.
 * @author mhorst
 *
 */
public class DataProviderBrowseProperties extends DataProviderProperties {

	private List<String> data;

	/**
	 * Default constructor.
	 * @param expiryTime
	 * @param data
	 */
	public DataProviderBrowseProperties(int expiryTime,  List<String> data) {
		super(expiryTime);
		this.data = data;
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.data.index.ws.dataprov.CreateBulkDataDTO#getNumberOfResults()
	 */
	@Override
	public int getNumberOfResults() {
		if (data==null)
			return 0;
		else
			return data.size();
	}

	/* (non-Javadoc)
	 * @see eu.dnetlib.data.index.ws.dataprov.DataProviderProperties#getType()
	 */
	@Override
	Type getType() {
		return Type.BROWSE;
	}

	public List<String> getData() {
		return data;
	}

	/**
	 * Returns part of data for given range.
	 * @param fromPosition fromPostition of the first element is 1.
	 * @param toPosition
	 * @return part of data for given range.
	 */
	public String[] getPartOfData(int fromPosition, int toPosition) {
		if (fromPosition > this.getNumberOfResults())
			return new String[0];
		if (toPosition > this.getNumberOfResults())
			toPosition = this.getNumberOfResults();
		return data.subList(--fromPosition, toPosition).toArray(new String[0]);
	}

}
