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