001    /*
002     *  www.ti.bfh.ch
003     *
004     *  Copyright 2007, Berne University of Applied Sciences, 
005     *  School of Engineering and Information Technology
006     *  and individual contributors as indicated by the @authors tag.
007     *
008     *  This is free software; you can redistribute it and/or modify it under the terms of the 
009     *  GNU Lesser General Public License as published by the Free Software Foundation; 
010     *  either version 3 of the License, or (at your option) any later version.
011     *
012     *  This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
013     *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
014     *  See the GNU Lesser General Public License for more details.
015     *
016     *  You should have received a copy of the GNU Lesser General Public License along with this software; 
017     *  if not, see <http://www.gnu.org/licenses/>.
018     *
019     */
020    package ch.bfh.algo.sequence;
021    
022    
023    import java.util.Collection;
024    
025    import ch.bfh.algo.Position;
026    import ch.bfh.algo.core.sequence.ArrayFactory;
027    import ch.bfh.algo.core.sequence.DefaultGenericArrayStrategy;
028    import ch.bfh.algo.core.sequence.GenericArraySequence;
029    
030    
031    public class ArraySequence<E> extends GenericArraySequence<E,ArrayPosition<E>>{
032            
033            private static class DefaultSequenceFactory<E> implements SequenceFactory<ArrayPosition<E>>{  
034                    public ArrayPosition<E> createPosition(){ return new ArrayPosition<E>(); }
035                    public ArrayPosition<E> cast(Position<?> position){ return (ArrayPosition<E>)position; }      
036            }
037            
038            private static class DefaultArrayStrategy<E> extends DefaultGenericArrayStrategy<ArrayPosition<E>>{   
039                    public DefaultArrayStrategy(){ 
040                            super(
041                                    new ArrayFactory<ArrayPosition<E>>(){       
042                                            public ArrayPosition<E>[] createArray(int size){ return new ArrayPosition[size]; }
043                                    }
044                            );
045                    }
046            }
047            
048            public ArraySequence(int size, SequenceFactory<ArrayPosition<E>> factory) {
049                    super(size, factory, new DefaultArrayStrategy<E>());
050            }
051    
052            public ArraySequence(SequenceFactory<ArrayPosition<E>> factory) {
053                    super(100, factory, new DefaultArrayStrategy<E>());
054            }
055    
056            public ArraySequence(int size) {
057                    super(size, new DefaultSequenceFactory<E>(), new DefaultArrayStrategy<E>());
058            }
059    
060            public ArraySequence() {
061                    super(100, new DefaultSequenceFactory<E>(), new DefaultArrayStrategy<E>());
062            }
063            
064            public ArraySequence(Collection<? extends E> c) {
065                    this(c.size());
066                    this.addAll(c);
067            }
068    
069    }