@@ -0,0 +1,2325 @@
+/**%0A * JLibs: Common Utilities for Java%0A * Copyright (C) 2009  Santhosh Kumar T %3Csanthosh.tekuri@gmail.com%3E%0A *%0A * This library is free software; you can redistribute it and/or%0A * modify it under the terms of the GNU Lesser General Public%0A * License as published by the Free Software Foundation; either%0A * version 2.1 of the License, or (at your option) any later version.%0A *%0A * This library is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A * Lesser General Public License for more details.%0A */%0A%0Apackage jlibs.core.graph.sequences;%0A%0Aimport jlibs.core.graph.Sequence;%0A%0A/**%0A * A Sequence that can repeat given sequence specified number of%0A * times%0A *%0A * @author Santhosh Kumar T%0A */%0Apublic class RepeatSequence%3CE%3E extends AbstractSequence%3CE%3E%7B%0A    private Sequence%3CE%3E sequence;%0A    private int count;%0A%0A    public RepeatSequence(Sequence%3CE%3E sequence, int count)%7B%0A        if(count%3C0)%0A            throw new IllegalArgumentException(String.format(%22can't repeat %25d times%22, count));%0A        this.sequence = sequence;%0A        this.count = count;%0A    %7D%0A%0A    /*-------------------------------------------------%5B Advancing %5D---------------------------------------------------*/%0A%0A    private int pos;%0A%0A    @Override%0A    protected E findNext()%7B%0A        if(pos==count)%0A            return null;%0A        while(true)%7B%0A            E next = sequence.next();%0A            if(next==null)%7B%0A                pos++;%0A                if(pos==count)%0A                    return null;%0A                sequence = sequence.copy();%0A            %7Delse%0A                return next;%0A        %7D%0A    %7D%0A%0A    /*-------------------------------------------------%5B Reuse %5D---------------------------------------------------*/%0A%0A    @Override%0A    public void reset()%7B%0A        super.reset();%0A        _reset();%0A    %7D%0A%0A    private void _reset()%7B%0A        sequence = sequence.copy();%0A        pos = 0;%0A    %7D%0A%0A    @Override%0A    public RepeatSequence%3CE%3E copy()%7B%0A        return new RepeatSequence%3CE%3E(sequence.copy(), count);%0A    %7D%0A%0A    /*-------------------------------------------------%5B Optimization %5D---------------------------------------------------*/%0A%0A    @Override%0A    public int length()%7B%0A        return sequence.length() * count;%0A    %7D%0A%7D%0A

A Sequence that can repeat given sequence specified number of times