001    /*
002     * JBoss DNA (http://www.jboss.org/dna)
003     * See the COPYRIGHT.txt file distributed with this work for information
004     * regarding copyright ownership.  Some portions may be licensed
005     * to Red Hat, Inc. under one or more contributor license agreements.
006     * See the AUTHORS.txt file in the distribution for a full listing of 
007     * individual contributors. 
008     *
009     * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
010     * is licensed to you under the terms of the GNU Lesser General Public License as
011     * published by the Free Software Foundation; either version 2.1 of
012     * the License, or (at your option) any later version.
013     *
014     * JBoss DNA is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017     * Lesser General Public License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this software; if not, write to the Free
021     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023     */
024    package org.jboss.dna.graph.property.basic;
025    
026    import java.util.Iterator;
027    import java.util.NoSuchElementException;
028    import net.jcip.annotations.Immutable;
029    import org.jboss.dna.graph.property.Name;
030    
031    /**
032     * An immutable version of a property that has no values. This is done for efficiency of the in-memory representation, since many
033     * properties will have just a single value, while others will have multiple values.
034     * 
035     * @author Randall Hauch
036     */
037    @Immutable
038    public class BasicEmptyProperty extends BasicProperty {
039    
040        private static final Iterator<Object> SHARED_ITERATOR = new EmptyIterator<Object>();
041    
042        /**
043         * Create a property with no values.
044         * 
045         * @param name the property name
046         */
047        public BasicEmptyProperty( Name name ) {
048            super(name);
049        }
050    
051        /**
052         * {@inheritDoc}
053         */
054        public boolean isEmpty() {
055            return true;
056        }
057    
058        /**
059         * {@inheritDoc}
060         */
061        public boolean isMultiple() {
062            return false;
063        }
064    
065        /**
066         * {@inheritDoc}
067         */
068        public boolean isSingle() {
069            return false;
070        }
071    
072        /**
073         * {@inheritDoc}
074         */
075        public int size() {
076            return 0;
077        }
078    
079        /**
080         * {@inheritDoc}
081         * 
082         * @see org.jboss.dna.graph.property.Property#getFirstValue()
083         */
084        public Object getFirstValue() {
085            return null;
086        }
087    
088        /**
089         * {@inheritDoc}
090         */
091        public Iterator<Object> iterator() {
092            return SHARED_ITERATOR;
093        }
094    
095        protected static class EmptyIterator<T> implements Iterator<T> {
096    
097            protected EmptyIterator() {
098            }
099    
100            /**
101             * {@inheritDoc}
102             */
103            public boolean hasNext() {
104                return false;
105            }
106    
107            /**
108             * {@inheritDoc}
109             */
110            public T next() {
111                throw new NoSuchElementException();
112            }
113    
114            /**
115             * {@inheritDoc}
116             */
117            public void remove() {
118                throw new UnsupportedOperationException();
119            }
120    
121        }
122    
123    }