001/*
002 *  Copyright 2011 Anyware Services
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.ametys.plugins.repository;
017
018import java.util.NoSuchElementException;
019
020/**
021 * Empty implementation of an {@link AmetysObjectIterable}.
022 * @param <A> the actual type of {@link AmetysObject}s
023 */
024public class EmptyIterable<A extends AmetysObject> implements AmetysObjectIterable<A>
025{
026    /**
027     * Creates a {@link EmptyIterable}.
028     */
029    public EmptyIterable()
030    {
031        // Nothing to do.
032    }
033    
034    @Override
035    public long getSize()
036    {
037        return 0;
038    }
039    
040    public AmetysObjectIterator<A> iterator()
041    {
042        return new EmptyIterator();
043    }
044    
045    public void close()
046    {
047        // nothing to do
048    }
049    
050    class EmptyIterator implements AmetysObjectIterator<A>
051    {
052        @Override
053        public long getPosition()
054        {
055            return 0;
056        }
057        
058        @Override
059        public long getSize()
060        {
061            return 0;
062        }
063        
064        @Override
065        public void skip(long skipNum)
066        {
067            // Nothing to do
068        }
069        
070        @Override
071        public boolean hasNext()
072        {
073            return false;
074        }
075        
076        @Override
077        public A next()
078        {
079            throw new NoSuchElementException();
080        }
081        
082        public void remove()
083        {
084            // Nothing to do.
085        }
086    }
087}