001package org.clafer.compiler; 002 003import java.util.ArrayList; 004import java.util.List; 005import org.clafer.instance.InstanceModel; 006 007/** 008 * 009 * @author jimmy 010 */ 011public interface InstanceIterator { 012 013 /** 014 * Find the next instance. 015 * 016 * @return {@code true} if and only if another solution is found, 017 * {@code false} otherwise 018 * @throws ReachedLimitException if resource limit reached 019 */ 020 public boolean find(); 021 022 /** 023 * Return the instance from the last {@link #find()} operation, if 024 * successful. 025 * 026 * @return the instance 027 */ 028 public InstanceModel instance(); 029 030 /** 031 * Return all the remaining instances. 032 * 033 * @return all the remaining instances 034 * @throws ReachedLimitException if resource limit reached 035 */ 036 public default InstanceModel[] allInstances() throws ReachedLimitException { 037 List<InstanceModel> instances = new ArrayList<>(); 038 while (find()) { 039 instances.add(instance()); 040 } 041 return instances.toArray(new InstanceModel[instances.size()]); 042 } 043 044 /** 045 * Return the number of instances found so far. 046 * 047 * @return the number of instances found so far 048 */ 049 public int instanceCount(); 050}