/** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.master.convention.impl; import java.util.Iterator; import com.opengamma.master.convention.ConventionDocument; import com.opengamma.master.convention.ConventionMaster; import com.opengamma.master.convention.ConventionSearchRequest; import com.opengamma.master.convention.ConventionSearchResult; import com.opengamma.master.impl.AbstractSearchIterator; import com.opengamma.util.ArgumentChecker; /** * An iterator that searches a convention 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 ConventionSearchIterator extends AbstractSearchIterator<ConventionDocument, ConventionMaster, ConventionSearchRequest> { /** * 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<ConventionDocument> iterable(final ConventionMaster master, final ConventionSearchRequest request) { ArgumentChecker.notNull(master, "master"); ArgumentChecker.notNull(request, "request"); return new Iterable<ConventionDocument>() { @Override public Iterator<ConventionDocument> iterator() { return new ConventionSearchIterator(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 ConventionSearchIterator(ConventionMaster master, ConventionSearchRequest request) { super(master, request); } //------------------------------------------------------------------------- @Override protected ConventionSearchResult doSearch(ConventionSearchRequest request) { return getMaster().search(request); } }