001/* 002 * Copyright 2001-2006 Stephen Colebourne 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.joda.primitives.collection.impl; 017 018import org.joda.primitives.PrimitiveCollectable; 019 020/** 021 * Abstract base class for collections of primitive elements. 022 * 023 * @author Stephen Colebourne 024 * @since 1.0 025 */ 026public abstract class AbstractPrimitiveCollectable<N> implements PrimitiveCollectable<N> { 027 028 /** 029 * Constructor. 030 */ 031 protected AbstractPrimitiveCollectable() { 032 super(); 033 } 034 035 // PrimitiveCollectable 036 //----------------------------------------------------------------------- 037 /** 038 * Optimizes the implementation after initialization. 039 * <p> 040 * This implementation does nothing. 041 */ 042 public void optimize() { 043 // do nothing 044 } 045 046 /** 047 * Checks whether the object can currently be modified. 048 * <p> 049 * This implementation returns false. 050 * 051 * @return <code>false</code> 052 */ 053 public boolean isModifiable() { 054 return false; 055 } 056 057 /** 058 * Checks if the collection is empty. 059 * 060 * @return true if empty 061 */ 062 public boolean isEmpty() { 063 return (size() == 0); 064 } 065 066 /** 067 * Clone implementation that calls Object clone(). 068 * 069 * @return the clone 070 */ 071 public Object clone() { 072 try { 073 return super.clone(); 074 } catch (Exception ex) { 075 throw new UnsupportedOperationException("Clone not supported"); 076 } 077 } 078 079}