001
002/*
003 * $Id$
004 */
005
006package edu.jas.poly;
007
008import java.util.Map;
009import java.util.SortedMap;
010import java.util.Iterator;
011
012import edu.jas.structure.RingElem;
013
014import edu.jas.poly.Word;
015
016
017/**
018 * Iterator over monomials of a polynomial. 
019 * Adaptor for val.entrySet().iterator().
020 * @author Heinz Kredel
021 */
022
023public class WordPolyIterator<C extends RingElem<C> > 
024             implements Iterator< WordMonomial<C> > {
025
026
027    /** 
028     * Internal iterator over polynomial map.
029     */
030    protected final Iterator< Map.Entry<Word,C> > ms;
031
032
033    /** 
034     * Constructor of polynomial iterator.
035     * @param m SortetMap of a polynomial.
036     */
037    public WordPolyIterator( SortedMap<Word,C> m ) {
038        ms = m.entrySet().iterator();
039    }
040
041
042    /** 
043     * Test for availability of a next monomial.
044     * @return true if the iteration has more monomials, else false.
045     */
046    public boolean hasNext() {
047        return ms.hasNext();
048    }
049
050
051    /** 
052     * Get next monomial element.
053     * @return next monomial.
054     */
055    public WordMonomial<C> next() {
056        return new WordMonomial<C>( ms.next() );
057    }
058
059
060    /** 
061     * Remove the last monomial returned from underlying set if allowed.
062     */
063    public void remove() {
064        ms.remove();
065    }
066
067}