View Javadoc

1   /*
2    *  Copyright 2001-2006 Stephen Colebourne
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.joda.primitives.collection.impl;
17  
18  import org.joda.primitives.PrimitiveCollectable;
19  
20  /**
21   * Abstract base class for collections of primitive elements.
22   *
23   * @author Stephen Colebourne
24   * @since 1.0
25   */
26  public abstract class AbstractPrimitiveCollectable<N> implements PrimitiveCollectable<N> {
27  
28      /**
29       * Constructor.
30       */
31      protected AbstractPrimitiveCollectable() {
32          super();
33      }
34  
35      // PrimitiveCollectable
36      //-----------------------------------------------------------------------
37      /**
38       * Optimizes the implementation after initialization.
39       * <p>
40       * This implementation does nothing.
41       */
42      public void optimize() {
43          // do nothing
44      }
45  
46      /**
47       * Checks whether the object can currently be modified.
48       * <p>
49       * This implementation returns false.
50       *
51       * @return <code>false</code>
52       */
53      public boolean isModifiable() {
54          return false;
55      }
56  
57      /**
58       * Checks if the collection is empty.
59       *
60       * @return true if empty
61       */
62      public boolean isEmpty() {
63          return (size() == 0);
64      }
65  
66      /**
67       * Clone implementation that calls Object clone().
68       * 
69       * @return the clone
70       */
71      public Object clone() {
72          try {
73              return super.clone();
74          } catch (Exception ex) {
75              throw new UnsupportedOperationException("Clone not supported");
76          }
77      }
78  
79  }