| /******************************************************************************* |
| * Copyright (c) 2004-2008 Akos Horvath, Gergely Varro and Daniel Varro |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Akos Horvath, Gergely Varro - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.gtasm.patternmatcher.impl.patternmatcher.internal.callgraph;
|
|
|
| import java.util.Iterator; |
| import java.util.LinkedList; |
| import java.util.List; |
| import java.util.NoSuchElementException; |
|
|
|
|
| public class PatternVariantIterator implements Iterator<List<IFlattenedPatternElement>> {
|
| private PatternNode root;
|
| private LinkedList<IFlattenedPatternElement> solution;
|
| private boolean hasNext;
|
|
|
| public PatternVariantIterator(PatternNode root) {
|
| this.root = root;
|
| this.solution = new LinkedList<IFlattenedPatternElement>();
|
| this.hasNext = (root.isRoot() ? root.traverse(this) : false);
|
| }
|
|
|
| void addLast(IFlattenedPatternElement element) {
|
| solution.addLast(element);
|
| }
|
|
|
| void removeLast() {
|
| solution.removeLast();
|
| }
|
|
|
| public boolean hasNext() {
|
| return hasNext;
|
| }
|
|
|
| public List<IFlattenedPatternElement> next() {
|
| if (hasNext) {
|
| List<IFlattenedPatternElement> result = new LinkedList<IFlattenedPatternElement>(solution);
|
| hasNext = root.traverse(this);
|
| return result;
|
| } else {
|
| throw new NoSuchElementException();
|
| }
|
| }
|
|
|
| public void remove() {
|
| throw new UnsupportedOperationException();
|
| }
|
| }
|