View Javadoc

1   /*
2    * Copyright (C) 2004 Christian Siefkes <christian@siefkes.net>.
3    * Development of this software is supported by the German Research Society,
4    * Berlin-Brandenburg Graduate School in Distributed Information Systems
5    * (DFG grant no. GRK 316).
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 2.1 of the License, or (at your option) any later version.
11   *
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, visit
19   * http://www.gnu.org/licenses/lgpl.html or write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21   */
22  package de.fu_berlin.ties.classify.feature;
23  
24  import java.util.ArrayList;
25  import java.util.Collection;
26  
27  /***
28   * This feature vector implementation stores an ordered sequence of features.
29   * Internally it uses an {@link java.util.ArrayList} as storage.
30   *
31   * <p>Instances of this class are not thread-safe and must be synchronized
32   * externally, if required.
33   *
34   * @author Christian Siefkes
35   * @version $Revision: 1.2 $, $Date: 2004/09/06 17:22:10 $, $Author: siefkes $
36   */
37  public class DefaultFeatureVector extends FeatureVector {
38  
39      /***
40       * Store features in an array list.
41       */
42      private final ArrayList<Feature> store = new ArrayList<Feature>();
43  
44      /***
45       * Creates a new instance.
46       */
47      public DefaultFeatureVector() {
48          super();
49      }
50  
51      /***
52       * {@inheritDoc}
53       */
54      public void addAll(final Collection coll) throws ClassCastException {
55          // ensure there is enough room for efficiency
56          store.ensureCapacity(store.size() + coll.size());
57  
58          // delegate to parent
59          super.addAll(coll);
60      }
61  
62      /***
63       * {@inheritDoc}
64       */
65      protected Collection<Feature> store() {
66          return store;
67      }
68  
69  }