001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.collections.primitives.adapters;
018    
019    import java.io.Serializable;
020    import java.util.List;
021    
022    import org.apache.commons.collections.primitives.LongList;
023    
024    /**
025     * Adapts an {@link LongList LongList} to the
026     * {@link List List} interface.
027     * <p />
028     * This implementation delegates most methods
029     * to the provided {@link LongList LongList} 
030     * implementation in the "obvious" way.
031     *
032     * @since Commons Primitives 1.0
033     * @version $Revision: 480462 $ $Date: 2006-11-29 09:15:00 +0100 (Wed, 29 Nov 2006) $
034     * @author Rodney Waldhoff 
035     */
036    final public class LongListList extends AbstractLongListList implements Serializable {
037        
038        /**
039         * Create a {@link List List} wrapping
040         * the specified {@link LongList LongList}.  When
041         * the given <i>list</i> is <code>null</code>,
042         * returns <code>null</code>.
043         * 
044         * @param list the (possibly <code>null</code>) 
045         *        {@link LongList LongList} to wrap
046         * @return a {@link List List} wrapping the given 
047         *         <i>list</i>, or <code>null</code> when <i>list</i> is
048         *         <code>null</code>.
049         */
050        public static List wrap(LongList list) {
051            if(null == list) {
052                return null;
053            } else if(list instanceof Serializable) {
054                return new LongListList(list);
055            } else {
056                return new NonSerializableLongListList(list);
057            }
058        }
059        
060        /**
061         * Creates a {@link List List} wrapping
062         * the specified {@link LongList LongList}.
063         * @see #wrap
064         */
065        public LongListList(LongList list) {
066            _list = list;
067        }
068        
069        protected LongList getLongList() {
070            return _list;
071        }    
072        
073        private LongList _list = null;
074    }