blob: a8dad7674cdded5d13ab19ea1050ce76e87df942 [file] [log] [blame]
/*******************************************************************************
* 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;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import org.eclipse.viatra2.gtasm.patternmatcher.IMatching;
public class MatchingTable extends AbstractCollection<IMatching> {
private Map<MatchingKey,Collection<MatchingFrame>> matchings;
private class MatchingIterator implements Iterator<IMatching> {
Iterator<Entry<MatchingKey, Collection<MatchingFrame>>> iterator;
private MatchingIterator() {
iterator = matchings.entrySet().iterator();
}
public boolean hasNext() {
return iterator.hasNext();
}
public IMatching next() {
if (hasNext()) {
Iterator<MatchingFrame> frameIterator = iterator.next().getValue().iterator();
if (frameIterator.hasNext()) {
return frameIterator.next();
} else {
throw new NoSuchElementException();
}
} else {
throw new NoSuchElementException();
}
}
public void remove() {
throw new UnsupportedOperationException();
}
}
MatchingTable() {
matchings = new HashMap<MatchingKey, Collection<MatchingFrame>>();
}
@Override
public Iterator<IMatching> iterator() {
return new MatchingIterator();
}
@Override
public int size() {
return matchings.keySet().size();
}
void put(MatchingKey key, MatchingFrame value) {
Collection<MatchingFrame> coll = matchings.get(key);
if (coll == null) {
coll = new HashSet<MatchingFrame>();
}
coll.add(value);
matchings.put(key, coll);
}
}