/**
* Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.master.region.impl;
import java.util.Iterator;
import com.opengamma.master.impl.AbstractSearchIterator;
import com.opengamma.master.region.RegionDocument;
import com.opengamma.master.region.RegionMaster;
import com.opengamma.master.region.RegionSearchRequest;
import com.opengamma.master.region.RegionSearchResult;
import com.opengamma.util.ArgumentChecker;
/**
* An iterator that searches a region master as an iterator.
* <p>
* Large systems may store a large amount of data in each master.
* A simple search request that pulls back the entire database is unrealistic.
* This remote iterator allows the database to be queried in a consistent way remotely.
*/
public class RegionSearchIterator extends AbstractSearchIterator<RegionDocument, RegionMaster, RegionSearchRequest> {
/**
* Creates an instance based on a request.
* <p>
* The request will be altered during the iteration.
*
* @param master the underlying master, not null
* @param request the request object, not null
* @return an iterable suitable for use in a for-each loop, not null
*/
public static Iterable<RegionDocument> iterable(final RegionMaster master, final RegionSearchRequest request) {
ArgumentChecker.notNull(master, "master");
ArgumentChecker.notNull(request, "request");
return new Iterable<RegionDocument>() {
@Override
public Iterator<RegionDocument> iterator() {
return new RegionSearchIterator(master, request);
}
};
}
/**
* Creates an instance based on a request.
* <p>
* The request will be altered during the iteration.
*
* @param master the underlying master, not null
* @param request the request object, not null
*/
public RegionSearchIterator(RegionMaster master, RegionSearchRequest request) {
super(master, request);
}
//-------------------------------------------------------------------------
@Override
protected RegionSearchResult doSearch(RegionSearchRequest request) {
return getMaster().search(request);
}
}